UNPKG

flowbite-react

Version:

Official React components built for Flowbite and Tailwind CSS

1 lines 3.87 kB
{"version":3,"file":"Alert.mjs","sources":["../../../../src/components/Alert/Alert.tsx"],"sourcesContent":["import type { ComponentProps, FC, ReactNode } from \"react\";\nimport { HiX } from \"react-icons/hi\";\nimport { twMerge } from \"tailwind-merge\";\nimport { mergeDeep } from \"../../helpers/merge-deep\";\nimport { getTheme } from \"../../theme-store\";\nimport type { DeepPartial } from \"../../types\";\nimport type { FlowbiteColors } from \"../Flowbite\";\n\nexport interface FlowbiteAlertTheme {\n base: string;\n borderAccent: string;\n closeButton: FlowbiteAlertCloseButtonTheme;\n color: FlowbiteColors;\n icon: string;\n rounded: string;\n wrapper: string;\n}\n\nexport interface FlowbiteAlertCloseButtonTheme {\n base: string;\n color: FlowbiteColors;\n icon: string;\n}\n\nexport interface AlertProps extends Omit<ComponentProps<\"div\">, \"color\"> {\n additionalContent?: ReactNode;\n color?: keyof FlowbiteColors;\n icon?: FC<ComponentProps<\"svg\">>;\n onDismiss?: boolean | (() => void);\n rounded?: boolean;\n theme?: DeepPartial<FlowbiteAlertTheme>;\n withBorderAccent?: boolean;\n}\n\nexport const Alert: FC<AlertProps> = ({\n additionalContent,\n children,\n className,\n color = \"info\",\n icon: Icon,\n onDismiss,\n rounded = true,\n theme: customTheme = {},\n withBorderAccent,\n ...props\n}) => {\n const theme = mergeDeep(getTheme().alert, customTheme);\n\n return (\n <div\n className={twMerge(\n theme.base,\n theme.color[color],\n rounded && theme.rounded,\n withBorderAccent && theme.borderAccent,\n className,\n )}\n role=\"alert\"\n {...props}\n >\n <div className={theme.wrapper} data-testid=\"flowbite-alert-wrapper\">\n {Icon && <Icon className={theme.icon} data-testid=\"flowbite-alert-icon\" />}\n <div>{children}</div>\n {typeof onDismiss === \"function\" && (\n <button\n aria-label=\"Dismiss\"\n className={twMerge(theme.closeButton.base, theme.closeButton.color[color])}\n onClick={onDismiss}\n type=\"button\"\n >\n <HiX aria-hidden className={theme.closeButton.ic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