@lobehub/ui
Version:
Lobe UI is an open-source UI component library for building AIGC web apps
1 lines • 5.18 kB
Source Map (JSON)
{"version":3,"file":"FormGroup.mjs","names":[],"sources":["../../../../src/base-ui/Form/components/FormGroup.tsx"],"sourcesContent":["'use client';\n\nimport { Collapsible } from '@base-ui/react/collapsible';\nimport { cx, useResponsive } from 'antd-style';\nimport { ChevronDown } from 'lucide-react';\nimport { memo, type ReactNode } from 'react';\n\nimport Icon from '@/Icon';\n\nimport { groupStyles, groupVariants } from '../style';\nimport type { FormGroupProps } from '../type';\n\nconst GroupTitle = memo<{\n desc?: ReactNode;\n icon?: FormGroupProps['icon'];\n mobile?: boolean;\n title?: ReactNode;\n variant?: FormGroupProps['variant'];\n}>(({ icon, title, desc, variant, mobile }) => (\n <div\n className={cx(\n groupStyles.title,\n variant === 'borderless' && !mobile && groupStyles.titleBorderless,\n mobile && groupStyles.mobileTitle,\n )}\n >\n {icon && <Icon icon={icon} />}\n <div>\n {title}\n {desc && <div className={groupStyles.desc}>{desc}</div>}\n </div>\n </div>\n));\n\nGroupTitle.displayName = 'GroupTitle';\n\nconst FormGroup = memo<FormGroupProps>(\n ({\n className,\n icon,\n title,\n children,\n extra,\n variant = 'borderless',\n defaultActive = true,\n collapsible,\n active,\n onCollapse,\n desc,\n keyValue: _keyValue,\n ...rest\n }) => {\n const { mobile } = useResponsive();\n const isBorderless = variant === 'borderless';\n const isCollapsible = collapsible === undefined ? !isBorderless : collapsible;\n\n if (mobile)\n return (\n <div className={className} {...rest}>\n <div className={cx(groupStyles.header, groupStyles.mobileHeader)}>\n <GroupTitle mobile desc={desc} icon={icon} title={title} />\n {extra}\n </div>\n <div className={groupStyles.mobileBody}>{children}</div>\n </div>\n );\n\n if (!isCollapsible)\n return (\n <div className={cx(groupVariants({ variant }), className)} {...rest}>\n {title && (\n <div\n className={cx(\n groupStyles.header,\n isBorderless ? groupStyles.headerBorderless : groupStyles.headerBoxed,\n )}\n >\n <GroupTitle desc={desc} icon={icon} title={title} variant={variant} />\n {extra}\n </div>\n )}\n <div className={cx(groupStyles.body, !isBorderless && groupStyles.bodyBoxed)}>\n {children}\n </div>\n </div>\n );\n\n return (\n <Collapsible.Root\n className={cx(groupVariants({ variant }), className)}\n defaultOpen={defaultActive}\n open={active}\n onOpenChange={onCollapse}\n {...rest}\n >\n <div\n className={cx(\n groupStyles.header,\n isBorderless ? groupStyles.headerBorderless : groupStyles.headerBoxed,\n )}\n >\n <Collapsible.Trigger className={groupStyles.trigger}>\n <GroupTitle desc={desc} icon={icon} title={title} variant={variant} />\n <Icon className={groupStyles.chevron} icon={ChevronDown} />\n </Collapsible.Trigger>\n {extra}\n </div>\n <Collapsible.Panel className={groupStyles.panel}>\n <div className={cx(groupStyles.body, !isBorderless && groupStyles.bodyBoxed)}>\n {children}\n </div>\n </Collapsible.Panel>\n </Collapsible.Root>\n );\n },\n);\n\nFormGroup.displayName = 'FormGroup';\n\nexport default FormGroup;\n"],"mappings":";;;;;;;;;AAYA,MAAM,aAAa,MAMf,EAAE,MAAM,OAAO,MAAM,SAAS,aAChC,qBAAC,OAAD;CACE,WAAW,GACT,YAAY,OACZ,YAAY,gBAAgB,CAAC,UAAU,YAAY,iBACnD,UAAU,YAAY,YACvB;WALH,CAOG,QAAQ,oBAAC,MAAD,EAAY,MAAQ,CAAA,EAC7B,qBAAC,OAAD,EAAA,UAAA,CACG,OACA,QAAQ,oBAAC,OAAD;EAAK,WAAW,YAAY;YAAO;EAAW,CAAA,CACnD,EAAA,CAAA,CACF;GACN;AAEF,WAAW,cAAc;AAEzB,MAAM,YAAY,MACf,EACC,WACA,MACA,OACA,UACA,OACA,UAAU,cACV,gBAAgB,MAChB,aACA,QACA,YACA,MACA,UAAU,WACV,GAAG,WACC;CACJ,MAAM,EAAE,WAAW,eAAe;CAClC,MAAM,eAAe,YAAY;CACjC,MAAM,gBAAgB,gBAAgB,KAAA,IAAY,CAAC,eAAe;AAElE,KAAI,OACF,QACE,qBAAC,OAAD;EAAgB;EAAW,GAAI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