UNPKG

@legion-ui-kit/react-core

Version:

To install the package into your project:

1 lines 7.93 kB
{"version":3,"file":"index.cjs","sources":["../../../../src/components/TextField/index.tsx"],"sourcesContent":["// Modules\r\nimport { useId } from 'react';\r\nimport cn from 'classnames';\r\n\r\n// Types\r\nimport type { TTextFieldProps, TTextFieldStatus } from './TextField.type';\r\n\r\n// Styles\r\nimport styles from './styles/styles.module.scss';\r\n\r\n// Components\r\nimport Icon from '../Icon';\r\n\r\n// Helpers\r\nimport { kebabCase } from '../../helpers/typography';\r\n\r\n// Constants\r\nimport { TEXT_FIELD_DEFAULT_PROPS, TEXT_FIELD_STATUS, TEXT_FIELD_VARIANT } from './TextField.constant';\r\nimport { ICON_NAME } from '../Icon/Icon.constant';\r\n\r\nconst getCaptionIcon = (status: TTextFieldStatus) => {\r\n switch (status) {\r\n case TEXT_FIELD_STATUS.error:\r\n return ICON_NAME['error-triangle'];\r\n case TEXT_FIELD_STATUS.success:\r\n return ICON_NAME['success-circle'];\r\n default:\r\n return ICON_NAME['info-circle'];\r\n }\r\n};\r\n\r\nconst TextField = (props: TTextFieldProps) => {\r\n const {\r\n block,\r\n caption,\r\n captionClassName,\r\n captionStyle,\r\n className,\r\n disabled,\r\n hint,\r\n hintClassName,\r\n hintStyle,\r\n iconLeft,\r\n iconLeftClassName,\r\n iconLeftStyle,\r\n iconRight,\r\n iconRightClassName,\r\n iconRightStyle,\r\n id,\r\n inputClassName,\r\n inputStyle,\r\n inputWrapperClassName,\r\n inputWrapperStyle,\r\n label,\r\n labelClassName,\r\n labelStyle,\r\n placeholder,\r\n prefix,\r\n prefixClassName,\r\n prefixStyle,\r\n size = TEXT_FIELD_DEFAULT_PROPS.size,\r\n status = TEXT_FIELD_DEFAULT_PROPS.status,\r\n style,\r\n suffix,\r\n suffixClassName,\r\n suffixStyle,\r\n variant = TEXT_FIELD_DEFAULT_PROPS.variant,\r\n ...restProps\r\n } = props;\r\n const initId = useId();\r\n const inputId = id || `legion_textfield_${kebabCase(initId)}`;\r\n const isOutline = variant === TEXT_FIELD_VARIANT.outline;\r\n\r\n const textFieldCN = cn(styles.legion_text_field, className, styles[size!], styles[status!], {\r\n [styles.block]: block,\r\n [styles.disabled]: disabled,\r\n [styles[variant!]]: variant\r\n });\r\n const captionCN = cn(styles.text_field_caption, captionClassName);\r\n const hintCN = cn(styles.text_field_hint, hintClassName);\r\n const inputCN = cn(styles.text_field_input, inputClassName);\r\n const inputWrapperCN = cn(styles.input_wrapper, inputWrapperClassName);\r\n const labelCN = cn(styles.text_field_label, labelClassName);\r\n const iconLeftCN = cn(styles.icon_left, iconLeftClassName);\r\n const iconRightCN = cn(styles.icon_right, iconRightClassName);\r\n const prefixCN = cn(styles.input_prefix, prefixClassName);\r\n const suffixCN = cn(styles.input_suffix, suffixClassName);\r\n\r\n const captionIcon = getCaptionIcon(status!);\r\n\r\n return (\r\n <div className={textFieldCN} style={style}>\r\n {label && (\r\n <label\r\n htmlFor={inputId}\r\n className={labelCN}\r\n style={labelStyle}\r\n >\r\n {label}\r\n </label>\r\n )}\r\n <div className={inputWrapperCN} style={inputWrapperStyle}>\r\n {prefix && (\r\n <span className={prefixCN} style={prefixStyle}>\r\n\t\t\t\t\t\t{prefix}\r\n\t\t\t\t\t</span>\r\n )}\r\n {iconLeft && (\r\n <span className={iconLeftCN} style={iconLeftStyle}>\r\n\t\t\t\t\t\t{iconLeft}\r\n\t\t\t\t\t</span>\r\n )}\r\n <input\r\n className={inputCN}\r\n id={inputId}\r\n placeholder={placeholder}\r\n disabled={disabled}\r\n style={inputStyle}\r\n {...restProps}\r\n />\r\n {isOutline && (\r\n <svg\r\n xmlns={'http://www.w3.org/2000/svg'}\r\n >\r\n <rect height={'100%'} width={'100%'} fill={'none'}/>\r\n </svg>\r\n )}\r\n {iconRight && (\r\n <span className={iconRightCN} style={iconRightStyle}>\r\n\t\t\t\t\t\t{iconRight}\r\n\t\t\t\t\t</span>\r\n )}\r\n {suffix && (\r\n <span className={suffixCN} style={suffixStyle}>\r\n\t\t\t\t\t\t{suffix}\r\n\t\t\t\t\t</span>\r\n )}\r\n </div>\r\n {caption && (\r\n <p className={captionCN} style={captionStyle}>\r\n <Icon className={styles.caption_icon} icon={captionIcon}/>\r\n {caption}\r\n </p>\r\n )}\r\n {hint && (\r\n <p className={hintCN} style={hintStyle}>\r\n {hint}\r\n </p>\r\n )}\r\n </div>\r\n );\r\n};\r\n\r\nexport default TextField;\r\n"],"names":["props","block","caption","captionClassName","captionStyle","className","disabled","hint","hintClassName","hintStyle","iconLeft","iconLeftClassName","iconLeftStyle","iconRight","iconRightClassName","iconRightStyle","id","inputClassName","inputStyle","inputWrapperClassName","inputWrapperStyle","label","labelClassName","labelStyle","placeholder","prefix","prefixClassName","prefixStyle","size","TEXT_FIELD_DEFAULT_PROPS","status","style","suffix","suffixClassName","suffixStyle","variant","restProps","initId","useId","inputId","kebabCase","isOutline","TEXT_FIELD_VARIANT","outline","textFieldCN","cn","styles","legion_text_field","captionCN","text_field_caption","hintCN","text_field_hint","inputCN","text_field_input","inputWrapperCN","input_wrapper","labelCN","text_field_label","iconLeftCN","icon_left","iconRightCN","icon_right","prefixCN","input_prefix","suffixCN","input_suffix","captionIcon","TEXT_FIELD_STATUS","error","ICON_NAME","success","getCaptionIcon","_jsxs","children","_jsx","htmlFor","xmlns","height","width","fill","Icon","caption_icon","icon"],"mappings":"maA+BmBA,IACjB,MAAMC,MACJA,EAAKC,QACLA,EAAOC,iBACPA,EAAgBC,aAChBA,EAAYC,UACZA,EAASC,SACTA,EAAQC,KACRA,EAAIC,cACJA,EAAaC,UACbA,EAASC,SACTA,EAAQC,kBACRA,EAAiBC,cACjBA,EAAaC,UACbA,EAASC,mBACTA,EAAkBC,eAClBA,EAAcC,GACdA,EAAEC,eACFA,EAAcC,WACdA,EAAUC,sBACVA,EAAqBC,kBACrBA,EAAiBC,MACjBA,EAAKC,eACLA,EAAcC,WACdA,EAAUC,YACVA,EAAWC,OACXA,EAAMC,gBACNA,EAAeC,YACfA,EAAWC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