@mantine/core
Version:
React components library focused on usability, accessibility and developer experience
1 lines • 6.16 kB
Source Map (JSON)
{"version":3,"file":"Notification.cjs","names":["createVarsResolver","getRadius","getThemeColor","factory","useProps","useStyles","Box","Loader","CloseButton","classes"],"sources":["../../../src/components/Notification/Notification.tsx"],"sourcesContent":["import {\n Box,\n BoxProps,\n createVarsResolver,\n DataAttributes,\n ElementProps,\n factory,\n Factory,\n getRadius,\n getThemeColor,\n MantineColor,\n MantineRadius,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../core';\nimport { CloseButton } from '../CloseButton';\nimport { Loader, LoaderProps } from '../Loader';\nimport classes from './Notification.module.css';\n\nexport type NotificationStylesNames =\n | 'root'\n | 'icon'\n | 'loader'\n | 'body'\n | 'title'\n | 'description'\n | 'closeButton';\nexport type NotificationCssVariables = {\n root: '--notification-radius' | '--notification-color';\n};\n\nexport interface NotificationProps\n extends BoxProps, StylesApiProps<NotificationFactory>, ElementProps<'div', 'title'> {\n /** Called when the close button is clicked */\n onClose?: () => void;\n\n /** Controls icon background color or notification accent line color, key of `theme.colors` or any valid CSS color. When `icon` is provided, sets the icon background color. When no icon is provided, sets the colored accent line on the left. @default theme.primaryColor */\n color?: MantineColor;\n\n /** Key of `theme.radius` or any valid CSS value to set `border-radius` @default theme.defaultRadius */\n radius?: MantineRadius;\n\n /** Notification icon, replaces color line */\n icon?: React.ReactNode;\n\n /** Notification title, displayed above the message body */\n title?: React.ReactNode;\n\n /** Notification description, displayed below the title. When no title is provided, this serves as the main message. */\n children?: React.ReactNode;\n\n /** If set, displays a `Loader` component instead of the icon. Takes precedence over the `icon` prop if both are provided. */\n loading?: boolean;\n\n /** Adds border to the root element */\n withBorder?: boolean;\n\n /** If set, the close button is visible @default true */\n withCloseButton?: boolean;\n\n /** Props passed down to the close button */\n closeButtonProps?: ElementProps<'button'> & DataAttributes;\n\n /** Props passed down to the `Loader` component */\n loaderProps?: LoaderProps;\n}\n\nexport type NotificationFactory = Factory<{\n props: NotificationProps;\n ref: HTMLDivElement;\n stylesNames: NotificationStylesNames;\n vars: NotificationCssVariables;\n}>;\n\nconst defaultProps = {\n withCloseButton: true,\n} satisfies Partial<NotificationProps>;\n\nconst varsResolver = createVarsResolver<NotificationFactory>((theme, { radius, color }) => ({\n root: {\n '--notification-radius': radius === undefined ? undefined : getRadius(radius),\n '--notification-color': color ? getThemeColor(color, theme) : undefined,\n },\n}));\n\nexport const Notification = factory<NotificationFactory>((_props) => {\n const props = useProps('Notification', defaultProps, _props);\n const {\n className,\n color,\n radius,\n loading,\n withCloseButton,\n withBorder,\n title,\n icon,\n children,\n onClose,\n closeButtonProps,\n classNames,\n style,\n styles,\n unstyled,\n vars,\n mod,\n loaderProps,\n role,\n attributes,\n ...others\n } = props;\n\n const getStyles = useStyles<NotificationFactory>({\n name: 'Notification',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n return (\n <Box\n {...getStyles('root')}\n mod={[{ 'data-with-icon': !!icon || loading, 'data-with-border': withBorder }, mod]}\n role={role || 'alert'}\n {...others}\n >\n {icon && !loading && <div {...getStyles('icon')}>{icon}</div>}\n {loading && <Loader size={28} color={color} {...getStyles('loader')} {...loaderProps} />}\n\n <div {...getStyles('body')}>\n {title && <div {...getStyles('title')}>{title}</div>}\n\n <Box {...getStyles('description')} mod={{ 'data-with-title': !!title }}>\n {children}\n </Box>\n </div>\n\n {withCloseButton && (\n <CloseButton\n iconSize={16}\n color=\"gray\"\n {...closeButtonProps}\n unstyled={unstyled}\n onClick={(event) => {\n closeButtonProps?.onClick?.(event);\n onClose?.();\n }}\n {...getStyles('closeButton')}\n />\n )}\n </Box>\n );\n});\n\nNotification.classes = classes;\nNotification.varsResolver = varsResolver;\nNotification.displayName = '@mantine/core/Notification';\n"],"mappings":";;;;;;;;;;;;;;AA2EA,MAAM,eAAe,EACnB,iBAAiB,MAClB;AAED,MAAM,eAAeA,6BAAAA,oBAAyC,OAAO,EAAE,QAAQ,a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