Skip to content

Commit

Permalink
Update toast styles (#2020)
Browse files Browse the repository at this point in the history
  • Loading branch information
OKendigelyan authored Oct 10, 2024
1 parent 7b3f52c commit 3fed35a
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 1 deletion.
11 changes: 11 additions & 0 deletions apps/web/src/assets/icons/alert-octagon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions apps/web/src/assets/icons/alert-triangle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions apps/web/src/assets/icons/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export { default as AddContactIcon } from "./add-contact-s.svg";
export { default as AlertCircleIcon } from "./alert-circle.svg";
export { default as AlertTriangleIcon } from "./alert-triangle.svg";
export { default as AlertOctagonIcon } from "./alert-octagon.svg";
export { default as AlertIcon } from "./alert.svg";
export { default as ArrowDownLeftIcon } from "./arrow-down-left.svg";
export { default as ArrowLeftCircleIcon } from "./arrow-left-circle.svg";
Expand Down
77 changes: 77 additions & 0 deletions apps/web/src/components/CustomToast/CustomToast.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import {
Alert,
AlertDescription,
AlertTitle,
Flex,
Icon,
IconButton,
type UseToastOptions,
} from "@chakra-ui/react";
import { type ReactNode } from "react";

import {
AlertCircleIcon,
AlertOctagonIcon,
AlertTriangleIcon,
CheckCircleIcon,
CloseIcon,
} from "../../assets/icons";
import { useColor } from "../../styles/useColor";

type CustomToastProps = {
onClose: () => void;
} & UseToastOptions;

export const CustomToast = (props: CustomToastProps): ReactNode => {
const color = useColor();

const { status, id, title, isClosable, onClose, description } = props;

const ids = id
? {
root: `toast-${id}`,
title: `toast-${id}-title`,
description: `toast-${id}-description`,
}
: undefined;

const AlertIcon = () => {
switch (props.status) {
case "info":
return <AlertCircleIcon />;
case "success":
return <CheckCircleIcon />;
case "error":
return <AlertTriangleIcon />;
case "warning":
return <AlertOctagonIcon />;
default:
return null;
}
};

return (
<Alert addRole={false} id={ids?.root} status={status}>
<Icon as={AlertIcon} />
<Flex width="full" marginLeft="6px">
{title && <AlertTitle id={ids?.title}>{title}</AlertTitle>}
{description && (
<AlertDescription marginRight="12px" id={ids?.description}>
{description}
</AlertDescription>
)}
</Flex>
{isClosable && (
<IconButton
boxSize="24px"
marginLeft="auto"
color={color("400")}
aria-label="Close toast"
icon={<CloseIcon />}
onClick={onClose}
variant="empty"
/>
)}
</Alert>
);
};
1 change: 1 addition & 0 deletions apps/web/src/components/CustomToast/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./CustomToast";
10 changes: 9 additions & 1 deletion apps/web/src/providers/UmamiTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Global, css } from "@emotion/react";
import { type PropsWithChildren } from "react";
import "focus-visible/dist/focus-visible";

import { CustomToast } from "../components/CustomToast/CustomToast";
import theme from "../styles/theme";

const GlobalStyles = css`
Expand All @@ -17,7 +18,14 @@ const GlobalStyles = css`
`;

export const UmamiTheme = ({ children }: PropsWithChildren) => (
<ChakraProvider theme={theme}>
<ChakraProvider
theme={theme}
toastOptions={{
defaultOptions: {
render: CustomToast,
},
}}
>
<Global styles={GlobalStyles} />
<ColorModeScript initialColorMode={theme.config.initialColorMode} />
{children}
Expand Down
30 changes: 30 additions & 0 deletions apps/web/src/styles/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,36 @@ const theme = extendTheme({
},
}),
},
Alert: {
baseStyle: (props: StyleFunctionProps) => {
let accentColor;

switch (props.status) {
case "success":
accentColor = light.green;
break;
case "warning":
case "error":
accentColor = light.redDark;
break;
default:
accentColor = light.grey[400];
}

return {
container: {
borderRadius: "6px",
boxShadow: "0px 0px 8px 0px rgba(45, 55, 72, 0.25)",
borderLeft: `4px solid ${accentColor}`,
color: accentColor,
background: light.grey["white"],
},
description: {
color: light.grey[900],
},
};
},
},
Link: {
baseStyle: {
color: "gray.600",
Expand Down

1 comment on commit 3fed35a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title Lines Statements Branches Functions
apps/desktop Coverage: 83%
83.6% (1765/2111) 78.81% (837/1062) 78.14% (447/572)
apps/web Coverage: 83%
83.6% (1765/2111) 78.81% (837/1062) 78.14% (447/572)
packages/components Coverage: 97%
97.28% (179/184) 95.23% (80/84) 86.53% (45/52)
packages/core Coverage: 81%
82.22% (222/270) 71.73% (99/138) 81.96% (50/61)
packages/crypto Coverage: 100%
100% (28/28) 100% (3/3) 100% (5/5)
packages/data-polling Coverage: 97%
95.27% (141/148) 87.5% (21/24) 92.85% (39/42)
packages/multisig Coverage: 98%
98.47% (129/131) 85.71% (18/21) 100% (35/35)
packages/social-auth Coverage: 100%
100% (21/21) 100% (11/11) 100% (3/3)
packages/state Coverage: 85%
84.61% (792/936) 80.97% (166/205) 78.72% (296/376)
packages/tezos Coverage: 86%
85.57% (89/104) 89.47% (17/19) 82.75% (24/29)
packages/tzkt Coverage: 86%
84.05% (58/69) 81.25% (13/16) 76.92% (30/39)

Please sign in to comment.