@razorpay/blade 12.37.0 → 12.39.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/Accordion/AccordionItem.js +1 -1
- package/build/lib/native/components/Accordion/AccordionItem.js.map +1 -1
- package/build/lib/native/components/Alert/Alert.js +2 -1
- package/build/lib/native/components/Alert/Alert.js.map +1 -1
- package/build/lib/native/components/Card/Card.js +1 -1
- package/build/lib/native/components/Card/Card.js.map +1 -1
- package/build/lib/native/components/Card/CardContext.js +2 -2
- package/build/lib/native/components/Card/CardContext.js.map +1 -1
- package/build/lib/native/components/Card/CardFooter.js +2 -1
- package/build/lib/native/components/Card/CardFooter.js.map +1 -1
- package/build/lib/native/components/Card/CardHeader.js +3 -3
- package/build/lib/native/components/Card/CardHeader.js.map +1 -1
- package/build/lib/native/components/Chip/Chip.js +1 -1
- package/build/lib/native/components/Chip/Chip.js.map +1 -1
- package/build/lib/native/components/Form/FormLabel.js +1 -1
- package/build/lib/native/components/Form/FormLabel.js.map +1 -1
- package/build/lib/native/components/Input/BaseInput/BaseInput.js +1 -1
- package/build/lib/native/components/Input/BaseInput/BaseInput.js.map +1 -1
- package/build/lib/native/components/Input/BaseInput/BaseInputVisuals.js +1 -1
- package/build/lib/native/components/Input/BaseInput/BaseInputVisuals.js.map +1 -1
- package/build/lib/native/components/Input/OTPInput/OTPInput.js +1 -1
- package/build/lib/native/components/Input/OTPInput/OTPInput.js.map +1 -1
- package/build/lib/native/components/Input/PasswordInput/PasswordInput.js +1 -1
- package/build/lib/native/components/Input/PasswordInput/PasswordInput.js.map +1 -1
- package/build/lib/native/components/Input/SearchInput/SearchInput.js +1 -1
- package/build/lib/native/components/Input/SearchInput/SearchInput.js.map +1 -1
- package/build/lib/native/components/Input/TextArea/TextArea.js +1 -1
- package/build/lib/native/components/Input/TextArea/TextArea.js.map +1 -1
- package/build/lib/native/components/Input/TextInput/TextInput.js +1 -1
- package/build/lib/native/components/Input/TextInput/TextInput.js.map +1 -1
- package/build/lib/native/components/List/ListItem.js +1 -1
- package/build/lib/native/components/List/ListItem.js.map +1 -1
- package/build/lib/native/components/QuickFilters/QuickFilter.js +1 -1
- package/build/lib/native/components/QuickFilters/QuickFilter.js.map +1 -1
- package/build/lib/native/utils/makeAnalyticsAttribute/makeAnalyticsConstants.js +4 -0
- package/build/lib/native/utils/makeAnalyticsAttribute/makeAnalyticsConstants.js.map +1 -0
- package/build/lib/web/development/components/Accordion/AccordionButton.web.js +5 -7
- package/build/lib/web/development/components/Accordion/AccordionButton.web.js.map +1 -1
- package/build/lib/web/development/components/Accordion/AccordionItem.js +7 -5
- package/build/lib/web/development/components/Accordion/AccordionItem.js.map +1 -1
- package/build/lib/web/development/components/Alert/Alert.js +2 -0
- package/build/lib/web/development/components/Alert/Alert.js.map +1 -1
- package/build/lib/web/development/components/Avatar/AvatarButton.js +3 -0
- package/build/lib/web/development/components/Avatar/AvatarButton.js.map +1 -1
- package/build/lib/web/development/components/Card/Card.js +4 -1
- package/build/lib/web/development/components/Card/Card.js.map +1 -1
- package/build/lib/web/development/components/Card/CardContext.js +11 -6
- package/build/lib/web/development/components/Card/CardContext.js.map +1 -1
- package/build/lib/web/development/components/Card/CardFooter.js +3 -0
- package/build/lib/web/development/components/Card/CardFooter.js.map +1 -1
- package/build/lib/web/development/components/Card/CardHeader.js +38 -44
- package/build/lib/web/development/components/Card/CardHeader.js.map +1 -1
- package/build/lib/web/development/components/Chip/Chip.js +5 -5
- package/build/lib/web/development/components/Chip/Chip.js.map +1 -1
- package/build/lib/web/development/components/DatePicker/BaseDatePicker.web.js +6 -2
- package/build/lib/web/development/components/DatePicker/BaseDatePicker.web.js.map +1 -1
- package/build/lib/web/development/components/DatePicker/Calendar.web.js +4 -2
- package/build/lib/web/development/components/DatePicker/Calendar.web.js.map +1 -1
- package/build/lib/web/development/components/DatePicker/CalendarFooter.web.js +4 -0
- package/build/lib/web/development/components/DatePicker/CalendarFooter.web.js.map +1 -1
- package/build/lib/web/development/components/DatePicker/DateInput.web.js +10 -4
- package/build/lib/web/development/components/DatePicker/DateInput.web.js.map +1 -1
- package/build/lib/web/development/components/DatePicker/QuickSelection/PresetSideBar.web.js +1 -0
- package/build/lib/web/development/components/DatePicker/QuickSelection/PresetSideBar.web.js.map +1 -1
- package/build/lib/web/development/components/DatePicker/QuickSelection/QuickSelectionItem.web.js +2 -1
- package/build/lib/web/development/components/DatePicker/QuickSelection/QuickSelectionItem.web.js.map +1 -1
- package/build/lib/web/development/components/FileUpload/FileUploadItem.js +3 -0
- package/build/lib/web/development/components/FileUpload/FileUploadItem.js.map +1 -1
- package/build/lib/web/development/components/Form/FormLabel.js +24 -4
- package/build/lib/web/development/components/Form/FormLabel.js.map +1 -1
- package/build/lib/web/development/components/Input/BaseInput/BaseInput.js +6 -2
- package/build/lib/web/development/components/Input/BaseInput/BaseInput.js.map +1 -1
- package/build/lib/web/development/components/Input/BaseInput/BaseInputVisuals.js +1 -1
- package/build/lib/web/development/components/Input/BaseInput/BaseInputVisuals.js.map +1 -1
- package/build/lib/web/development/components/Input/OTPInput/OTPInput.js +5 -1
- package/build/lib/web/development/components/Input/OTPInput/OTPInput.js.map +1 -1
- package/build/lib/web/development/components/Input/PasswordInput/PasswordInput.js +5 -1
- package/build/lib/web/development/components/Input/PasswordInput/PasswordInput.js.map +1 -1
- package/build/lib/web/development/components/Input/PhoneNumberInput/PhoneNumberInput.web.js +5 -1
- package/build/lib/web/development/components/Input/PhoneNumberInput/PhoneNumberInput.web.js.map +1 -1
- package/build/lib/web/development/components/Input/SearchInput/SearchInput.js +5 -1
- package/build/lib/web/development/components/Input/SearchInput/SearchInput.js.map +1 -1
- package/build/lib/web/development/components/Input/TextArea/TextArea.js +5 -1
- package/build/lib/web/development/components/Input/TextArea/TextArea.js.map +1 -1
- package/build/lib/web/development/components/Input/TextInput/TextInput.js +5 -1
- package/build/lib/web/development/components/Input/TextInput/TextInput.js.map +1 -1
- package/build/lib/web/development/components/List/ListItem.js +1 -1
- package/build/lib/web/development/components/List/ListItem.js.map +1 -1
- package/build/lib/web/development/components/Modal/Modal.web.js +6 -7
- package/build/lib/web/development/components/Modal/Modal.web.js.map +1 -1
- package/build/lib/web/development/components/Preview/Preview.web.js +8 -7
- package/build/lib/web/development/components/Preview/Preview.web.js.map +1 -1
- package/build/lib/web/development/components/QuickFilters/QuickFilter.js +9 -7
- package/build/lib/web/development/components/QuickFilters/QuickFilter.js.map +1 -1
- package/build/lib/web/development/components/SpotlightPopoverTour/TourFooter.web.js +12 -2
- package/build/lib/web/development/components/SpotlightPopoverTour/TourFooter.web.js.map +1 -1
- package/build/lib/web/development/components/Table/Table.web.js +6 -3
- package/build/lib/web/development/components/Table/Table.web.js.map +1 -1
- package/build/lib/web/development/components/Table/TableBody.web.js +5 -3
- package/build/lib/web/development/components/Table/TableBody.web.js.map +1 -1
- package/build/lib/web/development/components/Table/TableEditableCell.web.js +11 -8
- package/build/lib/web/development/components/Table/TableEditableCell.web.js.map +1 -1
- package/build/lib/web/development/components/Table/TableHeader.web.js +4 -2
- package/build/lib/web/development/components/Table/TableHeader.web.js.map +1 -1
- package/build/lib/web/development/components/Table/TablePagination.web.js +12 -6
- package/build/lib/web/development/components/Table/TablePagination.web.js.map +1 -1
- package/build/lib/web/development/components/Table/TableToolbar.web.js +5 -8
- package/build/lib/web/development/components/Table/TableToolbar.web.js.map +1 -1
- package/build/lib/web/development/components/Toast/Toast.web.js +2 -0
- package/build/lib/web/development/components/Toast/Toast.web.js.map +1 -1
- package/build/lib/web/development/utils/makeAnalyticsAttribute/index.js +1 -0
- package/build/lib/web/development/utils/makeAnalyticsAttribute/index.js.map +1 -1
- package/build/lib/web/development/utils/makeAnalyticsAttribute/makeAnalyticsConstants.js +32 -0
- package/build/lib/web/development/utils/makeAnalyticsAttribute/makeAnalyticsConstants.js.map +1 -0
- package/build/lib/web/production/components/Accordion/AccordionButton.web.js +5 -7
- package/build/lib/web/production/components/Accordion/AccordionButton.web.js.map +1 -1
- package/build/lib/web/production/components/Accordion/AccordionItem.js +7 -5
- package/build/lib/web/production/components/Accordion/AccordionItem.js.map +1 -1
- package/build/lib/web/production/components/Alert/Alert.js +2 -0
- package/build/lib/web/production/components/Alert/Alert.js.map +1 -1
- package/build/lib/web/production/components/Avatar/AvatarButton.js +3 -0
- package/build/lib/web/production/components/Avatar/AvatarButton.js.map +1 -1
- package/build/lib/web/production/components/Card/Card.js +4 -1
- package/build/lib/web/production/components/Card/Card.js.map +1 -1
- package/build/lib/web/production/components/Card/CardContext.js +11 -6
- package/build/lib/web/production/components/Card/CardContext.js.map +1 -1
- package/build/lib/web/production/components/Card/CardFooter.js +3 -0
- package/build/lib/web/production/components/Card/CardFooter.js.map +1 -1
- package/build/lib/web/production/components/Card/CardHeader.js +38 -44
- package/build/lib/web/production/components/Card/CardHeader.js.map +1 -1
- package/build/lib/web/production/components/Chip/Chip.js +5 -5
- package/build/lib/web/production/components/Chip/Chip.js.map +1 -1
- package/build/lib/web/production/components/DatePicker/BaseDatePicker.web.js +6 -2
- package/build/lib/web/production/components/DatePicker/BaseDatePicker.web.js.map +1 -1
- package/build/lib/web/production/components/DatePicker/Calendar.web.js +4 -2
- package/build/lib/web/production/components/DatePicker/Calendar.web.js.map +1 -1
- package/build/lib/web/production/components/DatePicker/CalendarFooter.web.js +4 -0
- package/build/lib/web/production/components/DatePicker/CalendarFooter.web.js.map +1 -1
- package/build/lib/web/production/components/DatePicker/DateInput.web.js +10 -4
- package/build/lib/web/production/components/DatePicker/DateInput.web.js.map +1 -1
- package/build/lib/web/production/components/DatePicker/QuickSelection/PresetSideBar.web.js +1 -0
- package/build/lib/web/production/components/DatePicker/QuickSelection/PresetSideBar.web.js.map +1 -1
- package/build/lib/web/production/components/DatePicker/QuickSelection/QuickSelectionItem.web.js +2 -1
- package/build/lib/web/production/components/DatePicker/QuickSelection/QuickSelectionItem.web.js.map +1 -1
- package/build/lib/web/production/components/FileUpload/FileUploadItem.js +3 -0
- package/build/lib/web/production/components/FileUpload/FileUploadItem.js.map +1 -1
- package/build/lib/web/production/components/Form/FormLabel.js +24 -4
- package/build/lib/web/production/components/Form/FormLabel.js.map +1 -1
- package/build/lib/web/production/components/Input/BaseInput/BaseInput.js +6 -2
- package/build/lib/web/production/components/Input/BaseInput/BaseInput.js.map +1 -1
- package/build/lib/web/production/components/Input/BaseInput/BaseInputVisuals.js +1 -1
- package/build/lib/web/production/components/Input/BaseInput/BaseInputVisuals.js.map +1 -1
- package/build/lib/web/production/components/Input/OTPInput/OTPInput.js +5 -1
- package/build/lib/web/production/components/Input/OTPInput/OTPInput.js.map +1 -1
- package/build/lib/web/production/components/Input/PasswordInput/PasswordInput.js +5 -1
- package/build/lib/web/production/components/Input/PasswordInput/PasswordInput.js.map +1 -1
- package/build/lib/web/production/components/Input/PhoneNumberInput/PhoneNumberInput.web.js +5 -1
- package/build/lib/web/production/components/Input/PhoneNumberInput/PhoneNumberInput.web.js.map +1 -1
- package/build/lib/web/production/components/Input/SearchInput/SearchInput.js +5 -1
- package/build/lib/web/production/components/Input/SearchInput/SearchInput.js.map +1 -1
- package/build/lib/web/production/components/Input/TextArea/TextArea.js +5 -1
- package/build/lib/web/production/components/Input/TextArea/TextArea.js.map +1 -1
- package/build/lib/web/production/components/Input/TextInput/TextInput.js +5 -1
- package/build/lib/web/production/components/Input/TextInput/TextInput.js.map +1 -1
- package/build/lib/web/production/components/List/ListItem.js +1 -1
- package/build/lib/web/production/components/List/ListItem.js.map +1 -1
- package/build/lib/web/production/components/Modal/Modal.web.js +6 -7
- package/build/lib/web/production/components/Modal/Modal.web.js.map +1 -1
- package/build/lib/web/production/components/Preview/Preview.web.js +8 -7
- package/build/lib/web/production/components/Preview/Preview.web.js.map +1 -1
- package/build/lib/web/production/components/QuickFilters/QuickFilter.js +9 -7
- package/build/lib/web/production/components/QuickFilters/QuickFilter.js.map +1 -1
- package/build/lib/web/production/components/SpotlightPopoverTour/TourFooter.web.js +12 -2
- package/build/lib/web/production/components/SpotlightPopoverTour/TourFooter.web.js.map +1 -1
- package/build/lib/web/production/components/Table/Table.web.js +6 -3
- package/build/lib/web/production/components/Table/Table.web.js.map +1 -1
- package/build/lib/web/production/components/Table/TableBody.web.js +5 -3
- package/build/lib/web/production/components/Table/TableBody.web.js.map +1 -1
- package/build/lib/web/production/components/Table/TableEditableCell.web.js +11 -8
- package/build/lib/web/production/components/Table/TableEditableCell.web.js.map +1 -1
- package/build/lib/web/production/components/Table/TableHeader.web.js +4 -2
- package/build/lib/web/production/components/Table/TableHeader.web.js.map +1 -1
- package/build/lib/web/production/components/Table/TablePagination.web.js +12 -6
- package/build/lib/web/production/components/Table/TablePagination.web.js.map +1 -1
- package/build/lib/web/production/components/Table/TableToolbar.web.js +5 -8
- package/build/lib/web/production/components/Table/TableToolbar.web.js.map +1 -1
- package/build/lib/web/production/components/Toast/Toast.web.js +2 -0
- package/build/lib/web/production/components/Toast/Toast.web.js.map +1 -1
- package/build/lib/web/production/utils/makeAnalyticsAttribute/index.js +1 -0
- package/build/lib/web/production/utils/makeAnalyticsAttribute/index.js.map +1 -1
- package/build/lib/web/production/utils/makeAnalyticsAttribute/makeAnalyticsConstants.js +32 -0
- package/build/lib/web/production/utils/makeAnalyticsAttribute/makeAnalyticsConstants.js.map +1 -0
- package/build/types/components/index.d.ts +44 -11
- package/build/types/components/index.native.d.ts +40 -9
- package/package.json +1 -1
|
@@ -35,7 +35,7 @@ import { jsx, jsxs } from 'react/jsx-runtime';
|
|
|
35
35
|
import { getOuterMotionRef, getInnerMotionRef } from '../../utils/getMotionRefs.js';
|
|
36
36
|
import { makeAnalyticsAttribute } from '../../utils/makeAnalyticsAttribute/makeAnalyticsAttribute.js';
|
|
37
37
|
|
|
38
|
-
var _excluded=["isDisabled","value","children","icon","color","testID","_motionMeta","width","maxWidth","minWidth"];var _Chip=function _Chip(_ref,ref){var _groupProps$state,_groupProps$defaultVa,_ref2;var isDisabled=_ref.isDisabled,value=_ref.value,children=_ref.children,Icon=_ref.icon,color=_ref.color,testID=_ref.testID,_motionMeta=_ref._motionMeta,width=_ref.width,maxWidth=_ref.maxWidth,minWidth=_ref.minWidth,rest=_objectWithoutProperties(_ref,_excluded);var _useTheme=useTheme(),theme=_useTheme.theme;var _useBreakpoint=useBreakpoint({breakpoints:theme.breakpoints}),matchedDeviceType=_useBreakpoint.matchedDeviceType;var groupProps=useChipGroupContext();var isInsideGroup=!isEmpty(groupProps);var _React$useState=React__default.useState(false),_React$useState2=_slicedToArray(_React$useState,2),isPressed=_React$useState2[0],setIsPressed=_React$useState2[1];if(__DEV__){if(!isInsideGroup){throwBladeError({moduleName:'Chip',message:'<Chip /> component should only be used within the context of a <ChipGroup /> component'});}}var hasError=(groupProps==null?void 0:groupProps.validationState)==='error';var _isDisabled=isDisabled!=null?isDisabled:groupProps==null?void 0:groupProps.isDisabled;var _isRequired=(groupProps==null?void 0:groupProps.isRequired)||(groupProps==null?void 0:groupProps.necessityIndicator)==='required';var _name=groupProps==null?void 0:groupProps.name;var _isChecked=groupProps==null?void 0:(_groupProps$state=groupProps.state)==null?void 0:_groupProps$state.isChecked(value);var defaultChecked=typeof(groupProps==null?void 0:groupProps.defaultValue)==='undefined'?undefined:groupProps==null?void 0:(_groupProps$defaultVa=groupProps.defaultValue)==null?void 0:_groupProps$defaultVa.includes(value);var useChip=(groupProps==null?void 0:groupProps.selectionType)==='single'?useRadio:useCheckbox;var _size=(groupProps==null?void 0:groupProps.size)||'small';var chipColor=(_ref2=color!=null?color:groupProps==null?void 0:groupProps.color)!=null?_ref2:'primary';var handleChange=function handleChange(_ref3){var isChecked=_ref3.isChecked,value=_ref3.value;if(isChecked){var _groupProps$state2;groupProps==null?void 0:(_groupProps$state2=groupProps.state)==null?void 0:_groupProps$state2.addValue(value);}else {var _groupProps$state3;groupProps==null?void 0:(_groupProps$state3=groupProps.state)==null?void 0:_groupProps$state3.removeValue(value);}};var _useChip=useChip({defaultChecked:defaultChecked,isChecked:_isChecked,isDisabled:_isDisabled,isRequired:_isRequired,hasError:hasError,name:_name,value:value,onChange:handleChange}),state=_useChip.state,inputProps=_useChip.inputProps;var handlePointerPressedIn=React__default.useCallback(function(){if(_isDisabled)return;setIsPressed(true);},[_isDisabled]);var handlePointerPressedOut=React__default.useCallback(function(){if(_isDisabled)return;setIsPressed(false);},[_isDisabled]);var handleKeyboardPressedIn=React__default.useCallback(function(e){if(_isDisabled)return;if(e.key===' '){setIsPressed(true);}},[_isDisabled]);var handleKeyboardPressedOut=React__default.useCallback(function(e){if(_isDisabled)return;if(e.key===' '){setIsPressed(false);}},[_isDisabled]);var textVariant='unchecked';if(_isChecked&&chipColor){textVariant=chipColor;}if(_isDisabled){textVariant='disabled';}var chipTextColor=chipColorTokens.text[textVariant];var chipIconColor=chipColorTokens.icon[textVariant];var colorVariant='unchecked';var stateVariant=_isDisabled?'disabled':'default';if(_isChecked&&chipColor){colorVariant=chipColor;}var chipBackgroundColor=chipColorTokens.background[colorVariant][stateVariant];var chipBorderColor=chipColorTokens.border[colorVariant][stateVariant];return jsx(BaseBox,Object.assign({},metaAttribute({name:MetaConstants.Chip,testID:testID}),getStyledProps(rest),
|
|
38
|
+
var _excluded=["isDisabled","value","children","icon","color","testID","_motionMeta","width","maxWidth","minWidth"];var _Chip=function _Chip(_ref,ref){var _groupProps$state,_groupProps$defaultVa,_ref2;var isDisabled=_ref.isDisabled,value=_ref.value,children=_ref.children,Icon=_ref.icon,color=_ref.color,testID=_ref.testID,_motionMeta=_ref._motionMeta,width=_ref.width,maxWidth=_ref.maxWidth,minWidth=_ref.minWidth,rest=_objectWithoutProperties(_ref,_excluded);var _useTheme=useTheme(),theme=_useTheme.theme;var _useBreakpoint=useBreakpoint({breakpoints:theme.breakpoints}),matchedDeviceType=_useBreakpoint.matchedDeviceType;var groupProps=useChipGroupContext();var isInsideGroup=!isEmpty(groupProps);var _React$useState=React__default.useState(false),_React$useState2=_slicedToArray(_React$useState,2),isPressed=_React$useState2[0],setIsPressed=_React$useState2[1];if(__DEV__){if(!isInsideGroup){throwBladeError({moduleName:'Chip',message:'<Chip /> component should only be used within the context of a <ChipGroup /> component'});}}var hasError=(groupProps==null?void 0:groupProps.validationState)==='error';var _isDisabled=isDisabled!=null?isDisabled:groupProps==null?void 0:groupProps.isDisabled;var _isRequired=(groupProps==null?void 0:groupProps.isRequired)||(groupProps==null?void 0:groupProps.necessityIndicator)==='required';var _name=groupProps==null?void 0:groupProps.name;var _isChecked=groupProps==null?void 0:(_groupProps$state=groupProps.state)==null?void 0:_groupProps$state.isChecked(value);var defaultChecked=typeof(groupProps==null?void 0:groupProps.defaultValue)==='undefined'?undefined:groupProps==null?void 0:(_groupProps$defaultVa=groupProps.defaultValue)==null?void 0:_groupProps$defaultVa.includes(value);var useChip=(groupProps==null?void 0:groupProps.selectionType)==='single'?useRadio:useCheckbox;var _size=(groupProps==null?void 0:groupProps.size)||'small';var chipColor=(_ref2=color!=null?color:groupProps==null?void 0:groupProps.color)!=null?_ref2:'primary';var handleChange=function handleChange(_ref3){var isChecked=_ref3.isChecked,value=_ref3.value;if(isChecked){var _groupProps$state2;groupProps==null?void 0:(_groupProps$state2=groupProps.state)==null?void 0:_groupProps$state2.addValue(value);}else {var _groupProps$state3;groupProps==null?void 0:(_groupProps$state3=groupProps.state)==null?void 0:_groupProps$state3.removeValue(value);}};var _useChip=useChip({defaultChecked:defaultChecked,isChecked:_isChecked,isDisabled:_isDisabled,isRequired:_isRequired,hasError:hasError,name:_name,value:value,onChange:handleChange}),state=_useChip.state,inputProps=_useChip.inputProps;var handlePointerPressedIn=React__default.useCallback(function(){if(_isDisabled)return;setIsPressed(true);},[_isDisabled]);var handlePointerPressedOut=React__default.useCallback(function(){if(_isDisabled)return;setIsPressed(false);},[_isDisabled]);var handleKeyboardPressedIn=React__default.useCallback(function(e){if(_isDisabled)return;if(e.key===' '){setIsPressed(true);}},[_isDisabled]);var handleKeyboardPressedOut=React__default.useCallback(function(e){if(_isDisabled)return;if(e.key===' '){setIsPressed(false);}},[_isDisabled]);var textVariant='unchecked';if(_isChecked&&chipColor){textVariant=chipColor;}if(_isDisabled){textVariant='disabled';}var chipTextColor=chipColorTokens.text[textVariant];var chipIconColor=chipColorTokens.icon[textVariant];var colorVariant='unchecked';var stateVariant=_isDisabled?'disabled':'default';if(_isChecked&&chipColor){colorVariant=chipColor;}var chipBackgroundColor=chipColorTokens.background[colorVariant][stateVariant];var chipBorderColor=chipColorTokens.border[colorVariant][stateVariant];return jsx(BaseBox,Object.assign({},metaAttribute({name:MetaConstants.Chip,testID:testID}),getStyledProps(rest),{display:isReactNative()?'flex':'inline-flex',ref:getOuterMotionRef({_motionMeta:_motionMeta,ref:ref}),width:width,maxWidth:maxWidth,minWidth:minWidth,children:jsx(SelectorLabel,{componentName:MetaConstants.ChipLabel,onTouchStart:handlePointerPressedIn,onTouchEnd:handlePointerPressedOut,onMouseDown:handlePointerPressedIn,onMouseUp:handlePointerPressedOut,onMouseOut:handlePointerPressedOut,onKeyDown:handleKeyboardPressedIn,onKeyUp:handleKeyboardPressedOut,inputProps:isReactNative()?inputProps:{},style:{cursor:_isDisabled?'not-allowed':'pointer',width:'100%'},children:jsx(BaseBox,{display:"flex",flexDirection:"column",width:"100%",children:jsxs(BaseBox,{display:"flex",alignItems:"center",flexDirection:"row",children:[jsx(SelectorInput,Object.assign({hoverTokens:getChipInputHoverTokens(chipColor),isChecked:state.isChecked,isDisabled:_isDisabled,inputProps:inputProps,hasError:hasError,ref:getInnerMotionRef({_motionMeta:_motionMeta,ref:ref})},makeAnalyticsAttribute(rest))),jsx(AnimatedChip,{borderColor:chipBorderColor,isDisabled:_isDisabled,isPressed:isPressed,isDesktop:matchedDeviceType==='desktop',children:jsxs(StyledChipWrapper,{borderColor:chipBorderColor,isChecked:_isChecked,isDisabled:_isDisabled,color:chipColor,display:"flex",flexDirection:"row",justifyContent:"center",alignItems:"center",overflow:"hidden",backgroundColor:chipBackgroundColor,borderRadius:"max",borderWidth:['xsmall','small'].includes(_size)?'thinner':'thin',paddingLeft:chipHorizontalPaddingTokens[Boolean(Icon)?'withIcon':'withoutIcon'].left[_size],paddingRight:chipHorizontalPaddingTokens[Boolean(Icon)?'withIcon':'withoutIcon'].right[_size],height:makeSize(chipHeightTokens[_size]),gap:"spacing.3",width:"100%",children:[Icon?jsx(BaseBox,{display:"flex",children:jsx(Icon,{color:chipIconColor,size:chipIconSizes[_size]})}):null,children?jsx(Text,Object.assign({},chipTextSizes[_size],{truncateAfterLines:1,color:chipTextColor,children:children})):null]})})]})})})}));};var Chip=assignWithoutSideEffects(React__default.forwardRef(_Chip),{displayName:'Chip'});
|
|
39
39
|
|
|
40
40
|
export { Chip };
|
|
41
41
|
//# sourceMappingURL=Chip.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chip.js","sources":["../../../../../src/components/Chip/Chip.tsx"],"sourcesContent":["import React from 'react';\nimport { useChipGroupContext } from './ChipGroupContext';\nimport {\n chipIconSizes,\n chipTextSizes,\n chipColorTokens,\n getChipInputHoverTokens,\n chipHeightTokens,\n chipHorizontalPaddingTokens,\n} from './chipTokens';\nimport type { ChipProps } from './types';\nimport { AnimatedChip } from './AnimatedChip';\nimport { StyledChipWrapper } from './StyledChipWrapper';\nimport isEmpty from '~utils/lodashButBetter/isEmpty';\nimport { metaAttribute, MetaConstants } from '~utils/metaAttribute';\nimport { getStyledProps } from '~components/Box/styledProps';\nimport BaseBox from '~components/Box/BaseBox';\nimport { SelectorLabel } from '~components/Form/Selector/SelectorLabel';\nimport { SelectorInput } from '~components/Form/Selector/SelectorInput';\nimport type { BladeElementRef } from '~utils/types';\nimport { assignWithoutSideEffects } from '~utils/assignWithoutSideEffects';\nimport { throwBladeError } from '~utils/logger';\nimport { useCheckbox } from '~components/Checkbox/useCheckbox';\nimport { useRadio } from '~components/Radio/useRadio';\nimport { isReactNative, makeSize, useBreakpoint } from '~utils';\nimport { Text } from '~components/Typography';\nimport { useTheme } from '~components/BladeProvider';\nimport { getInnerMotionRef, getOuterMotionRef } from '~utils/getMotionRefs';\nimport { makeAnalyticsAttribute } from '~utils/makeAnalyticsAttribute';\n\ntype OnChange = ({\n isChecked,\n event,\n value,\n}: {\n isChecked: boolean;\n event?: React.ChangeEvent;\n value?: string;\n}) => void;\n\nconst _Chip: React.ForwardRefRenderFunction<BladeElementRef, ChipProps> = (\n {\n isDisabled,\n value,\n children,\n icon: Icon,\n color,\n testID,\n _motionMeta,\n width,\n maxWidth,\n minWidth,\n ...rest\n },\n ref,\n) => {\n const { theme } = useTheme();\n const { matchedDeviceType } = useBreakpoint({ breakpoints: theme.breakpoints });\n const groupProps = useChipGroupContext();\n const isInsideGroup = !isEmpty(groupProps);\n const [isPressed, setIsPressed] = React.useState(false);\n\n if (__DEV__) {\n if (!isInsideGroup) {\n throwBladeError({\n moduleName: 'Chip',\n message:\n '<Chip /> component should only be used within the context of a <ChipGroup /> component',\n });\n }\n }\n\n const hasError = groupProps?.validationState === 'error';\n const _isDisabled = isDisabled ?? groupProps?.isDisabled;\n const _isRequired = groupProps?.isRequired || groupProps?.necessityIndicator === 'required';\n const _name = groupProps?.name;\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n const _isChecked = groupProps?.state?.isChecked(value!);\n // Check if the defaultValue property of groupProps is undefined\n const defaultChecked =\n typeof groupProps?.defaultValue === 'undefined'\n ? undefined // If undefined, defaultChecked is also undefined\n : groupProps?.defaultValue?.includes(value as string); // If multiple selection, check if value is in defaultValue array\n const useChip = groupProps?.selectionType === 'single' ? useRadio : useCheckbox;\n const _size = groupProps?.size || 'small';\n const chipColor = color ?? groupProps?.color ?? 'primary';\n const handleChange: OnChange = ({ isChecked, value }) => {\n if (isChecked) {\n groupProps?.state?.addValue(value!);\n } else {\n groupProps?.state?.removeValue(value!);\n }\n };\n\n const { state, inputProps } = useChip({\n defaultChecked,\n isChecked: _isChecked,\n isDisabled: _isDisabled,\n isRequired: _isRequired,\n hasError,\n name: _name,\n value,\n onChange: handleChange,\n });\n\n const handlePointerPressedIn = React.useCallback(() => {\n if (_isDisabled) return;\n setIsPressed(true);\n }, [_isDisabled]);\n\n const handlePointerPressedOut = React.useCallback(() => {\n if (_isDisabled) return;\n setIsPressed(false);\n }, [_isDisabled]);\n\n const handleKeyboardPressedIn = React.useCallback(\n (e: React.KeyboardEvent) => {\n if (_isDisabled) return;\n if (e.key === ' ') {\n setIsPressed(true);\n }\n },\n [_isDisabled],\n );\n\n const handleKeyboardPressedOut = React.useCallback(\n (e: React.KeyboardEvent) => {\n if (_isDisabled) return;\n if (e.key === ' ') {\n setIsPressed(false);\n }\n },\n [_isDisabled],\n );\n\n let textVariant = 'unchecked';\n if (_isChecked && chipColor) {\n textVariant = chipColor;\n }\n if (_isDisabled) {\n textVariant = 'disabled';\n }\n const chipTextColor = chipColorTokens.text[textVariant];\n const chipIconColor = chipColorTokens.icon[textVariant];\n\n let colorVariant = 'unchecked';\n const stateVariant = _isDisabled ? 'disabled' : 'default';\n if (_isChecked && chipColor) {\n colorVariant = chipColor;\n }\n const chipBackgroundColor = chipColorTokens.background[colorVariant][stateVariant];\n const chipBorderColor = chipColorTokens.border[colorVariant][stateVariant];\n\n return (\n <BaseBox\n {...metaAttribute({ name: MetaConstants.Chip, testID })}\n {...getStyledProps(rest)}\n {...makeAnalyticsAttribute(rest)}\n display={(isReactNative() ? 'flex' : 'inline-flex') as never}\n ref={getOuterMotionRef({ _motionMeta, ref })}\n width={width}\n maxWidth={maxWidth}\n minWidth={minWidth}\n >\n <SelectorLabel\n componentName={MetaConstants.ChipLabel}\n onTouchStart={handlePointerPressedIn}\n onTouchEnd={handlePointerPressedOut}\n onMouseDown={handlePointerPressedIn}\n onMouseUp={handlePointerPressedOut}\n onMouseOut={handlePointerPressedOut}\n onKeyDown={handleKeyboardPressedIn}\n onKeyUp={handleKeyboardPressedOut}\n inputProps={isReactNative() ? inputProps : {}}\n style={{\n cursor: _isDisabled ? 'not-allowed' : 'pointer',\n width: '100%',\n }}\n >\n <BaseBox display=\"flex\" flexDirection=\"column\" width=\"100%\">\n <BaseBox display=\"flex\" alignItems=\"center\" flexDirection=\"row\">\n <SelectorInput\n hoverTokens={getChipInputHoverTokens(chipColor)}\n isChecked={state.isChecked}\n isDisabled={_isDisabled}\n inputProps={inputProps}\n hasError={hasError}\n ref={getInnerMotionRef({ _motionMeta, ref })}\n />\n <AnimatedChip\n borderColor={chipBorderColor}\n isDisabled={_isDisabled}\n isPressed={isPressed}\n isDesktop={matchedDeviceType === 'desktop'}\n >\n <StyledChipWrapper\n borderColor={chipBorderColor}\n isChecked={_isChecked}\n isDisabled={_isDisabled}\n color={chipColor}\n display=\"flex\"\n flexDirection=\"row\"\n justifyContent=\"center\"\n alignItems=\"center\"\n overflow=\"hidden\"\n backgroundColor={chipBackgroundColor}\n borderRadius=\"max\"\n borderWidth={['xsmall', 'small'].includes(_size) ? 'thinner' : 'thin'}\n paddingLeft={\n chipHorizontalPaddingTokens[Boolean(Icon) ? 'withIcon' : 'withoutIcon'].left[\n _size\n ]\n }\n paddingRight={\n chipHorizontalPaddingTokens[Boolean(Icon) ? 'withIcon' : 'withoutIcon'].right[\n _size\n ]\n }\n height={makeSize(chipHeightTokens[_size])}\n gap=\"spacing.3\"\n width=\"100%\"\n >\n {Icon ? (\n <BaseBox display=\"flex\">\n <Icon color={chipIconColor} size={chipIconSizes[_size]} />\n </BaseBox>\n ) : null}\n {children ? (\n <Text {...chipTextSizes[_size]} truncateAfterLines={1} color={chipTextColor}>\n {children}\n </Text>\n ) : null}\n </StyledChipWrapper>\n </AnimatedChip>\n </BaseBox>\n </BaseBox>\n </SelectorLabel>\n </BaseBox>\n );\n};\n\nconst Chip = assignWithoutSideEffects(React.forwardRef(_Chip), {\n displayName: 'Chip',\n});\n\nexport { Chip };\nexport type { ChipProps };\n"],"names":["_Chip","_ref","ref","_groupProps$state","_groupProps$defaultVa","_ref2","isDisabled","value","children","Icon","icon","color","testID","_motionMeta","width","maxWidth","minWidth","rest","_objectWithoutProperties","_excluded","_useTheme","useTheme","theme","_useBreakpoint","useBreakpoint","breakpoints","matchedDeviceType","groupProps","useChipGroupContext","isInsideGroup","isEmpty","_React$useState","React","useState","_React$useState2","_slicedToArray","isPressed","setIsPressed","__DEV__","throwBladeError","moduleName","message","hasError","validationState","_isDisabled","_isRequired","isRequired","necessityIndicator","_name","name","_isChecked","state","isChecked","defaultChecked","defaultValue","undefined","includes","useChip","selectionType","useRadio","useCheckbox","_size","size","chipColor","handleChange","_ref3","_groupProps$state2","addValue","_groupProps$state3","removeValue","_useChip","onChange","inputProps","handlePointerPressedIn","useCallback","handlePointerPressedOut","handleKeyboardPressedIn","e","key","handleKeyboardPressedOut","textVariant","chipTextColor","chipColorTokens","text","chipIconColor","colorVariant","stateVariant","chipBackgroundColor","background","chipBorderColor","border","_jsx","BaseBox","Object","assign","metaAttribute","MetaConstants","Chip","getStyledProps","makeAnalyticsAttribute","display","isReactNative","getOuterMotionRef","SelectorLabel","componentName","ChipLabel","onTouchStart","onTouchEnd","onMouseDown","onMouseUp","onMouseOut","onKeyDown","onKeyUp","style","cursor","flexDirection","_jsxs","alignItems","SelectorInput","hoverTokens","getChipInputHoverTokens","getInnerMotionRef","AnimatedChip","borderColor","isDesktop","StyledChipWrapper","justifyContent","overflow","backgroundColor","borderRadius","borderWidth","paddingLeft","chipHorizontalPaddingTokens","Boolean","left","paddingRight","right","height","makeSize","chipHeightTokens","gap","chipIconSizes","Text","chipTextSizes","truncateAfterLines","assignWithoutSideEffects","forwardRef","displayName"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA,SAAA,CAAA,CAAA,YAAA,CAAA,OAAA,CAAA,UAAA,CAAA,MAAA,CAAA,OAAA,CAAA,QAAA,CAAA,aAAA,CAAA,OAAA,CAAA,UAAA,CAAA,UAAA,CAAA,CAwCA,IAAMA,KAAiE,CAAG,SAApEA,KAAiEA,CAAAC,IAAA,CAcrEC,GAAG,CACA,CAAAC,IAAAA,iBAAA,CAAAC,qBAAA,CAAAC,KAAA,CAAA,IAbDC,U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KAAK,CAAC,MAAM,CAAAN,QAAA,EAEXC,IAAI,CACHkF,GAAA,CAACC,OAAO,CAACQ,CAAAA,OAAO,CAAC,MAAM,CAAA5F,QAAA,CACrBmF,GAAA,CAAClF,IAAI,CAACE,CAAAA,KAAK,CAAEyE,aAAc,CAACtB,IAAI,CAAE+E,aAAa,CAAChF,KAAK,CAAE,CAAE,CAAC,CACnD,CAAC,CACR,IAAI,CACPrD,QAAQ,CACPmF,GAAA,CAACmD,IAAI,CAAAjD,MAAA,CAAAC,MAAA,CAAA,EAAA,CAAKiD,aAAa,CAAClF,KAAK,CAAC,CAAA,CAAEmF,kBAAkB,CAAE,CAAE,CAACrI,KAAK,CAAEsE,aAAc,CAAAzE,QAAA,CACzEA,QAAQ,CACL,CAAA,CAAC,CACL,IAAI,EACS,CAAC,CACR,CAAC,CAAA,CACR,CAAC,CACH,CAAC,CACG,CAAC,EACT,CAAC,CAEd,CAAC,CAEK,IAAAyF,IAAI,CAAGgD,wBAAwB,CAACjH,cAAK,CAACkH,UAAU,CAAClJ,KAAK,CAAC,CAAE,CAC7DmJ,WAAW,CAAE,MACf,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"Chip.js","sources":["../../../../../src/components/Chip/Chip.tsx"],"sourcesContent":["import React from 'react';\nimport { useChipGroupContext } from './ChipGroupContext';\nimport {\n chipIconSizes,\n chipTextSizes,\n chipColorTokens,\n getChipInputHoverTokens,\n chipHeightTokens,\n chipHorizontalPaddingTokens,\n} from './chipTokens';\nimport type { ChipProps } from './types';\nimport { AnimatedChip } from './AnimatedChip';\nimport { StyledChipWrapper } from './StyledChipWrapper';\nimport isEmpty from '~utils/lodashButBetter/isEmpty';\nimport { metaAttribute, MetaConstants } from '~utils/metaAttribute';\nimport { getStyledProps } from '~components/Box/styledProps';\nimport BaseBox from '~components/Box/BaseBox';\nimport { SelectorLabel } from '~components/Form/Selector/SelectorLabel';\nimport { SelectorInput } from '~components/Form/Selector/SelectorInput';\nimport type { BladeElementRef } from '~utils/types';\nimport { assignWithoutSideEffects } from '~utils/assignWithoutSideEffects';\nimport { throwBladeError } from '~utils/logger';\nimport { useCheckbox } from '~components/Checkbox/useCheckbox';\nimport { useRadio } from '~components/Radio/useRadio';\nimport { isReactNative, makeSize, useBreakpoint } from '~utils';\nimport { Text } from '~components/Typography';\nimport { useTheme } from '~components/BladeProvider';\nimport { getInnerMotionRef, getOuterMotionRef } from '~utils/getMotionRefs';\nimport { makeAnalyticsAttribute } from '~utils/makeAnalyticsAttribute';\n\ntype OnChange = ({\n isChecked,\n event,\n value,\n}: {\n isChecked: boolean;\n event?: React.ChangeEvent;\n value?: string;\n}) => void;\n\nconst _Chip: React.ForwardRefRenderFunction<BladeElementRef, ChipProps> = (\n {\n isDisabled,\n value,\n children,\n icon: Icon,\n color,\n testID,\n _motionMeta,\n width,\n maxWidth,\n minWidth,\n ...rest\n },\n ref,\n) => {\n const { theme } = useTheme();\n const { matchedDeviceType } = useBreakpoint({ breakpoints: theme.breakpoints });\n const groupProps = useChipGroupContext();\n const isInsideGroup = !isEmpty(groupProps);\n const [isPressed, setIsPressed] = React.useState(false);\n\n if (__DEV__) {\n if (!isInsideGroup) {\n throwBladeError({\n moduleName: 'Chip',\n message:\n '<Chip /> component should only be used within the context of a <ChipGroup /> component',\n });\n }\n }\n\n const hasError = groupProps?.validationState === 'error';\n const _isDisabled = isDisabled ?? groupProps?.isDisabled;\n const _isRequired = groupProps?.isRequired || groupProps?.necessityIndicator === 'required';\n const _name = groupProps?.name;\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n const _isChecked = groupProps?.state?.isChecked(value!);\n // Check if the defaultValue property of groupProps is undefined\n const defaultChecked =\n typeof groupProps?.defaultValue === 'undefined'\n ? undefined // If undefined, defaultChecked is also undefined\n : groupProps?.defaultValue?.includes(value as string); // If multiple selection, check if value is in defaultValue array\n const useChip = groupProps?.selectionType === 'single' ? useRadio : useCheckbox;\n const _size = groupProps?.size || 'small';\n const chipColor = color ?? groupProps?.color ?? 'primary';\n const handleChange: OnChange = ({ isChecked, value }) => {\n if (isChecked) {\n groupProps?.state?.addValue(value!);\n } else {\n groupProps?.state?.removeValue(value!);\n }\n };\n\n const { state, inputProps } = useChip({\n defaultChecked,\n isChecked: _isChecked,\n isDisabled: _isDisabled,\n isRequired: _isRequired,\n hasError,\n name: _name,\n value,\n onChange: handleChange,\n });\n\n const handlePointerPressedIn = React.useCallback(() => {\n if (_isDisabled) return;\n setIsPressed(true);\n }, [_isDisabled]);\n\n const handlePointerPressedOut = React.useCallback(() => {\n if (_isDisabled) return;\n setIsPressed(false);\n }, [_isDisabled]);\n\n const handleKeyboardPressedIn = React.useCallback(\n (e: React.KeyboardEvent) => {\n if (_isDisabled) return;\n if (e.key === ' ') {\n setIsPressed(true);\n }\n },\n [_isDisabled],\n );\n\n const handleKeyboardPressedOut = React.useCallback(\n (e: React.KeyboardEvent) => {\n if (_isDisabled) return;\n if (e.key === ' ') {\n setIsPressed(false);\n }\n },\n [_isDisabled],\n );\n\n let textVariant = 'unchecked';\n if (_isChecked && chipColor) {\n textVariant = chipColor;\n }\n if (_isDisabled) {\n textVariant = 'disabled';\n }\n const chipTextColor = chipColorTokens.text[textVariant];\n const chipIconColor = chipColorTokens.icon[textVariant];\n\n let colorVariant = 'unchecked';\n const stateVariant = _isDisabled ? 'disabled' : 'default';\n if (_isChecked && chipColor) {\n colorVariant = chipColor;\n }\n const chipBackgroundColor = chipColorTokens.background[colorVariant][stateVariant];\n const chipBorderColor = chipColorTokens.border[colorVariant][stateVariant];\n\n return (\n <BaseBox\n {...metaAttribute({ name: MetaConstants.Chip, testID })}\n {...getStyledProps(rest)}\n display={(isReactNative() ? 'flex' : 'inline-flex') as never}\n ref={getOuterMotionRef({ _motionMeta, ref })}\n width={width}\n maxWidth={maxWidth}\n minWidth={minWidth}\n >\n <SelectorLabel\n componentName={MetaConstants.ChipLabel}\n onTouchStart={handlePointerPressedIn}\n onTouchEnd={handlePointerPressedOut}\n onMouseDown={handlePointerPressedIn}\n onMouseUp={handlePointerPressedOut}\n onMouseOut={handlePointerPressedOut}\n onKeyDown={handleKeyboardPressedIn}\n onKeyUp={handleKeyboardPressedOut}\n inputProps={isReactNative() ? inputProps : {}}\n style={{\n cursor: _isDisabled ? 'not-allowed' : 'pointer',\n width: '100%',\n }}\n >\n <BaseBox display=\"flex\" flexDirection=\"column\" width=\"100%\">\n <BaseBox display=\"flex\" alignItems=\"center\" flexDirection=\"row\">\n <SelectorInput\n hoverTokens={getChipInputHoverTokens(chipColor)}\n isChecked={state.isChecked}\n isDisabled={_isDisabled}\n inputProps={inputProps}\n hasError={hasError}\n ref={getInnerMotionRef({ _motionMeta, ref })}\n {...makeAnalyticsAttribute(rest)}\n />\n <AnimatedChip\n borderColor={chipBorderColor}\n isDisabled={_isDisabled}\n isPressed={isPressed}\n isDesktop={matchedDeviceType === 'desktop'}\n >\n <StyledChipWrapper\n borderColor={chipBorderColor}\n isChecked={_isChecked}\n isDisabled={_isDisabled}\n color={chipColor}\n display=\"flex\"\n flexDirection=\"row\"\n justifyContent=\"center\"\n alignItems=\"center\"\n overflow=\"hidden\"\n backgroundColor={chipBackgroundColor}\n borderRadius=\"max\"\n borderWidth={['xsmall', 'small'].includes(_size) ? 'thinner' : 'thin'}\n paddingLeft={\n chipHorizontalPaddingTokens[Boolean(Icon) ? 'withIcon' : 'withoutIcon'].left[\n _size\n ]\n }\n paddingRight={\n chipHorizontalPaddingTokens[Boolean(Icon) ? 'withIcon' : 'withoutIcon'].right[\n _size\n ]\n }\n height={makeSize(chipHeightTokens[_size])}\n gap=\"spacing.3\"\n width=\"100%\"\n >\n {Icon ? (\n <BaseBox display=\"flex\">\n <Icon color={chipIconColor} size={chipIconSizes[_size]} />\n </BaseBox>\n ) : null}\n {children ? (\n <Text {...chipTextSizes[_size]} truncateAfterLines={1} color={chipTextColor}>\n {children}\n </Text>\n ) : null}\n </StyledChipWrapper>\n </AnimatedChip>\n </BaseBox>\n </BaseBox>\n </SelectorLabel>\n </BaseBox>\n );\n};\n\nconst Chip = assignWithoutSideEffects(React.forwardRef(_Chip), {\n displayName: 'Chip',\n});\n\nexport { Chip };\nexport type { ChipProps };\n"],"names":["_Chip","_ref","ref","_groupProps$state","_groupProps$defaultVa","_ref2","isDisabled","value","children","Icon","icon","color","testID","_motionMeta","width","maxWidth","minWidth","rest","_objectWithoutProperties","_excluded","_useTheme","useTheme","theme","_useBreakpoint","useBreakpoint","breakpoints","matchedDeviceType","groupProps","useChipGroupContext","isInsideGroup","isEmpty","_React$useState","React","useState","_React$useState2","_slicedToArray","isPressed","setIsPressed","__DEV__","throwBladeError","moduleName","message","hasError","validationState","_isDisabled","_isRequired","isRequired","necessityIndicator","_name","name","_isChecked","state","isChecked","defaultChecked","defaultValue","undefined","includes","useChip","selectionType","useRadio","useCheckbox","_size","size","chipColor","handleChange","_ref3","_groupProps$state2","addValue","_groupProps$state3","removeValue","_useChip","onChange","inputProps","handlePointerPressedIn","useCallback","handlePointerPressedOut","handleKeyboardPressedIn","e","key","handleKeyboardPressedOut","textVariant","chipTextColor","chipColorTokens","text","chipIconColor","colorVariant","stateVariant","chipBackgroundColor","background","chipBorderColor","border","_jsx","BaseBox","Object","assign","metaAttribute","MetaConstants","Chip","getStyledProps","display","isReactNative","getOuterMotionRef","SelectorLabel","componentName","ChipLabel","onTouchStart","onTouchEnd","onMouseDown","onMouseUp","onMouseOut","onKeyDown","onKeyUp","style","cursor","flexDirection","_jsxs","alignItems","SelectorInput","hoverTokens","getChipInputHoverTokens","getInnerMotionRef","makeAnalyticsAttribute","AnimatedChip","borderColor","isDesktop","StyledChipWrapper","justifyContent","overflow","backgroundColor","borderRadius","borderWidth","paddingLeft","chipHorizontalPaddingTokens","Boolean","left","paddingRight","right","height","makeSize","chipHeightTokens","gap","chipIconSizes","Text","chipTextSizes","truncateAfterLines","assignWithoutSideEffects","forwardRef","displayName"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA,SAAA,C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,aAAa,CAAC,CAAC6H,IAAI,CAC1EzE,KAAK,CAER,CACD0E,YAAY,CACVH,2BAA2B,CAACC,OAAO,CAAC5H,IAAI,CAAC,CAAG,UAAU,CAAG,aAAa,CAAC,CAAC+H,KAAK,CAC3E3E,KAAK,CAER,CACD4E,MAAM,CAAEC,QAAQ,CAACC,gBAAgB,CAAC9E,KAAK,CAAC,CAAE,CAC1C+E,GAAG,CAAC,WAAW,CACf9H,KAAK,CAAC,MAAM,CAAAN,QAAA,EAEXC,IAAI,CACHkF,GAAA,CAACC,OAAO,CAACO,CAAAA,OAAO,CAAC,MAAM,CAAA3F,QAAA,CACrBmF,GAAA,CAAClF,IAAI,CAACE,CAAAA,KAAK,CAAEyE,aAAc,CAACtB,IAAI,CAAE+E,aAAa,CAAChF,KAAK,CAAE,CAAE,CAAC,CACnD,CAAC,CACR,IAAI,CACPrD,QAAQ,CACPmF,GAAA,CAACmD,IAAI,CAAAjD,MAAA,CAAAC,MAAA,CAAA,EAAA,CAAKiD,aAAa,CAAClF,KAAK,CAAC,CAAA,CAAEmF,kBAAkB,CAAE,CAAE,CAACrI,KAAK,CAAEsE,aAAc,CAAAzE,QAAA,CACzEA,QAAQ,CACL,CAAA,CAAC,CACL,IAAI,EACS,CAAC,CACR,CAAC,CAAA,CACR,CAAC,CACH,CAAC,CACG,CAAC,EACT,CAAC,CAEd,CAAC,CAEK,IAAAyF,IAAI,CAAGgD,wBAAwB,CAACjH,cAAK,CAACkH,UAAU,CAAClJ,KAAK,CAAC,CAAE,CAC7DmJ,WAAW,CAAE,MACf,CAAC;;;;"}
|
|
@@ -25,7 +25,7 @@ import '../../tokens/global/motion.js';
|
|
|
25
25
|
import { size } from '../../tokens/global/size.js';
|
|
26
26
|
import getIn from '../../utils/lodashButBetter/get.js';
|
|
27
27
|
|
|
28
|
-
var FormLabel=function FormLabel(_ref){var _ref$as=_ref.as,as=_ref$as===void 0?'span':_ref$as,_ref$position=_ref.position,position=_ref$position===void 0?'top':_ref$position,_ref$necessityIndicat=_ref.necessityIndicator,necessityIndicator=_ref$necessityIndicat===void 0?'none':_ref$necessityIndicat,accessibilityText=_ref.accessibilityText,children=_ref.children,id=_ref.id,htmlFor=_ref.htmlFor,_ref$size=_ref.size,size$1=_ref$size===void 0?'medium':_ref$size;var _useTheme=useTheme(),theme=_useTheme.theme;var _useBreakpoint=useBreakpoint({breakpoints:theme.breakpoints}),matchedDeviceType=_useBreakpoint.matchedDeviceType;var isDesktop=matchedDeviceType==='desktop';var isReactNative=getPlatformType()==='react-native';var necessityLabel=null;var isLabelLeftPositioned=position==='left'&&isDesktop;if(necessityIndicator==='optional'){necessityLabel=jsx(Text,{variant:"caption",size:labelOptionalIndicatorTextSize[size$1],color:"surface.text.gray.muted",children:"(optional)"});}if(necessityIndicator==='required'){necessityLabel=jsx(Text,{variant:"body",size:isLabelLeftPositioned?'medium':'small',color:"feedback.text.negative.intense",alignSelf:"flex-start",children:"*"});}var computedAccessibilityNode=jsxs(VisuallyHidden,{children:[necessityIndicator!=='none'&&jsx(Text,{children:necessityIndicator}),jsx(Text,{children:accessibilityText})]});var textNode=jsxs(BaseBox,{gap:necessityIndicator==='optional'?'spacing.2':'spacing.0',display:"flex",flexDirection:"row",alignItems:"center",maxHeight:makeSpace(size[36]),children:[jsx(Text,{variant:"body",size:labelTextSize[isLabelLeftPositioned?'left':'top'][size$1],color:isLabelLeftPositioned?'surface.text.gray.subtle':'surface.text.gray.muted',truncateAfterLines:2,weight:"semibold",wordBreak:isLabelLeftPositioned?'break-word':undefined,children:children}),computedAccessibilityNode,necessityLabel]});if(isReactNative){return jsx(BaseBox,{marginRight:"spacing.5",marginBottom:"spacing.2",children:textNode});}var Component=as;var width=isLabelLeftPositioned&&isDesktop?makeSize(labelWidth[size$1]):'
|
|
28
|
+
var FormLabel=function FormLabel(_ref){var _ref$as=_ref.as,as=_ref$as===void 0?'span':_ref$as,_ref$position=_ref.position,position=_ref$position===void 0?'top':_ref$position,_ref$necessityIndicat=_ref.necessityIndicator,necessityIndicator=_ref$necessityIndicat===void 0?'none':_ref$necessityIndicat,accessibilityText=_ref.accessibilityText,children=_ref.children,id=_ref.id,htmlFor=_ref.htmlFor,_ref$size=_ref.size,size$1=_ref$size===void 0?'medium':_ref$size,labelSuffix=_ref.labelSuffix,labelTrailing=_ref.labelTrailing;var _useTheme=useTheme(),theme=_useTheme.theme;var _useBreakpoint=useBreakpoint({breakpoints:theme.breakpoints}),matchedDeviceType=_useBreakpoint.matchedDeviceType;var isDesktop=matchedDeviceType==='desktop';var isReactNative=getPlatformType()==='react-native';var necessityLabel=null;var isLabelLeftPositioned=position==='left'&&isDesktop;if(necessityIndicator==='optional'){necessityLabel=jsx(Text,{variant:"caption",size:labelOptionalIndicatorTextSize[size$1],color:"surface.text.gray.muted",children:"(optional)"});}if(necessityIndicator==='required'){necessityLabel=jsx(Text,{variant:"body",size:isLabelLeftPositioned?'medium':'small',color:"feedback.text.negative.intense",alignSelf:"flex-start",children:"*"});}var computedAccessibilityNode=jsxs(VisuallyHidden,{children:[necessityIndicator!=='none'&&jsx(Text,{children:necessityIndicator}),jsx(Text,{children:accessibilityText})]});var textNode=jsxs(BaseBox,{gap:necessityIndicator==='optional'?'spacing.2':'spacing.0',display:"flex",flexDirection:"row",alignItems:"center",maxHeight:makeSpace(size[36]),children:[jsx(Text,{variant:"body",size:labelTextSize[isLabelLeftPositioned?'left':'top'][size$1],color:isLabelLeftPositioned?'surface.text.gray.subtle':'surface.text.gray.muted',truncateAfterLines:2,weight:"semibold",wordBreak:isLabelLeftPositioned?'break-word':undefined,children:children}),computedAccessibilityNode,necessityLabel]});if(isReactNative){return jsx(BaseBox,{marginRight:"spacing.5",marginBottom:"spacing.2",children:textNode});}var Component=as;var width=isLabelLeftPositioned&&isDesktop?makeSize(labelWidth[size$1]):'100%';return jsx(Component,Object.assign({htmlFor:htmlFor,style:{width:width,flexShrink:0,marginRight:isLabelLeftPositioned?makeSpace(getIn(theme,labelLeftMarginRight[size$1])):makeSpace(getIn(theme,'spacing.0'))},id:id},metaAttribute({name:MetaConstants.FormLabel}),{children:jsxs(BaseBox,{width:"100%",display:"flex",flexDirection:isLabelLeftPositioned?'column':'row',alignItems:isLabelLeftPositioned?'flex-start':'center',marginBottom:isLabelLeftPositioned?'spacing.0':labelMarginBottom[size$1],children:[jsxs(BaseBox,{display:"flex",flexDirection:"row",alignItems:"center",gap:"spacing.2",children:[jsx(BaseBox,{children:textNode}),labelSuffix?jsx(BaseBox,{display:"flex",children:labelSuffix}):null]}),labelTrailing?jsx(BaseBox,{marginLeft:isLabelLeftPositioned?'spacing.0':'auto',children:labelTrailing}):null]})}));};
|
|
29
29
|
|
|
30
30
|
export { FormLabel };
|
|
31
31
|
//# sourceMappingURL=FormLabel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormLabel.js","sources":["../../../../../src/components/Form/FormLabel.tsx"],"sourcesContent":["import React from 'react';\nimport {\n labelLeftMarginRight,\n labelMarginBottom,\n labelOptionalIndicatorTextSize,\n labelTextSize,\n labelWidth,\n} from './formTokens';\nimport { VisuallyHidden } from '~components/VisuallyHidden';\nimport { Text } from '~components/Typography';\nimport { getPlatformType, makeSize, useBreakpoint } from '~utils';\nimport { metaAttribute, MetaConstants } from '~utils/metaAttribute';\nimport BaseBox from '~components/Box/BaseBox';\nimport { useTheme } from '~components/BladeProvider';\nimport { makeSpace } from '~utils/makeSpace';\nimport { size as sizeToken } from '~tokens/global';\nimport getIn from '~utils/lodashButBetter/get';\n\ntype CommonProps = {\n as: 'span' | 'label';\n position?: 'top' | 'left';\n necessityIndicator?: 'required' | 'optional' | 'none';\n accessibilityText?: string;\n children: string | undefined;\n id?: string;\n /**\n * Sets the size of the label\n * @default medium\n */\n size?: 'small' | 'medium' | 'large';\n};\n\ntype LabelProps = CommonProps & {\n htmlFor: string;\n as: 'label';\n};\n\ntype SpanProps = CommonProps & {\n as: 'span';\n htmlFor?: undefined;\n};\n\ntype FormLabelProps = LabelProps | SpanProps;\n\nexport type FormInputLabelProps = {\n /**\n * Label to be shown for the input field\n */\n label?: string;\n /**\n * Desktop only prop. Default value on mobile will be `top`\n */\n labelPosition?: 'left' | 'top';\n /**\n * Displays `(optional)` when `optional` is passed or `*` when `required` is passed\n */\n necessityIndicator?: 'required' | 'optional' | 'none';\n};\n\nconst FormLabel = ({\n as = 'span',\n position = 'top',\n necessityIndicator = 'none',\n accessibilityText,\n children,\n id,\n htmlFor,\n size = 'medium',\n}: FormLabelProps): React.ReactElement => {\n const { theme } = useTheme();\n const { matchedDeviceType } = useBreakpoint({ breakpoints: theme.breakpoints });\n const isDesktop = matchedDeviceType === 'desktop';\n const isReactNative = getPlatformType() === 'react-native';\n\n let necessityLabel: React.ReactNode = null;\n\n const isLabelLeftPositioned = position === 'left' && isDesktop;\n\n if (necessityIndicator === 'optional') {\n necessityLabel = (\n <Text\n variant=\"caption\"\n size={labelOptionalIndicatorTextSize[size]}\n color=\"surface.text.gray.muted\"\n >\n (optional)\n </Text>\n );\n }\n if (necessityIndicator === 'required') {\n necessityLabel = (\n <Text\n variant=\"body\"\n size={isLabelLeftPositioned ? 'medium' : 'small'}\n color=\"feedback.text.negative.intense\"\n alignSelf=\"flex-start\"\n >\n *\n </Text>\n );\n }\n\n const computedAccessibilityNode = (\n <VisuallyHidden>\n {necessityIndicator !== 'none' && <Text>{necessityIndicator}</Text>}\n <Text>{accessibilityText}</Text>\n </VisuallyHidden>\n );\n\n const textNode = (\n <BaseBox\n gap={necessityIndicator === 'optional' ? 'spacing.2' : 'spacing.0'}\n display=\"flex\"\n flexDirection=\"row\"\n alignItems=\"center\"\n // flexWrap=\"wrap\"\n maxHeight={makeSpace(sizeToken[36])}\n >\n <Text\n variant=\"body\"\n size={labelTextSize[isLabelLeftPositioned ? 'left' : 'top'][size]}\n color={isLabelLeftPositioned ? 'surface.text.gray.subtle' : 'surface.text.gray.muted'}\n truncateAfterLines={2}\n weight=\"semibold\"\n wordBreak={isLabelLeftPositioned ? 'break-word' : undefined}\n >\n {children}\n </Text>\n {computedAccessibilityNode}\n {/* TODO: Hide from screen readers to prevent double announcement */}\n {necessityLabel}\n </BaseBox>\n );\n\n // What harm can it do?\n if (isReactNative) {\n return (\n <BaseBox marginRight=\"spacing.5\" marginBottom=\"spacing.2\">\n {textNode}\n </BaseBox>\n );\n }\n\n const Component = as;\n // only set 120px label when device is desktop\n const width = isLabelLeftPositioned && isDesktop ? makeSize(labelWidth[size]) : 'auto';\n\n return (\n <Component\n htmlFor={htmlFor}\n style={{\n width,\n flexShrink: 0,\n marginRight: isLabelLeftPositioned\n ? makeSpace(getIn(theme, labelLeftMarginRight[size]))\n : makeSpace(getIn(theme, 'spacing.0')),\n }}\n id={id}\n {...metaAttribute({ name: MetaConstants.FormLabel })}\n >\n <BaseBox marginBottom={isLabelLeftPositioned ? 'spacing.0' : labelMarginBottom[size]}>\n {textNode}\n </BaseBox>\n </Component>\n );\n};\n\nexport { FormLabel };\n"],"names":["FormLabel","_ref","_ref$as","as","_ref$position","position","_ref$necessityIndicat","necessityIndicator","accessibilityText","children","id","htmlFor","_ref$size","size","_useTheme","useTheme","theme","_useBreakpoint","useBreakpoint","breakpoints","matchedDeviceType","isDesktop","isReactNative","getPlatformType","necessityLabel","isLabelLeftPositioned","_jsx","Text","variant","labelOptionalIndicatorTextSize","color","alignSelf","computedAccessibilityNode","_jsxs","VisuallyHidden","textNode","BaseBox","gap","display","flexDirection","alignItems","maxHeight","makeSpace","sizeToken","labelTextSize","truncateAfterLines","weight","wordBreak","undefined","marginRight","marginBottom","Component","width","makeSize","labelWidth","Object","assign","style","flexShrink","getIn","labelLeftMarginRight","metaAttribute","name","MetaConstants","labelMarginBottom"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DM,IAAAA,SAAS,CAAG,SAAZA,SAASA,CAAAC,IAAA,CAS2B,CAAA,IAAAC,OAAA,CAAAD,IAAA,CARxCE,EAAE,CAAFA,EAAE,CAAAD,OAAA,GAAG,KAAA,CAAA,CAAA,MA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AC,WAAW,CAAAzC,QAAA,CACtD0B,QAAQ,CACF,CAAC,CAEd,CAEA,IAAMgB,SAAS,CAAGhD,EAAE,CAEpB,IAAMiD,KAAK,CAAG3B,qBAAqB,EAAIJ,SAAS,CAAGgC,QAAQ,CAACC,UAAU,CAACzC,MAAI,CAAC,CAAC,CAAG,MAAM,CAEtF,OACEa,GAAA,CAACyB,SAAS,CAAAI,MAAA,CAAAC,MAAA,CACR7C,CAAAA,OAAO,CAAEA,OAAQ,CACjB8C,KAAK,CAAE,CACLL,KAAK,CAALA,KAAK,CACLM,UAAU,CAAE,CAAC,CACbT,WAAW,CAAExB,qBAAqB,CAC9BiB,SAAS,CAACiB,KAAK,CAAC3C,KAAK,CAAE4C,oBAAoB,CAAC/C,MAAI,CAAC,CAAC,CAAC,CACnD6B,SAAS,CAACiB,KAAK,CAAC3C,KAAK,CAAE,WAAW,CAAC,CACzC,CAAE,CACFN,EAAE,CAAEA,EAAG,CACHmD,CAAAA,aAAa,CAAC,CAAEC,IAAI,CAAEC,aAAa,CAAC/D,SAAU,CAAC,CAAC,EAAAS,QAAA,CAEpDiB,GAAA,CAACU,OAAO,CAAA,CAACc,YAAY,CAAEzB,qBAAqB,CAAG,WAAW,CAAGuC,iBAAiB,CAACnD,MAAI,CAAE,CAAAJ,QAAA,CAClF0B,QAAQ,CACF,CAAC,EACD,CAAC,CAEhB;;;;"}
|
|
1
|
+
{"version":3,"file":"FormLabel.js","sources":["../../../../../src/components/Form/FormLabel.tsx"],"sourcesContent":["import React from 'react';\nimport {\n labelLeftMarginRight,\n labelMarginBottom,\n labelOptionalIndicatorTextSize,\n labelTextSize,\n labelWidth,\n} from './formTokens';\nimport { VisuallyHidden } from '~components/VisuallyHidden';\nimport { Text } from '~components/Typography';\nimport { getPlatformType, makeSize, useBreakpoint } from '~utils';\nimport { metaAttribute, MetaConstants } from '~utils/metaAttribute';\nimport BaseBox from '~components/Box/BaseBox';\nimport { useTheme } from '~components/BladeProvider';\nimport { makeSpace } from '~utils/makeSpace';\nimport { size as sizeToken } from '~tokens/global';\nimport getIn from '~utils/lodashButBetter/get';\n\ntype CommonProps = {\n as: 'span' | 'label';\n position?: 'top' | 'left';\n necessityIndicator?: 'required' | 'optional' | 'none';\n accessibilityText?: string;\n children: string | undefined;\n id?: string;\n /**\n * Sets the size of the label\n * @default medium\n */\n size?: 'small' | 'medium' | 'large';\n labelSuffix?: React.ReactNode;\n labelTrailing?: React.ReactNode;\n};\n\ntype LabelProps = CommonProps & {\n htmlFor: string;\n as: 'label';\n};\n\ntype SpanProps = CommonProps & {\n as: 'span';\n htmlFor?: undefined;\n};\n\ntype FormLabelProps = LabelProps | SpanProps;\n\nexport type FormInputLabelProps = {\n /**\n * Label to be shown for the input field\n */\n label?: string;\n /**\n * Desktop only prop. Default value on mobile will be `top`\n */\n labelPosition?: 'left' | 'top';\n /**\n * Displays `(optional)` when `optional` is passed or `*` when `required` is passed\n */\n necessityIndicator?: 'required' | 'optional' | 'none';\n\n /**\n * Suffix element to be shown for the input field\n *\n * @example\n * ```jsx\n * labelSuffix={\n * <Tooltip content=\"This is a tooltip\" placement=\"right\">\n * <TooltipInteractiveWrapper>\n * <InfoIcon size=\"small\" color=\"surface.icon.gray.subtle\" />\n * </TooltipInteractiveWrapper>\n * </Tooltip>\n * }\n * ```\n */\n labelSuffix?: React.ReactNode;\n\n /**\n * Trailing element to be shown for the input field\n */\n labelTrailing?: React.ReactNode;\n};\n\nconst FormLabel = ({\n as = 'span',\n position = 'top',\n necessityIndicator = 'none',\n accessibilityText,\n children,\n id,\n htmlFor,\n size = 'medium',\n labelSuffix,\n labelTrailing,\n}: FormLabelProps): React.ReactElement => {\n const { theme } = useTheme();\n const { matchedDeviceType } = useBreakpoint({ breakpoints: theme.breakpoints });\n const isDesktop = matchedDeviceType === 'desktop';\n const isReactNative = getPlatformType() === 'react-native';\n\n let necessityLabel: React.ReactNode = null;\n\n const isLabelLeftPositioned = position === 'left' && isDesktop;\n\n if (necessityIndicator === 'optional') {\n necessityLabel = (\n <Text\n variant=\"caption\"\n size={labelOptionalIndicatorTextSize[size]}\n color=\"surface.text.gray.muted\"\n >\n (optional)\n </Text>\n );\n }\n if (necessityIndicator === 'required') {\n necessityLabel = (\n <Text\n variant=\"body\"\n size={isLabelLeftPositioned ? 'medium' : 'small'}\n color=\"feedback.text.negative.intense\"\n alignSelf=\"flex-start\"\n >\n *\n </Text>\n );\n }\n\n const computedAccessibilityNode = (\n <VisuallyHidden>\n {necessityIndicator !== 'none' && <Text>{necessityIndicator}</Text>}\n <Text>{accessibilityText}</Text>\n </VisuallyHidden>\n );\n\n const textNode = (\n <BaseBox\n gap={necessityIndicator === 'optional' ? 'spacing.2' : 'spacing.0'}\n display=\"flex\"\n flexDirection=\"row\"\n alignItems=\"center\"\n // flexWrap=\"wrap\"\n maxHeight={makeSpace(sizeToken[36])}\n >\n <Text\n variant=\"body\"\n size={labelTextSize[isLabelLeftPositioned ? 'left' : 'top'][size]}\n color={isLabelLeftPositioned ? 'surface.text.gray.subtle' : 'surface.text.gray.muted'}\n truncateAfterLines={2}\n weight=\"semibold\"\n wordBreak={isLabelLeftPositioned ? 'break-word' : undefined}\n >\n {children}\n </Text>\n {computedAccessibilityNode}\n {/* TODO: Hide from screen readers to prevent double announcement */}\n {necessityLabel}\n </BaseBox>\n );\n\n // What harm can it do?\n if (isReactNative) {\n return (\n <BaseBox marginRight=\"spacing.5\" marginBottom=\"spacing.2\">\n {textNode}\n </BaseBox>\n );\n }\n\n const Component = as;\n // only set 120px label when device is desktop\n const width = isLabelLeftPositioned && isDesktop ? makeSize(labelWidth[size]) : '100%';\n\n return (\n <Component\n htmlFor={htmlFor}\n style={{\n width,\n flexShrink: 0,\n marginRight: isLabelLeftPositioned\n ? makeSpace(getIn(theme, labelLeftMarginRight[size]))\n : makeSpace(getIn(theme, 'spacing.0')),\n }}\n id={id}\n {...metaAttribute({ name: MetaConstants.FormLabel })}\n >\n <BaseBox\n width=\"100%\"\n display=\"flex\"\n flexDirection={isLabelLeftPositioned ? 'column' : 'row'}\n alignItems={isLabelLeftPositioned ? 'flex-start' : 'center'}\n marginBottom={isLabelLeftPositioned ? 'spacing.0' : labelMarginBottom[size]}\n >\n <BaseBox display=\"flex\" flexDirection=\"row\" alignItems=\"center\" gap=\"spacing.2\">\n <BaseBox>{textNode}</BaseBox>\n {labelSuffix ? <BaseBox display=\"flex\">{labelSuffix}</BaseBox> : null}\n </BaseBox>\n {labelTrailing ? (\n <BaseBox marginLeft={isLabelLeftPositioned ? 'spacing.0' : 'auto'}>\n {labelTrailing}\n </BaseBox>\n ) : null}\n </BaseBox>\n </Component>\n );\n};\n\nexport { FormLabel };\n"],"names":["FormLabel","_ref","_ref$as","as","_ref$position","position","_ref$necessityIndicat","necessityIndicator","accessibilityText","children","id","htmlFor","_ref$size","size","labelSuffix","labelTrailing","_useTheme","useTheme","theme","_useBreakpoint","useBreakpoint","breakpoints","matchedDeviceType","isDesktop","isReactNative","getPlatformType","necessityLabel","isLabelLeftPositioned","_jsx","Text","variant","labelOptionalIndicatorTextSize","color","alignSelf","computedAccessibilityNode","_jsxs","VisuallyHidden","textNode","BaseBox","gap","display","flexDirection","alignItems","maxHeight","makeSpace","sizeToken","labelTextSize","truncateAfterLines","weight","wordBreak","undefined","marginRight","marginBottom","Component","width","makeSize","labelWidth","Object","assign","style","flexShrink","getIn","labelLeftMarginRight","metaAttribute","name","MetaConstants","labelMarginBottom","marginLeft"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFM,IAAAA,SAAS,CAAG,SAAZA,SAASA,CAAAC,IAAA,CAW2B,CAAA,IAAAC,OAAA,CAAAD,IAAA,CAVxCE,EAAE,CAAFA,EAAE,CAAAD,OAAA,GAAG,KAAA,CAAA,CAAA,MAAM,CAAAA,OAAA,CAAAE,aAAA,CAAAH,IAAA,CACXI,QAAQ,CAARA,QAAQ,CAAAD,aAAA,GAAA,KAAA,CAAA,CAAG,KAAK,CAAAA,aAAA,CAAAE,qBAAA,CAAAL,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AAa,CACZa,GAAA,CAACU,OAAO,CAAA,CAAC6B,UAAU,CAAExC,qBAAqB,CAAG,WAAW,CAAG,MAAO,CAAAlB,QAAA,CAC/DM,aAAa,CACP,CAAC,CACR,IAAI,CAAA,CACD,CAAC,CACD,CAAA,CAAC,CAEhB;;;;"}
|
|
@@ -41,7 +41,7 @@ import { getOuterMotionRef, getInnerMotionRef } from '../../../utils/getMotionRe
|
|
|
41
41
|
import { makeAnalyticsAttribute } from '../../../utils/makeAnalyticsAttribute/makeAnalyticsAttribute.js';
|
|
42
42
|
import { useInputGroupContext } from '../../InputGroup/InputGroupContext.js';
|
|
43
43
|
|
|
44
|
-
var _excluded=["as","label","labelPosition","placeholder","type","defaultValue","tags","showAllTags","activeTagIndex","setActiveTagIndex","name","value","onFocus","onChange","onInput","onBlur","onSubmit","onClick","onKeyDown","isDisabled","necessityIndicator","validationState","errorText","helpText","successText","isRequired","leadingIcon","prefix","trailingInteractionElement","onTrailingInteractionElementClick","leadingInteractionElement","suffix","trailingIcon","maxCharacters","textAlign","autoFocus","keyboardReturnKeyType","keyboardType","autoCompleteSuggestionType","trailingHeaderSlot","trailingFooterSlot","numberOfLines","id","componentName","accessibilityLabel","labelId","activeDescendant","hideLabelText","hideFormHint","hasPopup","popupId","isPopupExpanded","maxTagRows","shouldIgnoreBlurAnimation","setShouldIgnoreBlurAnimation","autoCapitalize","setInputWrapperRef","testID","isDropdownTrigger","isLabelInsideInput","size","trailingButton","valueComponentType","isTableInputCell","showHintsAsTooltip","_motionMeta","role","tabIndex","leadingDropDown","trailingDropDown"];var autoCompleteSuggestionTypeValues=['none','on','name','email','username','password','newPassword','oneTimeCode','telephone','postalCode','countryName','creditCardNumber','creditCardCSC','creditCardExpiry','creditCardExpiryMonth','creditCardExpiryYear'];var useTags=function useTags(tags,activeTagIndex,setActiveTagIndex){var visibleTagsCountRef=React__default.useRef(0);React__default.useEffect(function(){if(tags&&activeTagIndex>=0&&activeTagIndex<tags.length){var _tags$activeTagIndex,_tags$activeTagIndex$;var tagTitle=(_tags$activeTagIndex=tags[activeTagIndex])==null?void 0:(_tags$activeTagIndex$=_tags$activeTagIndex.props)==null?void 0:_tags$activeTagIndex$.children;if(tagTitle){announce(`Close ${tagTitle} Tag`);}}},[activeTagIndex,tags==null?void 0:tags.length]);var onTagLeft=function onTagLeft(){if(activeTagIndex<0){setActiveTagIndex==null?void 0:setActiveTagIndex(visibleTagsCountRef.current-1);}if(activeTagIndex>0){setActiveTagIndex==null?void 0:setActiveTagIndex(activeTagIndex-1);}};var onTagRight=function onTagRight(){if(activeTagIndex<visibleTagsCountRef.current-1){setActiveTagIndex==null?void 0:setActiveTagIndex(activeTagIndex+1);}};var onTagRemove=function onTagRemove(){if(activeTagIndex>=0&&activeTagIndex<visibleTagsCountRef.current&&tags){tags[activeTagIndex].props.onDismiss({tagIndex:activeTagIndex});}};var onInputKeydownTagHandler=function onInputKeydownTagHandler(key){if(tags&&tags.length>0){if(key==='ArrowRight'){onTagRight();}if(key==='ArrowLeft'){onTagLeft();}if(key==='Backspace'){onTagRemove();}}};return {onInputKeydownTagHandler:onInputKeydownTagHandler,visibleTagsCountRef:visibleTagsCountRef};};var useInput=function useInput(_ref){var value=_ref.value,defaultValue=_ref.defaultValue,onClick=_ref.onClick,onFocus=_ref.onFocus,onChange=_ref.onChange,onBlur=_ref.onBlur,onSubmit=_ref.onSubmit,onInput=_ref.onInput,onKeyDown=_ref.onKeyDown,onInputKeydownTagHandler=_ref.onInputKeydownTagHandler;if(__DEV__){if(value&&defaultValue){throwBladeError({message:`Either 'value' or 'defaultValue' shall be passed. This decides if the input field is controlled or uncontrolled`,moduleName:'Input'});}}var _React$useState=React__default.useState(defaultValue!=null?defaultValue:value),_React$useState2=_slicedToArray(_React$useState,2),inputValue=_React$useState2[0],setInputValue=_React$useState2[1];var handleOnFocus=React__default.useCallback(function(_ref2){var name=_ref2.name,value=_ref2.value;var _value='';if(getPlatformType()==='react-native'&&typeof value==='string'){_value=value;}else if(typeof value!=='string'){var _value$target$value;_value=(_value$target$value=value==null?void 0:value.target.value)!=null?_value$target$value:'';}onFocus==null?void 0:onFocus({name:name,value:_value});},[onFocus]);var handleOnClick=React__default.useCallback(function(_ref3){var name=_ref3.name,value=_ref3.value;var _value='';if(getPlatformType()==='react-native'&&typeof value==='string'){_value=value;}else if(typeof value!=='string'){var _value$currentTarget$;_value=(_value$currentTarget$=value==null?void 0:value.currentTarget.value)!=null?_value$currentTarget$:'';}onClick==null?void 0:onClick({name:name,value:_value});},[onClick]);var handleOnSubmit=React__default.useCallback(function(_ref4){var name=_ref4.name,value=_ref4.value;var _value='';if(getPlatformType()==='react-native'&&typeof value==='string'){_value=value;}else if(typeof value!=='string'){var _value$target$value2;_value=(_value$target$value2=value==null?void 0:value.target.value)!=null?_value$target$value2:'';}if(isReactNative()){onSubmit==null?void 0:onSubmit({name:name,value:_value});}},[onSubmit]);var handleOnBlur=React__default.useCallback(function(_ref5){var name=_ref5.name,value=_ref5.value;var _value='';if(getPlatformType()==='react-native'&&typeof value=='string'){_value=value;}else if(typeof value!=='string'){var _value$target$value3;_value=(_value$target$value3=value==null?void 0:value.target.value)!=null?_value$target$value3:'';}onBlur==null?void 0:onBlur({name:name,value:_value});},[onBlur]);var handleOnChange=React__default.useCallback(function(_ref6){var name=_ref6.name,value=_ref6.value;var _value='';if(getPlatformType()==='react-native'&&typeof value==='string'){_value=value;}else if(typeof value!=='string'){var _value$target$value4;_value=(_value$target$value4=value==null?void 0:value.target.value)!=null?_value$target$value4:'';}onChange==null?void 0:onChange({name:name,value:_value});setInputValue(_value);},[onChange]);var handleOnInput=React__default.useCallback(function(_ref7){var name=_ref7.name,value=_ref7.value;var _value='';if(getPlatformType()==='react-native'&&typeof value=='string'){_value=value;}else if(typeof value!=='string'){var _value$target$value5;_value=(_value$target$value5=value==null?void 0:value.target.value)!=null?_value$target$value5:'';}onInput==null?void 0:onInput({name:name,value:_value});},[onInput]);var handleOnKeyDown=React__default.useCallback(function(_ref8){var name=_ref8.name,key=_ref8.key,code=_ref8.code,event=_ref8.event;onInputKeydownTagHandler(key);onKeyDown==null?void 0:onKeyDown({name:name,key:key,code:code,event:event});},[onKeyDown]);return {handleOnFocus:handleOnFocus,handleOnClick:handleOnClick,handleOnChange:handleOnChange,handleOnBlur:handleOnBlur,handleOnSubmit:handleOnSubmit,handleOnInput:handleOnInput,handleOnKeyDown:handleOnKeyDown,inputValue:inputValue};};var getHintType=function getHintType(_ref9){var validationState=_ref9.validationState,hasHelpText=_ref9.hasHelpText;if(validationState==='error'){return 'error';}if(validationState==='success'){return 'success';}if(hasHelpText){return 'help';}return 'help';};var getDescribedByElementId=function getDescribedByElementId(_ref10){var validationState=_ref10.validationState,hasErrorText=_ref10.hasErrorText,hasSuccessText=_ref10.hasSuccessText,hasHelpText=_ref10.hasHelpText,errorTextId=_ref10.errorTextId,successTextId=_ref10.successTextId,helpTextId=_ref10.helpTextId;if(validationState==='error'&&hasErrorText){return errorTextId;}if(validationState==='success'&&hasSuccessText){return successTextId;}if(hasHelpText){return helpTextId;}return '';};var FocusRingWrapper=styled(BaseBox)(function(_ref11){var theme=_ref11.theme,currentInteraction=_ref11.currentInteraction,isTableInputCell=_ref11.isTableInputCell;return {borderRadius:makeBorderSize(isTableInputCell?theme.border.radius.none:theme.border.radius.medium),width:'100%','&:focus-within':!isTableInputCell?Object.assign({},getFocusRingStyles(),{transitionDuration:castWebType(makeMotionTime(getIn(theme.motion.duration,baseInputBorderBackgroundMotion[currentInteraction==='focus'?'enter':'exit'].duration))),transitionTimingFunction:castWebType(theme.motion.easing[baseInputBorderBackgroundMotion[currentInteraction==='focus'?'enter':'exit'].easing])}):{}};});var _BaseInput=function _BaseInput(_ref12,ref){var _inputGroupProps$isDi,_inputGroupProps$size;var _ref12$as=_ref12.as,as=_ref12$as===void 0?'input':_ref12$as,label=_ref12.label,_ref12$labelPosition=_ref12.labelPosition,labelPosition=_ref12$labelPosition===void 0?'top':_ref12$labelPosition,placeholder=_ref12.placeholder,_ref12$type=_ref12.type,type=_ref12$type===void 0?'text':_ref12$type,defaultValue=_ref12.defaultValue,tags=_ref12.tags,_ref12$showAllTags=_ref12.showAllTags,showAllTags=_ref12$showAllTags===void 0?false:_ref12$showAllTags,_ref12$activeTagIndex=_ref12.activeTagIndex,activeTagIndex=_ref12$activeTagIndex===void 0?-1:_ref12$activeTagIndex,setActiveTagIndex=_ref12.setActiveTagIndex,name=_ref12.name,value=_ref12.value,onFocus=_ref12.onFocus,onChange=_ref12.onChange,onInput=_ref12.onInput,onBlur=_ref12.onBlur,onSubmit=_ref12.onSubmit,onClick=_ref12.onClick,onKeyDown=_ref12.onKeyDown,isDisabled=_ref12.isDisabled,necessityIndicator=_ref12.necessityIndicator,validationState=_ref12.validationState,errorText=_ref12.errorText,helpText=_ref12.helpText,successText=_ref12.successText,isRequired=_ref12.isRequired,leadingIcon=_ref12.leadingIcon,prefix=_ref12.prefix,trailingInteractionElement=_ref12.trailingInteractionElement,onTrailingInteractionElementClick=_ref12.onTrailingInteractionElementClick,leadingInteractionElement=_ref12.leadingInteractionElement,suffix=_ref12.suffix,trailingIcon=_ref12.trailingIcon,maxCharacters=_ref12.maxCharacters,textAlign=_ref12.textAlign,autoFocus=_ref12.autoFocus,keyboardReturnKeyType=_ref12.keyboardReturnKeyType,keyboardType=_ref12.keyboardType,autoCompleteSuggestionType=_ref12.autoCompleteSuggestionType,trailingHeaderSlot=_ref12.trailingHeaderSlot,trailingFooterSlot=_ref12.trailingFooterSlot,numberOfLines=_ref12.numberOfLines,id=_ref12.id,componentName=_ref12.componentName,accessibilityLabel=_ref12.accessibilityLabel,labelId=_ref12.labelId,activeDescendant=_ref12.activeDescendant,hideLabelText=_ref12.hideLabelText,hideFormHint=_ref12.hideFormHint,hasPopup=_ref12.hasPopup,popupId=_ref12.popupId,isPopupExpanded=_ref12.isPopupExpanded,maxTagRows=_ref12.maxTagRows,shouldIgnoreBlurAnimation=_ref12.shouldIgnoreBlurAnimation,setShouldIgnoreBlurAnimation=_ref12.setShouldIgnoreBlurAnimation,autoCapitalize=_ref12.autoCapitalize,setInputWrapperRef=_ref12.setInputWrapperRef,testID=_ref12.testID,isDropdownTrigger=_ref12.isDropdownTrigger,isLabelInsideInput=_ref12.isLabelInsideInput,_ref12$size=_ref12.size,size=_ref12$size===void 0?'medium':_ref12$size,trailingButton=_ref12.trailingButton,_ref12$valueComponent=_ref12.valueComponentType,valueComponentType=_ref12$valueComponent===void 0?'text':_ref12$valueComponent,_ref12$isTableInputCe=_ref12.isTableInputCell,isTableInputCell=_ref12$isTableInputCe===void 0?false:_ref12$isTableInputCe,_ref12$showHintsAsToo=_ref12.showHintsAsTooltip,showHintsAsTooltip=_ref12$showHintsAsToo===void 0?false:_ref12$showHintsAsToo,_motionMeta=_ref12._motionMeta,role=_ref12.role,tabIndex=_ref12.tabIndex,leadingDropDown=_ref12.leadingDropDown,trailingDropDown=_ref12.trailingDropDown,rest=_objectWithoutProperties(_ref12,_excluded);var _useTheme=useTheme(),theme=_useTheme.theme;var inputRef=React__default.useRef(null);var mergedInputRef=useMergeRefs(ref,inputRef);var inputWrapperRef=React__default.useRef(null);var _useTags=useTags(tags,activeTagIndex,setActiveTagIndex),onInputKeydownTagHandler=_useTags.onInputKeydownTagHandler,visibleTagsCountRef=_useTags.visibleTagsCountRef;var _React$useState3=React__default.useState(false),_React$useState4=_slicedToArray(_React$useState3,2),showAllTagsWithAnimation=_React$useState4[0],setShowAllTagsWithAnimation=_React$useState4[1];var isReactNative=getPlatformType()==='react-native';var defaultRole=hasPopup?'combobox':undefined;var inputGroupProps=useInputGroupContext();var isInsideInputGroup=inputGroupProps.isInsideInputGroup;var _isDisabled=(_inputGroupProps$isDi=inputGroupProps.isDisabled)!=null?_inputGroupProps$isDi:isDisabled;var _size=(_inputGroupProps$size=inputGroupProps.size)!=null?_inputGroupProps$size:size;React__default.useEffect(function(){if(showAllTags){setShowAllTagsWithAnimation(true);}else if(maxTagRows!=='expandable'){setShowAllTagsWithAnimation(false);}},[showAllTags,maxTagRows]);var _useInput=useInput({defaultValue:defaultValue,value:value,onFocus:onFocus,onClick:onClick,onChange:onChange,onBlur:onBlur,onSubmit:onSubmit,onInput:onInput,onKeyDown:onKeyDown,onInputKeydownTagHandler:onInputKeydownTagHandler}),handleOnFocus=_useInput.handleOnFocus,handleOnChange=_useInput.handleOnChange,handleOnClick=_useInput.handleOnClick,handleOnBlur=_useInput.handleOnBlur,handleOnSubmit=_useInput.handleOnSubmit,handleOnInput=_useInput.handleOnInput,handleOnKeyDown=_useInput.handleOnKeyDown,inputValue=_useInput.inputValue;var _useFormId=useFormId(id),inputId=_useFormId.inputId,helpTextId=_useFormId.helpTextId,errorTextId=_useFormId.errorTextId,successTextId=_useFormId.successTextId;var _useBreakpoint=useBreakpoint({breakpoints:theme.breakpoints}),matchedDeviceType=_useBreakpoint.matchedDeviceType;var isLabelLeftPositioned=labelPosition==='left'&&matchedDeviceType==='desktop';var _useInteraction=useInteraction(),currentInteraction=_useInteraction.currentInteraction,setCurrentInteraction=_useInteraction.setCurrentInteraction;var _isRequired=isRequired||necessityIndicator==='required';var accessibilityProps=makeAccessible({required:Boolean(_isRequired),disabled:Boolean(_isDisabled),invalid:Boolean(validationState==='error'),describedBy:getDescribedByElementId({validationState:validationState,hasErrorText:Boolean(errorText),hasSuccessText:Boolean(successText),hasHelpText:Boolean(helpText),errorTextId:errorTextId,successTextId:successTextId,helpTextId:helpTextId}),label:accessibilityLabel,hasPopup:hasPopup,expanded:hasPopup?isPopupExpanded:undefined,controls:hasPopup?popupId:undefined,role:role!=null?role:defaultRole,activeDescendant:activeDescendant});var willRenderHintText=Boolean(helpText)||validationState==='success'&&Boolean(successText)||validationState==='error'&&Boolean(errorText);if(__DEV__){if(autoCompleteSuggestionType&&!autoCompleteSuggestionTypeValues.includes(autoCompleteSuggestionType)){throwBladeError({message:`Expected autoCompleteSuggestionType to be one of ${autoCompleteSuggestionTypeValues.join(', ')} but received ${autoCompleteSuggestionType}`,moduleName:'Input'});}}var isTextArea=as==='textarea';return jsxs(BaseBox,Object.assign({ref:getOuterMotionRef({_motionMeta:_motionMeta,ref:ref})},metaAttribute({name:componentName,testID:testID}),getStyledProps(rest),{children:[jsxs(BaseBox,{display:"flex",flexDirection:isLabelLeftPositioned?'row':'column',justifyContent:isLabelLeftPositioned?'center':undefined,alignItems:isLabelLeftPositioned?'center':undefined,position:"relative",width:"100%",children:[!hideLabelText&&!isLabelInsideInput&&label&&!isInsideInputGroup&&jsxs(BaseBox,{display:"flex",flexDirection:isLabelLeftPositioned?'column':'row',justifyContent:"space-between",alignSelf:isTextArea?'flex-start':undefined,marginY:isTextArea&&isLabelLeftPositioned?'spacing.3':'spacing.0',children:[jsx(FormLabel,{as:"label",necessityIndicator:necessityIndicator,position:labelPosition,id:labelId,htmlFor:inputId,size:_size,children:label}),trailingHeaderSlot==null?void 0:trailingHeaderSlot(value!=null?value:inputValue)]}),jsx(FocusRingWrapper,{currentInteraction:currentInteraction,isTableInputCell:isTableInputCell,className:"focus-ring-wrapper",children:jsxs(BaseInputWrapper,{isDropdownTrigger:isDropdownTrigger,isTextArea:isTextArea,isDisabled:_isDisabled,validationState:validationState,currentInteraction:currentInteraction,isLabelLeftPositioned:isLabelLeftPositioned,showAllTags:showAllTags,setShowAllTagsWithAnimation:setShowAllTagsWithAnimation,ref:function ref(refNode){if(refNode){setInputWrapperRef==null?void 0:setInputWrapperRef(refNode);inputWrapperRef.current=refNode;}},maxTagRows:maxTagRows,size:_size,numberOfLines:numberOfLines,onClick:function onClick(){if(!isReactNative){var _inputRef$current;(_inputRef$current=inputRef.current)==null?void 0:_inputRef$current.focus();}},isTableInputCell:isTableInputCell,children:[jsx(BaseInputVisuals,{size:_size,leadingIcon:leadingIcon,prefix:prefix,isDisabled:_isDisabled,leadingInteractionElement:leadingInteractionElement,leadingDropDown:leadingDropDown}),jsx(BaseInputTagSlot,{renderAs:as,tags:tags,isDisabled:_isDisabled,showAllTags:showAllTagsWithAnimation,setFocusOnInput:function setFocusOnInput(){var innerRef=getInnerMotionRef({_motionMeta:_motionMeta,ref:ref});if(innerRef&&!isReactNative&&'current'in innerRef){var _innerRef$current;(_innerRef$current=innerRef.current)==null?void 0:_innerRef$current.focus();}},labelPrefix:isLabelInsideInput?label:undefined,isDropdownTrigger:isDropdownTrigger,visibleTagsCountRef:visibleTagsCountRef,handleOnInputClick:function handleOnInputClick(e){handleOnClick({name:name,value:isReactNative?value:e});},setShouldIgnoreBlurAnimation:setShouldIgnoreBlurAnimation,maxTagRows:maxTagRows,inputWrapperRef:inputWrapperRef,size:_size,numberOfLines:numberOfLines,isTextArea:isTextArea,hasLeadingDropDown:Boolean(leadingDropDown),children:jsx(StyledBaseInput,Object.assign({as:as,id:inputId,ref:getInnerMotionRef({_motionMeta:_motionMeta,ref:mergedInputRef}),name:name,type:type,defaultValue:defaultValue,value:value,placeholder:placeholder,isDisabled:_isDisabled,validationState:validationState,isRequired:_isRequired,handleOnFocus:handleOnFocus,handleOnChange:handleOnChange,handleOnBlur:handleOnBlur,handleOnSubmit:handleOnSubmit,handleOnInput:handleOnInput,handleOnKeyDown:handleOnKeyDown,handleOnClick:handleOnClick,leadingIcon:leadingIcon,prefix:prefix,trailingInteractionElement:trailingInteractionElement,leadingInteractionElement:leadingInteractionElement,suffix:suffix,trailingIcon:trailingIcon,maxCharacters:maxCharacters,textAlign:textAlign,autoFocus:autoFocus,keyboardReturnKeyType:keyboardReturnKeyType,keyboardType:keyboardType,autoCompleteSuggestionType:autoCompleteSuggestionType,accessibilityProps:accessibilityProps,currentInteraction:currentInteraction,setCurrentInteraction:setCurrentInteraction,numberOfLines:numberOfLines,isTextArea:isTextArea||maxTagRows==='multiple'||maxTagRows==='expandable',hasPopup:hasPopup,hasTags:!!(tags&&tags.length>0),shouldIgnoreBlurAnimation:shouldIgnoreBlurAnimation,autoCapitalize:autoCapitalize,isDropdownTrigger:isDropdownTrigger,$size:_size,valueComponentType:valueComponentType,isTableInputCell:isTableInputCell,tabIndex:tabIndex,hasLeadingDropdown:Boolean(leadingDropDown)},metaAttribute({name:MetaConstants.StyledBaseInput}),makeAnalyticsAttribute(rest)))}),jsx(BaseInputVisuals,{trailingInteractionElement:trailingInteractionElement,onTrailingInteractionElementClick:onTrailingInteractionElementClick,suffix:suffix,trailingIcon:trailingIcon,isDisabled:_isDisabled,validationState:validationState,trailingButton:trailingButton,size:_size,errorText:errorText,successText:successText,showHintsAsTooltip:showHintsAsTooltip,trailingDropDown:trailingDropDown})]})})]}),hideFormHint||showHintsAsTooltip||isInsideInputGroup?null:jsx(BaseBox,{marginLeft:makeSize(isLabelLeftPositioned&&!hideLabelText?formHintLeftLabelMarginLeft[_size]:0),children:jsxs(BaseBox,{display:"flex",flexDirection:"row",justifyContent:willRenderHintText?'space-between':'flex-end',children:[jsx(FormHint,{type:getHintType({validationState:validationState,hasHelpText:Boolean(helpText)}),helpText:helpText,errorText:errorText,successText:successText,helpTextId:helpTextId,errorTextId:errorTextId,successTextId:successTextId,size:_size}),trailingFooterSlot==null?void 0:trailingFooterSlot(value!=null?value:inputValue)]})})]}));};var BaseInputWithRef=React__default.forwardRef(_BaseInput);var BaseInput=assignWithoutSideEffects(BaseInputWithRef,{displayName:'BaseInput'});
|
|
44
|
+
var _excluded=["as","label","labelPosition","placeholder","type","defaultValue","tags","showAllTags","activeTagIndex","setActiveTagIndex","name","value","onFocus","onChange","onInput","onBlur","onSubmit","onClick","onKeyDown","isDisabled","necessityIndicator","validationState","errorText","helpText","successText","isRequired","leadingIcon","prefix","trailingInteractionElement","onTrailingInteractionElementClick","leadingInteractionElement","suffix","trailingIcon","maxCharacters","textAlign","autoFocus","keyboardReturnKeyType","keyboardType","autoCompleteSuggestionType","trailingHeaderSlot","trailingFooterSlot","numberOfLines","id","componentName","accessibilityLabel","labelId","activeDescendant","hideLabelText","hideFormHint","hasPopup","popupId","isPopupExpanded","maxTagRows","shouldIgnoreBlurAnimation","setShouldIgnoreBlurAnimation","autoCapitalize","setInputWrapperRef","testID","isDropdownTrigger","isLabelInsideInput","size","trailingButton","valueComponentType","isTableInputCell","showHintsAsTooltip","_motionMeta","role","tabIndex","leadingDropDown","trailingDropDown","labelSuffix","labelTrailing"];var autoCompleteSuggestionTypeValues=['none','on','name','email','username','password','newPassword','oneTimeCode','telephone','postalCode','countryName','creditCardNumber','creditCardCSC','creditCardExpiry','creditCardExpiryMonth','creditCardExpiryYear'];var useTags=function useTags(tags,activeTagIndex,setActiveTagIndex){var visibleTagsCountRef=React__default.useRef(0);React__default.useEffect(function(){if(tags&&activeTagIndex>=0&&activeTagIndex<tags.length){var _tags$activeTagIndex,_tags$activeTagIndex$;var tagTitle=(_tags$activeTagIndex=tags[activeTagIndex])==null?void 0:(_tags$activeTagIndex$=_tags$activeTagIndex.props)==null?void 0:_tags$activeTagIndex$.children;if(tagTitle){announce(`Close ${tagTitle} Tag`);}}},[activeTagIndex,tags==null?void 0:tags.length]);var onTagLeft=function onTagLeft(){if(activeTagIndex<0){setActiveTagIndex==null?void 0:setActiveTagIndex(visibleTagsCountRef.current-1);}if(activeTagIndex>0){setActiveTagIndex==null?void 0:setActiveTagIndex(activeTagIndex-1);}};var onTagRight=function onTagRight(){if(activeTagIndex<visibleTagsCountRef.current-1){setActiveTagIndex==null?void 0:setActiveTagIndex(activeTagIndex+1);}};var onTagRemove=function onTagRemove(){if(activeTagIndex>=0&&activeTagIndex<visibleTagsCountRef.current&&tags){tags[activeTagIndex].props.onDismiss({tagIndex:activeTagIndex});}};var onInputKeydownTagHandler=function onInputKeydownTagHandler(key){if(tags&&tags.length>0){if(key==='ArrowRight'){onTagRight();}if(key==='ArrowLeft'){onTagLeft();}if(key==='Backspace'){onTagRemove();}}};return {onInputKeydownTagHandler:onInputKeydownTagHandler,visibleTagsCountRef:visibleTagsCountRef};};var useInput=function useInput(_ref){var value=_ref.value,defaultValue=_ref.defaultValue,onClick=_ref.onClick,onFocus=_ref.onFocus,onChange=_ref.onChange,onBlur=_ref.onBlur,onSubmit=_ref.onSubmit,onInput=_ref.onInput,onKeyDown=_ref.onKeyDown,onInputKeydownTagHandler=_ref.onInputKeydownTagHandler;if(__DEV__){if(value&&defaultValue){throwBladeError({message:`Either 'value' or 'defaultValue' shall be passed. This decides if the input field is controlled or uncontrolled`,moduleName:'Input'});}}var _React$useState=React__default.useState(defaultValue!=null?defaultValue:value),_React$useState2=_slicedToArray(_React$useState,2),inputValue=_React$useState2[0],setInputValue=_React$useState2[1];var handleOnFocus=React__default.useCallback(function(_ref2){var name=_ref2.name,value=_ref2.value;var _value='';if(getPlatformType()==='react-native'&&typeof value==='string'){_value=value;}else if(typeof value!=='string'){var _value$target$value;_value=(_value$target$value=value==null?void 0:value.target.value)!=null?_value$target$value:'';}onFocus==null?void 0:onFocus({name:name,value:_value});},[onFocus]);var handleOnClick=React__default.useCallback(function(_ref3){var name=_ref3.name,value=_ref3.value;var _value='';if(getPlatformType()==='react-native'&&typeof value==='string'){_value=value;}else if(typeof value!=='string'){var _value$currentTarget$;_value=(_value$currentTarget$=value==null?void 0:value.currentTarget.value)!=null?_value$currentTarget$:'';}onClick==null?void 0:onClick({name:name,value:_value});},[onClick]);var handleOnSubmit=React__default.useCallback(function(_ref4){var name=_ref4.name,value=_ref4.value;var _value='';if(getPlatformType()==='react-native'&&typeof value==='string'){_value=value;}else if(typeof value!=='string'){var _value$target$value2;_value=(_value$target$value2=value==null?void 0:value.target.value)!=null?_value$target$value2:'';}if(isReactNative()){onSubmit==null?void 0:onSubmit({name:name,value:_value});}},[onSubmit]);var handleOnBlur=React__default.useCallback(function(_ref5){var name=_ref5.name,value=_ref5.value;var _value='';if(getPlatformType()==='react-native'&&typeof value=='string'){_value=value;}else if(typeof value!=='string'){var _value$target$value3;_value=(_value$target$value3=value==null?void 0:value.target.value)!=null?_value$target$value3:'';}onBlur==null?void 0:onBlur({name:name,value:_value});},[onBlur]);var handleOnChange=React__default.useCallback(function(_ref6){var name=_ref6.name,value=_ref6.value;var _value='';if(getPlatformType()==='react-native'&&typeof value==='string'){_value=value;}else if(typeof value!=='string'){var _value$target$value4;_value=(_value$target$value4=value==null?void 0:value.target.value)!=null?_value$target$value4:'';}onChange==null?void 0:onChange({name:name,value:_value});setInputValue(_value);},[onChange]);var handleOnInput=React__default.useCallback(function(_ref7){var name=_ref7.name,value=_ref7.value;var _value='';if(getPlatformType()==='react-native'&&typeof value=='string'){_value=value;}else if(typeof value!=='string'){var _value$target$value5;_value=(_value$target$value5=value==null?void 0:value.target.value)!=null?_value$target$value5:'';}onInput==null?void 0:onInput({name:name,value:_value});},[onInput]);var handleOnKeyDown=React__default.useCallback(function(_ref8){var name=_ref8.name,key=_ref8.key,code=_ref8.code,event=_ref8.event;onInputKeydownTagHandler(key);onKeyDown==null?void 0:onKeyDown({name:name,key:key,code:code,event:event});},[onKeyDown]);return {handleOnFocus:handleOnFocus,handleOnClick:handleOnClick,handleOnChange:handleOnChange,handleOnBlur:handleOnBlur,handleOnSubmit:handleOnSubmit,handleOnInput:handleOnInput,handleOnKeyDown:handleOnKeyDown,inputValue:inputValue};};var getHintType=function getHintType(_ref9){var validationState=_ref9.validationState,hasHelpText=_ref9.hasHelpText;if(validationState==='error'){return 'error';}if(validationState==='success'){return 'success';}if(hasHelpText){return 'help';}return 'help';};var getDescribedByElementId=function getDescribedByElementId(_ref10){var validationState=_ref10.validationState,hasErrorText=_ref10.hasErrorText,hasSuccessText=_ref10.hasSuccessText,hasHelpText=_ref10.hasHelpText,errorTextId=_ref10.errorTextId,successTextId=_ref10.successTextId,helpTextId=_ref10.helpTextId;if(validationState==='error'&&hasErrorText){return errorTextId;}if(validationState==='success'&&hasSuccessText){return successTextId;}if(hasHelpText){return helpTextId;}return '';};var FocusRingWrapper=styled(BaseBox)(function(_ref11){var theme=_ref11.theme,currentInteraction=_ref11.currentInteraction,isTableInputCell=_ref11.isTableInputCell;return {borderRadius:makeBorderSize(isTableInputCell?theme.border.radius.none:theme.border.radius.medium),width:'100%','&:focus-within':!isTableInputCell?Object.assign({},getFocusRingStyles(),{transitionDuration:castWebType(makeMotionTime(getIn(theme.motion.duration,baseInputBorderBackgroundMotion[currentInteraction==='focus'?'enter':'exit'].duration))),transitionTimingFunction:castWebType(theme.motion.easing[baseInputBorderBackgroundMotion[currentInteraction==='focus'?'enter':'exit'].easing])}):{}};});var _BaseInput=function _BaseInput(_ref12,ref){var _inputGroupProps$isDi,_inputGroupProps$size;var _ref12$as=_ref12.as,as=_ref12$as===void 0?'input':_ref12$as,label=_ref12.label,_ref12$labelPosition=_ref12.labelPosition,labelPosition=_ref12$labelPosition===void 0?'top':_ref12$labelPosition,placeholder=_ref12.placeholder,_ref12$type=_ref12.type,type=_ref12$type===void 0?'text':_ref12$type,defaultValue=_ref12.defaultValue,tags=_ref12.tags,_ref12$showAllTags=_ref12.showAllTags,showAllTags=_ref12$showAllTags===void 0?false:_ref12$showAllTags,_ref12$activeTagIndex=_ref12.activeTagIndex,activeTagIndex=_ref12$activeTagIndex===void 0?-1:_ref12$activeTagIndex,setActiveTagIndex=_ref12.setActiveTagIndex,name=_ref12.name,value=_ref12.value,onFocus=_ref12.onFocus,onChange=_ref12.onChange,onInput=_ref12.onInput,onBlur=_ref12.onBlur,onSubmit=_ref12.onSubmit,onClick=_ref12.onClick,onKeyDown=_ref12.onKeyDown,isDisabled=_ref12.isDisabled,necessityIndicator=_ref12.necessityIndicator,validationState=_ref12.validationState,errorText=_ref12.errorText,helpText=_ref12.helpText,successText=_ref12.successText,isRequired=_ref12.isRequired,leadingIcon=_ref12.leadingIcon,prefix=_ref12.prefix,trailingInteractionElement=_ref12.trailingInteractionElement,onTrailingInteractionElementClick=_ref12.onTrailingInteractionElementClick,leadingInteractionElement=_ref12.leadingInteractionElement,suffix=_ref12.suffix,trailingIcon=_ref12.trailingIcon,maxCharacters=_ref12.maxCharacters,textAlign=_ref12.textAlign,autoFocus=_ref12.autoFocus,keyboardReturnKeyType=_ref12.keyboardReturnKeyType,keyboardType=_ref12.keyboardType,autoCompleteSuggestionType=_ref12.autoCompleteSuggestionType,trailingHeaderSlot=_ref12.trailingHeaderSlot,trailingFooterSlot=_ref12.trailingFooterSlot,numberOfLines=_ref12.numberOfLines,id=_ref12.id,componentName=_ref12.componentName,accessibilityLabel=_ref12.accessibilityLabel,labelId=_ref12.labelId,activeDescendant=_ref12.activeDescendant,hideLabelText=_ref12.hideLabelText,hideFormHint=_ref12.hideFormHint,hasPopup=_ref12.hasPopup,popupId=_ref12.popupId,isPopupExpanded=_ref12.isPopupExpanded,maxTagRows=_ref12.maxTagRows,shouldIgnoreBlurAnimation=_ref12.shouldIgnoreBlurAnimation,setShouldIgnoreBlurAnimation=_ref12.setShouldIgnoreBlurAnimation,autoCapitalize=_ref12.autoCapitalize,setInputWrapperRef=_ref12.setInputWrapperRef,testID=_ref12.testID,isDropdownTrigger=_ref12.isDropdownTrigger,isLabelInsideInput=_ref12.isLabelInsideInput,_ref12$size=_ref12.size,size=_ref12$size===void 0?'medium':_ref12$size,trailingButton=_ref12.trailingButton,_ref12$valueComponent=_ref12.valueComponentType,valueComponentType=_ref12$valueComponent===void 0?'text':_ref12$valueComponent,_ref12$isTableInputCe=_ref12.isTableInputCell,isTableInputCell=_ref12$isTableInputCe===void 0?false:_ref12$isTableInputCe,_ref12$showHintsAsToo=_ref12.showHintsAsTooltip,showHintsAsTooltip=_ref12$showHintsAsToo===void 0?false:_ref12$showHintsAsToo,_motionMeta=_ref12._motionMeta,role=_ref12.role,tabIndex=_ref12.tabIndex,leadingDropDown=_ref12.leadingDropDown,trailingDropDown=_ref12.trailingDropDown,labelSuffix=_ref12.labelSuffix,labelTrailing=_ref12.labelTrailing,rest=_objectWithoutProperties(_ref12,_excluded);var _useTheme=useTheme(),theme=_useTheme.theme;var inputRef=React__default.useRef(null);var mergedInputRef=useMergeRefs(ref,inputRef);var inputWrapperRef=React__default.useRef(null);var _useTags=useTags(tags,activeTagIndex,setActiveTagIndex),onInputKeydownTagHandler=_useTags.onInputKeydownTagHandler,visibleTagsCountRef=_useTags.visibleTagsCountRef;var _React$useState3=React__default.useState(false),_React$useState4=_slicedToArray(_React$useState3,2),showAllTagsWithAnimation=_React$useState4[0],setShowAllTagsWithAnimation=_React$useState4[1];var isReactNative=getPlatformType()==='react-native';var defaultRole=hasPopup?'combobox':undefined;var inputGroupProps=useInputGroupContext();var isInsideInputGroup=inputGroupProps.isInsideInputGroup;var _isDisabled=(_inputGroupProps$isDi=inputGroupProps.isDisabled)!=null?_inputGroupProps$isDi:isDisabled;var _size=(_inputGroupProps$size=inputGroupProps.size)!=null?_inputGroupProps$size:size;React__default.useEffect(function(){if(showAllTags){setShowAllTagsWithAnimation(true);}else if(maxTagRows!=='expandable'){setShowAllTagsWithAnimation(false);}},[showAllTags,maxTagRows]);var _useInput=useInput({defaultValue:defaultValue,value:value,onFocus:onFocus,onClick:onClick,onChange:onChange,onBlur:onBlur,onSubmit:onSubmit,onInput:onInput,onKeyDown:onKeyDown,onInputKeydownTagHandler:onInputKeydownTagHandler}),handleOnFocus=_useInput.handleOnFocus,handleOnChange=_useInput.handleOnChange,handleOnClick=_useInput.handleOnClick,handleOnBlur=_useInput.handleOnBlur,handleOnSubmit=_useInput.handleOnSubmit,handleOnInput=_useInput.handleOnInput,handleOnKeyDown=_useInput.handleOnKeyDown,inputValue=_useInput.inputValue;var _useFormId=useFormId(id),inputId=_useFormId.inputId,helpTextId=_useFormId.helpTextId,errorTextId=_useFormId.errorTextId,successTextId=_useFormId.successTextId;var _useBreakpoint=useBreakpoint({breakpoints:theme.breakpoints}),matchedDeviceType=_useBreakpoint.matchedDeviceType;var isLabelLeftPositioned=labelPosition==='left'&&matchedDeviceType==='desktop';var _useInteraction=useInteraction(),currentInteraction=_useInteraction.currentInteraction,setCurrentInteraction=_useInteraction.setCurrentInteraction;var _isRequired=isRequired||necessityIndicator==='required';var accessibilityProps=makeAccessible({required:Boolean(_isRequired),disabled:Boolean(_isDisabled),invalid:Boolean(validationState==='error'),describedBy:getDescribedByElementId({validationState:validationState,hasErrorText:Boolean(errorText),hasSuccessText:Boolean(successText),hasHelpText:Boolean(helpText),errorTextId:errorTextId,successTextId:successTextId,helpTextId:helpTextId}),label:accessibilityLabel,hasPopup:hasPopup,expanded:hasPopup?isPopupExpanded:undefined,controls:hasPopup?popupId:undefined,role:role!=null?role:defaultRole,activeDescendant:activeDescendant});var willRenderHintText=Boolean(helpText)||validationState==='success'&&Boolean(successText)||validationState==='error'&&Boolean(errorText);if(__DEV__){if(autoCompleteSuggestionType&&!autoCompleteSuggestionTypeValues.includes(autoCompleteSuggestionType)){throwBladeError({message:`Expected autoCompleteSuggestionType to be one of ${autoCompleteSuggestionTypeValues.join(', ')} but received ${autoCompleteSuggestionType}`,moduleName:'Input'});}}var isTextArea=as==='textarea';return jsxs(BaseBox,Object.assign({ref:getOuterMotionRef({_motionMeta:_motionMeta,ref:ref})},metaAttribute({name:componentName,testID:testID}),getStyledProps(rest),{children:[jsxs(BaseBox,{display:"flex",flexDirection:isLabelLeftPositioned?'row':'column',justifyContent:isLabelLeftPositioned?'center':undefined,alignItems:isLabelLeftPositioned?'center':undefined,position:"relative",width:"100%",children:[!hideLabelText&&!isLabelInsideInput&&label&&!isInsideInputGroup&&jsxs(BaseBox,{display:"flex",flexDirection:isLabelLeftPositioned?'column':'row',justifyContent:"space-between",alignSelf:isTextArea&&isLabelLeftPositioned?'flex-start':undefined,marginY:isTextArea&&isLabelLeftPositioned?'spacing.3':'spacing.0',children:[jsx(FormLabel,{as:"label",necessityIndicator:necessityIndicator,position:labelPosition,id:labelId,htmlFor:inputId,size:_size,labelSuffix:labelSuffix,labelTrailing:labelTrailing,children:label}),trailingHeaderSlot==null?void 0:trailingHeaderSlot(value!=null?value:inputValue)]}),jsx(FocusRingWrapper,{currentInteraction:currentInteraction,isTableInputCell:isTableInputCell,className:"focus-ring-wrapper",children:jsxs(BaseInputWrapper,{isDropdownTrigger:isDropdownTrigger,isTextArea:isTextArea,isDisabled:_isDisabled,validationState:validationState,currentInteraction:currentInteraction,isLabelLeftPositioned:isLabelLeftPositioned,showAllTags:showAllTags,setShowAllTagsWithAnimation:setShowAllTagsWithAnimation,ref:function ref(refNode){if(refNode){setInputWrapperRef==null?void 0:setInputWrapperRef(refNode);inputWrapperRef.current=refNode;}},maxTagRows:maxTagRows,size:_size,numberOfLines:numberOfLines,onClick:function onClick(){if(!isReactNative){var _inputRef$current;(_inputRef$current=inputRef.current)==null?void 0:_inputRef$current.focus();}},isTableInputCell:isTableInputCell,children:[jsx(BaseInputVisuals,{size:_size,leadingIcon:leadingIcon,prefix:prefix,isDisabled:_isDisabled,leadingInteractionElement:leadingInteractionElement,leadingDropDown:leadingDropDown}),jsx(BaseInputTagSlot,{renderAs:as,tags:tags,isDisabled:_isDisabled,showAllTags:showAllTagsWithAnimation,setFocusOnInput:function setFocusOnInput(){var innerRef=getInnerMotionRef({_motionMeta:_motionMeta,ref:ref});if(innerRef&&!isReactNative&&'current'in innerRef){var _innerRef$current;(_innerRef$current=innerRef.current)==null?void 0:_innerRef$current.focus();}},labelPrefix:isLabelInsideInput?label:undefined,isDropdownTrigger:isDropdownTrigger,visibleTagsCountRef:visibleTagsCountRef,handleOnInputClick:function handleOnInputClick(e){handleOnClick({name:name,value:isReactNative?value:e});},setShouldIgnoreBlurAnimation:setShouldIgnoreBlurAnimation,maxTagRows:maxTagRows,inputWrapperRef:inputWrapperRef,size:_size,numberOfLines:numberOfLines,isTextArea:isTextArea,hasLeadingDropDown:Boolean(leadingDropDown),children:jsx(StyledBaseInput,Object.assign({as:as,id:inputId,ref:getInnerMotionRef({_motionMeta:_motionMeta,ref:mergedInputRef}),name:name,type:type,defaultValue:defaultValue,value:value,placeholder:placeholder,isDisabled:_isDisabled,validationState:validationState,isRequired:_isRequired,handleOnFocus:handleOnFocus,handleOnChange:handleOnChange,handleOnBlur:handleOnBlur,handleOnSubmit:handleOnSubmit,handleOnInput:handleOnInput,handleOnKeyDown:handleOnKeyDown,handleOnClick:handleOnClick,leadingIcon:leadingIcon,prefix:prefix,trailingInteractionElement:trailingInteractionElement,leadingInteractionElement:leadingInteractionElement,suffix:suffix,trailingIcon:trailingIcon,maxCharacters:maxCharacters,textAlign:textAlign,autoFocus:autoFocus,keyboardReturnKeyType:keyboardReturnKeyType,keyboardType:keyboardType,autoCompleteSuggestionType:autoCompleteSuggestionType,accessibilityProps:accessibilityProps,currentInteraction:currentInteraction,setCurrentInteraction:setCurrentInteraction,numberOfLines:numberOfLines,isTextArea:isTextArea||maxTagRows==='multiple'||maxTagRows==='expandable',hasPopup:hasPopup,hasTags:!!(tags&&tags.length>0),shouldIgnoreBlurAnimation:shouldIgnoreBlurAnimation,autoCapitalize:autoCapitalize,isDropdownTrigger:isDropdownTrigger,$size:_size,valueComponentType:valueComponentType,isTableInputCell:isTableInputCell,tabIndex:tabIndex,hasLeadingDropdown:Boolean(leadingDropDown)},metaAttribute({name:MetaConstants.StyledBaseInput}),makeAnalyticsAttribute(rest)))}),jsx(BaseInputVisuals,{trailingInteractionElement:trailingInteractionElement,onTrailingInteractionElementClick:onTrailingInteractionElementClick,suffix:suffix,trailingIcon:trailingIcon,isDisabled:_isDisabled,validationState:validationState,trailingButton:trailingButton,size:_size,errorText:errorText,successText:successText,showHintsAsTooltip:showHintsAsTooltip,trailingDropDown:trailingDropDown})]})})]}),hideFormHint||showHintsAsTooltip||isInsideInputGroup?null:jsx(BaseBox,{marginLeft:makeSize(isLabelLeftPositioned&&!hideLabelText?formHintLeftLabelMarginLeft[_size]:0),children:jsxs(BaseBox,{display:"flex",flexDirection:"row",justifyContent:willRenderHintText?'space-between':'flex-end',children:[jsx(FormHint,{type:getHintType({validationState:validationState,hasHelpText:Boolean(helpText)}),helpText:helpText,errorText:errorText,successText:successText,helpTextId:helpTextId,errorTextId:errorTextId,successTextId:successTextId,size:_size}),trailingFooterSlot==null?void 0:trailingFooterSlot(value!=null?value:inputValue)]})})]}));};var BaseInputWithRef=React__default.forwardRef(_BaseInput);var BaseInput=assignWithoutSideEffects(BaseInputWithRef,{displayName:'BaseInput'});
|
|
45
45
|
|
|
46
46
|
export { BaseInput, getHintType };
|
|
47
47
|
//# sourceMappingURL=BaseInput.js.map
|