UNPKG

flowbite-react

Version:

Official React components built for Flowbite and Tailwind CSS

1 lines 3.22 kB
{"version":3,"file":"Badge.mjs","sources":["../../../../src/components/Badge/Badge.tsx"],"sourcesContent":["import type { ComponentProps, FC } from \"react\";\nimport { twMerge } from \"tailwind-merge\";\nimport { mergeDeep } from \"../../helpers/merge-deep\";\nimport { getTheme } from \"../../theme-store\";\nimport type { DeepPartial } from \"../../types\";\nimport type { FlowbiteBoolean, FlowbiteColors, FlowbiteSizes } from \"../Flowbite\";\n\nexport interface FlowbiteBadgeTheme {\n root: FlowbiteBadgeRootTheme;\n icon: FlowbiteBadgeIconTheme;\n}\n\nexport interface FlowbiteBadgeRootTheme {\n base: string;\n color: FlowbiteColors;\n href: string;\n size: BadgeSizes;\n}\n\nexport interface FlowbiteBadgeIconTheme extends FlowbiteBoolean {\n size: BadgeSizes;\n}\n\nexport interface BadgeSizes extends Pick<FlowbiteSizes, \"xs\" | \"sm\"> {\n [key: string]: string;\n}\n\nexport interface BadgeProps extends Omit<ComponentProps<\"span\">, \"color\"> {\n color?: keyof FlowbiteColors;\n href?: string;\n icon?: FC<ComponentProps<\"svg\">>;\n size?: keyof BadgeSizes;\n theme?: DeepPartial<FlowbiteBadgeTheme>;\n}\n\nexport const Badge: FC<BadgeProps> = ({\n children,\n color = \"info\",\n href,\n icon: Icon,\n size = \"xs\",\n className,\n theme: customTheme = {},\n ...props\n}) => {\n const theme = mergeDeep(getTheme().badge, customTheme);\n\n const Content: FC = () => (\n <span\n className={twMerge(\n theme.root.base,\n theme.root.color[color],\n theme.root.size[size],\n theme.icon[Icon ? \"on\" : \"off\"],\n className,\n )}\n data-testid=\"flowbite-badge\"\n {...props}\n >\n {Icon && <Icon aria-hidden className={theme.icon.size[size]} data-testid=\"flowbite-badge-icon\" />}\n {children && <span>{children}</span>}\n </span>\n );\n\n return href ? (\n <a className={theme.root.href} href={href}>\n <Content />\n </a>\n ) : (\n <Content />\n );\n};\n\nBadge.displayName = \"Badge\";\n"],"names":[],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