UNPKG

flowbite-react

Version:

Official React components built for Flowbite and Tailwind CSS

1 lines 5.88 kB
{"version":3,"file":"TextInput.cjs","sources":["../../../src/components/TextInput/TextInput.tsx"],"sourcesContent":["\"use client\";\n\nimport type { ComponentProps, FC, ReactNode } from \"react\";\nimport { forwardRef } from \"react\";\nimport { get } from \"../../helpers/get\";\nimport { resolveProps } from \"../../helpers/resolve-props\";\nimport { useResolveTheme } from \"../../helpers/resolve-theme\";\nimport { twMerge } from \"../../helpers/tailwind-merge\";\nimport { useThemeProvider } from \"../../theme/provider\";\nimport type {\n DynamicStringEnumKeysOf,\n FlowbiteBoolean,\n FlowbiteColors,\n FlowbiteSizes,\n ThemingProps,\n} from \"../../types\";\nimport { textInputTheme } from \"./theme\";\n\nexport interface TextInputTheme {\n base: string;\n addon: string;\n field: {\n base: string;\n icon: {\n base: string;\n svg: string;\n };\n rightIcon: {\n base: string;\n svg: string;\n };\n input: {\n base: string;\n sizes: TextInputSizes;\n colors: TextInputColors;\n withIcon: FlowbiteBoolean;\n withRightIcon: FlowbiteBoolean;\n withAddon: FlowbiteBoolean;\n withShadow: FlowbiteBoolean;\n };\n };\n}\n\nexport interface TextInputColors extends Pick<FlowbiteColors, \"gray\" | \"info\" | \"failure\" | \"warning\" | \"success\"> {\n [key: string]: string;\n}\n\nexport interface TextInputSizes extends Pick<FlowbiteSizes, \"sm\" | \"md\" | \"lg\"> {\n [key: string]: string;\n}\n\nexport interface TextInputProps extends Omit<ComponentProps<\"input\">, \"ref\" | \"color\">, ThemingProps<TextInputTheme> {\n addon?: ReactNode;\n color?: DynamicStringEnumKeysOf<TextInputColors>;\n icon?: FC<ComponentProps<\"svg\">>;\n rightIcon?: FC<ComponentProps<\"svg\">>;\n shadow?: boolean;\n sizing?: DynamicStringEnumKeysOf<TextInputSizes>;\n}\n\nexport const TextInput = forwardRef<HTMLInputElement, TextInputProps>((props, ref) => {\n const provider = useThemeProvider();\n const theme = useResolveTheme(\n [textInputTheme, provider.theme?.textInput, props.theme],\n [get(provider.clearTheme, \"textInput\"), props.clearTheme],\n [get(provider.applyTheme, \"textInput\"), props.applyTheme],\n );\n\n const {\n addon,\n className,\n color = \"gray\",\n icon: Icon,\n rightIcon: RightIcon,\n shadow,\n sizing = \"md\",\n type = \"text\",\n ...restProps\n } = resolveProps(props, provider.props?.textInput);\n\n return (\n <div className={twMerge(theme.base, className)}>\n {addon && <span className={theme.addon}>{addon}</span>}\n <div className={theme.field.base}>\n {Icon && (\n <div className={theme.field.icon.base}>\n <Icon className={theme.field.icon.svg} />\n </div>\n )}\n {RightIcon && (\n <div data-testid=\"right-icon\" className={theme.field.rightIcon.base}>\n <RightIcon className={theme.field.rightIcon.svg} />\n </div>\n )}\n <input\n className={twMerge(\n theme.field.input.base,\n theme.field.input.colors[color],\n theme.field.input.sizes[sizing],\n theme.field.input.withIcon[Icon ? \"on\" : \"off\"],\n theme.field.input.withRightIcon[RightIcon ? \"on\" : \"off\"],\n theme.field.input.withAddon[addon ? \"on\" : \"off\"],\n theme.field.input.withShadow[shadow ? \"on\" : \"off\"],\n )}\n type={type}\n {...restProps}\n ref={ref}\n />\n </div>\n </div>\n );\n});\n\nTextInput.displayName = \"TextInput\";\n"],"names":["forwardRef","provider","useThemeProvider","theme","useResolveTheme","textInputTheme","get","resolveProps","jsxs","twMerge","jsx"],"mappings":";;;;;;;;;;;AAUY,MAAC,SAAS,GAAGA,gBAAU,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK;AACpD,EAAE,MAAMC,UAAQ,GAAGC,yBAAgB,EAAE;AACrC,EAAE,MAAMC,OAAK,GAAGC,4BAAe;AAC/B,IAAI,CAACC,oBAAc,EAAEJ,UAAQ,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC;AAC5D,IAAI,CAACK,OAAG,CAACL,UAAQ,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC;AAC7D,IAAI,CAACK,OAAG,CAACL,UAAQ,CAAC,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