Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update toast styles #2020

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading