@razorpay/blade 12.34.1 → 12.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/lib/native/components/Input/TextInput/TextInput.js +2 -1
- package/build/lib/native/components/Input/TextInput/TextInput.js.map +1 -1
- package/build/lib/native/components/Input/TextInput/useFormattedInput.js +7 -0
- package/build/lib/native/components/Input/TextInput/useFormattedInput.js.map +1 -0
- package/build/lib/web/development/components/Input/TextInput/TextInput.js +68 -19
- package/build/lib/web/development/components/Input/TextInput/TextInput.js.map +1 -1
- package/build/lib/web/development/components/Input/TextInput/useFormattedInput.js +171 -0
- package/build/lib/web/development/components/Input/TextInput/useFormattedInput.js.map +1 -0
- package/build/lib/web/production/components/Input/TextInput/TextInput.js +68 -19
- package/build/lib/web/production/components/Input/TextInput/TextInput.js.map +1 -1
- package/build/lib/web/production/components/Input/TextInput/useFormattedInput.js +171 -0
- package/build/lib/web/production/components/Input/TextInput/useFormattedInput.js.map +1 -0
- package/build/types/components/index.d.ts +17 -1
- package/build/types/components/index.native.d.ts +17 -1
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ import React__default, { useState, useRef, useEffect } from 'react';
|
|
|
4
4
|
import { BaseInput } from '../BaseInput/BaseInput.js';
|
|
5
5
|
import { getKeyboardAndAutocompleteProps } from '../BaseInput/utils.js';
|
|
6
6
|
import { useTaggedInput } from '../BaseInput/useTaggedInput.js';
|
|
7
|
+
import { useFormattedInput } from './useFormattedInput.js';
|
|
7
8
|
import isEmpty from '../../../utils/lodashButBetter/isEmpty.js';
|
|
8
9
|
import 'react-native-svg';
|
|
9
10
|
import '@babel/runtime/helpers/defineProperty';
|
|
@@ -36,7 +37,7 @@ import '../../Dropdown/DropdownLink.js';
|
|
|
36
37
|
import '../../Dropdown/DropdownIconButton.js';
|
|
37
38
|
import '../../Dropdown/DropdownHeaderFooter.js';
|
|
38
39
|
|
|
39
|
-
var _excluded=["label","accessibilityLabel","labelPosition","placeholder","type","defaultValue","name","value","maxCharacters","onChange","onClick","onFocus","onBlur","onSubmit","isDisabled","necessityIndicator","validationState","errorText","helpText","successText","isRequired","icon","prefix","showClearButton","onClearButtonClick","isLoading","suffix","autoFocus","keyboardReturnKeyType","autoCompleteSuggestionType","autoCapitalize","testID","size","leadingIcon","trailingIcon","isTaggedInput","tags","onTagChange","trailing","leading"];var isReactNative=function isReactNative(_textInputRef){return getPlatformType()==='react-native';};var _TextInput=function _TextInput(_ref,ref){var _leading$name,_trailing$name,
|
|
40
|
+
var _excluded=["label","accessibilityLabel","labelPosition","placeholder","type","defaultValue","name","value","maxCharacters","format","onChange","onClick","onFocus","onBlur","onSubmit","isDisabled","necessityIndicator","validationState","errorText","helpText","successText","isRequired","icon","prefix","showClearButton","onClearButtonClick","isLoading","suffix","autoFocus","keyboardReturnKeyType","autoCompleteSuggestionType","autoCapitalize","testID","size","leadingIcon","trailingIcon","isTaggedInput","tags","onTagChange","trailing","leading"];var isReactNative=function isReactNative(_textInputRef){return getPlatformType()==='react-native';};var _TextInput=function _TextInput(_ref,ref){var _leading$name,_trailing$name,_ref4;var label=_ref.label,accessibilityLabel=_ref.accessibilityLabel,_ref$labelPosition=_ref.labelPosition,labelPosition=_ref$labelPosition===void 0?'top':_ref$labelPosition,placeholder=_ref.placeholder,_ref$type=_ref.type,type=_ref$type===void 0?'text':_ref$type,defaultValue=_ref.defaultValue,name=_ref.name,value=_ref.value,maxCharacters=_ref.maxCharacters,format=_ref.format,onChange=_ref.onChange,onClick=_ref.onClick,_onFocus=_ref.onFocus,_onBlur=_ref.onBlur,onSubmit=_ref.onSubmit,isDisabled=_ref.isDisabled,necessityIndicator=_ref.necessityIndicator,validationState=_ref.validationState,errorText=_ref.errorText,helpText=_ref.helpText,successText=_ref.successText,isRequired=_ref.isRequired,icon=_ref.icon,prefix=_ref.prefix,showClearButton=_ref.showClearButton,onClearButtonClick=_ref.onClearButtonClick,isLoading=_ref.isLoading,suffix=_ref.suffix,autoFocus=_ref.autoFocus,keyboardReturnKeyType=_ref.keyboardReturnKeyType,autoCompleteSuggestionType=_ref.autoCompleteSuggestionType,autoCapitalize=_ref.autoCapitalize,testID=_ref.testID,_ref$size=_ref.size,size=_ref$size===void 0?'medium':_ref$size,leadingIcon=_ref.leadingIcon,trailingIcon=_ref.trailingIcon,isTaggedInput=_ref.isTaggedInput,tags=_ref.tags,onTagChange=_ref.onTagChange,trailing=_ref.trailing,leading=_ref.leading,rest=_objectWithoutProperties(_ref,_excluded);var textInputRef=React__default.useRef(null);var mergedRef=useMergeRefs(ref,textInputRef);var _useState=useState(false),_useState2=_slicedToArray(_useState,2),shouldShowClearButton=_useState2[0],setShouldShowClearButton=_useState2[1];var _useState3=useState(autoFocus!=null?autoFocus:false),_useState4=_slicedToArray(_useState3,2),isInputFocussed=_useState4[0],setIsInputFocussed=_useState4[1];if(__DEV__){if(format){var hasAlphanumeric=/[a-zA-Z0-9]/.test(format);if(hasAlphanumeric){throw new Error(`[Blade: TextInput] Invalid format "${format}". Only # and special characters allowed, no letters/numbers.`);}}}var formattingResult=useFormattedInput({format:format,onChange:onChange,value:value,defaultValue:defaultValue});var inputValue=format?formattingResult.formattedValue:value;var effectiveMaxCharacters=format?formattingResult.maxLength:maxCharacters;var handleOnChange=React__default.useCallback(function(_ref2){var name=_ref2.name,inputValue=_ref2.value;if(format){formattingResult.handleChange({name:name,value:inputValue});}else {onChange==null?void 0:onChange({name:name,value:inputValue});}},[format,formattingResult.handleChange,onChange]);var _useTaggedInput=useTaggedInput({isTaggedInput:isTaggedInput,tags:tags,onTagChange:onTagChange,isDisabled:isDisabled,onChange:handleOnChange,name:name,value:inputValue,inputRef:textInputRef}),activeTagIndex=_useTaggedInput.activeTagIndex,setActiveTagIndex=_useTaggedInput.setActiveTagIndex,getTags=_useTaggedInput.getTags,handleTaggedInputKeydown=_useTaggedInput.handleTaggedInputKeydown,handleTaggedInputChange=_useTaggedInput.handleTaggedInputChange,handleTagsClear=_useTaggedInput.handleTagsClear;var _React$useState=React__default.useState(false),_React$useState2=_slicedToArray(_React$useState,2),isTrailingDropDownOpen=_React$useState2[0],setIsTrailingDropDownOpen=_React$useState2[1];var _React$useState3=React__default.useState(false),_React$useState4=_slicedToArray(_React$useState3,2),isLeadingDropDownOpen=_React$useState4[0],setIsLeadingDropDownOpen=_React$useState4[1];var textInputWrapperRef=useRef(null);useEffect(function(){if(isTrailingDropDownOpen&&isLeadingDropDownOpen){setIsLeadingDropDownOpen(false);}},[isTrailingDropDownOpen]);useEffect(function(){if(isLeadingDropDownOpen&&isTrailingDropDownOpen){setIsTrailingDropDownOpen(false);}},[isLeadingDropDownOpen]);var leadingDropDown=leading&&getComponentId(leading)==='Dropdown'?leading:null;var trailingDropdown=trailing&&getComponentId(trailing)==='Dropdown'?trailing:null;var _leadingIcon=leading&&typeof leading==='function'&&(_leading$name=leading.name)!=null&&_leading$name.endsWith('Icon')?leading:undefined;var _trailingIcon=trailing&&typeof trailing==='function'&&(_trailing$name=trailing.name)!=null&&_trailing$name.endsWith('Icon')?trailing:undefined;var hasLeadingInteractionElement=!_leadingIcon&&!leadingDropDown&&leading;var hasTrailingInteractionElement=!_trailingIcon&&!trailingDropdown&&trailing;var renderDropdown=function renderDropdown(dropdown,isOpen,setIsOpen,defaultPlacement){if(!dropdown){return null;}return React__default.cloneElement(dropdown,{selectionType:'single',isOpen:isOpen,onOpenChange:function onOpenChange(isOpen){setIsOpen(isOpen);},children:React__default.Children.map(dropdown.props.children,function(child){if(child.type===DropdownOverlay){return React__default.cloneElement(child,{referenceRef:textInputWrapperRef,_isNestedDropdown:true,defaultPlacement:defaultPlacement});}return child;})});};var renderLeadingDropDown=renderDropdown(leadingDropDown,isLeadingDropDownOpen,setIsLeadingDropDownOpen,'bottom-start');var renderTrailingDropDown=renderDropdown(trailingDropdown,isTrailingDropDownOpen,setIsTrailingDropDownOpen,'bottom-end');React__default.useEffect(function(){setShouldShowClearButton(Boolean(showClearButton&&(defaultValue!=null?defaultValue:inputValue)));},[showClearButton,defaultValue,inputValue]);var renderClearButton=function renderClearButton(){return jsx(IconButton,{size:"medium",icon:CloseIcon,onClick:function onClick(){var _textInputRef$current;if(isEmpty(inputValue)&&textInputRef.current){if(isReactNative(textInputRef.current)){textInputRef.current.clear();textInputRef.current.focus();}else if(textInputRef.current instanceof HTMLInputElement){textInputRef.current.value='';textInputRef.current.focus();}}handleTagsClear();onClearButtonClick==null?void 0:onClearButtonClick();textInputRef==null?void 0:(_textInputRef$current=textInputRef.current)==null?void 0:_textInputRef$current.focus();setShouldShowClearButton(false);},isDisabled:isDisabled,accessibilityLabel:"Clear Input Content"});};var hasTrailingDropDown=Boolean(trailingDropdown);var renderInteractionElement=function renderInteractionElement(){if(isLoading){return jsx(Spinner,{accessibilityLabel:"Loading Content",color:"primary"});}if(shouldShowClearButton&&hasTrailingDropDown){return jsxs(BaseBox,{display:"flex",gap:"spacing.3",children:[renderClearButton()," ",jsx(Divider,{orientation:"vertical"})]});}if(showClearButton&&hasTrailingInteractionElement){return jsxs(BaseBox,{display:"flex",gap:"spacing.3",children:[renderClearButton()," ",jsx(Divider,{orientation:"vertical"})," ",trailing]});}if(shouldShowClearButton){return renderClearButton();}if(hasTrailingInteractionElement){return trailing;}return null;};return jsx(BaseInput,Object.assign({id:"textinput",componentName:MetaConstants.TextInput,ref:mergedRef,setInputWrapperRef:function setInputWrapperRef(wrapperNode){textInputWrapperRef.current=wrapperNode;},label:label,accessibilityLabel:accessibilityLabel,hideLabelText:!Boolean(label),labelPosition:labelPosition,placeholder:placeholder,defaultValue:format?value!==undefined&&defaultValue!==undefined?defaultValue:undefined:defaultValue,value:format?inputValue:value,name:name,maxCharacters:effectiveMaxCharacters,isDropdownTrigger:isTaggedInput,tags:isTaggedInput?getTags({size:size}):undefined,showAllTags:isInputFocussed,maxTagRows:"single",activeTagIndex:activeTagIndex,setActiveTagIndex:setActiveTagIndex,leadingDropDown:renderLeadingDropDown,trailingDropDown:renderTrailingDropDown,leadingInteractionElement:hasLeadingInteractionElement?leading:null,onChange:function onChange(_ref3){var name=_ref3.name,value=_ref3.value;if(showClearButton&&value!=null&&value.length){setShouldShowClearButton(true);}if(shouldShowClearButton&&!(value!=null&&value.length)){setShouldShowClearButton(false);}handleTaggedInputChange({name:name,value:value});handleOnChange({name:name,value:value});},onClick:onClick,onFocus:function onFocus(e){setIsInputFocussed(true);_onFocus==null?void 0:_onFocus(e);},onBlur:function onBlur(e){setIsInputFocussed(false);_onBlur==null?void 0:_onBlur(e);},onKeyDown:function onKeyDown(e){handleTaggedInputKeydown(e);if(format){formattingResult.handleKeyDown(e.event);}},onSubmit:onSubmit,isDisabled:isDisabled,necessityIndicator:necessityIndicator,isRequired:isRequired,leadingIcon:(_ref4=_leadingIcon!=null?_leadingIcon:leadingIcon)!=null?_ref4:icon,prefix:prefix,trailingInteractionElement:renderInteractionElement(),trailingIcon:_trailingIcon!=null?_trailingIcon:trailingIcon,suffix:suffix,validationState:validationState,errorText:errorText,helpText:helpText,successText:successText,trailingFooterSlot:function trailingFooterSlot(value){var _value$length;return format?null:effectiveMaxCharacters?jsx(BaseBox,{marginTop:hintMarginTop[size],marginRight:"spacing.1",children:jsx(CharacterCounter,{currentCount:(_value$length=value==null?void 0:value.length)!=null?_value$length:0,maxCount:effectiveMaxCharacters,size:size})}):null;},autoFocus:autoFocus,testID:testID},getKeyboardAndAutocompleteProps({type:type,keyboardReturnKeyType:keyboardReturnKeyType,autoCompleteSuggestionType:autoCompleteSuggestionType,autoCapitalize:autoCapitalize}),{size:size},rest));};var TextInput=assignWithoutSideEffects(React__default.forwardRef(_TextInput),{displayName:'TextInput'});
|
|
40
41
|
|
|
41
42
|
export { TextInput };
|
|
42
43
|
//# sourceMappingURL=TextInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextInput.js","sources":["../../../../../../src/components/Input/TextInput/TextInput.tsx"],"sourcesContent":["import React, { useEffect, useState, useRef } from 'react';\nimport type { ReactElement, ReactNode } from 'react';\nimport type { TextInput as TextInputReactNative } from 'react-native';\nimport type { BaseInputProps } from '../BaseInput';\nimport { BaseInput } from '../BaseInput';\nimport { getKeyboardAndAutocompleteProps } from '../BaseInput/utils';\nimport type { TaggedInputProps } from '../BaseInput/useTaggedInput';\nimport { useTaggedInput } from '../BaseInput/useTaggedInput';\nimport isEmpty from '~utils/lodashButBetter/isEmpty';\nimport type { IconComponent } from '~components/Icons';\nimport { CloseIcon } from '~components/Icons';\nimport { IconButton } from '~components/Button/IconButton';\nimport type { StyledPropsBlade } from '~components/Box/styledProps';\nimport { MetaConstants } from '~utils/metaAttribute';\nimport { CharacterCounter } from '~components/Form/CharacterCounter';\nimport BaseBox from '~components/Box/BaseBox';\nimport { Spinner } from '~components/Spinner';\nimport { assignWithoutSideEffects } from '~utils/assignWithoutSideEffects';\nimport { getPlatformType } from '~utils';\nimport { useMergeRefs } from '~utils/useMergeRefs';\nimport type {\n BladeElementRef,\n BladeElementRefWithValue,\n ContainerElementType,\n DataAnalyticsAttribute,\n} from '~utils/types';\nimport { hintMarginTop } from '~components/Form/formTokens';\nimport { Divider } from '~components/Divider';\nimport { getComponentId } from '~utils/isValidAllowedChildren';\nimport { DropdownOverlay } from '~components/Dropdown';\n\n// Users should use PasswordInput for input type password\ntype Type = Exclude<BaseInputProps['type'], 'password'>;\n\ntype TextInputCommonProps = Pick<\n BaseInputProps,\n | 'label'\n | 'accessibilityLabel'\n | 'labelPosition'\n | 'necessityIndicator'\n | 'validationState'\n | 'helpText'\n | 'errorText'\n | 'successText'\n | 'placeholder'\n | 'defaultValue'\n | 'name'\n | 'onChange'\n | 'onFocus'\n | 'onBlur'\n | 'value'\n | 'isDisabled'\n | 'isRequired'\n | 'prefix'\n | 'suffix'\n | 'maxCharacters'\n | 'autoFocus'\n | 'keyboardReturnKeyType'\n | 'autoCompleteSuggestionType'\n | 'onSubmit'\n | 'autoCapitalize'\n | 'testID'\n | 'onClick'\n | 'size'\n | 'leadingIcon'\n | 'trailingButton'\n | 'trailingIcon'\n | 'textAlign'\n | keyof DataAnalyticsAttribute\n> & {\n /**\n * Decides whether to render a clear icon button\n */\n showClearButton?: boolean;\n\n /**\n * Event handler to handle the onClick event for clear button. Used when `showClearButton` is `true`\n */\n onClearButtonClick?: () => void;\n\n /**\n * Decides whether to show a loading spinner for the input field.\n */\n isLoading?: boolean;\n\n /**\n * Icon that will be rendered at the beginning of the input field\n * @deprecated Use `leading` instead. This prop will be removed in the next major version.\n */\n icon?: IconComponent;\n /**\n * Type of Input Field to be rendered. Use `PasswordInput` for type `password`\n *\n *\n * **Note on number type**\n *\n * `type=\"number\"` internally uses `inputMode=\"numeric\"` instead of HTML's `type=\"number\"` which also allows text characters.\n * If you have a usecase where you only want to support number input, you can handle it on validations end.\n *\n * Check out [Why the GOV.UK Design System team changed the input type for numbers](https://technology.blog.gov.uk/2020/02/24/why-the-gov-uk-design-system-team-changed-the-input-type-for-numbers/) for reasoning\n *\n * @default text\n */\n type?: Type;\n /**\n *\n * Icon or React Element to be rendered at the end of the input field\n */\n trailing?: React.ReactElement | IconComponent;\n /**\n * Icon or React Element to be rendered at the beginning of the input field\n */\n leading?: React.ReactElement | IconComponent;\n} & TaggedInputProps &\n StyledPropsBlade;\n\n/*\n Mandatory accessibilityLabel prop when label is not provided\n*/\ntype TextInputPropsWithA11yLabel = {\n /**\n * Label to be shown for the input field\n */\n label?: undefined;\n /**\n * Accessibility label for the input\n */\n accessibilityLabel: string;\n};\n\n/*\n Optional accessibilityLabel prop when label is provided\n*/\ntype TextInputPropsWithLabel = {\n /**\n * Label to be shown for the input field\n */\n label: string;\n /**\n * Accessibility label for the input\n */\n accessibilityLabel?: string;\n};\n\ntype TextInputProps = (TextInputPropsWithA11yLabel | TextInputPropsWithLabel) &\n TextInputCommonProps;\n\n// need to do this to tell TS to infer type as TextInput of React Native and make it believe that `ref.current.clear()` exists\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst isReactNative = (_textInputRef: any): _textInputRef is TextInputReactNative => {\n return getPlatformType() === 'react-native';\n};\n\nconst _TextInput: React.ForwardRefRenderFunction<BladeElementRef, TextInputProps> = (\n {\n label,\n accessibilityLabel,\n labelPosition = 'top',\n placeholder,\n type = 'text',\n defaultValue,\n name,\n value,\n maxCharacters,\n onChange,\n onClick,\n onFocus,\n onBlur,\n onSubmit,\n isDisabled,\n necessityIndicator,\n validationState,\n errorText,\n helpText,\n successText,\n isRequired,\n icon,\n prefix,\n showClearButton,\n onClearButtonClick,\n isLoading,\n suffix,\n autoFocus,\n keyboardReturnKeyType,\n autoCompleteSuggestionType,\n autoCapitalize,\n testID,\n size = 'medium',\n leadingIcon,\n trailingIcon,\n isTaggedInput,\n tags,\n onTagChange,\n trailing,\n leading,\n ...rest\n },\n ref,\n): ReactElement => {\n const textInputRef = React.useRef<BladeElementRefWithValue>(null);\n const mergedRef = useMergeRefs(ref, textInputRef);\n const [shouldShowClearButton, setShouldShowClearButton] = useState(false);\n const [isInputFocussed, setIsInputFocussed] = useState(autoFocus ?? false);\n const {\n activeTagIndex,\n setActiveTagIndex,\n getTags,\n handleTaggedInputKeydown,\n handleTaggedInputChange,\n handleTagsClear,\n } = useTaggedInput({\n isTaggedInput,\n tags,\n onTagChange,\n isDisabled,\n onChange,\n name,\n value,\n inputRef: textInputRef,\n });\n const [isTrailingDropDownOpen, setIsTrailingDropDownOpen] = React.useState(false);\n const [isLeadingDropDownOpen, setIsLeadingDropDownOpen] = React.useState(false);\n const textInputWrapperRef = useRef<ContainerElementType | null>(null);\n\n useEffect(() => {\n if (isTrailingDropDownOpen && isLeadingDropDownOpen) {\n setIsLeadingDropDownOpen(false);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isTrailingDropDownOpen]);\n\n useEffect(() => {\n if (isLeadingDropDownOpen && isTrailingDropDownOpen) {\n setIsTrailingDropDownOpen(false);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isLeadingDropDownOpen]);\n\n const leadingDropDown =\n leading && getComponentId(leading as React.ReactElement) === 'Dropdown' ? leading : null;\n\n const trailingDropdown =\n trailing && getComponentId(trailing as React.ReactElement) === 'Dropdown' ? trailing : null;\n // we need to look into name of component and check if it 's and icon or a dropdown\n const _leadingIcon: IconComponent | undefined =\n leading && typeof leading === 'function' && leading.name?.endsWith('Icon')\n ? (leading as IconComponent)\n : undefined;\n\n const _trailingIcon: IconComponent | undefined =\n trailing && typeof trailing === 'function' && trailing.name?.endsWith('Icon')\n ? (trailing as IconComponent)\n : undefined;\n const hasLeadingInteractionElement = !_leadingIcon && !leadingDropDown && leading;\n\n const hasTrailingInteractionElement = !_trailingIcon && !trailingDropdown && trailing;\n\n const renderDropdown = (\n dropdown: React.ReactElement,\n isOpen: boolean,\n setIsOpen: (isOpen: boolean) => void,\n defaultPlacement: 'bottom-start' | 'bottom-end',\n ): React.ReactElement | null => {\n if (!dropdown) {\n return null;\n }\n return React.cloneElement(dropdown, {\n selectionType: 'single',\n isOpen,\n onOpenChange: (isOpen: boolean) => {\n setIsOpen(isOpen);\n },\n children: React.Children.map(dropdown.props.children, (child) => {\n if (child.type === DropdownOverlay) {\n return React.cloneElement(child, {\n referenceRef: textInputWrapperRef,\n _isNestedDropdown: true,\n defaultPlacement,\n });\n }\n return child;\n }),\n });\n };\n\n const renderLeadingDropDown = renderDropdown(\n leadingDropDown as React.ReactElement,\n isLeadingDropDownOpen,\n setIsLeadingDropDownOpen,\n 'bottom-start',\n );\n const renderTrailingDropDown = renderDropdown(\n trailingDropdown as React.ReactElement,\n isTrailingDropDownOpen,\n setIsTrailingDropDownOpen,\n 'bottom-end',\n );\n\n React.useEffect(() => {\n setShouldShowClearButton(Boolean(showClearButton && (defaultValue ?? value)));\n }, [showClearButton, defaultValue, value]);\n\n const renderClearButton = (): React.ReactElement => {\n return (\n <IconButton\n size=\"medium\"\n icon={CloseIcon}\n onClick={() => {\n if (isEmpty(value) && textInputRef.current) {\n // when the input field is uncontrolled take the ref and clear the input and then call the onClearButtonClick function\n if (isReactNative(textInputRef.current)) {\n textInputRef.current.clear();\n textInputRef.current.focus();\n } else if (textInputRef.current instanceof HTMLInputElement) {\n textInputRef.current.value = '';\n textInputRef.current.focus();\n }\n }\n handleTagsClear();\n // if the input field is controlled just call the click handler and the value change shall be left upto the consumer\n onClearButtonClick?.();\n textInputRef?.current?.focus();\n setShouldShowClearButton(false);\n }}\n isDisabled={isDisabled}\n accessibilityLabel=\"Clear Input Content\"\n />\n );\n };\n const hasTrailingDropDown = Boolean(trailingDropdown);\n\n const renderInteractionElement = (): ReactNode => {\n if (isLoading) {\n return <Spinner accessibilityLabel=\"Loading Content\" color=\"primary\" />;\n }\n\n if (shouldShowClearButton && hasTrailingDropDown) {\n return (\n <BaseBox display=\"flex\" gap=\"spacing.3\">\n {renderClearButton()} <Divider orientation=\"vertical\" />\n </BaseBox>\n );\n }\n\n if (showClearButton && hasTrailingInteractionElement) {\n return (\n <BaseBox display=\"flex\" gap=\"spacing.3\">\n {renderClearButton()} <Divider orientation=\"vertical\" /> {trailing as React.ReactElement}\n </BaseBox>\n );\n }\n\n if (shouldShowClearButton) {\n return renderClearButton();\n }\n\n if (hasTrailingInteractionElement) {\n return trailing as React.ReactElement;\n }\n return null;\n };\n return (\n <BaseInput\n id=\"textinput\"\n componentName={MetaConstants.TextInput}\n ref={mergedRef}\n setInputWrapperRef={(wrapperNode) => {\n textInputWrapperRef.current = wrapperNode;\n }}\n label={label as string}\n accessibilityLabel={accessibilityLabel}\n hideLabelText={!Boolean(label)}\n labelPosition={labelPosition}\n placeholder={placeholder}\n defaultValue={defaultValue}\n value={value}\n name={name}\n maxCharacters={maxCharacters}\n isDropdownTrigger={isTaggedInput}\n tags={isTaggedInput ? getTags({ size }) : undefined}\n showAllTags={isInputFocussed}\n maxTagRows=\"single\"\n activeTagIndex={activeTagIndex}\n setActiveTagIndex={setActiveTagIndex}\n leadingDropDown={renderLeadingDropDown}\n trailingDropDown={renderTrailingDropDown}\n leadingInteractionElement={\n hasLeadingInteractionElement ? (leading as React.ReactElement) : null\n }\n onChange={({ name, value }) => {\n if (showClearButton && value?.length) {\n // show the clear button when the user starts typing in\n setShouldShowClearButton(true);\n }\n\n if (shouldShowClearButton && !value?.length) {\n // hide the clear button when the input field is empty\n setShouldShowClearButton(false);\n }\n\n handleTaggedInputChange({ name, value });\n onChange?.({ name, value });\n }}\n onClick={onClick}\n onFocus={(e) => {\n setIsInputFocussed(true);\n onFocus?.(e);\n }}\n onBlur={(e) => {\n setIsInputFocussed(false);\n onBlur?.(e);\n }}\n onKeyDown={(e) => {\n handleTaggedInputKeydown(e);\n }}\n onSubmit={onSubmit}\n isDisabled={isDisabled}\n necessityIndicator={necessityIndicator}\n isRequired={isRequired}\n leadingIcon={_leadingIcon ?? leadingIcon ?? icon}\n prefix={prefix}\n trailingInteractionElement={renderInteractionElement()}\n trailingIcon={_trailingIcon ?? trailingIcon}\n suffix={suffix}\n validationState={validationState}\n errorText={errorText}\n helpText={helpText}\n successText={successText}\n trailingFooterSlot={(value) => {\n return maxCharacters ? (\n <BaseBox marginTop={hintMarginTop[size]} marginRight=\"spacing.1\">\n <CharacterCounter\n currentCount={value?.length ?? 0}\n maxCount={maxCharacters}\n size={size}\n />\n </BaseBox>\n ) : null;\n }}\n // eslint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={autoFocus}\n testID={testID}\n {...getKeyboardAndAutocompleteProps({\n type,\n keyboardReturnKeyType,\n autoCompleteSuggestionType,\n autoCapitalize,\n })}\n size={size}\n {...rest}\n />\n );\n};\n\nconst TextInput = assignWithoutSideEffects(React.forwardRef(_TextInput), {\n displayName: 'TextInput',\n});\n\nexport type { TextInputProps };\nexport { TextInput };\n"],"names":["isReactNative","_textInputRef","getPlatformType","_TextInput","_ref","ref","_leading$name","_trailing$name","_ref3","label","accessibilityLabel","_ref$labelPosition","labelPosition","placeholder","_ref$type","type","defaultValue","name","value","maxCharacters","onChange","onClick","onFocus","onBlur","onSubmit","isDisabled","necessityIndicator","validationState","errorText","helpText","successText","isRequired","icon","prefix","showClearButton","onClearButtonClick","isLoading","suffix","autoFocus","keyboardReturnKeyType","autoCompleteSuggestionType","autoCapitalize","testID","_ref$size","size","leadingIcon","trailingIcon","isTaggedInput","tags","onTagChange","trailing","leading","rest","_objectWithoutProperties","_excluded","textInputRef","React","useRef","mergedRef","useMergeRefs","_useState","useState","_useState2","_slicedToArray","shouldShowClearButton","setShouldShowClearButton","_useState3","_useState4","isInputFocussed","setIsInputFocussed","_useTaggedInput","useTaggedInput","inputRef","activeTagIndex","setActiveTagIndex","getTags","handleTaggedInputKeydown","handleTaggedInputChange","handleTagsClear","_React$useState","_React$useState2","isTrailingDropDownOpen","setIsTrailingDropDownOpen","_React$useState3","_React$useState4","isLeadingDropDownOpen","setIsLeadingDropDownOpen","textInputWrapperRef","useEffect","leadingDropDown","getComponentId","trailingDropdown","_leadingIcon","endsWith","undefined","_trailingIcon","hasLeadingInteractionElement","hasTrailingInteractionElement","renderDropdown","dropdown","isOpen","setIsOpen","defaultPlacement","cloneElement","selectionType","onOpenChange","children","Children","map","props","child","DropdownOverlay","referenceRef","_isNestedDropdown","renderLeadingDropDown","renderTrailingDropDown","Boolean","renderClearButton","_jsx","IconButton","CloseIcon","_textInputRef$current","isEmpty","current","clear","focus","HTMLInputElement","hasTrailingDropDown","renderInteractionElement","Spinner","color","_jsxs","BaseBox","display","gap","Divider","orientation","BaseInput","Object","assign","id","componentName","MetaConstants","TextInput","setInputWrapperRef","wrapperNode","hideLabelText","isDropdownTrigger","showAllTags","maxTagRows","trailingDropDown","leadingInteractionElement","_ref2","length","e","onKeyDown","trailingInteractionElement","trailingFooterSlot","_value$length","marginTop","hintMarginTop","marginRight","CharacterCounter","currentCount","maxCount","getKeyboardAndAutocompleteProps","assignWithoutSideEffects","forwardRef","displayName"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8hBAqJA,IAAMA,aAAa,CAAG,SAAhBA,aAAaA,CAAIC,aAAkB,CAA4C,CACnF,OAAOC,eAAe,EAAE,GAAK,cAAc,CAC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,CAAC9G,cAAK,CAAC+G,UAAU,CAACpK,UAAU,CAAC,CAAE,CACvEqK,WAAW,CAAE,WACf,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"TextInput.js","sources":["../../../../../../src/components/Input/TextInput/TextInput.tsx"],"sourcesContent":["import React, { useEffect, useState, useRef } from 'react';\nimport type { ReactElement, ReactNode } from 'react';\nimport type { TextInput as TextInputReactNative } from 'react-native';\nimport type { BaseInputProps } from '../BaseInput';\nimport { BaseInput } from '../BaseInput';\nimport { getKeyboardAndAutocompleteProps } from '../BaseInput/utils';\nimport type { TaggedInputProps } from '../BaseInput/useTaggedInput';\nimport { useTaggedInput } from '../BaseInput/useTaggedInput';\nimport { useFormattedInput } from './useFormattedInput';\nimport isEmpty from '~utils/lodashButBetter/isEmpty';\nimport type { IconComponent } from '~components/Icons';\nimport { CloseIcon } from '~components/Icons';\nimport { IconButton } from '~components/Button/IconButton';\nimport type { StyledPropsBlade } from '~components/Box/styledProps';\nimport { MetaConstants } from '~utils/metaAttribute';\nimport { CharacterCounter } from '~components/Form/CharacterCounter';\nimport BaseBox from '~components/Box/BaseBox';\nimport { Spinner } from '~components/Spinner';\nimport { assignWithoutSideEffects } from '~utils/assignWithoutSideEffects';\nimport { getPlatformType } from '~utils';\nimport { useMergeRefs } from '~utils/useMergeRefs';\nimport type {\n BladeElementRef,\n BladeElementRefWithValue,\n ContainerElementType,\n DataAnalyticsAttribute,\n} from '~utils/types';\nimport { hintMarginTop } from '~components/Form/formTokens';\nimport { Divider } from '~components/Divider';\nimport { getComponentId } from '~utils/isValidAllowedChildren';\nimport { DropdownOverlay } from '~components/Dropdown';\nimport type { FormInputOnEvent } from '~components/Form/FormTypes';\n\n// Users should use PasswordInput for input type password\ntype Type = Exclude<BaseInputProps['type'], 'password'>;\n\ntype TextInputCommonProps = Pick<\n BaseInputProps,\n | 'label'\n | 'accessibilityLabel'\n | 'labelPosition'\n | 'necessityIndicator'\n | 'validationState'\n | 'helpText'\n | 'errorText'\n | 'successText'\n | 'placeholder'\n | 'defaultValue'\n | 'name'\n | 'onChange'\n | 'onFocus'\n | 'onBlur'\n | 'value'\n | 'isDisabled'\n | 'isRequired'\n | 'prefix'\n | 'suffix'\n | 'maxCharacters'\n | 'autoFocus'\n | 'keyboardReturnKeyType'\n | 'autoCompleteSuggestionType'\n | 'onSubmit'\n | 'autoCapitalize'\n | 'testID'\n | 'onClick'\n | 'size'\n | 'leadingIcon'\n | 'trailingButton'\n | 'trailingIcon'\n | 'textAlign'\n | keyof DataAnalyticsAttribute\n> & {\n /**\n * Decides whether to render a clear icon button\n */\n showClearButton?: boolean;\n\n /**\n * Event handler to handle the onClick event for clear button. Used when `showClearButton` is `true`\n */\n onClearButtonClick?: () => void;\n\n /**\n * Decides whether to show a loading spinner for the input field.\n */\n isLoading?: boolean;\n\n /**\n * Icon that will be rendered at the beginning of the input field\n * @deprecated Use `leading` instead. This prop will be removed in the next major version.\n */\n icon?: IconComponent;\n /**\n * Type of Input Field to be rendered. Use `PasswordInput` for type `password`\n *\n *\n * **Note on number type**\n *\n * `type=\"number\"` internally uses `inputMode=\"numeric\"` instead of HTML's `type=\"number\"` which also allows text characters.\n * If you have a usecase where you only want to support number input, you can handle it on validations end.\n *\n * Check out [Why the GOV.UK Design System team changed the input type for numbers](https://technology.blog.gov.uk/2020/02/24/why-the-gov-uk-design-system-team-changed-the-input-type-for-numbers/) for reasoning\n *\n * @default text\n */\n type?: Type;\n /**\n *\n * Icon or React Element to be rendered at the end of the input field\n */\n trailing?: React.ReactElement | IconComponent;\n /**\n * Icon or React Element to be rendered at the beginning of the input field\n */\n leading?: React.ReactElement | IconComponent;\n /**\n * Format pattern where # represents input characters and other symbols act as delimiters\n * When provided, input will be automatically formatted and onChange will include rawValue\n *\n * **Note:**\n * 1. Format pattern should only contain # symbols and special characters as delimiters.\n * Alphanumeric characters (letters and numbers) are not allowed in the format pattern.\n * 2. When format is provided, user input is restricted to alphanumeric characters only.\n * Special characters and symbols will be filtered out automatically from user input.\n *\n * @example \"#### #### #### ####\" for card numbers\n * @example \"##/##\" for expiry dates\n * @example \"(###) ###-####\" for phone numbers\n */\n format?:\n | '#### #### #### ####'\n | '##/##'\n | '##/##/####'\n | '(###) ###-####'\n | '###-##-####'\n | '##:##'\n | '##:##:##'\n | '#### #### ####'\n | '###.###.###.###'\n | '## ## ####'\n | '##-###-##'\n // eslint-disable-next-line @typescript-eslint/ban-types\n | (string & {});\n} & TaggedInputProps &\n StyledPropsBlade;\n\n/*\n Mandatory accessibilityLabel prop when label is not provided\n*/\ntype TextInputPropsWithA11yLabel = {\n /**\n * Label to be shown for the input field\n */\n label?: undefined;\n /**\n * Accessibility label for the input\n */\n accessibilityLabel: string;\n};\n\n/*\n Optional accessibilityLabel prop when label is provided\n*/\ntype TextInputPropsWithLabel = {\n /**\n * Label to be shown for the input field\n */\n label: string;\n /**\n * Accessibility label for the input\n */\n accessibilityLabel?: string;\n};\n\ntype TextInputProps = (TextInputPropsWithA11yLabel | TextInputPropsWithLabel) &\n TextInputCommonProps;\n\n// need to do this to tell TS to infer type as TextInput of React Native and make it believe that `ref.current.clear()` exists\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst isReactNative = (_textInputRef: any): _textInputRef is TextInputReactNative => {\n return getPlatformType() === 'react-native';\n};\n\nconst _TextInput: React.ForwardRefRenderFunction<BladeElementRef, TextInputProps> = (\n {\n label,\n accessibilityLabel,\n labelPosition = 'top',\n placeholder,\n type = 'text',\n defaultValue,\n name,\n value,\n maxCharacters,\n format,\n onChange,\n onClick,\n onFocus,\n onBlur,\n onSubmit,\n isDisabled,\n necessityIndicator,\n validationState,\n errorText,\n helpText,\n successText,\n isRequired,\n icon,\n prefix,\n showClearButton,\n onClearButtonClick,\n isLoading,\n suffix,\n autoFocus,\n keyboardReturnKeyType,\n autoCompleteSuggestionType,\n autoCapitalize,\n testID,\n size = 'medium',\n leadingIcon,\n trailingIcon,\n isTaggedInput,\n tags,\n onTagChange,\n trailing,\n leading,\n ...rest\n },\n ref,\n): ReactElement => {\n const textInputRef = React.useRef<BladeElementRefWithValue>(null);\n const mergedRef = useMergeRefs(ref, textInputRef);\n const [shouldShowClearButton, setShouldShowClearButton] = useState(false);\n const [isInputFocussed, setIsInputFocussed] = useState(autoFocus ?? false);\n\n if (__DEV__) {\n if (format) {\n const hasAlphanumeric = /[a-zA-Z0-9]/.test(format);\n if (hasAlphanumeric) {\n throw new Error(\n `[Blade: TextInput] Invalid format \"${format}\". Only # and special characters allowed, no letters/numbers.`,\n );\n }\n }\n }\n\n const formattingResult = useFormattedInput({\n format,\n onChange,\n value,\n defaultValue,\n });\n\n const inputValue = format ? formattingResult.formattedValue : value;\n const effectiveMaxCharacters = format ? formattingResult.maxLength : maxCharacters;\n\n const handleOnChange: FormInputOnEvent = React.useCallback(\n ({ name, value: inputValue }) => {\n if (format) {\n formattingResult.handleChange({ name, value: inputValue });\n } else {\n onChange?.({ name, value: inputValue });\n }\n },\n [format, formattingResult.handleChange, onChange],\n );\n\n const {\n activeTagIndex,\n setActiveTagIndex,\n getTags,\n handleTaggedInputKeydown,\n handleTaggedInputChange,\n handleTagsClear,\n } = useTaggedInput({\n isTaggedInput,\n tags,\n onTagChange,\n isDisabled,\n onChange: handleOnChange,\n name,\n value: inputValue,\n inputRef: textInputRef,\n });\n const [isTrailingDropDownOpen, setIsTrailingDropDownOpen] = React.useState(false);\n const [isLeadingDropDownOpen, setIsLeadingDropDownOpen] = React.useState(false);\n const textInputWrapperRef = useRef<ContainerElementType | null>(null);\n\n useEffect(() => {\n if (isTrailingDropDownOpen && isLeadingDropDownOpen) {\n setIsLeadingDropDownOpen(false);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isTrailingDropDownOpen]);\n\n useEffect(() => {\n if (isLeadingDropDownOpen && isTrailingDropDownOpen) {\n setIsTrailingDropDownOpen(false);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isLeadingDropDownOpen]);\n\n const leadingDropDown =\n leading && getComponentId(leading as React.ReactElement) === 'Dropdown' ? leading : null;\n\n const trailingDropdown =\n trailing && getComponentId(trailing as React.ReactElement) === 'Dropdown' ? trailing : null;\n // we need to look into name of component and check if it 's and icon or a dropdown\n const _leadingIcon: IconComponent | undefined =\n leading && typeof leading === 'function' && leading.name?.endsWith('Icon')\n ? (leading as IconComponent)\n : undefined;\n\n const _trailingIcon: IconComponent | undefined =\n trailing && typeof trailing === 'function' && trailing.name?.endsWith('Icon')\n ? (trailing as IconComponent)\n : undefined;\n const hasLeadingInteractionElement = !_leadingIcon && !leadingDropDown && leading;\n\n const hasTrailingInteractionElement = !_trailingIcon && !trailingDropdown && trailing;\n\n const renderDropdown = (\n dropdown: React.ReactElement,\n isOpen: boolean,\n setIsOpen: (isOpen: boolean) => void,\n defaultPlacement: 'bottom-start' | 'bottom-end',\n ): React.ReactElement | null => {\n if (!dropdown) {\n return null;\n }\n return React.cloneElement(dropdown, {\n selectionType: 'single',\n isOpen,\n onOpenChange: (isOpen: boolean) => {\n setIsOpen(isOpen);\n },\n children: React.Children.map(dropdown.props.children, (child) => {\n if (child.type === DropdownOverlay) {\n return React.cloneElement(child, {\n referenceRef: textInputWrapperRef,\n _isNestedDropdown: true,\n defaultPlacement,\n });\n }\n return child;\n }),\n });\n };\n\n const renderLeadingDropDown = renderDropdown(\n leadingDropDown as React.ReactElement,\n isLeadingDropDownOpen,\n setIsLeadingDropDownOpen,\n 'bottom-start',\n );\n const renderTrailingDropDown = renderDropdown(\n trailingDropdown as React.ReactElement,\n isTrailingDropDownOpen,\n setIsTrailingDropDownOpen,\n 'bottom-end',\n );\n\n React.useEffect(() => {\n setShouldShowClearButton(Boolean(showClearButton && (defaultValue ?? inputValue)));\n }, [showClearButton, defaultValue, inputValue]);\n\n const renderClearButton = (): React.ReactElement => {\n return (\n <IconButton\n size=\"medium\"\n icon={CloseIcon}\n onClick={() => {\n if (isEmpty(inputValue) && textInputRef.current) {\n // when the input field is uncontrolled take the ref and clear the input and then call the onClearButtonClick function\n if (isReactNative(textInputRef.current)) {\n textInputRef.current.clear();\n textInputRef.current.focus();\n } else if (textInputRef.current instanceof HTMLInputElement) {\n textInputRef.current.value = '';\n textInputRef.current.focus();\n }\n }\n handleTagsClear();\n // if the input field is controlled just call the click handler and the value change shall be left upto the consumer\n onClearButtonClick?.();\n textInputRef?.current?.focus();\n setShouldShowClearButton(false);\n }}\n isDisabled={isDisabled}\n accessibilityLabel=\"Clear Input Content\"\n />\n );\n };\n const hasTrailingDropDown = Boolean(trailingDropdown);\n\n const renderInteractionElement = (): ReactNode => {\n if (isLoading) {\n return <Spinner accessibilityLabel=\"Loading Content\" color=\"primary\" />;\n }\n\n if (shouldShowClearButton && hasTrailingDropDown) {\n return (\n <BaseBox display=\"flex\" gap=\"spacing.3\">\n {renderClearButton()} <Divider orientation=\"vertical\" />\n </BaseBox>\n );\n }\n\n if (showClearButton && hasTrailingInteractionElement) {\n return (\n <BaseBox display=\"flex\" gap=\"spacing.3\">\n {renderClearButton()} <Divider orientation=\"vertical\" /> {trailing as React.ReactElement}\n </BaseBox>\n );\n }\n\n if (shouldShowClearButton) {\n return renderClearButton();\n }\n\n if (hasTrailingInteractionElement) {\n return trailing as React.ReactElement;\n }\n return null;\n };\n return (\n <BaseInput\n id=\"textinput\"\n componentName={MetaConstants.TextInput}\n ref={mergedRef}\n setInputWrapperRef={(wrapperNode) => {\n textInputWrapperRef.current = wrapperNode;\n }}\n label={label as string}\n accessibilityLabel={accessibilityLabel}\n hideLabelText={!Boolean(label)}\n labelPosition={labelPosition}\n placeholder={placeholder}\n // CONTROLLED/UNCONTROLLED INPUT LOGIC:\n // For inputs WITHOUT format:\n // - Use standard React controlled/uncontrolled logic\n // - Controlled: user provides `value` prop → use `value` prop\n // - Uncontrolled: user provides `defaultValue` prop → use `defaultValue` prop\n //\n // For inputs WITH format:\n // - Formatting requires controlled mode to re-render and show formatted values\n // - Case 1: Only `value` provided → defaultValue: undefined, value: formattedValue (normal controlled)\n // - Case 2: Only `defaultValue` provided → defaultValue: undefined, value: formattedValue (convert to controlled)\n // - Case 3: Both `value` and `defaultValue` provided → defaultValue: defaultValue, value: formattedValue (let BaseInput detect conflict and throw error)\n //\n defaultValue={\n format\n ? value !== undefined && defaultValue !== undefined\n ? defaultValue\n : undefined\n : defaultValue\n }\n value={format ? inputValue : value}\n name={name}\n maxCharacters={effectiveMaxCharacters}\n isDropdownTrigger={isTaggedInput}\n tags={isTaggedInput ? getTags({ size }) : undefined}\n showAllTags={isInputFocussed}\n maxTagRows=\"single\"\n activeTagIndex={activeTagIndex}\n setActiveTagIndex={setActiveTagIndex}\n leadingDropDown={renderLeadingDropDown}\n trailingDropDown={renderTrailingDropDown}\n leadingInteractionElement={\n hasLeadingInteractionElement ? (leading as React.ReactElement) : null\n }\n onChange={({ name, value }: { name?: string; value?: string }) => {\n if (showClearButton && value?.length) {\n // show the clear button when the user starts typing in\n setShouldShowClearButton(true);\n }\n\n if (shouldShowClearButton && !value?.length) {\n // hide the clear button when the input field is empty\n setShouldShowClearButton(false);\n }\n\n handleTaggedInputChange({ name, value });\n handleOnChange({ name, value });\n }}\n onClick={onClick}\n onFocus={(e) => {\n setIsInputFocussed(true);\n onFocus?.(e);\n }}\n onBlur={(e) => {\n setIsInputFocussed(false);\n onBlur?.(e);\n }}\n onKeyDown={(e) => {\n handleTaggedInputKeydown(e);\n if (format) {\n formattingResult.handleKeyDown(e.event);\n }\n }}\n onSubmit={onSubmit}\n isDisabled={isDisabled}\n necessityIndicator={necessityIndicator}\n isRequired={isRequired}\n leadingIcon={_leadingIcon ?? leadingIcon ?? icon}\n prefix={prefix}\n trailingInteractionElement={renderInteractionElement()}\n trailingIcon={_trailingIcon ?? trailingIcon}\n suffix={suffix}\n validationState={validationState}\n errorText={errorText}\n helpText={helpText}\n successText={successText}\n trailingFooterSlot={(value) => {\n return format ? null : effectiveMaxCharacters ? (\n <BaseBox marginTop={hintMarginTop[size]} marginRight=\"spacing.1\">\n <CharacterCounter\n currentCount={value?.length ?? 0}\n maxCount={effectiveMaxCharacters}\n size={size}\n />\n </BaseBox>\n ) : null;\n }}\n // eslint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={autoFocus}\n testID={testID}\n {...getKeyboardAndAutocompleteProps({\n type,\n keyboardReturnKeyType,\n autoCompleteSuggestionType,\n autoCapitalize,\n })}\n size={size}\n {...rest}\n />\n );\n};\n\nconst TextInput = assignWithoutSideEffects(React.forwardRef(_TextInput), {\n displayName: 'TextInput',\n});\n\nexport type { TextInputProps };\nexport { TextInput };\n"],"names":["isReactNative","_textInputRef","getPlatformType","_TextInput","_ref","ref","_leading$name","_trailing$name","_ref4","label","accessibilityLabel","_ref$labelPosition","labelPosition","placeholder","_ref$type","type","defaultValue","name","value","maxCharacters","format","onChange","onClick","onFocus","onBlur","onSubmit","isDisabled","necessityIndicator","validationState","errorText","helpText","successText","isRequired","icon","prefix","showClearButton","onClearButtonClick","isLoading","suffix","autoFocus","keyboardReturnKeyType","autoCompleteSuggestionType","autoCapitalize","testID","_ref$size","size","leadingIcon","trailingIcon","isTaggedInput","tags","onTagChange","trailing","leading","rest","_objectWithoutProperties","_excluded","textInputRef","React","useRef","mergedRef","useMergeRefs","_useState","useState","_useState2","_slicedToArray","shouldShowClearButton","setShouldShowClearButton","_useState3","_useState4","isInputFocussed","setIsInputFocussed","__DEV__","hasAlphanumeric","test","Error","formattingResult","useFormattedInput","inputValue","formattedValue","effectiveMaxCharacters","maxLength","handleOnChange","useCallback","_ref2","handleChange","_useTaggedInput","useTaggedInput","inputRef","activeTagIndex","setActiveTagIndex","getTags","handleTaggedInputKeydown","handleTaggedInputChange","handleTagsClear","_React$useState","_React$useState2","isTrailingDropDownOpen","setIsTrailingDropDownOpen","_React$useState3","_React$useState4","isLeadingDropDownOpen","setIsLeadingDropDownOpen","textInputWrapperRef","useEffect","leadingDropDown","getComponentId","trailingDropdown","_leadingIcon","endsWith","undefined","_trailingIcon","hasLeadingInteractionElement","hasTrailingInteractionElement","renderDropdown","dropdown","isOpen","setIsOpen","defaultPlacement","cloneElement","selectionType","onOpenChange","children","Children","map","props","child","DropdownOverlay","referenceRef","_isNestedDropdown","renderLeadingDropDown","renderTrailingDropDown","Boolean","renderClearButton","_jsx","IconButton","CloseIcon","_textInputRef$current","isEmpty","current","clear","focus","HTMLInputElement","hasTrailingDropDown","renderInteractionElement","Spinner","color","_jsxs","BaseBox","display","gap","Divider","orientation","BaseInput","Object","assign","id","componentName","MetaConstants","TextInput","setInputWrapperRef","wrapperNode","hideLabelText","isDropdownTrigger","showAllTags","maxTagRows","trailingDropDown","leadingInteractionElement","_ref3","length","e","onKeyDown","handleKeyDown","event","trailingInteractionElement","trailingFooterSlot","_value$length","marginTop","hintMarginTop","marginRight","CharacterCounter","currentCount","maxCount","getKeyboardAndAutocompleteProps","assignWithoutSideEffects","forwardRef","displayName"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uiBAmLA,IAAMA,aAAa,CAAG,SAAhBA,aAAaA,CAAIC,aAAkB,CAA4C,CACnF,OAAOC,eAAe,EAAE,GAAK,cAAc,CAC7C,CAAC,CAED,IAAMC,UAA2E,CAAG,SAA9EA,UAA2EA,CAAAC,IAAA,CA6C/EC,GAAG,CACc,CAAA,IAAAC,aAAA,CAAAC,cAAA,CAAAC,KAAA,CAAA,IA5CfC,KAAK,CAAAL,IAAA,CAALK,KAAK,CACLC,kBAAkB,CAAAN,IAAA,CAAlBM,kBAAkB,CAAAC,kBAAA,CAAAP,IAAA,CAClBQ,aAAa,CAAbA,aAAa,CAAAD,kBAAA,GAAA,KAAA,CAAA,CAAG,KAAK,CAAAA,kBAAA,CACrBE,WAAW,CAAAT,IAAA,CAAXS,WAAW,CAAAC,SAAA,CAAAV,IAAA,CACXW,IAAI,CAAJA,IAAI,CAAAD,SAAA,GAAG,KAAA,CAAA,CAAA,MAAM,CAAAA,SAAA,CACbE,YAAY,CAAAZ,IAAA,CAAZY,YAAY,CACZC,IAAI,CAAAb,IAAA,CAAJa,IAAI,C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AEA,eAAgB,CACjCC,SAAS,CAAEA,SAAU,CACrBC,QAAQ,CAAEA,QAAS,CACnBC,WAAW,CAAEA,WAAY,CACzB+I,kBAAkB,CAAE,SAAAA,kBAAC5J,CAAAA,KAAK,CAAK,CAAA,IAAA6J,aAAA,CAC7B,OAAO3J,MAAM,CAAG,IAAI,CAAG2D,sBAAsB,CAC3CsD,GAAA,CAACc,OAAO,CAAA,CAAC6B,SAAS,CAAEC,aAAa,CAACpI,IAAI,CAAE,CAACqI,WAAW,CAAC,WAAW,CAAAzD,QAAA,CAC9DY,GAAA,CAAC8C,gBAAgB,CAAA,CACfC,YAAY,CAAA,CAAAL,aAAA,CAAE7J,KAAK,EAALA,IAAAA,CAAAA,KAAAA,CAAAA,CAAAA,KAAK,CAAEsJ,MAAM,GAAAO,IAAAA,CAAAA,aAAA,CAAI,CAAE,CACjCM,QAAQ,CAAEtG,sBAAuB,CACjClC,IAAI,CAAEA,IAAK,CACZ,CAAC,CACK,CAAC,CACR,IAAI,CACV,CAAE,CAEFN,SAAS,CAAEA,SAAU,CACrBI,MAAM,CAAEA,MAAO,CACX2I,CAAAA,+BAA+B,CAAC,CAClCvK,IAAI,CAAJA,IAAI,CACJyB,qBAAqB,CAArBA,qBAAqB,CACrBC,0BAA0B,CAA1BA,0BAA0B,CAC1BC,cAAc,CAAdA,cACF,CAAC,CAAC,CACFG,CAAAA,IAAI,CAAEA,IAAK,EACPQ,IAAI,CACT,CAAC,CAEN,CAAC,CAEK,IAAAyG,SAAS,CAAGyB,wBAAwB,CAAC9H,cAAK,CAAC+H,UAAU,CAACrL,UAAU,CAAC,CAAE,CACvEsL,WAAW,CAAE,WACf,CAAC;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
|
+
import { useMemo, useState, useRef, useEffect, useCallback } from 'react';
|
|
3
|
+
|
|
4
|
+
var format=function format(value,pattern){if(!pattern)return value;var result='';var valueIndex=0;for(var i=0;i<pattern.length;i++){var patternChar=pattern[i];if(patternChar==='#'){if(valueIndex<value.length){result+=value[valueIndex];valueIndex++;}else {break;}}else {result+=patternChar;}}return result;};var stripPatternCharacters=function stripPatternCharacters(value){return value.replace(/[^\dA-z]/g,'');};var isUserCharacter=function isUserCharacter(character){return /[\dA-z]/.test(character);};var useFormattedInput=function useFormattedInput(_ref){var pattern=_ref.format,onChange=_ref.onChange,userValue=_ref.value,_ref$defaultValue=_ref.defaultValue,defaultValue=_ref$defaultValue===void 0?'':_ref$defaultValue;var initialValue=useMemo(function(){return format(userValue!=null?userValue:defaultValue,pattern!=null?pattern:'');},[userValue,defaultValue,pattern]);var _useState=useState(initialValue),_useState2=_slicedToArray(_useState,2),internalValue=_useState2[0],setInternalValue=_useState2[1];var inputRef=useRef(null);var infoRef=useRef({});var maxLength=useMemo(function(){return pattern==null?void 0:pattern.length;},[pattern]);useEffect(function(){if((userValue===''||userValue===undefined)&&defaultValue===''){var emptyFormatted=format('',pattern!=null?pattern:'');setInternalValue(emptyFormatted);}},[userValue,pattern]);useEffect(function(){var _infoRef$current=infoRef.current,cursorPosition=_infoRef$current.cursorPosition,endOfSection=_infoRef$current.endOfSection;if(endOfSection||cursorPosition===undefined)return;if(inputRef.current){inputRef.current.setSelectionRange(cursorPosition,cursorPosition);}},[internalValue]);var handleChange=useCallback(function(_ref2){var _inputRef$current$sel,_inputRef$current;var name=_ref2.name,inputValue=_ref2.value;if(!pattern){var cleanValue=inputValue!=null?inputValue:'';onChange==null?void 0:onChange({name:name,value:cleanValue});setInternalValue(cleanValue);return;}var currentValue=internalValue;var newInputValue=inputValue!=null?inputValue:'';var cursorPosition=(_inputRef$current$sel=(_inputRef$current=inputRef.current)==null?void 0:_inputRef$current.selectionStart)!=null?_inputRef$current$sel:0;var didDelete=newInputValue.length<currentValue.length;infoRef.current.cursorPosition=cursorPosition;var rawValue=stripPatternCharacters(newInputValue);if(didDelete){var _currentValue$cursorP;var deletedChar=(_currentValue$cursorP=currentValue[cursorPosition])!=null?_currentValue$cursorP:'';var deletedDelimiter=!isUserCharacter(deletedChar);if(deletedDelimiter){var beforeCursor=newInputValue.substring(0,cursorPosition);var afterCursor=newInputValue.substring(cursorPosition);var rawBefore=stripPatternCharacters(beforeCursor);var rawAfter=stripPatternCharacters(afterCursor);rawValue=rawBefore.slice(0,-1)+rawAfter;infoRef.current.cursorPosition=beforeCursor.replace(/([\d\w]+)[^\dA-z]+$/,'$1').length-1;}}var formattedValue=format(rawValue,pattern);infoRef.current.endOfSection=false;if(!didDelete){var nextChar=formattedValue[cursorPosition];var nextIsDelimiter=nextChar?!isUserCharacter(nextChar):false;var remainingText=formattedValue.substring(cursorPosition);var nextUserCharIndex=remainingText.search(/[\dA-z]/);var hasMoreUserChars=nextUserCharIndex!==-1;infoRef.current.endOfSection=nextIsDelimiter&&!hasMoreUserChars;if(nextIsDelimiter&&hasMoreUserChars){var _formattedValue;var prevChar=(_formattedValue=formattedValue[cursorPosition-1])!=null?_formattedValue:'';var prevIsDelimiter=!isUserCharacter(prevChar);if(prevIsDelimiter){infoRef.current.cursorPosition=cursorPosition+nextUserCharIndex+1;}}}onChange==null?void 0:onChange({name:name,value:formattedValue,rawValue:rawValue});setInternalValue(formattedValue);},[pattern,onChange,internalValue]);var handleKeyDown=useCallback(function(event){if(event.currentTarget&&inputRef.current!==event.currentTarget){inputRef.current=event.currentTarget;}},[]);return {formattedValue:internalValue,handleChange:handleChange,handleKeyDown:handleKeyDown,maxLength:maxLength};};
|
|
5
|
+
|
|
6
|
+
export { useFormattedInput };
|
|
7
|
+
//# sourceMappingURL=useFormattedInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormattedInput.js","sources":["../../../../../../src/components/Input/TextInput/useFormattedInput.ts"],"sourcesContent":["import type React from 'react';\nimport { useCallback, useRef, useState, useEffect, useMemo } from 'react';\nimport type { FormInputOnEvent } from '~components/Form/FormTypes';\n\n/**\n * Formats user input according to pattern. format(\"1234\", \"##/##\") → \"12/34\"\n */\nconst format = (value: string, pattern: string): string => {\n if (!pattern) return value;\n\n let result = '';\n let valueIndex = 0;\n\n for (let i = 0; i < pattern.length; i++) {\n const patternChar = pattern[i]; // \"#\" or \"/\"\n\n if (patternChar === '#') {\n if (valueIndex < value.length) {\n result += value[valueIndex]; // add \"1\" from \"1234\"\n valueIndex++;\n } else {\n break; // No more input chars, stop\n }\n } else {\n result += patternChar; // add \"/\" delimiter\n }\n }\n\n return result; // \"12/34\"\n};\n\n/**\n * Removes delimiters, keeps only user input. stripPatternCharacters(\"12/34\") → \"1234\"\n */\nconst stripPatternCharacters = (value: string): string => {\n return value.replace(/[^\\dA-z]/g, ''); // \"12/34\" → \"1234\" (removes \"/\")\n};\n\n/**\n * Checks if character is user input vs delimiter. isUserCharacter('1') → true, isUserCharacter('/') → false\n */\nconst isUserCharacter = (character: string): boolean => {\n return /[\\dA-z]/.test(character); // \"1\" → true, \"/\" → false\n};\n\ntype UseFormattedInputProps = {\n format?: string;\n onChange?: (params: { name?: string; value?: string; rawValue?: string }) => void;\n value?: string;\n defaultValue?: string;\n};\n\ntype UseFormattedInputReturn = {\n formattedValue: string;\n handleChange: FormInputOnEvent;\n handleKeyDown: (event: React.KeyboardEvent<HTMLInputElement>) => void;\n maxLength?: number;\n};\n\n/**\n * Hook for pattern-based input formatting with smart cursor positioning.\n * useFormattedInput({ format: \"##/##\" }) transforms \"1234\" → \"12/34\"\n */\nexport const useFormattedInput = ({\n format: pattern,\n onChange,\n value: userValue,\n defaultValue = '',\n}: UseFormattedInputProps): UseFormattedInputReturn => {\n const initialValue = useMemo(() => {\n return format(userValue ?? defaultValue, pattern ?? '');\n }, [userValue, defaultValue, pattern]);\n\n const [internalValue, setInternalValue] = useState(initialValue);\n const inputRef = useRef<HTMLInputElement | null>(null);\n const infoRef = useRef<{\n cursorPosition?: number;\n endOfSection?: boolean;\n }>({});\n\n const maxLength = useMemo(() => pattern?.length, [pattern]);\n\n // Reset internal state when parent clears value (form resets, external state changes)\n // Preserves format delimiters for visual guidance. Example: \"(###)\" → \"( )\" when cleared\n useEffect(() => {\n if ((userValue === '' || userValue === undefined) && defaultValue === '') {\n const emptyFormatted = format('', pattern ?? '');\n setInternalValue(emptyFormatted);\n }\n }, [userValue, pattern]);\n\n // Apply calculated cursor position after value updates\n useEffect(() => {\n const { cursorPosition, endOfSection } = infoRef.current;\n\n if (endOfSection || cursorPosition === undefined) return; // Skip if no position or end section\n\n if (inputRef.current) {\n inputRef.current.setSelectionRange(cursorPosition, cursorPosition);\n }\n }, [internalValue]);\n\n const handleChange: FormInputOnEvent = useCallback(\n ({ name, value: inputValue }) => {\n if (!pattern) {\n // No pattern = regular input\n const cleanValue = inputValue ?? '';\n onChange?.({ name, value: cleanValue });\n setInternalValue(cleanValue);\n return;\n }\n\n const currentValue = internalValue; // \"12/34\" (user wants to delete \"/\")\n const newInputValue = inputValue ?? ''; // \"1234\" (after deleting \"/\")\n const cursorPosition = inputRef.current?.selectionStart ?? 0; // 2 (cursor where \"/\" was)\n const didDelete = newInputValue.length < currentValue.length; // 4 < 5 → true\n\n infoRef.current.cursorPosition = cursorPosition;\n\n let rawValue = stripPatternCharacters(newInputValue); // \"1234\" → \"1234\"\n\n // Handle special case: user deleted a delimiter (like deleting \"/\" in \"12/|34\")\n if (didDelete) {\n const deletedChar = currentValue[cursorPosition] ?? ''; // \"12/34\"[2] → \"/\"\n const deletedDelimiter = !isUserCharacter(deletedChar); // \"/\" → true (is delimiter)\n\n if (deletedDelimiter) {\n // true (will execute for \"/\" deletion)\n const beforeCursor = newInputValue.substring(0, cursorPosition); // \"12\" (before cursor)\n const afterCursor = newInputValue.substring(cursorPosition); // \"34\" (after cursor)\n const rawBefore = stripPatternCharacters(beforeCursor); // \"12\" → \"12\"\n const rawAfter = stripPatternCharacters(afterCursor); // \"34\" → \"34\"\n\n rawValue = rawBefore.slice(0, -1) + rawAfter; // \"12\".slice(0,-1) + \"34\" → \"1\" + \"34\" → \"134\"\n\n // Removes trailing non-alphanumeric characters from the end of the string, preserving the last alphanumeric word before them.\n infoRef.current.cursorPosition =\n beforeCursor.replace(/([\\d\\w]+)[^\\dA-z]+$/, '$1').length - 1;\n }\n }\n\n const formattedValue = format(rawValue, pattern); // format(\"134\", \"##/##\") → \"13/4\"\n infoRef.current.endOfSection = false;\n\n // Handle cursor positioning when typing (not deleting)\n if (!didDelete) {\n // User types \"2\" in \"1|\" → becomes \"12|/\" → should jump to \"12/|\"\n const nextChar = formattedValue[cursorPosition]; // \"12/\"[2] → \"/\" (delimiter)\n const nextIsDelimiter = nextChar ? !isUserCharacter(nextChar) : false; // \"/\" → true\n\n const remainingText = formattedValue.substring(cursorPosition); // \"12/\".substring(2) → \"/\"\n const nextUserCharIndex = remainingText.search(/[\\dA-z]/); // \"/\".search() → -1 (no user chars)\n const hasMoreUserChars = nextUserCharIndex !== -1; // -1 !== -1 → false\n\n infoRef.current.endOfSection = nextIsDelimiter && !hasMoreUserChars; // true && false → false\n\n // Move cursor past auto-inserted delimiters for smooth typing\n if (nextIsDelimiter && hasMoreUserChars) {\n const prevChar = formattedValue[cursorPosition - 1] ?? '';\n const prevIsDelimiter = !isUserCharacter(prevChar);\n\n if (prevIsDelimiter) {\n infoRef.current.cursorPosition = cursorPosition + nextUserCharIndex + 1;\n }\n }\n }\n\n onChange?.({ name, value: formattedValue, rawValue });\n setInternalValue(formattedValue);\n },\n [pattern, onChange, internalValue],\n );\n\n const handleKeyDown = useCallback((event: React.KeyboardEvent<HTMLInputElement>) => {\n if (event.currentTarget && inputRef.current !== event.currentTarget) {\n inputRef.current = event.currentTarget;\n }\n }, []);\n\n return {\n formattedValue: internalValue,\n handleChange,\n handleKeyDown,\n maxLength,\n };\n};\n"],"names":["format","value","pattern","result","valueIndex","i","length","patternChar","stripPatternCharacters","replace","isUserCharacter","character","test","useFormattedInput","_ref","onChange","userValue","_ref$defaultValue","defaultValue","initialValue","useMemo","_useState","useState","_useState2","_slicedToArray","internalValue","setInternalValue","inputRef","useRef","infoRef","maxLength","useEffect","undefined","emptyFormatted","_infoRef$current","current","cursorPosition","endOfSection","setSelectionRange","handleChange","useCallback","_ref2","_inputRef$current$sel","_inputRef$current","name","inputValue","cleanValue","currentValue","newInputValue","selectionStart","didDelete","rawValue","_currentValue$cursorP","deletedChar","deletedDelimiter","beforeCursor","substring","afterCursor","rawBefore","rawAfter","slice","formattedValue","nextChar","nextIsDelimiter","remainingText","nextUserCharIndex","search","hasMoreUserChars","_formattedValue","prevChar","prevIsDelimiter","handleKeyDown","event","currentTarget"],"mappings":";;;AAOA,IAAMA,MAAM,CAAG,SAATA,MAAMA,CAAIC,KAAa,CAAEC,OAAe,CAAa,CACzD,GAAI,CAACA,OAAO,CAAE,OAAOD,KAAK,CAE1B,IAAIE,MAAM,CAAG,EAAE,CACf,IAAIC,UAAU,CAAG,CAAC,CAElB,IAAK,IAAIC,CAAC,CAAG,CAAC,CAAEA,CAAC,CAAGH,OAAO,CAACI,MAAM,CAAED,CAAC,EAAE,CAAE,CACvC,IAAME,WAAW,CAAGL,OAAO,CAACG,CAAC,CAAC,CAE9B,GAAIE,WAAW,GAAK,GAAG,CAAE,CACvB,GAAIH,UAAU,CAAGH,KAAK,CAACK,MAAM,CAAE,CAC7BH,MAAM,EAAIF,KAAK,CAACG,UAAU,CAAC,CAC3BA,UAAU,EAAE,CACd,CAAC,KAAM,CACL,MACF,CACF,CAAC,KAAM,CACLD,MAAM,EAAII,WAAW,CACvB,CACF,CAEA,OAAOJ,MAAM,CACf,CAAC,CAKD,IAAMK,sBAAsB,CAAG,SAAzBA,sBAAsBA,CAAIP,KAAa,CAAa,CACxD,OAAOA,KAAK,CAACQ,OAAO,CAAC,WAAW,CAAE,EAAE,CAAC,CACvC,CAAC,CAKD,IAAMC,eAAe,CAAG,SAAlBA,eAAeA,CAAIC,SAAiB,CAAc,CACtD,OAAO,SAAS,CAACC,IAAI,CAACD,SAAS,CAAC,CAClC,CAAC,CAoBY,IAAAE,iBAAiB,CAAG,SAAp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6 +5,7 @@ import React__default, { useState, useRef, useEffect } from 'react';
|
|
|
5
5
|
import '../BaseInput/index.js';
|
|
6
6
|
import { getKeyboardAndAutocompleteProps } from '../BaseInput/utils.js';
|
|
7
7
|
import { useTaggedInput } from '../BaseInput/useTaggedInput.js';
|
|
8
|
+
import { useFormattedInput } from './useFormattedInput.js';
|
|
8
9
|
import isEmpty from '../../../utils/lodashButBetter/isEmpty.js';
|
|
9
10
|
import '../../Icons/index.js';
|
|
10
11
|
import '../../Button/IconButton/index.js';
|
|
@@ -33,7 +34,7 @@ import { MetaConstants } from '../../../utils/metaAttribute/metaConstants.js';
|
|
|
33
34
|
import { CharacterCounter } from '../../Form/CharacterCounter/CharacterCounter.js';
|
|
34
35
|
import { assignWithoutSideEffects } from '../../../utils/assignWithoutSideEffects/assignWithoutSideEffects.js';
|
|
35
36
|
|
|
36
|
-
var _excluded = ["label", "accessibilityLabel", "labelPosition", "placeholder", "type", "defaultValue", "name", "value", "maxCharacters", "onChange", "onClick", "onFocus", "onBlur", "onSubmit", "isDisabled", "necessityIndicator", "validationState", "errorText", "helpText", "successText", "isRequired", "icon", "prefix", "showClearButton", "onClearButtonClick", "isLoading", "suffix", "autoFocus", "keyboardReturnKeyType", "autoCompleteSuggestionType", "autoCapitalize", "testID", "size", "leadingIcon", "trailingIcon", "isTaggedInput", "tags", "onTagChange", "trailing", "leading"];
|
|
37
|
+
var _excluded = ["label", "accessibilityLabel", "labelPosition", "placeholder", "type", "defaultValue", "name", "value", "maxCharacters", "format", "onChange", "onClick", "onFocus", "onBlur", "onSubmit", "isDisabled", "necessityIndicator", "validationState", "errorText", "helpText", "successText", "isRequired", "icon", "prefix", "showClearButton", "onClearButtonClick", "isLoading", "suffix", "autoFocus", "keyboardReturnKeyType", "autoCompleteSuggestionType", "autoCapitalize", "testID", "size", "leadingIcon", "trailingIcon", "isTaggedInput", "tags", "onTagChange", "trailing", "leading"];
|
|
37
38
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
38
39
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
39
40
|
// need to do this to tell TS to infer type as TextInput of React Native and make it believe that `ref.current.clear()` exists
|
|
@@ -42,7 +43,7 @@ var isReactNative = function isReactNative(_textInputRef) {
|
|
|
42
43
|
return getPlatformType() === 'react-native';
|
|
43
44
|
};
|
|
44
45
|
var _TextInput = function _TextInput(_ref, ref) {
|
|
45
|
-
var _leading$name, _trailing$name,
|
|
46
|
+
var _leading$name, _trailing$name, _ref4;
|
|
46
47
|
var label = _ref.label,
|
|
47
48
|
accessibilityLabel = _ref.accessibilityLabel,
|
|
48
49
|
_ref$labelPosition = _ref.labelPosition,
|
|
@@ -54,7 +55,8 @@ var _TextInput = function _TextInput(_ref, ref) {
|
|
|
54
55
|
name = _ref.name,
|
|
55
56
|
value = _ref.value,
|
|
56
57
|
maxCharacters = _ref.maxCharacters,
|
|
57
|
-
|
|
58
|
+
format = _ref.format,
|
|
59
|
+
onChange = _ref.onChange,
|
|
58
60
|
onClick = _ref.onClick,
|
|
59
61
|
_onFocus = _ref.onFocus,
|
|
60
62
|
_onBlur = _ref.onBlur,
|
|
@@ -97,14 +99,45 @@ var _TextInput = function _TextInput(_ref, ref) {
|
|
|
97
99
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
98
100
|
isInputFocussed = _useState4[0],
|
|
99
101
|
setIsInputFocussed = _useState4[1];
|
|
102
|
+
if (true) {
|
|
103
|
+
if (format) {
|
|
104
|
+
var hasAlphanumeric = /[a-zA-Z0-9]/.test(format);
|
|
105
|
+
if (hasAlphanumeric) {
|
|
106
|
+
throw new Error("[Blade: TextInput] Invalid format \"".concat(format, "\". Only # and special characters allowed, no letters/numbers."));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
var formattingResult = useFormattedInput({
|
|
111
|
+
format: format,
|
|
112
|
+
onChange: onChange,
|
|
113
|
+
value: value,
|
|
114
|
+
defaultValue: defaultValue
|
|
115
|
+
});
|
|
116
|
+
var inputValue = format ? formattingResult.formattedValue : value;
|
|
117
|
+
var effectiveMaxCharacters = format ? formattingResult.maxLength : maxCharacters;
|
|
118
|
+
var handleOnChange = React__default.useCallback(function (_ref2) {
|
|
119
|
+
var name = _ref2.name,
|
|
120
|
+
inputValue = _ref2.value;
|
|
121
|
+
if (format) {
|
|
122
|
+
formattingResult.handleChange({
|
|
123
|
+
name: name,
|
|
124
|
+
value: inputValue
|
|
125
|
+
});
|
|
126
|
+
} else {
|
|
127
|
+
onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
128
|
+
name: name,
|
|
129
|
+
value: inputValue
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}, [format, formattingResult.handleChange, onChange]);
|
|
100
133
|
var _useTaggedInput = useTaggedInput({
|
|
101
134
|
isTaggedInput: isTaggedInput,
|
|
102
135
|
tags: tags,
|
|
103
136
|
onTagChange: onTagChange,
|
|
104
137
|
isDisabled: isDisabled,
|
|
105
|
-
onChange:
|
|
138
|
+
onChange: handleOnChange,
|
|
106
139
|
name: name,
|
|
107
|
-
value:
|
|
140
|
+
value: inputValue,
|
|
108
141
|
inputRef: textInputRef
|
|
109
142
|
}),
|
|
110
143
|
activeTagIndex = _useTaggedInput.activeTagIndex,
|
|
@@ -166,15 +199,15 @@ var _TextInput = function _TextInput(_ref, ref) {
|
|
|
166
199
|
var renderLeadingDropDown = renderDropdown(leadingDropDown, isLeadingDropDownOpen, setIsLeadingDropDownOpen, 'bottom-start');
|
|
167
200
|
var renderTrailingDropDown = renderDropdown(trailingDropdown, isTrailingDropDownOpen, setIsTrailingDropDownOpen, 'bottom-end');
|
|
168
201
|
React__default.useEffect(function () {
|
|
169
|
-
setShouldShowClearButton(Boolean(showClearButton && (defaultValue !== null && defaultValue !== void 0 ? defaultValue :
|
|
170
|
-
}, [showClearButton, defaultValue,
|
|
202
|
+
setShouldShowClearButton(Boolean(showClearButton && (defaultValue !== null && defaultValue !== void 0 ? defaultValue : inputValue)));
|
|
203
|
+
}, [showClearButton, defaultValue, inputValue]);
|
|
171
204
|
var renderClearButton = function renderClearButton() {
|
|
172
205
|
return /*#__PURE__*/jsx(IconButton, {
|
|
173
206
|
size: "medium",
|
|
174
207
|
icon: CloseIcon,
|
|
175
208
|
onClick: function onClick() {
|
|
176
209
|
var _textInputRef$current;
|
|
177
|
-
if (isEmpty(
|
|
210
|
+
if (isEmpty(inputValue) && textInputRef.current) {
|
|
178
211
|
// when the input field is uncontrolled take the ref and clear the input and then call the onClearButtonClick function
|
|
179
212
|
if (isReactNative(textInputRef.current)) {
|
|
180
213
|
textInputRef.current.clear();
|
|
@@ -239,11 +272,24 @@ var _TextInput = function _TextInput(_ref, ref) {
|
|
|
239
272
|
accessibilityLabel: accessibilityLabel,
|
|
240
273
|
hideLabelText: !Boolean(label),
|
|
241
274
|
labelPosition: labelPosition,
|
|
242
|
-
placeholder: placeholder
|
|
243
|
-
|
|
244
|
-
|
|
275
|
+
placeholder: placeholder
|
|
276
|
+
// CONTROLLED/UNCONTROLLED INPUT LOGIC:
|
|
277
|
+
// For inputs WITHOUT format:
|
|
278
|
+
// - Use standard React controlled/uncontrolled logic
|
|
279
|
+
// - Controlled: user provides `value` prop → use `value` prop
|
|
280
|
+
// - Uncontrolled: user provides `defaultValue` prop → use `defaultValue` prop
|
|
281
|
+
//
|
|
282
|
+
// For inputs WITH format:
|
|
283
|
+
// - Formatting requires controlled mode to re-render and show formatted values
|
|
284
|
+
// - Case 1: Only `value` provided → defaultValue: undefined, value: formattedValue (normal controlled)
|
|
285
|
+
// - Case 2: Only `defaultValue` provided → defaultValue: undefined, value: formattedValue (convert to controlled)
|
|
286
|
+
// - Case 3: Both `value` and `defaultValue` provided → defaultValue: defaultValue, value: formattedValue (let BaseInput detect conflict and throw error)
|
|
287
|
+
//
|
|
288
|
+
,
|
|
289
|
+
defaultValue: format ? value !== undefined && defaultValue !== undefined ? defaultValue : undefined : defaultValue,
|
|
290
|
+
value: format ? inputValue : value,
|
|
245
291
|
name: name,
|
|
246
|
-
maxCharacters:
|
|
292
|
+
maxCharacters: effectiveMaxCharacters,
|
|
247
293
|
isDropdownTrigger: isTaggedInput,
|
|
248
294
|
tags: isTaggedInput ? getTags({
|
|
249
295
|
size: size
|
|
@@ -255,9 +301,9 @@ var _TextInput = function _TextInput(_ref, ref) {
|
|
|
255
301
|
leadingDropDown: renderLeadingDropDown,
|
|
256
302
|
trailingDropDown: renderTrailingDropDown,
|
|
257
303
|
leadingInteractionElement: hasLeadingInteractionElement ? leading : null,
|
|
258
|
-
onChange: function onChange(
|
|
259
|
-
var name =
|
|
260
|
-
value =
|
|
304
|
+
onChange: function onChange(_ref3) {
|
|
305
|
+
var name = _ref3.name,
|
|
306
|
+
value = _ref3.value;
|
|
261
307
|
if (showClearButton && value !== null && value !== void 0 && value.length) {
|
|
262
308
|
// show the clear button when the user starts typing in
|
|
263
309
|
setShouldShowClearButton(true);
|
|
@@ -270,7 +316,7 @@ var _TextInput = function _TextInput(_ref, ref) {
|
|
|
270
316
|
name: name,
|
|
271
317
|
value: value
|
|
272
318
|
});
|
|
273
|
-
|
|
319
|
+
handleOnChange({
|
|
274
320
|
name: name,
|
|
275
321
|
value: value
|
|
276
322
|
});
|
|
@@ -286,12 +332,15 @@ var _TextInput = function _TextInput(_ref, ref) {
|
|
|
286
332
|
},
|
|
287
333
|
onKeyDown: function onKeyDown(e) {
|
|
288
334
|
handleTaggedInputKeydown(e);
|
|
335
|
+
if (format) {
|
|
336
|
+
formattingResult.handleKeyDown(e.event);
|
|
337
|
+
}
|
|
289
338
|
},
|
|
290
339
|
onSubmit: onSubmit,
|
|
291
340
|
isDisabled: isDisabled,
|
|
292
341
|
necessityIndicator: necessityIndicator,
|
|
293
342
|
isRequired: isRequired,
|
|
294
|
-
leadingIcon: (
|
|
343
|
+
leadingIcon: (_ref4 = _leadingIcon !== null && _leadingIcon !== void 0 ? _leadingIcon : leadingIcon) !== null && _ref4 !== void 0 ? _ref4 : icon,
|
|
295
344
|
prefix: prefix,
|
|
296
345
|
trailingInteractionElement: renderInteractionElement(),
|
|
297
346
|
trailingIcon: _trailingIcon !== null && _trailingIcon !== void 0 ? _trailingIcon : trailingIcon,
|
|
@@ -302,12 +351,12 @@ var _TextInput = function _TextInput(_ref, ref) {
|
|
|
302
351
|
successText: successText,
|
|
303
352
|
trailingFooterSlot: function trailingFooterSlot(value) {
|
|
304
353
|
var _value$length;
|
|
305
|
-
return
|
|
354
|
+
return format ? null : effectiveMaxCharacters ? /*#__PURE__*/jsx(BaseBox, {
|
|
306
355
|
marginTop: hintMarginTop[size],
|
|
307
356
|
marginRight: "spacing.1",
|
|
308
357
|
children: /*#__PURE__*/jsx(CharacterCounter, {
|
|
309
358
|
currentCount: (_value$length = value === null || value === void 0 ? void 0 : value.length) !== null && _value$length !== void 0 ? _value$length : 0,
|
|
310
|
-
maxCount:
|
|
359
|
+
maxCount: effectiveMaxCharacters,
|
|
311
360
|
size: size
|
|
312
361
|
})
|
|
313
362
|
}) : null;
|