flowbite-react
Version:
Official React components built for Flowbite and Tailwind CSS
1 lines • 6.76 kB
Source Map (JSON)
{"version":3,"file":"SidebarItem.mjs","sources":["../../../../src/components/Sidebar/SidebarItem.tsx"],"sourcesContent":["\"use client\";\n\nimport type { ComponentProps, ElementType, FC, PropsWithChildren, ReactNode } from \"react\";\nimport { forwardRef, useId } from \"react\";\nimport { twMerge } from \"tailwind-merge\";\nimport { mergeDeep } from \"../../helpers/merge-deep\";\nimport type { DeepPartial } from \"../../types\";\nimport { Badge } from \"../Badge\";\nimport type { FlowbiteColors } from \"../Flowbite\";\nimport { Tooltip } from \"../Tooltip\";\nimport { useSidebarContext } from \"./SidebarContext\";\nimport { useSidebarItemContext } from \"./SidebarItemContext\";\n\nexport interface FlowbiteSidebarItemTheme {\n active: string;\n base: string;\n collapsed: {\n insideCollapse: string;\n noIcon: string;\n };\n content: {\n base: string;\n };\n icon: {\n base: string;\n active: string;\n };\n label: string;\n listItem: string;\n}\n\nexport interface SidebarItemProps extends Omit<ComponentProps<\"div\">, \"ref\">, Record<string, unknown> {\n active?: boolean;\n as?: ElementType;\n href?: string;\n icon?: FC<ComponentProps<\"svg\">>;\n label?: string;\n labelColor?: keyof SidebarItemLabelColors;\n theme?: DeepPartial<FlowbiteSidebarItemTheme>;\n}\n\nexport interface SidebarItemLabelColors extends Pick<FlowbiteColors, \"gray\"> {\n [key: string]: string;\n}\n\nconst ListItem: FC<\n PropsWithChildren<{\n id: string;\n theme: FlowbiteSidebarItemTheme;\n isCollapsed: boolean;\n tooltipChildren: ReactNode | undefined;\n className?: string;\n }>\n> = ({ id, theme, isCollapsed, tooltipChildren, children: wrapperChildren, ...props }) => (\n <li {...props}>\n {isCollapsed ? (\n <Tooltip\n content={\n <Children id={id} theme={theme}>\n {tooltipChildren}\n </Children>\n }\n placement=\"right\"\n >\n {wrapperChildren}\n </Tooltip>\n ) : (\n wrapperChildren\n )}\n </li>\n);\n\nconst Children: FC<PropsWithChildren<{ id: string; theme: FlowbiteSidebarItemTheme }>> = ({ id, theme, children }) => {\n return (\n <span\n data-testid=\"flowbite-sidebar-item-content\"\n id={`flowbite-sidebar-item-${id}`}\n className={twMerge(theme.content.base)}\n >\n {children}\n </span>\n );\n};\n\nexport const SidebarItem = forwardRef<Element, SidebarItemProps>(\n (\n {\n active: isActive,\n as: Component = \"a\",\n children,\n className,\n icon: Icon,\n label,\n labelColor = \"info\",\n theme: customTheme = {},\n ...props\n },\n ref,\n ) => {\n const id = useId();\n const { theme: rootTheme, isCollapsed } = useSidebarContext();\n const { isInsideCollapse } = useSidebarItemContext();\n\n const theme = mergeDeep(rootTheme.item, customTheme);\n\n return (\n <ListItem theme={theme} className={theme.listItem} id={id} isCollapsed={isCollapsed} tooltipChildren={children}>\n <Component\n aria-labelledby={`flowbite-sidebar-item-${id}`}\n ref={ref}\n className={twMerge(\n theme.base,\n isActive && theme.active,\n !isCollapsed && isInsideCollapse && theme.collapsed?.insideCollapse,\n className,\n )}\n {...props}\n >\n {Icon && (\n <Icon\n aria-hidden\n data-testid=\"flowbite-sidebar-item-icon\"\n className={twMerge(theme.icon?.base, isActive && theme.icon?.active)}\n />\n )}\n {isCollapsed && !Icon && (\n <span className={theme.collapsed?.noIcon}>{(children as string).charAt(0).toLocaleUpperCase() ?? \"?\"}</span>\n )}\n {!isCollapsed && (\n <Children id={id} theme={theme}>\n {children}\n </Children>\n )}\n {!isCollapsed && label && (\n <Badge color={labelColor} data-testid=\"flowbite-sidebar-label\" hidden={isCollapsed} className={theme.label}>\n {label}\n </Badge>\n )}\n </Component>\n </ListItem>\n );\n },\n);\n\nSidebarItem.displayName = \"Sidebar.Item\";\n"],"names":[],"mappings":";;;;;;;;;AAUA,MAAM,QAAQ,GAAG,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,KAAK,EAAE,qBAAqB,GAAG,CAAC,IAAI,EAAE,EAAE,GAAG,KAAK,EAAE,QAAQ,EA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