flowbite-react
Version:
Official React components built for Flowbite and Tailwind CSS
1 lines • 2.62 kB
Source Map (JSON)
{"version":3,"file":"ToastToggle.mjs","sources":["../../../../src/components/Toast/ToastToggle.tsx"],"sourcesContent":["\"use client\";\n\nimport type { ComponentProps, FC, MouseEvent } from \"react\";\nimport { HiX } from \"react-icons/hi\";\nimport { twMerge } from \"tailwind-merge\";\nimport { mergeDeep } from \"../../helpers/merge-deep\";\nimport type { DeepPartial } from \"../../types\";\nimport { useToastContext } from \"./ToastContext\";\n\nexport interface FlowbiteToastToggleTheme {\n base: string;\n icon: string;\n}\n\nexport interface ToastToggleProps extends ComponentProps<\"button\"> {\n theme?: DeepPartial<FlowbiteToastToggleTheme>;\n xIcon?: FC<ComponentProps<\"svg\">>;\n onDismiss?: () => void;\n}\n\nexport const ToastToggle: FC<ToastToggleProps> = ({\n className,\n onClick,\n theme: customTheme = {},\n xIcon: XIcon = HiX,\n onDismiss,\n ...props\n}) => {\n const { theme: rootTheme, duration, isClosed, isRemoved, setIsClosed, setIsRemoved } = useToastContext();\n\n const theme = mergeDeep(rootTheme.toggle, customTheme);\n\n const handleClick = (e: MouseEvent<HTMLButtonElement>) => {\n if (onClick) onClick(e);\n\n if (onDismiss) {\n onDismiss();\n return;\n }\n\n setIsClosed(!isClosed);\n setTimeout(() => setIsRemoved(!isRemoved), duration);\n };\n\n return (\n <button\n aria-label=\"Close\"\n onClick={handleClick}\n type=\"button\"\n className={twMerge(theme.base, className)}\n {...props}\n >\n <XIcon aria-hidden className={theme.icon} />\n </button>\n );\n};\n"],"names":[],"mappings":";;;;;;AAOY,MAAC,WAAW,GAAG,CAAC;AAC5B,EAAE,SAAS;AACX,EAAE,OAAO;AACT,EAAE,KAAK,EAAE,WAAW,GAAG,EAAE;AACzB,EAAE,KAAK,EAAE,KAAK,GAAG,GAAG;AACpB,EAAE,SAAS;AACX,EAAE,GAAG,KAAK;AACV,CAAC,KAAK;AACN,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EA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