@lobehub/ui
Version:
Lobe UI is an open-source UI component library for building AIGC web apps
1 lines • 8.21 kB
Source Map (JSON)
{"version":3,"file":"Toast.mjs","names":["BaseToast"],"sources":["../../../src/base-ui/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 { memo, type ReactNode } from 'react';\n\nimport Icon from '@/Icon';\n\nimport { useToastContext } from './context';\nimport { actionVariants, rootVariants, styles } from './style';\nimport { type ToastOptions, type ToastProps, type 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 key={index}\n style={customStyles?.action}\n className={cx(\n actionVariants({ variant: action.variant ?? 'primary' }),\n classNames?.action,\n )}\n onClick={action.onClick}\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 swipeDirection={swipeDirection}\n toast={toast}\n style={{\n ...customStyles?.root,\n ...toastData?.style,\n }}\n >\n <BaseToast.Content\n className={cx(styles.content, classNames?.content)}\n style={customStyles?.content}\n >\n <div className={title ? styles.toastBody : styles.toastBodyCenter}>\n {renderIcon()}\n <div className={styles.contentArea}>\n {title ? (\n <>\n <div className={styles.titleRow}>\n <BaseToast.Title\n className={cx(styles.title, classNames?.title)}\n style={customStyles?.title}\n >\n {title}\n </BaseToast.Title>\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: 4,\n ...customStyles?.description,\n }}\n >\n {description}\n </BaseToast.Description>\n )}\n </>\n ) : (\n description && (\n <div className={styles.titleRow}>\n <BaseToast.Description\n className={cx(styles.description, classNames?.description)}\n style={customStyles?.description}\n >\n {description}\n </BaseToast.Description>\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 )\n )}\n {renderActions()}\n </div>\n </div>\n </BaseToast.Content>\n </BaseToast.Root>\n );\n});\n\nToastItem.displayName = 'ToastItem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