flowbite-react
Version:
Official React components built for Flowbite and Tailwind CSS
1 lines • 4.7 kB
Source Map (JSON)
{"version":3,"file":"Card.mjs","sources":["../../../../src/components/Card/Card.tsx"],"sourcesContent":["import type { ComponentProps, FC } from \"react\";\nimport { twMerge } from \"tailwind-merge\";\nimport { mergeDeep } from \"../../helpers/merge-deep\";\nimport { omit } from \"../../helpers/omit\";\nimport { getTheme } from \"../../theme-store\";\nimport type { DeepPartial } from \"../../types\";\nimport type { FlowbiteBoolean } from \"../Flowbite\";\n\nexport interface FlowbiteCardTheme {\n root: FlowbiteCardRootTheme;\n img: FlowbiteCardImageTheme;\n}\n\nexport interface FlowbiteCardRootTheme {\n base: string;\n children: string;\n horizontal: FlowbiteBoolean;\n href: string;\n}\n\nexport interface FlowbiteCardImageTheme {\n base: string;\n horizontal: FlowbiteBoolean;\n}\n\ninterface CommonCardProps extends ComponentProps<\"div\"> {\n horizontal?: boolean;\n href?: string;\n /** Overwrites the theme. Will be merged with the context theme.\n * @default {}\n */\n theme?: DeepPartial<FlowbiteCardTheme>;\n}\n\nexport type CardProps = (\n | { imgAlt?: string; imgSrc?: string; renderImage?: never }\n | {\n /** Allows to provide a custom render function for the image component. Useful in Next.JS and Gatsby. **Setting this will disable `imgSrc` and `imgAlt`**.\n */\n renderImage?: (theme: DeepPartial<FlowbiteCardTheme>, horizontal: boolean) => JSX.Element;\n imgAlt?: never;\n imgSrc?: never;\n }\n) &\n CommonCardProps;\n\nexport const Card: FC<CardProps> = (props) => {\n const { children, className, horizontal, href, theme: customTheme = {} } = props;\n const Component = typeof href === \"undefined\" ? \"div\" : \"a\";\n const theirProps = removeCustomProps(props);\n\n const theme = mergeDeep(getTheme().card, customTheme);\n\n return (\n <Component\n data-testid=\"flowbite-card\"\n href={href}\n className={twMerge(\n theme.root.base,\n theme.root.horizontal[horizontal ? \"on\" : \"off\"],\n href && theme.root.href,\n className,\n )}\n {...theirProps}\n >\n <Image {...props} />\n <div className={theme.root.children}>{children}</div>\n </Component>\n );\n};\n\nconst Image: FC<CardProps> = ({ theme: customTheme = {}, ...props }) => {\n const theme = mergeDeep(getTheme().card, customTheme);\n if (props.renderImage) {\n return props.renderImage(theme, props.horizontal ?? false);\n }\n if (props.imgSrc) {\n return (\n <img\n data-testid=\"flowbite-card-image\"\n alt={props.imgAlt ?? \"\"}\n src={props.imgSrc}\n className={twMerge(theme.img.base, theme.img.horizontal[props.horizontal ? \"on\" : \"off\"])}\n />\n );\n }\n return null;\n};\n\nconst removeCustomProps = omit([\n \"renderImage\",\n \"imgSrc\",\n \"imgAlt\",\n \"children\",\n \"className\",\n \"horizontal\",\n \"href\",\n \"theme\",\n]);\n"],"names":[],"mappings":";;;;;;AAMY,MAAC,IAAI,GAAG,CAAC,KAAK,KAAK;AAC/B,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,KAAK,CAAC;AACnF,EAAE,MAAM,SAAS,GAAG,OAAO,IAAI,KAAK,WAAW,GAAG,KAAK,GAAG,GAAG,CAAC;AAC9D,EAAE,MAAM,UAAU,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;AAC9C,EAAE,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;AACxD,EAAE,uBAAuB,IAAI;AAC7B,IAAI,SAAS;AACb,IAAI;AACJ,MAAM,aAAa,EAAE,eAAe;AACpC,MAAM,IAAI;AACV,MAAM,SAAS,EAAE,OAAO;AACxB,QAAQ,KAAK,CAAC,IAAI,CAAC,IAAI;AACvB,QAAQ,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,GAAG,IAAI,GAAG,KAAK,CAAC;AACxD,QAAQ,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI;AAC/B,QAAQ,SAAS;AACjB,OAAO;AACP,MAAM,GAAG,UAAU;AACnB,MAAM,QAAQ,E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