@lobehub/ui
Version:
Lobe UI is an open-source UI component library for building AIGC web apps
1 lines • 6.65 kB
Source Map (JSON)
{"version":3,"file":"Alert.mjs","names":["Alert","AntdAlert","ActionIcon","Icon","Flexbox","Accordion","AccordionItem"],"sources":["../../src/Alert/Alert.tsx"],"sourcesContent":["'use client';\n\nimport { Alert as AntdAlert } from 'antd';\nimport { cssVar, cx, useTheme } from 'antd-style';\nimport { camelCase } from 'es-toolkit/compat';\nimport { AlertTriangle, CheckCircle, Info, X, XCircle } from 'lucide-react';\nimport { memo } from 'react';\n\nimport { Accordion, AccordionItem } from '@/Accordion';\nimport ActionIcon from '@/ActionIcon';\nimport { Flexbox } from '@/Flex';\nimport Icon from '@/Icon';\n\nimport { extraHeaderVariants, extraVariants, rootVariants } from './style';\nimport type { AlertProps } from './type';\n\nconst typeIcons = {\n error: XCircle,\n info: Info,\n secondary: AlertTriangle,\n success: CheckCircle,\n warning: AlertTriangle,\n};\n\nconst colors = (theme: any, type: string = 'info', ...keys: string[]) => {\n if (type === 'secondary') return theme[camelCase(['color', ...keys].join('-'))] as string;\n return theme[camelCase(['color', type, ...keys].join('-'))] as string;\n};\n\nconst Alert = memo<AlertProps>(\n ({\n closable = false,\n description,\n showIcon = true,\n type = 'info',\n glass,\n icon,\n colorfulText = true,\n iconProps,\n style,\n extra,\n classNames,\n styles: customStyles,\n text,\n extraDefaultExpand = false,\n extraIsolate,\n banner,\n variant = 'filled',\n ref,\n ...rest\n }) => {\n const theme = useTheme();\n const hasTitle = !!description;\n const isClosable = !!closable;\n const isShowIcon = !!showIcon;\n\n const isInsideExtra = Boolean(!extraIsolate && !!extra);\n\n const alert = (\n <AntdAlert\n banner={banner}\n className={cx(\n rootVariants({\n closable: isClosable,\n colorfulText,\n glass,\n hasExtra: isInsideExtra,\n hasTitle,\n showIcon: isShowIcon,\n variant,\n }),\n classNames?.alert,\n )}\n closable={\n typeof closable === 'boolean'\n ? closable\n : {\n closeIcon: <ActionIcon color={colors(theme, type)} icon={X} size={'small'} />,\n ...closable,\n }\n }\n description={description}\n icon={\n <Icon\n color={type === 'secondary' ? cssVar.colorTextSecondary : undefined}\n icon={typeIcons[type] || icon}\n size={description ? 24 : 18}\n {...iconProps}\n />\n }\n ref={ref}\n showIcon={showIcon}\n style={{\n background: colors(theme, type, 'fillTertiary'),\n borderColor: colors(theme, type, 'fillSecondary'),\n color: colorfulText ? colors(theme, type) : undefined,\n ...style,\n ...customStyles?.alert,\n }}\n type={type === 'secondary' ? 'info' : type}\n {...rest}\n />\n );\n\n if (!extra) return alert;\n\n if (extraIsolate)\n return (\n <Flexbox className={classNames?.container} gap={8}>\n {alert}\n {extra}\n </Flexbox>\n );\n\n return (\n <Flexbox className={classNames?.container} style={customStyles?.container}>\n {alert}\n <Flexbox\n className={extraVariants({ banner, variant })}\n style={{\n background: colors(theme, type, 'fillTertiary'),\n borderColor: colors(theme, type, 'fillSecondary'),\n color: colors(theme, type),\n fontSize: description ? 14 : 12,\n }}\n >\n <Accordion defaultExpandedKeys={extraDefaultExpand ? ['extra'] : []}>\n <AccordionItem\n classNames={{\n content: classNames?.extraContent,\n header: extraHeaderVariants({ hasTitle, variant }),\n }}\n itemKey={'extra'}\n styles={{\n content: {\n fontSize: 12,\n ...customStyles?.extraContent,\n },\n header: {\n borderColor: colors(theme, type, 'fillSecondary'),\n },\n indicator: {\n color: colors(theme, type),\n },\n title: {\n color: colors(theme, type),\n fontSize: 12,\n },\n }}\n title={text?.detail || 'Show Details'}\n >\n {extra}\n </AccordionItem>\n </Accordion>\n </Flexbox>\n </Flexbox>\n );\n },\n);\n\nAlert.displayName = 'Alert';\n\nexport default Alert;\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,MAAM,YAAY;CAChB,OAAO;CACP,MAAM;CACN,WAAW;CACX,SAAS;CACT,SAAS;CACV;AAED,MAAM,UAAU,OAAY,OAAe,QAAQ,GAAG,SAAmB;AACvE,KAAI,SAAS,YAAa,QAAO,MAAM,UAAU,CAAC,SAAS,GAAG,KAA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