@razorpay/blade 12.33.1 → 12.33.2
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/AccordionButton.native.js +1 -1
- package/build/lib/native/components/Accordion/AccordionButton.native.js.map +1 -1
- package/build/lib/native/components/Accordion/AccordionItemHeader.js +2 -1
- package/build/lib/native/components/Accordion/AccordionItemHeader.js.map +1 -1
- package/build/lib/native/components/Accordion/commonStyles.js +1 -1
- package/build/lib/native/components/Accordion/commonStyles.js.map +1 -1
- package/build/lib/native/components/ActionList/ActionListItem.js +1 -1
- package/build/lib/native/components/ActionList/ActionListItem.js.map +1 -1
- package/build/lib/native/components/BaseHeaderFooter/BaseHeader.js +1 -1
- package/build/lib/native/components/BaseHeaderFooter/BaseHeader.js.map +1 -1
- package/build/lib/native/components/Button/BaseButton/BaseButton.js +1 -1
- package/build/lib/native/components/Button/BaseButton/BaseButton.js.map +1 -1
- package/build/lib/native/components/Button/BaseButton/buttonTokens.js +1 -1
- package/build/lib/native/components/Button/BaseButton/buttonTokens.js.map +1 -1
- package/build/lib/native/components/Dropdown/Dropdown.js +1 -1
- package/build/lib/native/components/Dropdown/Dropdown.js.map +1 -1
- package/build/lib/native/components/Dropdown/DropdownButton.js +1 -1
- package/build/lib/native/components/Dropdown/DropdownButton.js.map +1 -1
- package/build/lib/native/components/Dropdown/InputDropdownButton.native.js +7 -0
- package/build/lib/native/components/Dropdown/InputDropdownButton.native.js.map +1 -0
- package/build/lib/native/components/Dropdown/dropdownComponentIds.js +1 -1
- package/build/lib/native/components/Dropdown/dropdownComponentIds.js.map +1 -1
- package/build/lib/native/components/Dropdown/useDropdown.js.map +1 -1
- package/build/lib/native/components/Icons/ChevronUpDownIcon/ChevronUpDownIcon.js +12 -0
- package/build/lib/native/components/Icons/ChevronUpDownIcon/ChevronUpDownIcon.js.map +1 -0
- 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/BaseInput/baseInputStyles.js +1 -1
- package/build/lib/native/components/Input/BaseInput/baseInputStyles.js.map +1 -1
- package/build/lib/native/components/Input/BaseInput/baseInputTokens.js +1 -1
- package/build/lib/native/components/Input/BaseInput/baseInputTokens.js.map +1 -1
- package/build/lib/native/components/Input/DropdownInputTriggers/BaseDropdownInputTrigger.js +2 -5
- package/build/lib/native/components/Input/DropdownInputTriggers/BaseDropdownInputTrigger.js.map +1 -1
- package/build/lib/native/components/Input/SearchInput/SearchInput.js +12 -3
- package/build/lib/native/components/Input/SearchInput/SearchInput.js.map +1 -1
- package/build/lib/native/components/Input/TextInput/TextInput.js +11 -3
- package/build/lib/native/components/Input/TextInput/TextInput.js.map +1 -1
- package/build/lib/native/components/Typography/Text/Text.js +1 -1
- package/build/lib/native/components/Typography/Text/Text.js.map +1 -1
- package/build/lib/native/components/index.js +2 -0
- package/build/lib/native/components/index.js.map +1 -1
- package/build/lib/native/utils/useControlledDropdownInput/useControlledDropdownInput.js +14 -0
- package/build/lib/native/utils/useControlledDropdownInput/useControlledDropdownInput.js.map +1 -0
- package/build/lib/web/development/components/Accordion/AccordionItemHeader.js +18 -2
- package/build/lib/web/development/components/Accordion/AccordionItemHeader.js.map +1 -1
- package/build/lib/web/development/components/Accordion/StyledAccordionButton.web.js +4 -3
- package/build/lib/web/development/components/Accordion/StyledAccordionButton.web.js.map +1 -1
- package/build/lib/web/development/components/Accordion/commonStyles.js +1 -11
- package/build/lib/web/development/components/Accordion/commonStyles.js.map +1 -1
- package/build/lib/web/development/components/ActionList/ActionListItem.js +2 -1
- package/build/lib/web/development/components/ActionList/ActionListItem.js.map +1 -1
- package/build/lib/web/development/components/BaseHeaderFooter/BaseHeader.js +6 -3
- package/build/lib/web/development/components/BaseHeaderFooter/BaseHeader.js.map +1 -1
- package/build/lib/web/development/components/Button/BaseButton/BaseButton.js +24 -3
- package/build/lib/web/development/components/Button/BaseButton/BaseButton.js.map +1 -1
- package/build/lib/web/development/components/Button/BaseButton/StyledBaseButton.web.js +14 -2
- package/build/lib/web/development/components/Button/BaseButton/StyledBaseButton.web.js.map +1 -1
- package/build/lib/web/development/components/Button/BaseButton/buttonTokens.js +19 -0
- package/build/lib/web/development/components/Button/BaseButton/buttonTokens.js.map +1 -1
- package/build/lib/web/development/components/Dropdown/Dropdown.js +4 -1
- package/build/lib/web/development/components/Dropdown/Dropdown.js.map +1 -1
- package/build/lib/web/development/components/Dropdown/DropdownButton.js +4 -1
- package/build/lib/web/development/components/Dropdown/DropdownButton.js.map +1 -1
- package/build/lib/web/development/components/Dropdown/DropdownOverlay.web.js +4 -2
- package/build/lib/web/development/components/Dropdown/DropdownOverlay.web.js.map +1 -1
- package/build/lib/web/development/components/Dropdown/InputDropdownButton.web.js +180 -0
- package/build/lib/web/development/components/Dropdown/InputDropdownButton.web.js.map +1 -0
- package/build/lib/web/development/components/Dropdown/dropdownComponentIds.js +2 -1
- package/build/lib/web/development/components/Dropdown/dropdownComponentIds.js.map +1 -1
- package/build/lib/web/development/components/Dropdown/index.js +1 -0
- package/build/lib/web/development/components/Dropdown/index.js.map +1 -1
- package/build/lib/web/development/components/Dropdown/useDropdown.js.map +1 -1
- package/build/lib/web/development/components/Icons/ChevronUpDownIcon/ChevronUpDownIcon.js +40 -0
- package/build/lib/web/development/components/Icons/ChevronUpDownIcon/ChevronUpDownIcon.js.map +1 -0
- package/build/lib/web/development/components/Icons/ChevronUpDownIcon/index.js +2 -0
- package/build/lib/web/development/components/Icons/ChevronUpDownIcon/index.js.map +1 -0
- package/build/lib/web/development/components/Icons/index.js +1 -0
- package/build/lib/web/development/components/Icons/index.js.map +1 -1
- package/build/lib/web/development/components/Input/BaseInput/BaseInput.js +10 -4
- package/build/lib/web/development/components/Input/BaseInput/BaseInput.js.map +1 -1
- package/build/lib/web/development/components/Input/BaseInput/BaseInputVisuals.js +32 -8
- package/build/lib/web/development/components/Input/BaseInput/BaseInputVisuals.js.map +1 -1
- package/build/lib/web/development/components/Input/BaseInput/StyledBaseInput.web.js +2 -1
- package/build/lib/web/development/components/Input/BaseInput/StyledBaseInput.web.js.map +1 -1
- package/build/lib/web/development/components/Input/BaseInput/baseInputStyles.js +8 -4
- package/build/lib/web/development/components/Input/BaseInput/baseInputStyles.js.map +1 -1
- package/build/lib/web/development/components/Input/BaseInput/baseInputTokens.js +1 -1
- package/build/lib/web/development/components/Input/BaseInput/baseInputTokens.js.map +1 -1
- package/build/lib/web/development/components/Input/DropdownInputTriggers/BaseDropdownInputTrigger.js +25 -124
- package/build/lib/web/development/components/Input/DropdownInputTriggers/BaseDropdownInputTrigger.js.map +1 -1
- package/build/lib/web/development/components/Input/PhoneNumberInput/CountrySelector.web.js +6 -4
- package/build/lib/web/development/components/Input/PhoneNumberInput/CountrySelector.web.js.map +1 -1
- package/build/lib/web/development/components/Input/SearchInput/SearchInput.js +97 -30
- package/build/lib/web/development/components/Input/SearchInput/SearchInput.js.map +1 -1
- package/build/lib/web/development/components/Input/TextInput/TextInput.js +123 -31
- package/build/lib/web/development/components/Input/TextInput/TextInput.js.map +1 -1
- package/build/lib/web/development/components/Typography/Text/Text.js +0 -1
- package/build/lib/web/development/components/Typography/Text/Text.js.map +1 -1
- package/build/lib/web/development/components/index.js +2 -0
- package/build/lib/web/development/components/index.js.map +1 -1
- package/build/lib/web/development/utils/useControlledDropdownInput/index.js +2 -0
- package/build/lib/web/development/utils/useControlledDropdownInput/index.js.map +1 -0
- package/build/lib/web/development/utils/useControlledDropdownInput/useControlledDropdownInput.js +108 -0
- package/build/lib/web/development/utils/useControlledDropdownInput/useControlledDropdownInput.js.map +1 -0
- package/build/lib/web/production/components/Accordion/AccordionItemHeader.js +18 -2
- package/build/lib/web/production/components/Accordion/AccordionItemHeader.js.map +1 -1
- package/build/lib/web/production/components/Accordion/StyledAccordionButton.web.js +4 -3
- package/build/lib/web/production/components/Accordion/StyledAccordionButton.web.js.map +1 -1
- package/build/lib/web/production/components/Accordion/commonStyles.js +1 -11
- package/build/lib/web/production/components/Accordion/commonStyles.js.map +1 -1
- package/build/lib/web/production/components/ActionList/ActionListItem.js +2 -1
- package/build/lib/web/production/components/ActionList/ActionListItem.js.map +1 -1
- package/build/lib/web/production/components/BaseHeaderFooter/BaseHeader.js +6 -3
- package/build/lib/web/production/components/BaseHeaderFooter/BaseHeader.js.map +1 -1
- package/build/lib/web/production/components/Button/BaseButton/BaseButton.js +24 -3
- package/build/lib/web/production/components/Button/BaseButton/BaseButton.js.map +1 -1
- package/build/lib/web/production/components/Button/BaseButton/StyledBaseButton.web.js +14 -2
- package/build/lib/web/production/components/Button/BaseButton/StyledBaseButton.web.js.map +1 -1
- package/build/lib/web/production/components/Button/BaseButton/buttonTokens.js +19 -0
- package/build/lib/web/production/components/Button/BaseButton/buttonTokens.js.map +1 -1
- package/build/lib/web/production/components/Dropdown/Dropdown.js +4 -1
- package/build/lib/web/production/components/Dropdown/Dropdown.js.map +1 -1
- package/build/lib/web/production/components/Dropdown/DropdownButton.js +4 -1
- package/build/lib/web/production/components/Dropdown/DropdownButton.js.map +1 -1
- package/build/lib/web/production/components/Dropdown/DropdownOverlay.web.js +4 -2
- package/build/lib/web/production/components/Dropdown/DropdownOverlay.web.js.map +1 -1
- package/build/lib/web/production/components/Dropdown/InputDropdownButton.web.js +180 -0
- package/build/lib/web/production/components/Dropdown/InputDropdownButton.web.js.map +1 -0
- package/build/lib/web/production/components/Dropdown/dropdownComponentIds.js +2 -1
- package/build/lib/web/production/components/Dropdown/dropdownComponentIds.js.map +1 -1
- package/build/lib/web/production/components/Dropdown/index.js +1 -0
- package/build/lib/web/production/components/Dropdown/index.js.map +1 -1
- package/build/lib/web/production/components/Dropdown/useDropdown.js.map +1 -1
- package/build/lib/web/production/components/Icons/ChevronUpDownIcon/ChevronUpDownIcon.js +40 -0
- package/build/lib/web/production/components/Icons/ChevronUpDownIcon/ChevronUpDownIcon.js.map +1 -0
- package/build/lib/web/production/components/Icons/ChevronUpDownIcon/index.js +2 -0
- package/build/lib/web/production/components/Icons/ChevronUpDownIcon/index.js.map +1 -0
- package/build/lib/web/production/components/Icons/index.js +1 -0
- package/build/lib/web/production/components/Icons/index.js.map +1 -1
- package/build/lib/web/production/components/Input/BaseInput/BaseInput.js +10 -4
- package/build/lib/web/production/components/Input/BaseInput/BaseInput.js.map +1 -1
- package/build/lib/web/production/components/Input/BaseInput/BaseInputVisuals.js +32 -8
- package/build/lib/web/production/components/Input/BaseInput/BaseInputVisuals.js.map +1 -1
- package/build/lib/web/production/components/Input/BaseInput/StyledBaseInput.web.js +2 -1
- package/build/lib/web/production/components/Input/BaseInput/StyledBaseInput.web.js.map +1 -1
- package/build/lib/web/production/components/Input/BaseInput/baseInputStyles.js +8 -4
- package/build/lib/web/production/components/Input/BaseInput/baseInputStyles.js.map +1 -1
- package/build/lib/web/production/components/Input/BaseInput/baseInputTokens.js +1 -1
- package/build/lib/web/production/components/Input/BaseInput/baseInputTokens.js.map +1 -1
- package/build/lib/web/production/components/Input/DropdownInputTriggers/BaseDropdownInputTrigger.js +25 -124
- package/build/lib/web/production/components/Input/DropdownInputTriggers/BaseDropdownInputTrigger.js.map +1 -1
- package/build/lib/web/production/components/Input/PhoneNumberInput/CountrySelector.web.js +6 -4
- package/build/lib/web/production/components/Input/PhoneNumberInput/CountrySelector.web.js.map +1 -1
- package/build/lib/web/production/components/Input/SearchInput/SearchInput.js +97 -30
- package/build/lib/web/production/components/Input/SearchInput/SearchInput.js.map +1 -1
- package/build/lib/web/production/components/Input/TextInput/TextInput.js +123 -31
- package/build/lib/web/production/components/Input/TextInput/TextInput.js.map +1 -1
- package/build/lib/web/production/components/Typography/Text/Text.js +0 -1
- package/build/lib/web/production/components/Typography/Text/Text.js.map +1 -1
- package/build/lib/web/production/components/index.js +2 -0
- package/build/lib/web/production/components/index.js.map +1 -1
- package/build/lib/web/production/utils/useControlledDropdownInput/index.js +2 -0
- package/build/lib/web/production/utils/useControlledDropdownInput/index.js.map +1 -0
- package/build/lib/web/production/utils/useControlledDropdownInput/useControlledDropdownInput.js +108 -0
- package/build/lib/web/production/utils/useControlledDropdownInput/useControlledDropdownInput.js.map +1 -0
- package/build/types/components/index.d.ts +3098 -3001
- package/build/types/components/index.native.d.ts +2719 -2686
- package/package.json +1 -1
package/build/lib/web/production/components/Input/PhoneNumberInput/CountrySelector.web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CountrySelector.web.js","sources":["../../../../../../../src/components/Input/PhoneNumberInput/CountrySelector.web.tsx"],"sourcesContent":["import type { CountryCodeType, getFlagsForAllCountries } from '@razorpay/i18nify-js';\nimport { getDialCodeByCountryCode, getFlagOfCountry } from '@razorpay/i18nify-js';\nimport React from 'react';\nimport styled from 'styled-components';\nimport {\n ActionList,\n ActionListItem,\n ActionListItemAsset,\n ActionListItemText,\n} from '~components/ActionList';\nimport { BottomSheet, BottomSheetBody, BottomSheetHeader } from '~components/BottomSheet';\nimport type { DropdownOverlayProps } from '~components/Dropdown';\nimport { Dropdown, DropdownButton, DropdownOverlay } from '~components/Dropdown';\nimport {
|
|
1
|
+
{"version":3,"file":"CountrySelector.web.js","sources":["../../../../../../../src/components/Input/PhoneNumberInput/CountrySelector.web.tsx"],"sourcesContent":["import type { CountryCodeType, getFlagsForAllCountries } from '@razorpay/i18nify-js';\nimport { getDialCodeByCountryCode, getFlagOfCountry } from '@razorpay/i18nify-js';\nimport React from 'react';\nimport styled from 'styled-components';\nimport {\n ActionList,\n ActionListItem,\n ActionListItemAsset,\n ActionListItemText,\n} from '~components/ActionList';\nimport { BottomSheet, BottomSheetBody, BottomSheetHeader } from '~components/BottomSheet';\nimport type { DropdownOverlayProps } from '~components/Dropdown';\nimport { Dropdown, DropdownButton, DropdownOverlay } from '~components/Dropdown';\nimport { ChevronUpDownIcon } from '~components/Icons';\nimport { useIsMobile } from '~utils/useIsMobile';\nimport { size as sizes } from '~tokens/global';\nimport { makeSize } from '~utils';\nimport BaseBox from '~components/Box/BaseBox';\n\nconst countryNameFormatter = new Intl.DisplayNames(['en'], { type: 'region' });\n\ntype CountryData = {\n code: CountryCodeType;\n name: string;\n}[];\ntype CounterSelectorProps = {\n selectedCountry: CountryCodeType;\n inputWrapperRef: DropdownOverlayProps['referenceRef'];\n countryData: CountryData;\n onItemClick: (props: { name: string }) => void;\n flags: ReturnType<typeof getFlagsForAllCountries>;\n isDisabled?: boolean;\n size: 'medium' | 'large';\n};\n\nconst CountryDropdownButtonWrapper = styled(BaseBox)(() => {\n return {\n '& > button': {\n padding: '0',\n width: '100%',\n },\n };\n});\n\nconst CountrySelector = ({\n isDisabled,\n selectedCountry,\n inputWrapperRef,\n countryData,\n onItemClick,\n flags,\n size,\n}: CounterSelectorProps): React.ReactElement => {\n const [isDropdownOpen, setIsDropdownOpen] = React.useState(false);\n const isMobile = useIsMobile();\n\n const actionList = (\n <ActionList isVirtualized>\n {countryData.map((country) => {\n return (\n <ActionListItem\n key={country.code}\n onClick={onItemClick}\n leading={<ActionListItemAsset src={flags[country.code]['4X3']} alt={country.name} />}\n title={country.name}\n value={country.code}\n trailing={\n <ActionListItemText>{getDialCodeByCountryCode(country.code)}</ActionListItemText>\n }\n />\n );\n })}\n </ActionList>\n );\n\n const flagSize = {\n medium: makeSize(sizes[20]),\n large: makeSize(sizes[24]),\n } as const;\n\n return (\n <Dropdown isOpen={isDropdownOpen} onOpenChange={setIsDropdownOpen}>\n {/* TODO: Remove once CountrySelector's button sizing is fixed in figma */}\n <CountryDropdownButtonWrapper\n width={size === 'medium' ? '45px' : '60px'}\n marginLeft={size === 'medium' ? '-3px' : '-2px'}\n >\n <DropdownButton\n isDisabled={isDisabled}\n size={size === 'medium' ? 'xsmall' : 'medium'}\n variant=\"tertiary\"\n //@ts-expect-error\n color=\"transparent\"\n accessibilityLabel={`${countryNameFormatter.of(selectedCountry)} - Select Country`}\n icon={ChevronUpDownIcon}\n iconPosition=\"right\"\n // We need to prevent the click event from propagating to the BaseInputWrapper,\n // Because the BaseInputWrapper is listening for click events to focus the input.\n // We don't want that to happen when the user clicks on the dropdown button\n // otherwise the dropdown will close immediately after opening\n onClick={(e) => {\n e.stopPropagation();\n }}\n >\n {/* @ts-expect-error */}\n <img\n loading=\"lazy\"\n role=\"presentation\"\n width={flagSize[size]}\n src={getFlagOfCountry(selectedCountry)['4X3']}\n alt=\"\"\n />\n </DropdownButton>\n </CountryDropdownButtonWrapper>\n {isMobile ? (\n <BottomSheet>\n <BottomSheetHeader title=\"Select A Country\" />\n <BottomSheetBody>{actionList}</BottomSheetBody>\n </BottomSheet>\n ) : (\n <DropdownOverlay referenceRef={inputWrapperRef}>{actionList}</DropdownOverlay>\n )}\n </Dropdown>\n );\n};\n\nexport { CountrySelector, countryNameFormatter };\n"],"names":["countryNameFormatter","Intl","DisplayNames","type","CountryDropdownButtonWrapper","styled","BaseBox","withConfig","displayName","componentId","padding","width","CountrySelector","_ref","isDisabled","selectedCountry","inputWrapperRef","countryData","onItemClick","flags","size","_React$useState","React","useState","_React$useState2","_slicedToArray","isDropdownOpen","setIsDropdownOpen","isMobile","useIsMobile","actionList","_jsx","ActionList","isVirtualized","children","map","country","ActionListItem","onClick","leading","ActionListItemAsset","src","code","alt","name","title","value","trailing","ActionListItemText","getDialCodeByCountryCode","flagSize","medium","makeSize","sizes","large","_jsxs","Dropdown","isOpen","onOpenChange","marginLeft","DropdownButton","variant","color","accessibilityLabel","concat","of","icon","ChevronUpDownIcon","iconPosition","e","stopPropagation","loading","role","getFlagOfCountry","BottomSheet","BottomSheetHeader","BottomSheetBody","DropdownOverlay","referenceRef"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBMA,IAAAA,oBAAoB,GAAG,IAAIC,IAAI,CAACC,YAAY,CAAC,CAAC,IAAI,CAAC,EAAE;AAAEC,EAAAA,IAAI,EAAE,QAAA;AAAS,CAAC,EAA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AC,EAAoB,mBAAA,CAAA;AACnFmD,QAAAA,IAAI,EAAEC,iBAAkB;AACxBC,QAAAA,YAAY,EAAC,OAAA;AACb;AACA;AACA;AACA;AAAA;AACA9B,QAAAA,OAAO,EAAE,SAAAA,OAAC+B,CAAAA,CAAC,EAAK;UACdA,CAAC,CAACC,eAAe,EAAE,CAAA;SACnB;AAAApC,QAAAA,QAAA,eAGFH,GAAA,CAAA,KAAA,EAAA;AACEwC,UAAAA,OAAO,EAAC,MAAM;AACdC,UAAAA,IAAI,EAAC,cAAc;AACnB7D,UAAAA,KAAK,EAAEuC,QAAQ,CAAC9B,MAAI,CAAE;AACtBqB,UAAAA,GAAG,EAAEgC,gBAAgB,CAAC1D,eAAe,CAAC,CAAC,KAAK,CAAE;AAC9C4B,UAAAA,GAAG,EAAC,EAAA;SACL,CAAA;OACa,CAAA;AAAC,KACW,CAAC,EAC9Bf,QAAQ,gBACP2B,IAAA,CAACmB,WAAW,EAAA;MAAAxC,QAAA,EAAA,cACVH,GAAA,CAAC4C,iBAAiB,EAAA;AAAC9B,QAAAA,KAAK,EAAC,kBAAA;AAAkB,OAAE,CAAC,eAC9Cd,GAAA,CAAC6C,eAAe,EAAA;AAAA1C,QAAAA,QAAA,EAAEJ,UAAAA;AAAU,OAAkB,CAAC,CAAA;AAAA,KACpC,CAAC,gBAEdC,GAAA,CAAC8C,eAAe,EAAA;AAACC,MAAAA,YAAY,EAAE9D,eAAgB;AAAAkB,MAAAA,QAAA,EAAEJ,UAAAA;AAAU,KAAkB,CAC9E,CAAA;AAAA,GACO,CAAC,CAAA;AAEf;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
2
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
3
3
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
4
|
-
import React__default, { useState } from 'react';
|
|
4
|
+
import React__default, { useState, useEffect } from 'react';
|
|
5
5
|
import '../BaseInput/index.js';
|
|
6
6
|
import { getKeyboardAndAutocompleteProps } from '../BaseInput/utils.js';
|
|
7
7
|
import isEmpty from '../../../utils/lodashButBetter/isEmpty.js';
|
|
@@ -15,18 +15,25 @@ import '../../../utils/index.js';
|
|
|
15
15
|
import { useMergeRefs } from '../../../utils/useMergeRefs.js';
|
|
16
16
|
import { dropdownComponentIds } from '../../Dropdown/dropdownComponentIds.js';
|
|
17
17
|
import { useDropdown } from '../../Dropdown/useDropdown.js';
|
|
18
|
-
import
|
|
18
|
+
import '../../Dropdown/index.js';
|
|
19
|
+
import '../../Divider/index.js';
|
|
20
|
+
import '../../../utils/isValidAllowedChildren/index.js';
|
|
21
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
19
22
|
import { getPlatformType } from '../../../utils/getPlatformType/getPlatformType.js';
|
|
20
|
-
import {
|
|
23
|
+
import { getComponentId } from '../../../utils/isValidAllowedChildren/isValidAllowedChildren.js';
|
|
24
|
+
import { InputDropdownButton } from '../../Dropdown/InputDropdownButton.web.js';
|
|
25
|
+
import { DropdownOverlay } from '../../Dropdown/DropdownOverlay.web.js';
|
|
21
26
|
import { IconButton } from '../../Button/IconButton/IconButton.js';
|
|
22
27
|
import CloseIcon from '../../Icons/CloseIcon/CloseIcon.js';
|
|
28
|
+
import { Spinner } from '../../Spinner/Spinner/Spinner.js';
|
|
23
29
|
import { BaseBox } from '../../Box/BaseBox/BaseBox.web.js';
|
|
30
|
+
import { Divider } from '../../Divider/Divider.js';
|
|
24
31
|
import { BaseInput } from '../BaseInput/BaseInput.js';
|
|
25
32
|
import { MetaConstants } from '../../../utils/metaAttribute/metaConstants.js';
|
|
26
33
|
import SearchIcon from '../../Icons/SearchIcon/SearchIcon.js';
|
|
27
34
|
import { assignWithoutSideEffects } from '../../../utils/assignWithoutSideEffects/assignWithoutSideEffects.js';
|
|
28
35
|
|
|
29
|
-
var _excluded = ["label", "accessibilityLabel", "labelPosition", "placeholder", "defaultValue", "name", "value", "onChange", "onClick", "onFocus", "onBlur", "onSubmit", "isDisabled", "helpText", "onClearButtonClick", "isLoading", "autoCapitalize", "autoFocus", "testID", "size", "showSearchIcon"];
|
|
36
|
+
var _excluded = ["label", "accessibilityLabel", "labelPosition", "placeholder", "defaultValue", "name", "value", "onChange", "onClick", "onFocus", "onBlur", "onSubmit", "isDisabled", "helpText", "onClearButtonClick", "isLoading", "autoCapitalize", "autoFocus", "testID", "size", "showSearchIcon", "trailing"];
|
|
30
37
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
31
38
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
32
39
|
// need to do this to tell TS to infer type as SearchInput of React Native and make it believe that `ref.current.clear()` exists
|
|
@@ -59,6 +66,7 @@ var _SearchInput = function _SearchInput(_ref, ref) {
|
|
|
59
66
|
size = _ref$size === void 0 ? 'medium' : _ref$size,
|
|
60
67
|
_ref$showSearchIcon = _ref.showSearchIcon,
|
|
61
68
|
showSearchIcon = _ref$showSearchIcon === void 0 ? true : _ref$showSearchIcon,
|
|
69
|
+
trailing = _ref.trailing,
|
|
62
70
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
63
71
|
var textInputRef = React__default.useRef(null);
|
|
64
72
|
var mergedRef = useMergeRefs(ref, textInputRef);
|
|
@@ -66,15 +74,87 @@ var _SearchInput = function _SearchInput(_ref, ref) {
|
|
|
66
74
|
_useState2 = _slicedToArray(_useState, 2),
|
|
67
75
|
shouldShowClearButton = _useState2[0],
|
|
68
76
|
setShouldShowClearButton = _useState2[1];
|
|
77
|
+
var _useState3 = useState(false),
|
|
78
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
79
|
+
isTrailingDropDownOpen = _useState4[0],
|
|
80
|
+
setIsTrailingDropDownOpen = _useState4[1];
|
|
69
81
|
var _useDropdown = useDropdown(),
|
|
70
82
|
triggererWrapperRef = _useDropdown.triggererWrapperRef,
|
|
71
83
|
onTriggerKeydown = _useDropdown.onTriggerKeydown,
|
|
72
84
|
onTriggerClick = _useDropdown.onTriggerClick,
|
|
73
|
-
dropdownTriggerer = _useDropdown.dropdownTriggerer
|
|
85
|
+
dropdownTriggerer = _useDropdown.dropdownTriggerer,
|
|
86
|
+
closeParentDropDown = _useDropdown.close,
|
|
87
|
+
isParentDropDownOpen = _useDropdown.isOpen;
|
|
74
88
|
var isInsideDropdown = dropdownTriggerer === 'SearchInput';
|
|
75
89
|
React__default.useEffect(function () {
|
|
76
90
|
setShouldShowClearButton(Boolean(defaultValue !== null && defaultValue !== void 0 ? defaultValue : value));
|
|
77
91
|
}, [defaultValue, value]);
|
|
92
|
+
useEffect(function () {
|
|
93
|
+
if (isParentDropDownOpen && isTrailingDropDownOpen) {
|
|
94
|
+
setIsTrailingDropDownOpen(false);
|
|
95
|
+
}
|
|
96
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
97
|
+
}, [closeParentDropDown, isParentDropDownOpen]);
|
|
98
|
+
useEffect(function () {
|
|
99
|
+
if (isTrailingDropDownOpen && isParentDropDownOpen) {
|
|
100
|
+
closeParentDropDown();
|
|
101
|
+
}
|
|
102
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
103
|
+
}, [setIsTrailingDropDownOpen, isTrailingDropDownOpen]);
|
|
104
|
+
var trailingDropdown = trailing && getComponentId(trailing) === 'Dropdown' ? trailing : null;
|
|
105
|
+
var renderTrailingDropDown = function renderTrailingDropDown() {
|
|
106
|
+
if (!trailingDropdown) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
return /*#__PURE__*/React__default.cloneElement(trailingDropdown, {
|
|
110
|
+
selectionType: 'single',
|
|
111
|
+
isOpen: isTrailingDropDownOpen,
|
|
112
|
+
onOpenChange: function onOpenChange(isOpen) {
|
|
113
|
+
setIsTrailingDropDownOpen(isOpen);
|
|
114
|
+
},
|
|
115
|
+
children: React__default.Children.map(trailingDropdown.props.children, function (child) {
|
|
116
|
+
if (child.type === InputDropdownButton) {
|
|
117
|
+
return /*#__PURE__*/React__default.cloneElement(child, {
|
|
118
|
+
_isInsideSearchInput: true
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
if (child.type === DropdownOverlay) {
|
|
122
|
+
return /*#__PURE__*/React__default.cloneElement(child, {
|
|
123
|
+
referenceRef: triggererWrapperRef,
|
|
124
|
+
_isNestedDropdown: true,
|
|
125
|
+
defaultPlacement: 'bottom-end'
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return child;
|
|
129
|
+
})
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
var renderClearButton = function renderClearButton() {
|
|
133
|
+
return /*#__PURE__*/jsx(IconButton, {
|
|
134
|
+
size: "medium",
|
|
135
|
+
icon: CloseIcon,
|
|
136
|
+
onClick: function onClick() {
|
|
137
|
+
var _textInputRef$current;
|
|
138
|
+
if (isEmpty(value) && textInputRef.current) {
|
|
139
|
+
// when the input field is uncontrolled take the ref and clear the input and then call the onClearButtonClick function
|
|
140
|
+
if (isReactNative(textInputRef.current)) {
|
|
141
|
+
textInputRef.current.clear();
|
|
142
|
+
textInputRef.current.focus();
|
|
143
|
+
} else if (textInputRef.current instanceof HTMLInputElement) {
|
|
144
|
+
textInputRef.current.value = '';
|
|
145
|
+
textInputRef.current.focus();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// if the input field is controlled just call the click handler and the value change shall be left upto the consumer
|
|
150
|
+
onClearButtonClick === null || onClearButtonClick === void 0 ? void 0 : onClearButtonClick();
|
|
151
|
+
textInputRef === null || textInputRef === void 0 ? void 0 : (_textInputRef$current = textInputRef.current) === null || _textInputRef$current === void 0 ? void 0 : _textInputRef$current.focus();
|
|
152
|
+
setShouldShowClearButton(false);
|
|
153
|
+
},
|
|
154
|
+
isDisabled: isDisabled,
|
|
155
|
+
accessibilityLabel: "Clear Input Content"
|
|
156
|
+
});
|
|
157
|
+
};
|
|
78
158
|
var renderInteractionElement = function renderInteractionElement() {
|
|
79
159
|
if (isLoading) {
|
|
80
160
|
return /*#__PURE__*/jsx(Spinner, {
|
|
@@ -82,32 +162,18 @@ var _SearchInput = function _SearchInput(_ref, ref) {
|
|
|
82
162
|
color: "primary"
|
|
83
163
|
});
|
|
84
164
|
}
|
|
85
|
-
if (shouldShowClearButton) {
|
|
86
|
-
return /*#__PURE__*/
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// when the input field is uncontrolled take the ref and clear the input and then call the onClearButtonClick function
|
|
93
|
-
if (isReactNative(textInputRef.current)) {
|
|
94
|
-
textInputRef.current.clear();
|
|
95
|
-
textInputRef.current.focus();
|
|
96
|
-
} else if (textInputRef.current instanceof HTMLInputElement) {
|
|
97
|
-
textInputRef.current.value = '';
|
|
98
|
-
textInputRef.current.focus();
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// if the input field is controlled just call the click handler and the value change shall be left upto the consumer
|
|
103
|
-
onClearButtonClick === null || onClearButtonClick === void 0 ? void 0 : onClearButtonClick();
|
|
104
|
-
textInputRef === null || textInputRef === void 0 ? void 0 : (_textInputRef$current = textInputRef.current) === null || _textInputRef$current === void 0 ? void 0 : _textInputRef$current.focus();
|
|
105
|
-
setShouldShowClearButton(false);
|
|
106
|
-
},
|
|
107
|
-
isDisabled: isDisabled,
|
|
108
|
-
accessibilityLabel: "Clear Input Content"
|
|
165
|
+
if (shouldShowClearButton && trailingDropdown) {
|
|
166
|
+
return /*#__PURE__*/jsxs(BaseBox, {
|
|
167
|
+
display: "flex",
|
|
168
|
+
gap: "spacing.3",
|
|
169
|
+
children: [renderClearButton(), " ", /*#__PURE__*/jsx(Divider, {
|
|
170
|
+
orientation: "vertical"
|
|
171
|
+
})]
|
|
109
172
|
});
|
|
110
173
|
}
|
|
174
|
+
if (shouldShowClearButton) {
|
|
175
|
+
return renderClearButton();
|
|
176
|
+
}
|
|
111
177
|
return null;
|
|
112
178
|
};
|
|
113
179
|
return /*#__PURE__*/jsx(BaseBox, {
|
|
@@ -117,7 +183,7 @@ var _SearchInput = function _SearchInput(_ref, ref) {
|
|
|
117
183
|
componentName: MetaConstants.SearchInput,
|
|
118
184
|
ref: mergedRef,
|
|
119
185
|
isDropdownTrigger: true,
|
|
120
|
-
setInputWrapperRef: isInsideDropdown ? function (wrapperNode) {
|
|
186
|
+
setInputWrapperRef: isInsideDropdown || isTrailingDropDownOpen ? function (wrapperNode) {
|
|
121
187
|
triggererWrapperRef.current = wrapperNode;
|
|
122
188
|
} : undefined,
|
|
123
189
|
label: label,
|
|
@@ -158,6 +224,7 @@ var _SearchInput = function _SearchInput(_ref, ref) {
|
|
|
158
224
|
isDisabled: isDisabled,
|
|
159
225
|
leadingIcon: showSearchIcon ? SearchIcon : undefined,
|
|
160
226
|
trailingInteractionElement: renderInteractionElement(),
|
|
227
|
+
trailingDropDown: renderTrailingDropDown(),
|
|
161
228
|
helpText: helpText
|
|
162
229
|
// eslint-disable-next-line jsx-a11y/no-autofocus
|
|
163
230
|
,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchInput.js","sources":["../../../../../../../src/components/Input/SearchInput/SearchInput.tsx"],"sourcesContent":["import React, { useState } from 'react';\nimport type { ReactElement, ReactNode } from 'react';\nimport type { TextInput as TextInputReactNative } from 'react-native';\nimport type { BaseInputProps } from '../BaseInput';\nimport { BaseInput } from '../BaseInput';\nimport { getKeyboardAndAutocompleteProps } from '../BaseInput/utils';\nimport isEmpty from '~utils/lodashButBetter/isEmpty';\nimport { CloseIcon, SearchIcon } from '~components/Icons';\nimport { IconButton } from '~components/Button/IconButton';\nimport type { StyledPropsBlade } from '~components/Box/styledProps';\nimport { MetaConstants } from '~utils/metaAttribute';\nimport BaseBox from '~components/Box/BaseBox';\nimport { Spinner } from '~components/Spinner';\nimport { assignWithoutSideEffects } from '~utils/assignWithoutSideEffects';\nimport { getPlatformType } from '~utils';\nimport { useMergeRefs } from '~utils/useMergeRefs';\nimport type {\n BladeElementRef,\n BladeElementRefWithValue,\n DataAnalyticsAttribute,\n} from '~utils/types';\nimport { dropdownComponentIds } from '~components/Dropdown/dropdownComponentIds';\nimport { useDropdown } from '~components/Dropdown/useDropdown';\n\ntype SearchInputCommonProps = Pick<\n BaseInputProps,\n | 'label'\n | 'accessibilityLabel'\n | 'labelPosition'\n | 'helpText'\n | 'placeholder'\n | 'defaultValue'\n | 'name'\n | 'onChange'\n | 'onFocus'\n | 'onBlur'\n | 'value'\n | 'isDisabled'\n | 'autoFocus'\n | 'onSubmit'\n | 'autoCapitalize'\n | 'testID'\n | 'onClick'\n | 'size'\n | keyof DataAnalyticsAttribute\n> & {\n /**\n * Event handler to handle the onClick event for clear button.\n */\n onClearButtonClick?: () => void;\n\n /**\n * Decides whether to show a loading spinner for the input field.\n */\n isLoading?: boolean;\n /**\n * Toggle the visibility of the search icon.\n *\n * @default true\n */\n showSearchIcon?: boolean;\n} & StyledPropsBlade;\n\n/*\n Mandatory accessibilityLabel prop when label is not provided\n*/\ntype SearchInputPropsWithA11yLabel = {\n /**\n * Label to be shown for the input field\n */\n label?: undefined;\n /**\n * Accessibility label for the input\n */\n accessibilityLabel: string;\n};\n\n/*\n Optional accessibilityLabel prop when label is provided\n*/\ntype SearchInputPropsWithLabel = {\n /**\n * Label to be shown for the input field\n */\n label: string;\n /**\n * Accessibility label for the input\n */\n accessibilityLabel?: string;\n};\n\ntype SearchInputProps = (SearchInputPropsWithA11yLabel | SearchInputPropsWithLabel) &\n SearchInputCommonProps;\n\n// need to do this to tell TS to infer type as SearchInput of React Native and make it believe that `ref.current.clear()` exists\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst isReactNative = (_textInputRef?: any): _textInputRef is TextInputReactNative => {\n return getPlatformType() === 'react-native';\n};\n\nconst _SearchInput: React.ForwardRefRenderFunction<BladeElementRef, SearchInputProps> = (\n {\n label,\n accessibilityLabel,\n labelPosition = 'top',\n placeholder,\n defaultValue,\n name,\n value,\n onChange,\n onClick,\n onFocus,\n onBlur,\n onSubmit,\n isDisabled,\n helpText,\n onClearButtonClick,\n isLoading,\n autoCapitalize,\n autoFocus,\n testID,\n size = 'medium',\n showSearchIcon = true,\n ...rest\n },\n ref,\n): ReactElement => {\n const textInputRef = React.useRef<BladeElementRefWithValue>(null);\n const mergedRef = useMergeRefs(ref, textInputRef);\n const [shouldShowClearButton, setShouldShowClearButton] = useState(false);\n const {\n triggererWrapperRef,\n onTriggerKeydown,\n onTriggerClick,\n dropdownTriggerer,\n } = useDropdown();\n const isInsideDropdown = dropdownTriggerer === 'SearchInput';\n\n React.useEffect(() => {\n setShouldShowClearButton(Boolean(defaultValue ?? value));\n }, [defaultValue, value]);\n\n const renderInteractionElement = (): ReactNode => {\n if (isLoading) {\n return <Spinner accessibilityLabel=\"Loading Content\" color=\"primary\" />;\n }\n\n if (shouldShowClearButton) {\n return (\n <IconButton\n size=\"medium\"\n icon={CloseIcon}\n onClick={() => {\n if (isEmpty(value) && textInputRef.current) {\n // when the input field is uncontrolled take the ref and clear the input and then call the onClearButtonClick function\n if (isReactNative(textInputRef.current)) {\n textInputRef.current.clear();\n textInputRef.current.focus();\n } else if (textInputRef.current instanceof HTMLInputElement) {\n textInputRef.current.value = '';\n textInputRef.current.focus();\n }\n }\n\n // if the input field is controlled just call the click handler and the value change shall be left upto the consumer\n onClearButtonClick?.();\n textInputRef?.current?.focus();\n setShouldShowClearButton(false);\n }}\n isDisabled={isDisabled}\n accessibilityLabel=\"Clear Input Content\"\n />\n );\n }\n\n return null;\n };\n\n return (\n <BaseBox position=\"relative\">\n <BaseInput\n id=\"searchinput\"\n componentName={MetaConstants.SearchInput}\n ref={mergedRef}\n isDropdownTrigger={true}\n setInputWrapperRef={\n isInsideDropdown\n ? (wrapperNode) => {\n triggererWrapperRef.current = wrapperNode;\n }\n : undefined\n }\n label={label as string}\n accessibilityLabel={accessibilityLabel}\n hideLabelText={!Boolean(label)}\n labelPosition={labelPosition}\n placeholder={placeholder}\n defaultValue={defaultValue}\n value={value}\n name={name}\n onKeyDown={isInsideDropdown ? onTriggerKeydown : undefined}\n onChange={({ name, value }) => {\n if (value?.length) {\n // show the clear button when the user starts typing in\n setShouldShowClearButton(true);\n }\n\n if (shouldShowClearButton && !value?.length) {\n // hide the clear button when the input field is empty\n setShouldShowClearButton(false);\n }\n\n onChange?.({ name, value });\n }}\n onClick={(e) => {\n if (isDisabled) return;\n if (isInsideDropdown) {\n onTriggerClick();\n }\n onClick?.(e);\n }}\n onFocus={onFocus}\n onBlur={onBlur}\n onSubmit={onSubmit}\n isDisabled={isDisabled}\n leadingIcon={showSearchIcon ? SearchIcon : undefined}\n trailingInteractionElement={renderInteractionElement()}\n helpText={helpText}\n // eslint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={autoFocus}\n testID={testID}\n {...getKeyboardAndAutocompleteProps({\n type: 'search',\n autoCapitalize,\n })}\n size={size}\n {...rest}\n />\n </BaseBox>\n );\n};\n\nconst SearchInput = assignWithoutSideEffects(React.forwardRef(_SearchInput), {\n displayName: 'SearchInput',\n componentId: dropdownComponentIds.triggers.SearchInput,\n});\n\nexport type { SearchInputProps };\nexport { SearchInput };\n"],"names":["isReactNative","_textInputRef","getPlatformType","_SearchInput","_ref","ref","label","accessibilityLabel","_ref$labelPosition","labelPosition","placeholder","defaultValue","name","value","onChange","onClick","onFocus","onBlur","onSubmit","isDisabled","helpText","onClearButtonClick","isLoading","autoCapitalize","autoFocus","testID","_ref$size","size","_ref$showSearchIcon","showSearchIcon","rest","_objectWithoutProperties","_excluded","textInputRef","React","useRef","mergedRef","useMergeRefs","_useState","useState","_useState2","_slicedToArray","shouldShowClearButton","setShouldShowClearButton","_useDropdown","useDropdown","triggererWrapperRef","onTriggerKeydown","onTriggerClick","dropdownTriggerer","isInsideDropdown","useEffect","Boolean","renderInteractionElement","_jsx","Spinner","color","IconButton","icon","CloseIcon","_textInputRef$current","isEmpty","current","clear","focus","HTMLInputElement","BaseBox","position","children","BaseInput","_objectSpread","id","componentName","MetaConstants","SearchInput","isDropdownTrigger","setInputWrapperRef","wrapperNode","undefined","hideLabelText","onKeyDown","_ref2","length","e","leadingIcon","SearchIcon","trailingInteractionElement","getKeyboardAndAutocompleteProps","type","assignWithoutSideEffects","forwardRef","displayName","componentId","dropdownComponentIds","triggers"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8FA;AACA;AACA,IAAMA,aAAa,GAAG,SAAhBA,aAAaA,CAAIC,aAAmB,EAA4C;AACpF,EAAA,OAAOC,eAAe,EAAE,KAAK,cAAc,CAAA;AAC7C,CAAC,CAAA;AAED,IAAMC,YAA+E,GAAG,SAAlFA,YAA+EA,CAAAC,IAAA,EAyBnFC,GAAG,EACc;AAAA,EAAA,IAxBfC,KAAK,GAAAF,IAAA,CAALE,KAAK;IACLC,kBAAkB,GAAAH,IAAA,CAAlBG,kBAAkB;IAAAC,kBAAA,GAAAJ,IAAA,CAClBK,aAAa;AAAbA,IAAAA,aAAa,GAAAD,kBAAA,KAAG,KAAA,CAAA,GAAA,KAAK,GAAAA,kBAAA;IACrBE,WAAW,GAAAN,IAAA,CAAXM,WAAW;IACXC,YAAY,GAAAP,IAAA,CAAZO,YAAY;IACZC,IAAI,GAAAR,IAAA,CAAJQ,IAAI;IACJC,KAAK,GAAAT,IAAA,CAALS,KAAK;IACLC,SAAQ,GAAAV,IAAA,CAARU,QAAQ;IACRC,QAAO,GAAAX,IAAA,CAAPW,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O,CAAGoE,CAAC,CAAC,CAAA;OACZ;AACFnE,MAAAA,OAAO,EAAEA,OAAQ;AACjBC,MAAAA,MAAM,EAAEA,MAAO;AACfC,MAAAA,QAAQ,EAAEA,QAAS;AACnBC,MAAAA,UAAU,EAAEA,UAAW;AACvBiE,MAAAA,WAAW,EAAEvD,cAAc,GAAGwD,UAAU,GAAGP,SAAU;MACrDQ,0BAA0B,EAAEjC,wBAAwB,EAAG;AACvDjC,MAAAA,QAAQ,EAAEA,QAAAA;AACV;AAAA;AACAI,MAAAA,SAAS,EAAEA,SAAU;AACrBC,MAAAA,MAAM,EAAEA,MAAAA;AAAO,KAAA,EACX8D,+BAA+B,CAAC;AAClCC,MAAAA,IAAI,EAAE,QAAQ;AACdjE,MAAAA,cAAc,EAAdA,cAAAA;AACF,KAAC,CAAC,CAAA,EAAA,EAAA,EAAA;AACFI,MAAAA,IAAI,EAAEA,IAAAA;AAAK,KAAA,EACPG,IAAI,CACT,CAAA;AAAC,GACK,CAAC,CAAA;AAEd,CAAC,CAAA;AAEK4C,IAAAA,WAAW,gBAAGe,wBAAwB,eAACvD,cAAK,CAACwD,UAAU,CAACvF,YAAY,CAAC,EAAE;AAC3EwF,EAAAA,WAAW,EAAE,aAAa;AAC1BC,EAAAA,WAAW,EAAEC,oBAAoB,CAACC,QAAQ,CAACpB,WAAAA;AAC7C,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"SearchInput.js","sources":["../../../../../../../src/components/Input/SearchInput/SearchInput.tsx"],"sourcesContent":["import React, { useEffect, useState } from 'react';\nimport type { ReactElement, ReactNode } from 'react';\nimport type { TextInput as TextInputReactNative } from 'react-native';\nimport type { BaseInputProps } from '../BaseInput';\nimport { BaseInput } from '../BaseInput';\nimport { getKeyboardAndAutocompleteProps } from '../BaseInput/utils';\nimport isEmpty from '~utils/lodashButBetter/isEmpty';\nimport { CloseIcon, SearchIcon } from '~components/Icons';\nimport { IconButton } from '~components/Button/IconButton';\nimport type { StyledPropsBlade } from '~components/Box/styledProps';\nimport { MetaConstants } from '~utils/metaAttribute';\nimport BaseBox from '~components/Box/BaseBox';\nimport { Spinner } from '~components/Spinner';\nimport { assignWithoutSideEffects } from '~utils/assignWithoutSideEffects';\nimport { getPlatformType } from '~utils';\nimport { useMergeRefs } from '~utils/useMergeRefs';\nimport type {\n BladeElementRef,\n BladeElementRefWithValue,\n DataAnalyticsAttribute,\n} from '~utils/types';\nimport { dropdownComponentIds } from '~components/Dropdown/dropdownComponentIds';\nimport { useDropdown } from '~components/Dropdown/useDropdown';\nimport { DropdownOverlay, InputDropdownButton } from '~components/Dropdown';\nimport { Divider } from '~components/Divider';\nimport { getComponentId } from '~utils/isValidAllowedChildren';\n\ntype SearchInputCommonProps = Pick<\n BaseInputProps,\n | 'label'\n | 'accessibilityLabel'\n | 'labelPosition'\n | 'helpText'\n | 'placeholder'\n | 'defaultValue'\n | 'name'\n | 'onChange'\n | 'onFocus'\n | 'onBlur'\n | 'value'\n | 'isDisabled'\n | 'autoFocus'\n | 'onSubmit'\n | 'autoCapitalize'\n | 'testID'\n | 'onClick'\n | 'size'\n | keyof DataAnalyticsAttribute\n> & {\n /**\n * Event handler to handle the onClick event for clear button.\n */\n onClearButtonClick?: () => void;\n\n /**\n * Decides whether to show a loading spinner for the input field.\n */\n isLoading?: boolean;\n /**\n * Toggle the visibility of the search icon.\n *\n * @default true\n */\n showSearchIcon?: boolean;\n /**\n * Optional trailing to be shown at the end of the input.\n */\n trailing?: React.ReactNode;\n} & StyledPropsBlade;\n\n/*\n Mandatory accessibilityLabel prop when label is not provided\n*/\ntype SearchInputPropsWithA11yLabel = {\n /**\n * Label to be shown for the input field\n */\n label?: undefined;\n /**\n * Accessibility label for the input\n */\n accessibilityLabel: string;\n};\n\n/*\n Optional accessibilityLabel prop when label is provided\n*/\ntype SearchInputPropsWithLabel = {\n /**\n * Label to be shown for the input field\n */\n label: string;\n /**\n * Accessibility label for the input\n */\n accessibilityLabel?: string;\n};\n\ntype SearchInputProps = (SearchInputPropsWithA11yLabel | SearchInputPropsWithLabel) &\n SearchInputCommonProps;\n\n// need to do this to tell TS to infer type as SearchInput of React Native and make it believe that `ref.current.clear()` exists\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst isReactNative = (_textInputRef?: any): _textInputRef is TextInputReactNative => {\n return getPlatformType() === 'react-native';\n};\n\nconst _SearchInput: React.ForwardRefRenderFunction<BladeElementRef, SearchInputProps> = (\n {\n label,\n accessibilityLabel,\n labelPosition = 'top',\n placeholder,\n defaultValue,\n name,\n value,\n onChange,\n onClick,\n onFocus,\n onBlur,\n onSubmit,\n isDisabled,\n helpText,\n onClearButtonClick,\n isLoading,\n autoCapitalize,\n autoFocus,\n testID,\n size = 'medium',\n showSearchIcon = true,\n trailing,\n ...rest\n },\n ref,\n): ReactElement => {\n const textInputRef = React.useRef<BladeElementRefWithValue>(null);\n const mergedRef = useMergeRefs(ref, textInputRef);\n const [shouldShowClearButton, setShouldShowClearButton] = useState(false);\n const [isTrailingDropDownOpen, setIsTrailingDropDownOpen] = useState(false);\n const {\n triggererWrapperRef,\n onTriggerKeydown,\n onTriggerClick,\n dropdownTriggerer,\n close: closeParentDropDown,\n isOpen: isParentDropDownOpen,\n } = useDropdown();\n const isInsideDropdown = dropdownTriggerer === 'SearchInput';\n\n React.useEffect(() => {\n setShouldShowClearButton(Boolean(defaultValue ?? value));\n }, [defaultValue, value]);\n\n useEffect(() => {\n if (isParentDropDownOpen && isTrailingDropDownOpen) {\n setIsTrailingDropDownOpen(false);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [closeParentDropDown, isParentDropDownOpen]);\n\n useEffect(() => {\n if (isTrailingDropDownOpen && isParentDropDownOpen) {\n closeParentDropDown();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [setIsTrailingDropDownOpen, isTrailingDropDownOpen]);\n\n const trailingDropdown =\n trailing && getComponentId(trailing as React.ReactElement) === 'Dropdown' ? trailing : null;\n\n const renderTrailingDropDown = (): React.ReactElement | null => {\n if (!trailingDropdown) {\n return null;\n }\n return React.cloneElement(trailingDropdown as React.ReactElement, {\n selectionType: 'single',\n isOpen: isTrailingDropDownOpen,\n onOpenChange: (isOpen: boolean) => {\n setIsTrailingDropDownOpen(isOpen);\n },\n children: React.Children.map(\n (trailingDropdown as React.ReactElement).props.children,\n (child) => {\n if (child.type === InputDropdownButton) {\n return React.cloneElement(child, {\n _isInsideSearchInput: true,\n });\n }\n if (child.type === DropdownOverlay) {\n return React.cloneElement(child, {\n referenceRef: triggererWrapperRef,\n _isNestedDropdown: true,\n defaultPlacement: 'bottom-end',\n });\n }\n return child;\n },\n ),\n });\n };\n\n const renderClearButton = (): React.ReactElement => {\n return (\n <IconButton\n size=\"medium\"\n icon={CloseIcon}\n onClick={() => {\n if (isEmpty(value) && textInputRef.current) {\n // when the input field is uncontrolled take the ref and clear the input and then call the onClearButtonClick function\n if (isReactNative(textInputRef.current)) {\n textInputRef.current.clear();\n textInputRef.current.focus();\n } else if (textInputRef.current instanceof HTMLInputElement) {\n textInputRef.current.value = '';\n textInputRef.current.focus();\n }\n }\n\n // if the input field is controlled just call the click handler and the value change shall be left upto the consumer\n onClearButtonClick?.();\n textInputRef?.current?.focus();\n setShouldShowClearButton(false);\n }}\n isDisabled={isDisabled}\n accessibilityLabel=\"Clear Input Content\"\n />\n );\n };\n\n const renderInteractionElement = (): ReactNode => {\n if (isLoading) {\n return <Spinner accessibilityLabel=\"Loading Content\" color=\"primary\" />;\n }\n\n if (shouldShowClearButton && trailingDropdown) {\n return (\n <BaseBox display=\"flex\" gap=\"spacing.3\">\n {renderClearButton()} <Divider orientation=\"vertical\" />\n </BaseBox>\n );\n }\n if (shouldShowClearButton) {\n return renderClearButton();\n }\n\n return null;\n };\n\n return (\n <BaseBox position=\"relative\">\n <BaseInput\n id=\"searchinput\"\n componentName={MetaConstants.SearchInput}\n ref={mergedRef}\n isDropdownTrigger={true}\n setInputWrapperRef={\n isInsideDropdown || isTrailingDropDownOpen\n ? (wrapperNode) => {\n triggererWrapperRef.current = wrapperNode;\n }\n : undefined\n }\n label={label as string}\n accessibilityLabel={accessibilityLabel}\n hideLabelText={!Boolean(label)}\n labelPosition={labelPosition}\n placeholder={placeholder}\n defaultValue={defaultValue}\n value={value}\n name={name}\n onKeyDown={isInsideDropdown ? onTriggerKeydown : undefined}\n onChange={({ name, value }) => {\n if (value?.length) {\n // show the clear button when the user starts typing in\n setShouldShowClearButton(true);\n }\n\n if (shouldShowClearButton && !value?.length) {\n // hide the clear button when the input field is empty\n setShouldShowClearButton(false);\n }\n\n onChange?.({ name, value });\n }}\n onClick={(e) => {\n if (isDisabled) return;\n if (isInsideDropdown) {\n onTriggerClick();\n }\n onClick?.(e);\n }}\n onFocus={onFocus}\n onBlur={onBlur}\n onSubmit={onSubmit}\n isDisabled={isDisabled}\n leadingIcon={showSearchIcon ? SearchIcon : undefined}\n trailingInteractionElement={renderInteractionElement()}\n trailingDropDown={renderTrailingDropDown()}\n helpText={helpText}\n // eslint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={autoFocus}\n testID={testID}\n {...getKeyboardAndAutocompleteProps({\n type: 'search',\n autoCapitalize,\n })}\n size={size}\n {...rest}\n />\n </BaseBox>\n );\n};\n\nconst SearchInput = assignWithoutSideEffects(React.forwardRef(_SearchInput), {\n displayName: 'SearchInput',\n componentId: dropdownComponentIds.triggers.SearchInput,\n});\n\nexport type { SearchInputProps };\nexport { SearchInput };\n"],"names":["isReactNative","_textInputRef","getPlatformType","_SearchInput","_ref","ref","label","accessibilityLabel","_ref$labelPosition","labelPosition","placeholder","defaultValue","name","value","onChange","onClick","onFocus","onBlur","onSubmit","isDisabled","helpText","onClearButtonClick","isLoading","autoCapitalize","autoFocus","testID","_ref$size","size","_ref$showSearchIcon","showSearchIcon","trailing","rest","_objectWithoutProperties","_excluded","textInputRef","React","useRef","mergedRef","useMergeRefs","_useState","useState","_useState2","_slicedToArray","shouldShowClearButton","setShouldShowClearButton","_useState3","_useState4","isTrailingDropDownOpen","setIsTrailingDropDownOpen","_useDropdown","useDropdown","triggererWrapperRef","onTriggerKeydown","onTriggerClick","dropdownTriggerer","closeParentDropDown","close","isParentDropDownOpen","isOpen","isInsideDropdown","useEffect","Boolean","trailingDropdown","getComponentId","renderTrailingDropDown","cloneElement","selectionType","onOpenChange","children","Children","map","props","child","type","InputDropdownButton","_isInsideSearchInput","DropdownOverlay","referenceRef","_isNestedDropdown","defaultPlacement","renderClearButton","_jsx","IconButton","icon","CloseIcon","_textInputRef$current","isEmpty","current","clear","focus","HTMLInputElement","renderInteractionElement","Spinner","color","_jsxs","BaseBox","display","gap","Divider","orientation","position","BaseInput","_objectSpread","id","componentName","MetaConstants","SearchInput","isDropdownTrigger","setInputWrapperRef","wrapperNode","undefined","hideLabelText","onKeyDown","_ref2","length","e","leadingIcon","SearchIcon","trailingInteractionElement","trailingDropDown","getKeyboardAndAutocompleteProps","assignWithoutSideEffects","forwardRef","displayName","componentId","dropdownComponentIds","triggers"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqGA;AACA;AACA,IAAMA,aAAa,GAAG,SAAhBA,aAAaA,CAAIC,aAAmB,EAA4C;AACpF,EAAA,OAAOC,eAAe,EAAE,KAAK,cAAc,CAAA;AAC7C,CAAC,CAAA;AAED,IAAMC,YAA+E,GAAG,SAAlFA,YAA+EA,CAAAC,IAAA,EA0BnFC,GAAG,EACc;AAAA,EAAA,IAzBfC,KAAK,GAAAF,IAAA,CAALE,KAAK;IACLC,kBAAkB,GAAAH,IAAA,CAAlBG,kBAAkB;IAAAC,kBAAA,GAAAJ,IAAA,CAClBK,aAAa;AAAbA,IAAAA,aAAa,GAAAD,kBAAA,KAAG,KAAA,CAAA,GAAA,KAAK,GAAAA,kBAAA;IACrBE,WAAW,GAAAN,IAAA,CAAXM,WAAW;IACXC,YAAY,GAAAP,IAAA,CAAZO,YAAY;IACZC,IAAI,GAAAR,IAAA,CAAJQ,IAAI;IACJC,KAAK,GAAAT,I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;AACFnG,MAAAA,OAAO,EAAEA,OAAQ;AACjBC,MAAAA,MAAM,EAAEA,MAAO;AACfC,MAAAA,QAAQ,EAAEA,QAAS;AACnBC,MAAAA,UAAU,EAAEA,UAAW;AACvBiG,MAAAA,WAAW,EAAEvF,cAAc,GAAGwF,UAAU,GAAGP,SAAU;MACrDQ,0BAA0B,EAAE3B,wBAAwB,EAAG;MACvD4B,gBAAgB,EAAEvD,sBAAsB,EAAG;AAC3C5C,MAAAA,QAAQ,EAAEA,QAAAA;AACV;AAAA;AACAI,MAAAA,SAAS,EAAEA,SAAU;AACrBC,MAAAA,MAAM,EAAEA,MAAAA;AAAO,KAAA,EACX+F,+BAA+B,CAAC;AAClC/C,MAAAA,IAAI,EAAE,QAAQ;AACdlD,MAAAA,cAAc,EAAdA,cAAAA;AACF,KAAC,CAAC,CAAA,EAAA,EAAA,EAAA;AACFI,MAAAA,IAAI,EAAEA,IAAAA;AAAK,KAAA,EACPI,IAAI,CACT,CAAA;AAAC,GACK,CAAC,CAAA;AAEd,CAAC,CAAA;AAEK2E,IAAAA,WAAW,gBAAGe,wBAAwB,eAACtF,cAAK,CAACuF,UAAU,CAACvH,YAAY,CAAC,EAAE;AAC3EwH,EAAAA,WAAW,EAAE,aAAa;AAC1BC,EAAAA,WAAW,EAAEC,oBAAoB,CAACC,QAAQ,CAACpB,WAAAA;AAC7C,CAAC;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
2
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
3
3
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
4
|
-
import React__default, { useState } from 'react';
|
|
4
|
+
import React__default, { useState, useRef, useEffect } from 'react';
|
|
5
5
|
import '../BaseInput/index.js';
|
|
6
6
|
import { getKeyboardAndAutocompleteProps } from '../BaseInput/utils.js';
|
|
7
7
|
import { useTaggedInput } from '../BaseInput/useTaggedInput.js';
|
|
@@ -16,18 +16,24 @@ import '../../../utils/assignWithoutSideEffects/index.js';
|
|
|
16
16
|
import '../../../utils/index.js';
|
|
17
17
|
import { useMergeRefs } from '../../../utils/useMergeRefs.js';
|
|
18
18
|
import { hintMarginTop } from '../../Form/formTokens.js';
|
|
19
|
-
import
|
|
19
|
+
import '../../Divider/index.js';
|
|
20
|
+
import '../../../utils/isValidAllowedChildren/index.js';
|
|
21
|
+
import '../../Dropdown/index.js';
|
|
22
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
20
23
|
import { getPlatformType } from '../../../utils/getPlatformType/getPlatformType.js';
|
|
21
|
-
import {
|
|
24
|
+
import { getComponentId } from '../../../utils/isValidAllowedChildren/isValidAllowedChildren.js';
|
|
25
|
+
import { DropdownOverlay } from '../../Dropdown/DropdownOverlay.web.js';
|
|
22
26
|
import { IconButton } from '../../Button/IconButton/IconButton.js';
|
|
23
27
|
import CloseIcon from '../../Icons/CloseIcon/CloseIcon.js';
|
|
28
|
+
import { Spinner } from '../../Spinner/Spinner/Spinner.js';
|
|
29
|
+
import { BaseBox } from '../../Box/BaseBox/BaseBox.web.js';
|
|
30
|
+
import { Divider } from '../../Divider/Divider.js';
|
|
24
31
|
import { BaseInput } from '../BaseInput/BaseInput.js';
|
|
25
32
|
import { MetaConstants } from '../../../utils/metaAttribute/metaConstants.js';
|
|
26
|
-
import { BaseBox } from '../../Box/BaseBox/BaseBox.web.js';
|
|
27
33
|
import { CharacterCounter } from '../../Form/CharacterCounter/CharacterCounter.js';
|
|
28
34
|
import { assignWithoutSideEffects } from '../../../utils/assignWithoutSideEffects/assignWithoutSideEffects.js';
|
|
29
35
|
|
|
30
|
-
var _excluded = ["label", "accessibilityLabel", "labelPosition", "placeholder", "type", "defaultValue", "name", "value", "maxCharacters", "onChange", "onClick", "onFocus", "onBlur", "onSubmit", "isDisabled", "necessityIndicator", "validationState", "errorText", "helpText", "successText", "isRequired", "icon", "prefix", "showClearButton", "onClearButtonClick", "isLoading", "suffix", "autoFocus", "keyboardReturnKeyType", "autoCompleteSuggestionType", "autoCapitalize", "testID", "size", "leadingIcon", "trailingIcon", "isTaggedInput", "tags", "onTagChange"];
|
|
36
|
+
var _excluded = ["label", "accessibilityLabel", "labelPosition", "placeholder", "type", "defaultValue", "name", "value", "maxCharacters", "onChange", "onClick", "onFocus", "onBlur", "onSubmit", "isDisabled", "necessityIndicator", "validationState", "errorText", "helpText", "successText", "isRequired", "icon", "prefix", "showClearButton", "onClearButtonClick", "isLoading", "suffix", "autoFocus", "keyboardReturnKeyType", "autoCompleteSuggestionType", "autoCapitalize", "testID", "size", "leadingIcon", "trailingIcon", "isTaggedInput", "tags", "onTagChange", "trailing", "leading"];
|
|
31
37
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
32
38
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
33
39
|
// need to do this to tell TS to infer type as TextInput of React Native and make it believe that `ref.current.clear()` exists
|
|
@@ -36,6 +42,7 @@ var isReactNative = function isReactNative(_textInputRef) {
|
|
|
36
42
|
return getPlatformType() === 'react-native';
|
|
37
43
|
};
|
|
38
44
|
var _TextInput = function _TextInput(_ref, ref) {
|
|
45
|
+
var _leading$name, _trailing$name, _ref3;
|
|
39
46
|
var label = _ref.label,
|
|
40
47
|
accessibilityLabel = _ref.accessibilityLabel,
|
|
41
48
|
_ref$labelPosition = _ref.labelPosition,
|
|
@@ -77,6 +84,8 @@ var _TextInput = function _TextInput(_ref, ref) {
|
|
|
77
84
|
isTaggedInput = _ref.isTaggedInput,
|
|
78
85
|
tags = _ref.tags,
|
|
79
86
|
onTagChange = _ref.onTagChange,
|
|
87
|
+
trailing = _ref.trailing,
|
|
88
|
+
leading = _ref.leading,
|
|
80
89
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
81
90
|
var textInputRef = React__default.useRef(null);
|
|
82
91
|
var mergedRef = useMergeRefs(ref, textInputRef);
|
|
@@ -104,9 +113,88 @@ var _TextInput = function _TextInput(_ref, ref) {
|
|
|
104
113
|
handleTaggedInputKeydown = _useTaggedInput.handleTaggedInputKeydown,
|
|
105
114
|
handleTaggedInputChange = _useTaggedInput.handleTaggedInputChange,
|
|
106
115
|
handleTagsClear = _useTaggedInput.handleTagsClear;
|
|
116
|
+
var _React$useState = React__default.useState(false),
|
|
117
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
118
|
+
isTrailingDropDownOpen = _React$useState2[0],
|
|
119
|
+
setIsTrailingDropDownOpen = _React$useState2[1];
|
|
120
|
+
var _React$useState3 = React__default.useState(false),
|
|
121
|
+
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
122
|
+
isLeadingDropDownOpen = _React$useState4[0],
|
|
123
|
+
setIsLeadingDropDownOpen = _React$useState4[1];
|
|
124
|
+
var textInputWrapperRef = useRef(null);
|
|
125
|
+
useEffect(function () {
|
|
126
|
+
if (isTrailingDropDownOpen && isLeadingDropDownOpen) {
|
|
127
|
+
setIsLeadingDropDownOpen(false);
|
|
128
|
+
}
|
|
129
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
130
|
+
}, [isTrailingDropDownOpen]);
|
|
131
|
+
useEffect(function () {
|
|
132
|
+
if (isLeadingDropDownOpen && isTrailingDropDownOpen) {
|
|
133
|
+
setIsTrailingDropDownOpen(false);
|
|
134
|
+
}
|
|
135
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
136
|
+
}, [isLeadingDropDownOpen]);
|
|
137
|
+
var leadingDropDown = leading && getComponentId(leading) === 'Dropdown' ? leading : null;
|
|
138
|
+
var trailingDropdown = trailing && getComponentId(trailing) === 'Dropdown' ? trailing : null;
|
|
139
|
+
// we need to look into name of component and check if it 's and icon or a dropdown
|
|
140
|
+
var _leadingIcon = leading && typeof leading === 'function' && (_leading$name = leading.name) !== null && _leading$name !== void 0 && _leading$name.endsWith('Icon') ? leading : undefined;
|
|
141
|
+
var _trailingIcon = trailing && typeof trailing === 'function' && (_trailing$name = trailing.name) !== null && _trailing$name !== void 0 && _trailing$name.endsWith('Icon') ? trailing : undefined;
|
|
142
|
+
var hasLeadingInteractionElement = !_leadingIcon && !leadingDropDown && leading;
|
|
143
|
+
var hasTrailingInteractionElement = !_trailingIcon && !trailingDropdown && trailing;
|
|
144
|
+
var renderDropdown = function renderDropdown(dropdown, isOpen, setIsOpen, defaultPlacement) {
|
|
145
|
+
if (!dropdown) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
return /*#__PURE__*/React__default.cloneElement(dropdown, {
|
|
149
|
+
selectionType: 'single',
|
|
150
|
+
isOpen: isOpen,
|
|
151
|
+
onOpenChange: function onOpenChange(isOpen) {
|
|
152
|
+
setIsOpen(isOpen);
|
|
153
|
+
},
|
|
154
|
+
children: React__default.Children.map(dropdown.props.children, function (child) {
|
|
155
|
+
if (child.type === DropdownOverlay) {
|
|
156
|
+
return /*#__PURE__*/React__default.cloneElement(child, {
|
|
157
|
+
referenceRef: textInputWrapperRef,
|
|
158
|
+
_isNestedDropdown: true,
|
|
159
|
+
defaultPlacement: defaultPlacement
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return child;
|
|
163
|
+
})
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
var renderLeadingDropDown = renderDropdown(leadingDropDown, isLeadingDropDownOpen, setIsLeadingDropDownOpen, 'bottom-start');
|
|
167
|
+
var renderTrailingDropDown = renderDropdown(trailingDropdown, isTrailingDropDownOpen, setIsTrailingDropDownOpen, 'bottom-end');
|
|
107
168
|
React__default.useEffect(function () {
|
|
108
169
|
setShouldShowClearButton(Boolean(showClearButton && (defaultValue !== null && defaultValue !== void 0 ? defaultValue : value)));
|
|
109
170
|
}, [showClearButton, defaultValue, value]);
|
|
171
|
+
var renderClearButton = function renderClearButton() {
|
|
172
|
+
return /*#__PURE__*/jsx(IconButton, {
|
|
173
|
+
size: "medium",
|
|
174
|
+
icon: CloseIcon,
|
|
175
|
+
onClick: function onClick() {
|
|
176
|
+
var _textInputRef$current;
|
|
177
|
+
if (isEmpty(value) && textInputRef.current) {
|
|
178
|
+
// when the input field is uncontrolled take the ref and clear the input and then call the onClearButtonClick function
|
|
179
|
+
if (isReactNative(textInputRef.current)) {
|
|
180
|
+
textInputRef.current.clear();
|
|
181
|
+
textInputRef.current.focus();
|
|
182
|
+
} else if (textInputRef.current instanceof HTMLInputElement) {
|
|
183
|
+
textInputRef.current.value = '';
|
|
184
|
+
textInputRef.current.focus();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
handleTagsClear();
|
|
188
|
+
// if the input field is controlled just call the click handler and the value change shall be left upto the consumer
|
|
189
|
+
onClearButtonClick === null || onClearButtonClick === void 0 ? void 0 : onClearButtonClick();
|
|
190
|
+
textInputRef === null || textInputRef === void 0 ? void 0 : (_textInputRef$current = textInputRef.current) === null || _textInputRef$current === void 0 ? void 0 : _textInputRef$current.focus();
|
|
191
|
+
setShouldShowClearButton(false);
|
|
192
|
+
},
|
|
193
|
+
isDisabled: isDisabled,
|
|
194
|
+
accessibilityLabel: "Clear Input Content"
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
var hasTrailingDropDown = Boolean(trailingDropdown);
|
|
110
198
|
var renderInteractionElement = function renderInteractionElement() {
|
|
111
199
|
if (isLoading) {
|
|
112
200
|
return /*#__PURE__*/jsx(Spinner, {
|
|
@@ -114,38 +202,39 @@ var _TextInput = function _TextInput(_ref, ref) {
|
|
|
114
202
|
color: "primary"
|
|
115
203
|
});
|
|
116
204
|
}
|
|
117
|
-
if (shouldShowClearButton) {
|
|
118
|
-
return /*#__PURE__*/
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
handleTagsClear();
|
|
134
|
-
// if the input field is controlled just call the click handler and the value change shall be left upto the consumer
|
|
135
|
-
onClearButtonClick === null || onClearButtonClick === void 0 ? void 0 : onClearButtonClick();
|
|
136
|
-
textInputRef === null || textInputRef === void 0 ? void 0 : (_textInputRef$current = textInputRef.current) === null || _textInputRef$current === void 0 ? void 0 : _textInputRef$current.focus();
|
|
137
|
-
setShouldShowClearButton(false);
|
|
138
|
-
},
|
|
139
|
-
isDisabled: isDisabled,
|
|
140
|
-
accessibilityLabel: "Clear Input Content"
|
|
205
|
+
if (shouldShowClearButton && hasTrailingDropDown) {
|
|
206
|
+
return /*#__PURE__*/jsxs(BaseBox, {
|
|
207
|
+
display: "flex",
|
|
208
|
+
gap: "spacing.3",
|
|
209
|
+
children: [renderClearButton(), " ", /*#__PURE__*/jsx(Divider, {
|
|
210
|
+
orientation: "vertical"
|
|
211
|
+
})]
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
if (showClearButton && hasTrailingInteractionElement) {
|
|
215
|
+
return /*#__PURE__*/jsxs(BaseBox, {
|
|
216
|
+
display: "flex",
|
|
217
|
+
gap: "spacing.3",
|
|
218
|
+
children: [renderClearButton(), " ", /*#__PURE__*/jsx(Divider, {
|
|
219
|
+
orientation: "vertical"
|
|
220
|
+
}), " ", trailing]
|
|
141
221
|
});
|
|
142
222
|
}
|
|
223
|
+
if (shouldShowClearButton) {
|
|
224
|
+
return renderClearButton();
|
|
225
|
+
}
|
|
226
|
+
if (hasTrailingInteractionElement) {
|
|
227
|
+
return trailing;
|
|
228
|
+
}
|
|
143
229
|
return null;
|
|
144
230
|
};
|
|
145
231
|
return /*#__PURE__*/jsx(BaseInput, _objectSpread(_objectSpread({
|
|
146
232
|
id: "textinput",
|
|
147
233
|
componentName: MetaConstants.TextInput,
|
|
148
234
|
ref: mergedRef,
|
|
235
|
+
setInputWrapperRef: function setInputWrapperRef(wrapperNode) {
|
|
236
|
+
textInputWrapperRef.current = wrapperNode;
|
|
237
|
+
},
|
|
149
238
|
label: label,
|
|
150
239
|
accessibilityLabel: accessibilityLabel,
|
|
151
240
|
hideLabelText: !Boolean(label),
|
|
@@ -163,6 +252,9 @@ var _TextInput = function _TextInput(_ref, ref) {
|
|
|
163
252
|
maxTagRows: "single",
|
|
164
253
|
activeTagIndex: activeTagIndex,
|
|
165
254
|
setActiveTagIndex: setActiveTagIndex,
|
|
255
|
+
leadingDropDown: renderLeadingDropDown,
|
|
256
|
+
trailingDropDown: renderTrailingDropDown,
|
|
257
|
+
leadingInteractionElement: hasLeadingInteractionElement ? leading : null,
|
|
166
258
|
onChange: function onChange(_ref2) {
|
|
167
259
|
var name = _ref2.name,
|
|
168
260
|
value = _ref2.value;
|
|
@@ -199,10 +291,10 @@ var _TextInput = function _TextInput(_ref, ref) {
|
|
|
199
291
|
isDisabled: isDisabled,
|
|
200
292
|
necessityIndicator: necessityIndicator,
|
|
201
293
|
isRequired: isRequired,
|
|
202
|
-
leadingIcon:
|
|
294
|
+
leadingIcon: (_ref3 = _leadingIcon !== null && _leadingIcon !== void 0 ? _leadingIcon : leadingIcon) !== null && _ref3 !== void 0 ? _ref3 : icon,
|
|
203
295
|
prefix: prefix,
|
|
204
296
|
trailingInteractionElement: renderInteractionElement(),
|
|
205
|
-
trailingIcon: trailingIcon,
|
|
297
|
+
trailingIcon: _trailingIcon !== null && _trailingIcon !== void 0 ? _trailingIcon : trailingIcon,
|
|
206
298
|
suffix: suffix,
|
|
207
299
|
validationState: validationState,
|
|
208
300
|
errorText: errorText,
|