UNPKG

flowbite-react

Version:

Official React components built for Flowbite and Tailwind CSS

1 lines 8.3 kB
{"version":3,"file":"Button.mjs","sources":["../../../../src/components/Button/Button.tsx"],"sourcesContent":["import type { ElementType } from \"react\";\nimport { forwardRef, type ReactNode } from \"react\";\nimport { twMerge } from \"tailwind-merge\";\nimport type { PolymorphicComponentPropWithRef, PolymorphicRef } from \"../../helpers/generic-as-prop\";\nimport { mergeDeep } from \"../../helpers/merge-deep\";\nimport { getTheme } from \"../../theme-store\";\nimport type { DeepPartial } from \"../../types\";\nimport type {\n FlowbiteBoolean,\n FlowbiteColors,\n FlowbiteGradientColors,\n FlowbiteGradientDuoToneColors,\n FlowbiteSizes,\n} from \"../Flowbite\";\nimport { Spinner } from \"../Spinner\";\nimport { ButtonBase, type ButtonBaseProps } from \"./ButtonBase\";\nimport type { PositionInButtonGroup } from \"./ButtonGroup\";\nimport { ButtonGroup } from \"./ButtonGroup\";\n\nexport interface FlowbiteButtonTheme {\n base: string;\n fullSized: string;\n color: FlowbiteColors;\n disabled: string;\n isProcessing: string;\n spinnerSlot: string;\n spinnerLeftPosition: ButtonSizes;\n gradient: ButtonGradientColors;\n gradientDuoTone: ButtonGradientDuoToneColors;\n inner: FlowbiteButtonInnerTheme;\n label: string;\n outline: FlowbiteButtonOutlineTheme;\n pill: FlowbiteBoolean;\n size: ButtonSizes;\n}\n\nexport interface FlowbiteButtonInnerTheme {\n base: string;\n position: PositionInButtonGroup;\n outline: string;\n isProcessingPadding: ButtonSizes;\n}\n\nexport interface FlowbiteButtonOutlineTheme extends FlowbiteBoolean {\n color: ButtonOutlineColors;\n pill: FlowbiteBoolean;\n}\n\nexport interface ButtonColors\n extends Pick<FlowbiteColors, \"dark\" | \"failure\" | \"gray\" | \"info\" | \"light\" | \"purple\" | \"success\" | \"warning\"> {\n [key: string]: string;\n}\n\nexport interface ButtonGradientColors extends FlowbiteGradientColors {\n [key: string]: string;\n}\n\nexport interface ButtonGradientDuoToneColors extends FlowbiteGradientDuoToneColors {\n [key: string]: string;\n}\n\nexport interface ButtonOutlineColors extends Pick<FlowbiteColors, \"gray\"> {\n [key: string]: string;\n}\n\nexport interface ButtonSizes extends Pick<FlowbiteSizes, \"xs\" | \"sm\" | \"lg\" | \"xl\"> {\n [key: string]: string;\n}\n\nexport type ButtonProps<T extends ElementType = \"button\"> = PolymorphicComponentPropWithRef<\n T,\n {\n href?: string;\n color?: keyof FlowbiteColors;\n fullSized?: boolean;\n gradientDuoTone?: keyof ButtonGradientDuoToneColors;\n gradientMonochrome?: keyof ButtonGradientColors;\n target?: string;\n isProcessing?: boolean;\n processingLabel?: string;\n processingSpinner?: ReactNode;\n label?: ReactNode;\n outline?: boolean;\n pill?: boolean;\n positionInGroup?: keyof PositionInButtonGroup;\n size?: keyof ButtonSizes;\n theme?: DeepPartial<FlowbiteButtonTheme>;\n }\n>;\n\ntype ButtonComponentType = (<C extends ElementType = \"button\">(props: ButtonProps<C>) => JSX.Element) & {\n displayName?: string;\n};\n\nconst ButtonComponent = forwardRef(\n <T extends ElementType = \"button\">(\n {\n children,\n className,\n color = \"info\",\n disabled,\n fullSized,\n isProcessing = false,\n processingLabel = \"Loading...\",\n processingSpinner,\n gradientDuoTone,\n gradientMonochrome,\n label,\n outline = false,\n pill = false,\n positionInGroup = \"none\",\n size = \"md\",\n theme: customTheme = {},\n ...props\n }: ButtonProps<T>,\n ref: PolymorphicRef<T>,\n ) => {\n const { buttonGroup: groupTheme, button: buttonTheme } = getTheme();\n const theme = mergeDeep(buttonTheme, customTheme);\n\n const theirProps = props as ButtonBaseProps<T>;\n\n return (\n <ButtonBase\n ref={ref}\n disabled={disabled}\n className={twMerge(\n theme.base,\n disabled && theme.disabled,\n !gradientDuoTone && !gradientMonochrome && theme.color[color],\n gradientDuoTone && !gradientMonochrome && theme.gradientDuoTone[gradientDuoTone],\n !gradientDuoTone && gradientMonochrome && theme.gradient[gradientMonochrome],\n outline && (theme.outline.color[color] ?? theme.outline.color.default),\n theme.pill[pill ? \"on\" : \"off\"],\n fullSized && theme.fullSized,\n groupTheme.position[positionInGroup],\n className,\n )}\n {...theirProps}\n >\n <span\n className={twMerge(\n theme.inner.base,\n theme.outline[outline ? \"on\" : \"off\"],\n theme.outline.pill[outline && pill ? \"on\" : \"off\"],\n theme.size[size],\n outline && !theme.outline.color[color] && theme.inner.outline,\n isProcessing && theme.isProcessing,\n isProcessing && theme.inner.isProcessingPadding[size],\n theme.inner.position[positionInGroup],\n )}\n >\n <>\n {isProcessing && (\n <span className={twMerge(theme.spinnerSlot, theme.spinnerLeftPosition[size])}>\n {processingSpinner || <Spinner size={size} />}\n </span>\n )}\n {typeof children !== \"undefined\" ? (\n children\n ) : (\n <span data-testid=\"flowbite-button-label\" className={twMerge(theme.label)}>\n {isProcessing ? processingLabel : label}\n </span>\n )}\n </>\n </span>\n </ButtonBase>\n );\n },\n) as ButtonComponentType;\n\nButtonComponent.displayName = \"Button\";\n\nexport const Button = Object.assign(ButtonComponent, {\n Group: ButtonGroup,\n});\n"],"names":[],"mappings":";;;;;;;;;AASA,MAAM,eAAe,GAAG,UAAU;AAClC,EAAE,CAAC;AACH,IAAI,QAAQ;AACZ,IAAI,SAAS;AACb,IAAI,KAAK,GAAG,MAAM;AAClB,IAAI,QAAQ;AACZ,IAAI,SAAS;AACb,IAAI,YAAY,GAAG,KAAK;AACxB,IAAI,eAAe,GAAG,YAAY;AAClC,IAAI,iBAAiB;AACrB,IAAI,eAAe;AACnB,IAAI,kBAAkB;AACtB,IAAI,KAAK;AACT,IAAI,OAAO,GAAG,KAAK;AACnB,IAAI,IAAI,GAAG,KAAK;AAChB,IAAI,eAAe,GAAG,MAAM;AAC5B,IAAI,IAAI,GAAG,IAAI;AACf,IAAI,KAAK,EAAE,WAAW,GAAG,EAAE;AAC3B,IAAI,GAAG,KAAK;AACZ,GAAG,EAAE,GAAG,KAAK;AACb,IAAI,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,QAAQ,EAA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