@lobehub/ui
Version:
Lobe UI is an open-source UI component library for building AIGC web apps
1 lines • 7.37 kB
Source Map (JSON)
{"version":3,"file":"Drawer.mjs","names":["Drawer","headerBorder: CSSProperties","Flexbox","ActionIcon","AntdDrawer"],"sources":["../../src/Drawer/Drawer.tsx"],"sourcesContent":["'use client';\n\nimport { Drawer as AntdDrawer } from 'antd';\nimport { cssVar } from 'antd-style';\nimport { XIcon } from 'lucide-react';\nimport { CSSProperties, memo, useMemo } from 'react';\n\nimport ActionIcon from '@/ActionIcon';\nimport { Flexbox } from '@/Flex';\n\nimport type { DrawerProps } from './type';\n\nconst Drawer = memo<DrawerProps>(\n ({\n onClose,\n containerMaxWidth = 1024,\n classNames,\n title,\n placement,\n styles,\n children,\n height,\n width,\n extra,\n closeIconProps,\n noHeader,\n sidebarWidth = 280,\n sidebar,\n closeIcon,\n ref,\n ...rest\n }) => {\n const headerBorder: CSSProperties = useMemo(() => {\n if (height === '100%' || width === '100%' || height === '100vh' || width === '100vw')\n return {};\n\n switch (placement) {\n case 'top': {\n return {\n borderBottom: `1px solid ${cssVar.colorBorder}`,\n };\n }\n case 'bottom': {\n return {\n borderTop: `1px solid ${cssVar.colorBorder}`,\n };\n }\n case 'left': {\n return {\n borderRight: `1px solid ${cssVar.colorBorder}`,\n };\n }\n case 'right': {\n return {\n borderLeft: `1px solid ${cssVar.colorBorder}`,\n };\n }\n default: {\n return {};\n }\n }\n }, [placement, height, width]);\n\n const extraNode = (\n <Flexbox\n align={'center'}\n className={classNames?.extra}\n gap={4}\n horizontal\n justify={'flex-end'}\n style={{\n position: 'absolute',\n right: 4,\n top: 4,\n ...styles?.extra,\n }}\n >\n {extra}\n {closeIcon || <ActionIcon icon={XIcon} onClick={onClose} {...closeIconProps} />}\n </Flexbox>\n );\n\n const sidebarContent = (\n <>\n <Flexbox\n className={classNames?.sidebar}\n paddingBlock={12}\n paddingInline={16}\n style={{\n background: cssVar.colorBgLayout,\n borderRight: `1px solid ${cssVar.colorBorderSecondary}`,\n height: '100vh',\n overflowX: 'hidden',\n overflowY: 'auto',\n position: 'sticky',\n top: 0,\n ...styles?.sidebar,\n }}\n width={sidebarWidth}\n >\n {sidebar}\n </Flexbox>\n <Flexbox\n className={classNames?.sidebarContent}\n flex={1}\n paddingBlock={12}\n paddingInline={16}\n style={{\n background: cssVar.colorBgContainer,\n overflowX: 'hidden',\n overflowY: 'auto',\n ...styles?.sidebarContent,\n }}\n >\n {children}\n </Flexbox>\n </>\n );\n\n return (\n <AntdDrawer\n classNames={classNames}\n closable={false}\n extra={noHeader ? undefined : extraNode}\n height={height}\n keyboard={true}\n onClose={onClose}\n panelRef={ref}\n placement={placement}\n styles={\n typeof styles === 'function'\n ? styles\n : {\n ...styles,\n body: {\n background: 'transparent',\n paddingBlock: sidebar ? 0 : 12,\n paddingInline: sidebar ? 0 : 16,\n ...styles?.body,\n },\n header: {\n background: 'transparent',\n display: noHeader ? 'none' : undefined,\n padding: 4,\n ...styles?.header,\n },\n section: {\n background: sidebar\n ? `linear-gradient(to right, ${cssVar.colorBgLayout} 49.9%, ${cssVar.colorBgContainer} 50%)`\n : cssVar.colorBgContainer,\n ...styles?.section,\n },\n wrapper: {\n background: cssVar.colorBgContainer,\n ...headerBorder,\n ...styles?.wrapper,\n },\n }\n }\n title={\n <Flexbox\n align={'center'}\n className={classNames?.title}\n horizontal\n justify={'flex-start'}\n paddingBlock={8}\n paddingInline={16}\n style={{\n justifySelf: 'center',\n maxWidth: containerMaxWidth,\n width: '100%',\n ...styles?.title,\n }}\n >\n {title}\n </Flexbox>\n }\n width={width}\n {...rest}\n >\n <Flexbox\n className={classNames?.bodyContent}\n horizontal={!!sidebar}\n style={{\n justifySelf: 'center',\n maxWidth: containerMaxWidth,\n minHeight: '100%',\n overflow: sidebar ? 'visible' : undefined,\n width: '100%',\n ...styles?.bodyContent,\n }}\n >\n {noHeader && extraNode}\n {sidebar ? sidebarContent : children}\n </Flexbox>\n </AntdDrawer>\n );\n },\n);\n\nDrawer.displayName = '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