Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[web] Share notification icon size and color options

AswinAsoke7381158fda5
diff --git a/web/apps/photos/src/components/QuickLinkCreatedNotification.tsx b/web/apps/photos/src/components/QuickLinkCreatedNotification.tsx
index eb28118726..270934478d 100644
--- a/web/apps/photos/src/components/QuickLinkCreatedNotification.tsx
+++ b/web/apps/photos/src/components/QuickLinkCreatedNotification.tsx
@@ -1,6 +1,4 @@
import { Copy01Icon, Tick02Icon } from "@hugeicons/core-free-icons";
-import { HugeiconsIcon } from "@hugeicons/react";
-import { Box } from "@mui/material";
import { Notification } from "ente-base/components/Notification";
import { t } from "i18next";
import React, { useEffect, useRef, useState } from "react";
@@ -59,21 +57,9 @@ export const QuickLinkCreatedNotification: React.FC<
color: "inherit",
startIcon: null,
title: t("link_created"),
- endIcon: copied ? (
- <Box sx={{ color: "success.main", display: "flex" }}>
- <HugeiconsIcon
- icon={Tick02Icon}
- size={22}
- strokeWidth={1.8}
- />
- </Box>
- ) : (
- <HugeiconsIcon
- icon={Copy01Icon}
- size={18}
- strokeWidth={1.8}
- />
- ),
+ endIcon: copied ? Tick02Icon : Copy01Icon,
+ endIconSize: copied ? 22 : 18,
+ endIconColor: copied ? "success.main" : undefined,
endIconLabel: t("copy_link"),
onEndIconClick: handleCopy,
showCloseButtonWithEndIcon: true,
diff --git a/web/apps/photos/tests/notification-icons.test.tsx b/web/apps/photos/tests/notification-icons.test.tsx
index 3ac3265e3b..146c694336 100644
--- a/web/apps/photos/tests/notification-icons.test.tsx
+++ b/web/apps/photos/tests/notification-icons.test.tsx
@@ -41,6 +41,29 @@ describe("notification icons", () => {
expect(markup).toContain('aria-label="Retry"');
});
+ test("supports a smaller copy icon without changing the close icon", () => {
+ const markup = renderNotification({
+ startIcon: null,
+ endIcon: Copy01Icon,
+ endIconSize: 18,
+ showCloseButtonWithEndIcon: true,
+ });
+ const icons = markup.match(/<svg\b[^>]*>/g) ?? [];
+ expect(icons).toHaveLength(2);
+ expect(icons[0]).toContain('width="18"');
+ expect(icons[1]).toContain('width="22"');
+ });
+
+ test("resolves the copied icon color through the theme", () => {
+ const markup = renderNotification({
+ startIcon: null,
+ endIcon: Tick02Icon,
+ endIconColor: "success.main",
+ });
+ expect(markup).toContain("color:var(--mui-palette-success-main)");
+ expect(markup.match(/<svg\b[^>]*>/g)?.[0]).toContain('width="22"');
+ });
+
test("preserves custom icon elements and their sizing", () => {
const markup = renderNotification({
startIcon: null,
diff --git a/web/packages/base/components/Notification.tsx b/web/packages/base/components/Notification.tsx
index 1bf3e2f3c0..8877bca9ff 100644
--- a/web/packages/base/components/Notification.tsx
+++ b/web/packages/base/components/Notification.tsx
@@ -34,6 +34,8 @@ export interface NotificationAttributes {
caption?: React.ReactNode;
onClick?: () => void;
endIcon?: NotificationIcon;
+ endIconSize?: number;
+ endIconColor?: string;
endIconLabel?: string;
showCloseButtonWithEndIcon?: boolean;
onEndIconClick?: () => void;
@@ -48,11 +50,21 @@ type NotificationProps = ModalVisibilityProps & {
sx?: SxProps<Theme>;
};
-const renderIcon = (icon: NotificationIcon | undefined, size: number) =>
+const renderIcon = (
+ icon: NotificationIcon | undefined,
+ size: number,
+ color?: string,
+) =>
React.isValidElement(icon) || icon == null ? (
icon
) : (
- <HugeiconsIcon icon={icon} size={size} strokeWidth={1.8} />
+ <Box
+ component={HugeiconsIcon}
+ icon={icon}
+ size={size}
+ strokeWidth={1.8}
+ sx={{ color }}
+ />
);
const actionButtonSx = {
@@ -89,6 +101,8 @@ export const Notification: React.FC<NotificationProps> = ({
title,
caption,
endIcon,
+ endIconSize = 22,
+ endIconColor,
endIconLabel,
showCloseButtonWithEndIcon,
onClick,
@@ -253,7 +267,7 @@ export const Notification: React.FC<NotificationProps> = ({
}}
sx={buttonSx}
>
- {renderIcon(endIcon, 22)}
+ {renderIcon(endIcon, endIconSize, endIconColor)}
</IconButton>
)}
{(!endIcon || showCloseButtonWithEndIcon) && (