@lobehub/ui
Version:
Lobe UI is an open-source UI component library for building AIGC web apps
1 lines • 6.89 kB
Source Map (JSON)
{"version":3,"file":"Toast.mjs","names":["typeIcons: Record<ToastType, typeof Info>","typeColors: Record<ToastType, string>","Icon","BaseToast"],"sources":["../../src/Toast/Toast.tsx"],"sourcesContent":["'use client';\n\nimport { Toast as BaseToast } from '@base-ui/react/toast';\nimport { cssVar, cx } from 'antd-style';\nimport { AlertTriangle, CheckCircle, Info, Loader2, X, XCircle } from 'lucide-react';\nimport { type ReactNode, memo } from 'react';\n\nimport Icon from '@/Icon';\n\nimport { useToastContext } from './context';\nimport { actionVariants, rootVariants, styles } from './style';\nimport type { ToastOptions, ToastProps, ToastType } from './type';\n\nconst typeIcons: Record<ToastType, typeof Info> = {\n default: Info,\n error: XCircle,\n info: Info,\n loading: Loader2,\n success: CheckCircle,\n warning: AlertTriangle,\n};\n\nconst typeColors: Record<ToastType, string> = {\n default: cssVar.colorText,\n error: cssVar.colorError,\n info: cssVar.colorInfo,\n loading: cssVar.colorPrimary,\n success: cssVar.colorSuccess,\n warning: cssVar.colorWarning,\n};\n\nconst ToastItem = memo<ToastProps>(({ toast, classNames, styles: customStyles }) => {\n const { position, swipeDirection } = useToastContext();\n const toastData = toast.data as ToastOptions | undefined;\n const type = toastData?.type ?? 'default';\n const closable = toastData?.closable ?? true;\n const hideCloseButton = toastData?.hideCloseButton ?? false;\n const showCloseButton = closable && !hideCloseButton;\n const icon = toastData?.icon;\n const title = toast.title ?? toastData?.title;\n const description = toast.description ?? toastData?.description;\n const actionProps = toast.actionProps ?? toastData?.actionProps;\n const actions = toastData?.actions;\n\n const iconColor = typeColors[type];\n const IconComponent = icon ?? typeIcons[type];\n const isLoading = type === 'loading';\n\n const renderIcon = (): ReactNode => {\n if (!IconComponent) return null;\n return (\n <div className={cx(styles.icon, classNames?.icon)} style={customStyles?.icon}>\n <Icon color={iconColor} icon={IconComponent} size={18} spin={isLoading} />\n </div>\n );\n };\n\n const renderActions = (): ReactNode => {\n if (actions && actions.length > 0) {\n return (\n <div className={cx(styles.actions, classNames?.actions)} style={customStyles?.actions}>\n {actions.map((action, index) => (\n <BaseToast.Action\n className={cx(\n actionVariants({ variant: action.variant ?? 'primary' }),\n classNames?.action,\n )}\n key={index}\n onClick={action.onClick}\n style={customStyles?.action}\n {...action.props}\n >\n {action.label}\n </BaseToast.Action>\n ))}\n </div>\n );\n }\n if (actionProps) {\n return (\n <BaseToast.Action\n className={cx(actionVariants({ variant: 'primary' }), classNames?.action)}\n style={customStyles?.action}\n {...actionProps}\n />\n );\n }\n return null;\n };\n\n return (\n <BaseToast.Root\n className={cx(rootVariants({ position }), classNames?.root)}\n style={{\n ...customStyles?.root,\n ...toastData?.style,\n }}\n swipeDirection={swipeDirection}\n toast={toast}\n >\n <BaseToast.Content\n className={cx(styles.content, classNames?.content)}\n style={customStyles?.content}\n >\n <div className={styles.toastBody}>\n {renderIcon()}\n <div className={styles.contentArea}>\n <div className={styles.titleRow}>\n {title && (\n <BaseToast.Title\n className={cx(styles.title, classNames?.title)}\n style={customStyles?.title}\n >\n {title}\n </BaseToast.Title>\n )}\n {showCloseButton && (\n <BaseToast.Close\n aria-label=\"Close\"\n className={cx(styles.close, classNames?.close)}\n style={customStyles?.close}\n >\n <X size={14} />\n </BaseToast.Close>\n )}\n </div>\n {description && (\n <BaseToast.Description\n className={cx(styles.description, classNames?.description)}\n style={{\n marginBlockStart: title ? 4 : 0,\n ...customStyles?.description,\n }}\n >\n {description}\n </BaseToast.Description>\n )}\n {renderActions()}\n </div>\n </div>\n </BaseToast.Content>\n </BaseToast.Root>\n );\n});\n\nToastItem.displayName = 'ToastItem';\n\nexport default ToastItem;\n"],"mappings":";;;;;;;;;;;;AAaA,MAAMA,YAA4C;CAChD,SAAS;CACT,OAAO;CACP,MAAM;CACN,SAAS;CACT,SAAS;CACT,SAAS;CACV;AAED,MAAMC,aAAwC;CAC5C,SAAS,OAAO;CAChB,OAAO,OAAO;CACd,MAAM,OAAO;CACb,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