UNPKG

flowbite-react

Version:

Official React components built for Flowbite and Tailwind CSS

1 lines 6.04 kB
{"version":3,"file":"SidebarCollapse.mjs","sources":["../../../../src/components/Sidebar/SidebarCollapse.tsx"],"sourcesContent":["\"use client\";\n\nimport type { ComponentProps, FC, PropsWithChildren, ReactElement } from \"react\";\nimport { useEffect, useId, useState } from \"react\";\nimport { HiChevronDown } from \"react-icons/hi\";\nimport { twMerge } from \"tailwind-merge\";\nimport { mergeDeep } from \"../../helpers/merge-deep\";\nimport type { DeepPartial } from \"../../types\";\nimport type { FlowbiteBoolean } from \"../Flowbite\";\nimport { Tooltip } from \"../Tooltip\";\nimport { useSidebarContext } from \"./SidebarContext\";\nimport type { SidebarItemProps } from \"./SidebarItem\";\nimport { SidebarItemContext } from \"./SidebarItemContext\";\n\nexport interface FlowbiteSidebarCollapseTheme {\n button: string;\n icon: {\n base: string;\n open: FlowbiteBoolean;\n };\n label: {\n base: string;\n icon: {\n base: string;\n open: FlowbiteBoolean;\n };\n };\n list: string;\n}\n\nexport interface SidebarCollapseProps\n extends Pick<SidebarItemProps, \"active\" | \"as\" | \"href\" | \"icon\" | \"label\" | \"labelColor\">,\n ComponentProps<\"button\"> {\n onClick?: ComponentProps<\"button\">[\"onClick\"];\n open?: boolean;\n chevronIcon?: FC<ComponentProps<\"svg\">>;\n renderChevronIcon?: (theme: FlowbiteSidebarCollapseTheme, open: boolean) => ReactElement;\n theme?: DeepPartial<FlowbiteSidebarCollapseTheme>;\n}\n\nexport const SidebarCollapse: FC<SidebarCollapseProps> = ({\n children,\n className,\n icon: Icon,\n label,\n chevronIcon: ChevronIcon = HiChevronDown,\n renderChevronIcon,\n open = false,\n theme: customTheme = {},\n ...props\n}) => {\n const id = useId();\n const [isOpen, setOpen] = useState(open);\n const { theme: rootTheme, isCollapsed } = useSidebarContext();\n\n const theme = mergeDeep(rootTheme.collapse, customTheme);\n\n useEffect(() => setOpen(open), [open]);\n\n const Wrapper: FC<PropsWithChildren> = ({ children }) => (\n <li>\n {isCollapsed && !isOpen ? (\n <Tooltip content={label} placement=\"right\">\n {children}\n </Tooltip>\n ) : (\n children\n )}\n </li>\n );\n\n return (\n <Wrapper>\n <button\n id={`flowbite-sidebar-collapse-${id}`}\n onClick={() => setOpen(!isOpen)}\n title={label}\n type=\"button\"\n className={twMerge(theme.button, className)}\n {...props}\n >\n {Icon && (\n <Icon\n aria-hidden\n data-testid=\"flowbite-sidebar-collapse-icon\"\n className={twMerge(theme.icon.base, theme.icon.open[isOpen ? \"on\" : \"off\"])}\n />\n )}\n {isCollapsed ? (\n <span className=\"sr-only\">{label}</span>\n ) : (\n <>\n <span data-testid=\"flowbite-sidebar-collapse-label\" className={theme.label.base}>\n {label}\n </span>\n {renderChevronIcon ? (\n renderChevronIcon(theme, isOpen)\n ) : (\n <ChevronIcon\n aria-hidden\n className={twMerge(theme.label.icon.base, theme.label.icon.open[isOpen ? \"on\" : \"off\"])}\n />\n )}\n </>\n )}\n </button>\n <ul aria-labelledby={`flowbite-sidebar-collapse-${id}`} hidden={!isOpen} className={theme.list}>\n <SidebarItemContext.Provider value={{ isInsideCollapse: true }}>{children}</SidebarItemContext.Provider>\n </ul>\n </Wrapper>\n );\n};\n\nSidebarCollapse.displayName = \"Sidebar.Collapse\";\n"],"names":[],"mappings":";;;;;;;;;AAUY,MAAC,eAAe,GAAG,CAAC;AAChC,EAAE,QAAQ;AACV,EAAE,SAAS;AACX,EAAE,IAAI,EAAE,IAAI;AACZ,EAAE,KAAK;AACP,EAAE,WAAW,EAAE,WAAW,GAAG,aAAa;AAC1C,EAAE,iBAAiB;AACnB,EAAE,IAAI,GAAG,KAAK;AACd,EAAE,KAAK,EAAE,WAAW,GAAG,EAAE;AACzB,EAAE,GAAG,KAAK;AACV,CAAC,KAAK;AACN,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC;AACrB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC3C,E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