UNPKG

@transkripid/flowbite-react

Version:

Official React components built for Flowbite and Tailwind CSS - Transkrip.id fork

1 lines 6.33 kB
{"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 {/* eslint-disable-next-line jsx-a11y/alt-text -- jsx-ally/alt-text gives a false positive here. Since we use our own Image component, we cannot provide an \"alt\" prop.*/}\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":["Card","props","$","_c","children","className","horizontal","href","theme","t0","t1","undefined","customTheme","Component","t2","removeCustomProps","theirProps","T0","t3","t4","t5","mergeDeep","getTheme","card","twMerge","root","base","t6","jsx","Image","t7","t8","jsxs","Symbol","for","bb0","renderImage","imgSrc","imgAlt","img","omit"],"mappings":";;;;;;AA8CO,MAAMA,IAAsBC,CAAAA,MAAA;AAAAC,QAAAA,IAAAC,EAAA,EAAA,GACjC;AAAA,IAAAC,UAAAA;AAAAA,IAAAC,WAAAA;AAAAA,IAAAC,YAAAA;AAAAA,IAAAC,MAAAA;AAAAA,IAAAC,OAAAC;AAAAA,EAA2ER,IAAAA;AAAMS,MAAAA;AAAAR,EAAAA,SAAAO,KAA3BA,IAAAA,MAAgBE,cAAhBF,GAAgBP,OAAAO,GAAAP,OAAAQ,KAAAA,IAAAR,EAAA,CAAA;AAAhB,QAAAU,IAAAF,GACtDG,IAAkB,OAAON,IAAS,MAAc,QAAQ;AAAIO,MAAAA;AAAAZ,EAAAA,SAAAD,KACzCa,IAAAC,EAAkBd,CAAK,GAACC,OAAAD,GAAAC,OAAAY,KAAAA,IAAAZ,EAAA,CAAA;AAA3C,QAAAc,IAAmBF;AAAyBG,MAAAA,GAAAC,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