@pega/cosmos-react-core 4.0.0-dev.12.0 → 4.0.0-dev.13.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/lib/components/AppShell/AppShell.d.ts.map +1 -1
- package/lib/components/AppShell/AppShell.js +2 -1
- package/lib/components/AppShell/AppShell.js.map +1 -1
- package/lib/components/AppShell/NavigationList.d.ts.map +1 -1
- package/lib/components/AppShell/NavigationList.js +2 -2
- package/lib/components/AppShell/NavigationList.js.map +1 -1
- package/lib/components/ColorPicker/ColorPicker.d.ts +2 -2
- package/lib/components/ColorPicker/ColorPicker.d.ts.map +1 -1
- package/lib/components/ColorPicker/ColorPicker.js +5 -3
- package/lib/components/ColorPicker/ColorPicker.js.map +1 -1
- package/lib/components/ColorPicker/ColorPicker.test-ids.d.ts +2 -0
- package/lib/components/ColorPicker/ColorPicker.test-ids.d.ts.map +1 -0
- package/lib/components/ColorPicker/ColorPicker.test-ids.js +3 -0
- package/lib/components/ColorPicker/ColorPicker.test-ids.js.map +1 -0
- package/lib/components/ComboBox/ComboBox.d.ts.map +1 -1
- package/lib/components/ComboBox/ComboBox.js +6 -3
- package/lib/components/ComboBox/ComboBox.js.map +1 -1
- package/lib/components/ComboBox/ComboBox.types.d.ts +2 -2
- package/lib/components/ComboBox/ComboBox.types.d.ts.map +1 -1
- package/lib/components/ComboBox/ComboBox.types.js.map +1 -1
- package/lib/components/ComboBox/ComboxBox.test-ids.d.ts +2 -0
- package/lib/components/ComboBox/ComboxBox.test-ids.d.ts.map +1 -0
- package/lib/components/ComboBox/ComboxBox.test-ids.js +3 -0
- package/lib/components/ComboBox/ComboxBox.test-ids.js.map +1 -0
- package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.d.ts.map +1 -1
- package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.js +1 -1
- package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.js.map +1 -1
- package/lib/components/CompositeInput/CompositeInput.d.ts.map +1 -1
- package/lib/components/CompositeInput/CompositeInput.js +17 -4
- package/lib/components/CompositeInput/CompositeInput.js.map +1 -1
- package/lib/components/CompositeInput/CompositeInput.test-ids.d.ts +2 -0
- package/lib/components/CompositeInput/CompositeInput.test-ids.d.ts.map +1 -0
- package/lib/components/CompositeInput/CompositeInput.test-ids.js +3 -0
- package/lib/components/CompositeInput/CompositeInput.test-ids.js.map +1 -0
- package/lib/components/CompositeInput/CompositeInput.types.d.ts +2 -2
- package/lib/components/CompositeInput/CompositeInput.types.d.ts.map +1 -1
- package/lib/components/CompositeInput/CompositeInput.types.js.map +1 -1
- package/lib/components/Configuration/Configuration.d.ts +6 -0
- package/lib/components/Configuration/Configuration.d.ts.map +1 -1
- package/lib/components/Configuration/Configuration.js +3 -1
- package/lib/components/Configuration/Configuration.js.map +1 -1
- package/lib/components/Currency/Currency.test-ids.d.ts +2 -0
- package/lib/components/Currency/Currency.test-ids.d.ts.map +1 -0
- package/lib/components/Currency/Currency.test-ids.js +3 -0
- package/lib/components/Currency/Currency.test-ids.js.map +1 -0
- package/lib/components/Currency/CurrencyInput.d.ts.map +1 -1
- package/lib/components/Currency/CurrencyInput.js +6 -3
- package/lib/components/Currency/CurrencyInput.js.map +1 -1
- package/lib/components/Currency/CurrencyInput.types.d.ts +2 -2
- package/lib/components/Currency/CurrencyInput.types.d.ts.map +1 -1
- package/lib/components/Currency/CurrencyInput.types.js.map +1 -1
- package/lib/components/DateTime/utils.d.ts.map +1 -1
- package/lib/components/DateTime/utils.js +61 -1
- package/lib/components/DateTime/utils.js.map +1 -1
- package/lib/components/FieldGroup/FieldGroup.js +1 -1
- package/lib/components/FieldGroup/FieldGroup.js.map +1 -1
- package/lib/components/FieldValueList/FieldValueList.d.ts +4 -4
- package/lib/components/FieldValueList/FieldValueList.d.ts.map +1 -1
- package/lib/components/FieldValueList/FieldValueList.js +11 -9
- package/lib/components/FieldValueList/FieldValueList.js.map +1 -1
- package/lib/components/FieldValueList/FieldValueList.test-ids.d.ts +3 -0
- package/lib/components/FieldValueList/FieldValueList.test-ids.d.ts.map +1 -0
- package/lib/components/FieldValueList/FieldValueList.test-ids.js +7 -0
- package/lib/components/FieldValueList/FieldValueList.test-ids.js.map +1 -0
- package/lib/components/File/File.test-ids.d.ts +2 -0
- package/lib/components/File/File.test-ids.d.ts.map +1 -0
- package/lib/components/File/File.test-ids.js +3 -0
- package/lib/components/File/File.test-ids.js.map +1 -0
- package/lib/components/File/FileInput.d.ts +2 -2
- package/lib/components/File/FileInput.d.ts.map +1 -1
- package/lib/components/File/FileInput.js +15 -4
- package/lib/components/File/FileInput.js.map +1 -1
- package/lib/components/FormField/FormField.d.ts +2 -2
- package/lib/components/FormField/FormField.d.ts.map +1 -1
- package/lib/components/FormField/FormField.js +15 -10
- package/lib/components/FormField/FormField.js.map +1 -1
- package/lib/components/FormField/FormField.test-ids.d.ts +2 -0
- package/lib/components/FormField/FormField.test-ids.d.ts.map +1 -0
- package/lib/components/FormField/FormField.test-ids.js +9 -0
- package/lib/components/FormField/FormField.test-ids.js.map +1 -0
- package/lib/components/Input/Input.d.ts +2 -2
- package/lib/components/Input/Input.d.ts.map +1 -1
- package/lib/components/Input/Input.js +6 -2
- package/lib/components/Input/Input.js.map +1 -1
- package/lib/components/Input/Input.test-ids.d.ts +2 -0
- package/lib/components/Input/Input.test-ids.d.ts.map +1 -0
- package/lib/components/Input/Input.test-ids.js +3 -0
- package/lib/components/Input/Input.test-ids.js.map +1 -0
- package/lib/components/ListToolbar/ListToolbar.js +2 -2
- package/lib/components/ListToolbar/ListToolbar.js.map +1 -1
- package/lib/components/Location/Location.test-ids.d.ts +2 -0
- package/lib/components/Location/Location.test-ids.d.ts.map +1 -0
- package/lib/components/Location/Location.test-ids.js +3 -0
- package/lib/components/Location/Location.test-ids.js.map +1 -0
- package/lib/components/Location/LocationInput.d.ts +2 -2
- package/lib/components/Location/LocationInput.d.ts.map +1 -1
- package/lib/components/Location/LocationInput.js +17 -4
- package/lib/components/Location/LocationInput.js.map +1 -1
- package/lib/components/Menu/Menu.d.ts.map +1 -1
- package/lib/components/Menu/Menu.js +7 -5
- package/lib/components/Menu/Menu.js.map +1 -1
- package/lib/components/Menu/Menu.styles.d.ts +5 -1
- package/lib/components/Menu/Menu.styles.d.ts.map +1 -1
- package/lib/components/Menu/Menu.styles.js +80 -85
- package/lib/components/Menu/Menu.styles.js.map +1 -1
- package/lib/components/Menu/Menu.test-ids.d.ts +3 -0
- package/lib/components/Menu/Menu.test-ids.d.ts.map +1 -0
- package/lib/components/Menu/Menu.test-ids.js +4 -0
- package/lib/components/Menu/Menu.test-ids.js.map +1 -0
- package/lib/components/Menu/Menu.types.d.ts +3 -3
- package/lib/components/Menu/Menu.types.d.ts.map +1 -1
- package/lib/components/Menu/Menu.types.js.map +1 -1
- package/lib/components/Menu/MenuItem.d.ts.map +1 -1
- package/lib/components/Menu/MenuItem.js +70 -73
- package/lib/components/Menu/MenuItem.js.map +1 -1
- package/lib/components/Menu/MenuList.d.ts.map +1 -1
- package/lib/components/Menu/MenuList.js +3 -3
- package/lib/components/Menu/MenuList.js.map +1 -1
- package/lib/components/Menu/MenuListHeader.d.ts.map +1 -1
- package/lib/components/Menu/MenuListHeader.js +3 -4
- package/lib/components/Menu/MenuListHeader.js.map +1 -1
- package/lib/components/MetaList/MetaList.d.ts +2 -2
- package/lib/components/MetaList/MetaList.d.ts.map +1 -1
- package/lib/components/MetaList/MetaList.js +5 -3
- package/lib/components/MetaList/MetaList.js.map +1 -1
- package/lib/components/MetaList/MetaList.test-ids.d.ts +2 -0
- package/lib/components/MetaList/MetaList.test-ids.d.ts.map +1 -0
- package/lib/components/MetaList/MetaList.test-ids.js +3 -0
- package/lib/components/MetaList/MetaList.test-ids.js.map +1 -0
- package/lib/components/MultiStepForm/MultiStepForm.d.ts.map +1 -1
- package/lib/components/MultiStepForm/MultiStepForm.js +18 -6
- package/lib/components/MultiStepForm/MultiStepForm.js.map +1 -1
- package/lib/components/Number/Number.test-ids.d.ts +3 -0
- package/lib/components/Number/Number.test-ids.d.ts.map +1 -0
- package/lib/components/Number/Number.test-ids.js +8 -0
- package/lib/components/Number/Number.test-ids.js.map +1 -0
- package/lib/components/Number/NumberInput.d.ts.map +1 -1
- package/lib/components/Number/NumberInput.js +9 -6
- package/lib/components/Number/NumberInput.js.map +1 -1
- package/lib/components/Number/NumberInput.types.d.ts +2 -2
- package/lib/components/Number/NumberInput.types.d.ts.map +1 -1
- package/lib/components/Number/NumberInput.types.js.map +1 -1
- package/lib/components/Number/NumberRangeInput.d.ts.map +1 -1
- package/lib/components/Number/NumberRangeInput.js +6 -4
- package/lib/components/Number/NumberRangeInput.js.map +1 -1
- package/lib/components/Phone/Phone.test-ids.d.ts +2 -0
- package/lib/components/Phone/Phone.test-ids.d.ts.map +1 -0
- package/lib/components/Phone/Phone.test-ids.js +6 -0
- package/lib/components/Phone/Phone.test-ids.js.map +1 -0
- package/lib/components/Phone/PhoneInput.d.ts +2 -2
- package/lib/components/Phone/PhoneInput.d.ts.map +1 -1
- package/lib/components/Phone/PhoneInput.js +7 -4
- package/lib/components/Phone/PhoneInput.js.map +1 -1
- package/lib/components/RadioCheck/RadioCheck.d.ts +2 -0
- package/lib/components/RadioCheck/RadioCheck.d.ts.map +1 -1
- package/lib/components/RadioCheck/RadioCheck.js +3 -3
- package/lib/components/RadioCheck/RadioCheck.js.map +1 -1
- package/lib/components/Select/Select.d.ts +2 -2
- package/lib/components/Select/Select.d.ts.map +1 -1
- package/lib/components/Select/Select.js +6 -3
- package/lib/components/Select/Select.js.map +1 -1
- package/lib/components/Select/Select.test-ids.d.ts +2 -0
- package/lib/components/Select/Select.test-ids.d.ts.map +1 -0
- package/lib/components/Select/Select.test-ids.js +3 -0
- package/lib/components/Select/Select.test-ids.js.map +1 -0
- package/lib/components/Slider/Slider.d.ts.map +1 -1
- package/lib/components/Slider/Slider.js +7 -5
- package/lib/components/Slider/Slider.js.map +1 -1
- package/lib/components/Slider/Slider.test-ids.d.ts +2 -0
- package/lib/components/Slider/Slider.test-ids.d.ts.map +1 -0
- package/lib/components/Slider/Slider.test-ids.js +3 -0
- package/lib/components/Slider/Slider.test-ids.js.map +1 -0
- package/lib/components/Slider/Slider.types.d.ts +2 -2
- package/lib/components/Slider/Slider.types.d.ts.map +1 -1
- package/lib/components/Slider/Slider.types.js.map +1 -1
- package/lib/components/SummaryItem/SummaryItem.d.ts +2 -2
- package/lib/components/SummaryItem/SummaryItem.d.ts.map +1 -1
- package/lib/components/SummaryItem/SummaryItem.js +6 -3
- package/lib/components/SummaryItem/SummaryItem.js.map +1 -1
- package/lib/components/SummaryItem/SummaryItem.test-ids.d.ts +2 -0
- package/lib/components/SummaryItem/SummaryItem.test-ids.d.ts.map +1 -0
- package/lib/components/SummaryItem/SummaryItem.test-ids.js +8 -0
- package/lib/components/SummaryItem/SummaryItem.test-ids.js.map +1 -0
- package/lib/components/TextArea/TextArea.d.ts +2 -2
- package/lib/components/TextArea/TextArea.d.ts.map +1 -1
- package/lib/components/TextArea/TextArea.js +6 -2
- package/lib/components/TextArea/TextArea.js.map +1 -1
- package/lib/components/TextArea/TextArea.test-ids.d.ts +2 -0
- package/lib/components/TextArea/TextArea.test-ids.d.ts.map +1 -0
- package/lib/components/TextArea/TextArea.test-ids.js +3 -0
- package/lib/components/TextArea/TextArea.test-ids.js.map +1 -0
- package/lib/hooks/index.d.ts +1 -0
- package/lib/hooks/index.d.ts.map +1 -1
- package/lib/hooks/index.js +1 -0
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useActiveDescendant.d.ts.map +1 -1
- package/lib/hooks/useActiveDescendant.js +6 -2
- package/lib/hooks/useActiveDescendant.js.map +1 -1
- package/lib/hooks/useI18n.d.ts +15 -9
- package/lib/hooks/useI18n.d.ts.map +1 -1
- package/lib/hooks/useTestIds.d.ts +10 -0
- package/lib/hooks/useTestIds.d.ts.map +1 -0
- package/lib/hooks/useTestIds.js +18 -0
- package/lib/hooks/useTestIds.js.map +1 -0
- package/lib/i18n/default.d.ts +15 -9
- package/lib/i18n/default.d.ts.map +1 -1
- package/lib/i18n/default.js +20 -14
- package/lib/i18n/default.js.map +1 -1
- package/lib/i18n/i18n.d.ts +15 -9
- package/lib/i18n/i18n.d.ts.map +1 -1
- package/lib/theme/theme.d.ts +16 -16
- package/lib/types/types.d.ts +9 -0
- package/lib/types/types.d.ts.map +1 -1
- package/lib/types/types.js.map +1 -1
- package/lib/utils/createTestIds.d.ts +9 -0
- package/lib/utils/createTestIds.d.ts.map +1 -0
- package/lib/utils/createTestIds.js +10 -0
- package/lib/utils/createTestIds.js.map +1 -0
- package/lib/utils/index.d.ts +3 -0
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +2 -0
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/kebabToCamel.d.ts +7 -0
- package/lib/utils/kebabToCamel.d.ts.map +1 -0
- package/lib/utils/kebabToCamel.js +10 -0
- package/lib/utils/kebabToCamel.js.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetaList.js","sourceRoot":"","sources":["../../../src/components/MetaList/MetaList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAsD,UAAU,EAAE,MAAM,OAAO,CAAC;AACvF,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,IAAI,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"MetaList.js","sourceRoot":"","sources":["../../../src/components/MetaList/MetaList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAsD,UAAU,EAAE,MAAM,OAAO,CAAC;AACvF,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OA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AAG,CAAC,EAAE,CAKV;aACR,CAAC,MAAM,CACN,CAAC,KAAK,GAAG,CAAC,MAAM,GAAG,CAAC;gBAClB,CAAC,CAAC;oBACE,KAAC,IAAI,IACH,EAAE,EAAE,kBAAkB,EACtB,IAAI,EAAC,WAAW,EAEhB,OAAO,EAAC,WAAW,wBADd,GAAG,CAAC,GAAG,CAAC,MAAM,CAId;iBACR;gBACH,CAAC,CAAC,EAAE,CACP;YACH,CAAC,CAAC,EAAE,CACP,GACI,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["import { FunctionComponent, ReactNode, Ref, PropsWithoutRef, forwardRef } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport Text from '../Text';\nimport Flex from '../Flex';\nimport { BaseProps, ForwardProps, NoChildrenProp, TestIdProp } from '../../types';\nimport { useTestIds } from '../../hooks';\n\nimport { getMetaListTestIds } from './MetaList.test-ids';\n\nexport interface MetaListProps extends BaseProps, NoChildrenProp, TestIdProp {\n /** Array of nodes or text to be rendered in the list. */\n items: ReactNode[];\n /**\n * If true, MetaList items that extend past the MetaList's container will wrap to a new line.\n * @default true\n */\n wrapItems?: boolean;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLUListElement>;\n}\n\nexport const StyledMetaList = styled.ul<{ wrapItems: boolean }>(({ wrapItems }) => {\n return css`\n list-style: none;\n overflow: hidden;\n\n ${!wrapItems &&\n css`\n white-space: nowrap;\n `}\n `;\n});\n\nexport const StyledMetaListItem = styled.li<{ wrapItems: boolean }>(({ wrapItems }) => {\n return css`\n min-width: 0;\n display: inline-block;\n\n ${wrapItems\n ? css`\n overflow-wrap: break-word;\n `\n : css`\n white-space: nowrap;\n text-overflow: ellipsis;\n overflow: hidden;\n `}\n\n &[role='separator'] {\n -webkit-user-select: none;\n user-select: none;\n }\n `;\n});\n\nconst MetaList: FunctionComponent<MetaListProps & ForwardProps> = forwardRef(\n (\n { testId, items, wrapItems = true, ...restProps }: PropsWithoutRef<MetaListProps>,\n ref: MetaListProps['ref']\n ) => {\n const testIds = useTestIds(testId, getMetaListTestIds);\n\n return (\n <Flex\n data-testid={testIds.root}\n {...restProps}\n as={StyledMetaList}\n container={{ colGap: 0.5, alignItems: 'center', wrap: wrapItems ? 'wrap' : 'nowrap' }}\n wrapItems={wrapItems}\n ref={ref}\n >\n {items.flatMap((item, i, arr) =>\n item\n ? [\n <Text\n as={StyledMetaListItem}\n key={`${i + 0}`}\n variant='secondary'\n wrapItems={wrapItems}\n >\n {item}\n </Text>\n ].concat(\n i !== arr.length - 1\n ? [\n <Text\n as={StyledMetaListItem}\n role='separator'\n key={`${i + 0}-sep`}\n variant='secondary'\n >\n •\n </Text>\n ]\n : []\n )\n : []\n )}\n </Flex>\n );\n }\n);\n\nexport default MetaList;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MetaList.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/MetaList/MetaList.test-ids.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,uFAA0C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MetaList.test-ids.js","sourceRoot":"","sources":["../../../src/components/MetaList/MetaList.test-ids.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAAC,WAAW,EAAE,EAAW,CAAC,CAAC","sourcesContent":["import { createTestIds } from '../../utils';\n\nexport const getMetaListTestIds = createTestIds('meta-list', [] as const);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiStepForm.d.ts","sourceRoot":"","sources":["../../../src/components/MultiStepForm/MultiStepForm.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,iBAAiB,EAAsC,MAAM,OAAO,CAAC;AAI1F,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAU3C,OAAO,
|
|
1
|
+
{"version":3,"file":"MultiStepForm.d.ts","sourceRoot":"","sources":["../../../src/components/MultiStepForm/MultiStepForm.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,iBAAiB,EAAsC,MAAM,OAAO,CAAC;AAI1F,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAU3C,OAAO,kBAAkB,MAAM,uBAAuB,CAAC;AAIvD,eAAO,MAAM,UAAU,0GAWrB,CAAC;AAEH,eAAO,MAAM,iBAAiB,yGAAe,CAAC;AAE9C,eAAO,MAAM,yBAAyB,iKAqBpC,CAAC;AAIH,eAAO,MAAM,aAAa,EAAE,iBAAiB,CAAC,kBAAkB,GAAG,YAAY,CA2H9E,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -39,10 +39,10 @@ export const StyledRequiredFieldLegend = styled(Text)(({ theme }) => {
|
|
|
39
39
|
`;
|
|
40
40
|
});
|
|
41
41
|
StyledRequiredFieldLegend.defaultProps = defaultThemeProp;
|
|
42
|
-
export const MultiStepForm = forwardRef(({ currentStepId, steps, heading, stepIndicator: stepIndicatorProp = 'horizontal', ...restProps }, ref) => {
|
|
42
|
+
export const MultiStepForm = forwardRef(({ currentStepId, steps, heading, stepIndicator: stepIndicatorProp = steps.length < 2 ? 'none' : 'horizontal', ...restProps }, ref) => {
|
|
43
43
|
const multiStepContentRef = useRef(null);
|
|
44
44
|
const previousId = usePrevious(currentStepId);
|
|
45
|
-
const currentStep = steps.find(
|
|
45
|
+
const currentStep = steps.find(step => step.id === currentStepId);
|
|
46
46
|
const headingId = useUID();
|
|
47
47
|
const descriptionId = useUID();
|
|
48
48
|
const t = useI18n();
|
|
@@ -58,16 +58,28 @@ export const MultiStepForm = forwardRef(({ currentStepId, steps, heading, stepIn
|
|
|
58
58
|
}, [currentStepId, previousId]);
|
|
59
59
|
const isSmallOrAbove = useBreakpoint('sm');
|
|
60
60
|
const stepIndicator = stepIndicatorProp === 'vertical' && !isSmallOrAbove ? 'horizontal' : stepIndicatorProp;
|
|
61
|
-
let areaDef;
|
|
61
|
+
let areaDef = '';
|
|
62
62
|
switch (stepIndicator) {
|
|
63
63
|
case 'horizontal':
|
|
64
|
-
|
|
64
|
+
if (heading)
|
|
65
|
+
areaDef += '"heading" ';
|
|
66
|
+
areaDef += '"stepIndicator" "content"';
|
|
67
|
+
if (currentStep.actions)
|
|
68
|
+
areaDef += ' "actions"';
|
|
65
69
|
break;
|
|
66
70
|
case 'vertical':
|
|
67
|
-
|
|
71
|
+
if (heading)
|
|
72
|
+
areaDef += '"heading stepIndicator" ';
|
|
73
|
+
areaDef += '"content stepIndicator"';
|
|
74
|
+
if (currentStep.actions)
|
|
75
|
+
areaDef += ' "actions actions"';
|
|
68
76
|
break;
|
|
69
77
|
default:
|
|
70
|
-
|
|
78
|
+
if (heading)
|
|
79
|
+
areaDef += '"heading" ';
|
|
80
|
+
areaDef += '"content"';
|
|
81
|
+
if (currentStep.actions)
|
|
82
|
+
areaDef += ' "actions"';
|
|
71
83
|
}
|
|
72
84
|
return (_jsxs(Grid, { ref: ref, as: StyledForm, ...restProps, container: {
|
|
73
85
|
cols: stepIndicator === 'vertical' ? `1fr ${contentWidth.sm}` : '1fr',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiStepForm.js","sourceRoot":"","sources":["../../../src/components/MultiStepForm/MultiStepForm.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAsC,MAAM,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC1F,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEpF,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,IAAI,MAA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C,EAAE,GACa,IACpB,CACJ,IACA,CACJ,EAED,MAAC,IAAI,IAAC,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,aACnD,WAAW,CAAC,OAAO,EAEnB,WAAW,CAAC,WAAW,IAAI,CAC1B,KAAC,IAAI,IAAC,EAAE,EAAE,aAAa,EAAE,EAAE,EAAC,GAAG,EAAC,OAAO,EAAE,WAAW,CAAC,WAAW,GAAI,CACrE,EAED,KAAC,iBAAiB,IAAC,GAAG,EAAE,mBAAmB,YAAG,WAAW,CAAC,OAAO,GAAqB,IACjF,EACN,WAAW,CAAC,OAAO,IAAI,CACtB,KAAC,IAAI,IAAC,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,YAC7B,KAAC,IAAI,IAAC,SAAS,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,YAC1D,WAAW,CAAC,OAAO,GACf,GACF,CACR,IACI,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { forwardRef, FunctionComponent, PropsWithoutRef, useRef, useEffect } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport { useUID, useI18n, usePrevious, useBreakpoint, useTheme } from '../../hooks';\nimport { ForwardProps } from '../../types';\nimport { getFocusables } from '../../utils';\nimport { calculateFontSize } from '../../styles';\nimport Flex from '../Flex';\nimport Text from '../Text';\nimport HTML from '../HTML';\nimport VisuallyHiddenText from '../VisuallyHiddenText';\nimport Grid from '../Grid';\nimport { defaultThemeProp } from '../../theme';\n\nimport MultiStepFormProps, { Step } from './MultiStepForm.types';\nimport VerticalFormProgress from './VerticalFormProgress';\nimport HorizontalFormProgress from './HorizontalFormProgress';\n\nexport const StyledForm = styled.form(({ theme }) => {\n const {\n base: { spacing }\n } = theme;\n return css`\n height: 100%;\n width: 100%;\n flex-grow: 1;\n overflow-y: auto;\n padding: ${spacing};\n `;\n});\n\nexport const StyledFormContent = styled.div``;\n\nexport const StyledRequiredFieldLegend = styled(Text)(({ theme }) => {\n const {\n base: {\n 'font-size': fontSize,\n 'font-scale': fontScale,\n palette: { urgent }\n }\n } = theme;\n const { xxs: infoFontSize } = calculateFontSize(fontSize, fontScale);\n\n return css`\n font-size: ${infoFontSize};\n font-style: italic;\n\n &::before {\n display: 'inline';\n content: '\\\\00a0*';\n vertical-align: top;\n color: ${urgent};\n }\n `;\n});\n\nStyledRequiredFieldLegend.defaultProps = defaultThemeProp;\n\nexport const MultiStepForm: FunctionComponent<MultiStepFormProps & ForwardProps> = forwardRef(\n (\n {\n currentStepId,\n steps,\n heading,\n stepIndicator: stepIndicatorProp = 'horizontal',\n ...restProps\n }: PropsWithoutRef<MultiStepFormProps>,\n ref: MultiStepFormProps['ref']\n ) => {\n const multiStepContentRef = useRef(null);\n const previousId = usePrevious(currentStepId);\n const currentStep = steps.find((step: Step) => step.id === currentStepId)!;\n const headingId = useUID();\n const descriptionId = useUID();\n const t = useI18n();\n const {\n base: { 'content-width': contentWidth }\n } = useTheme();\n\n useEffect(() => {\n if (previousId === undefined) return;\n\n if (previousId !== currentStepId) {\n const focusableElements = getFocusables(multiStepContentRef);\n\n if (focusableElements.length) focusableElements[0].focus();\n }\n }, [currentStepId, previousId]);\n\n const isSmallOrAbove = useBreakpoint('sm');\n\n const stepIndicator =\n stepIndicatorProp === 'vertical' && !isSmallOrAbove ? 'horizontal' : stepIndicatorProp;\n\n let areaDef;\n switch (stepIndicator) {\n case 'horizontal':\n areaDef = '\"heading\" \"stepIndicator\" \"content\" \"actions\"';\n break;\n case 'vertical':\n areaDef = '\"heading stepIndicator\" \"content stepIndicator\" \"actions actions\"';\n break;\n default:\n areaDef = '\"heading\" \"content\" \"actions\"';\n }\n\n return (\n <Grid\n ref={ref}\n as={StyledForm}\n {...restProps}\n container={{\n cols: stepIndicator === 'vertical' ? `1fr ${contentWidth.sm}` : '1fr',\n areas: areaDef,\n gap: 3\n }}\n aria-labelledby={heading ? headingId : undefined}\n aria-describedby={currentStep.description ? descriptionId : undefined}\n >\n {(heading || steps.length > 1) && (\n <>\n {heading && (\n <Grid item={{ area: 'heading' }}>\n <Text id={headingId} variant='h3'>\n {heading}\n </Text>\n </Grid>\n )}\n {steps.length > 1 && (\n <>\n {stepIndicator === 'horizontal' && (\n <Grid\n item={{ area: 'stepIndicator' }}\n as={HorizontalFormProgress}\n steps={steps}\n currentStepId={currentStepId}\n />\n )}\n {stepIndicator === 'vertical' && (\n <Grid\n item={{ area: 'stepIndicator' }}\n as={VerticalFormProgress}\n steps={steps}\n currentStepId={currentStepId}\n />\n )}\n <VisuallyHiddenText aria-live='polite'>\n {previousId !== undefined && previousId !== currentStepId\n ? t('step_changed_to_name', [currentStep.name])\n : ''}\n </VisuallyHiddenText>\n </>\n )}\n </>\n )}\n\n <Grid item={{ area: 'content' }} container={{ gap: 3 }}>\n {currentStep.banners}\n\n {currentStep.description && (\n <HTML id={descriptionId} as='p' content={currentStep.description} />\n )}\n\n <StyledFormContent ref={multiStepContentRef}>{currentStep.content}</StyledFormContent>\n </Grid>\n {currentStep.actions && (\n <Grid item={{ area: 'actions' }}>\n <Flex container={{ justify: 'between', alignItems: 'center' }}>\n {currentStep.actions}\n </Flex>\n </Grid>\n )}\n </Grid>\n );\n }\n);\n\nexport default MultiStepForm;\n"]}
|
|
1
|
+
{"version":3,"file":"MultiStepForm.js","sourceRoot":"","sources":["../../../src/components/MultiStepForm/MultiStepForm.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAsC,MAAM,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC1F,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEpF,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CA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'react';\nimport styled, { css } from 'styled-components';\n\nimport { useUID, useI18n, usePrevious, useBreakpoint, useTheme } from '../../hooks';\nimport { ForwardProps } from '../../types';\nimport { getFocusables } from '../../utils';\nimport { calculateFontSize } from '../../styles';\nimport Flex from '../Flex';\nimport Text from '../Text';\nimport HTML from '../HTML';\nimport VisuallyHiddenText from '../VisuallyHiddenText';\nimport Grid from '../Grid';\nimport { defaultThemeProp } from '../../theme';\n\nimport MultiStepFormProps from './MultiStepForm.types';\nimport VerticalFormProgress from './VerticalFormProgress';\nimport HorizontalFormProgress from './HorizontalFormProgress';\n\nexport const StyledForm = styled.form(({ theme }) => {\n const {\n base: { spacing }\n } = theme;\n return css`\n height: 100%;\n width: 100%;\n flex-grow: 1;\n overflow-y: auto;\n padding: ${spacing};\n `;\n});\n\nexport const StyledFormContent = styled.div``;\n\nexport const StyledRequiredFieldLegend = styled(Text)(({ theme }) => {\n const {\n base: {\n 'font-size': fontSize,\n 'font-scale': fontScale,\n palette: { urgent }\n }\n } = theme;\n const { xxs: infoFontSize } = calculateFontSize(fontSize, fontScale);\n\n return css`\n font-size: ${infoFontSize};\n font-style: italic;\n\n &::before {\n display: 'inline';\n content: '\\\\00a0*';\n vertical-align: top;\n color: ${urgent};\n }\n `;\n});\n\nStyledRequiredFieldLegend.defaultProps = defaultThemeProp;\n\nexport const MultiStepForm: FunctionComponent<MultiStepFormProps & ForwardProps> = forwardRef(\n (\n {\n currentStepId,\n steps,\n heading,\n stepIndicator: stepIndicatorProp = steps.length < 2 ? 'none' : 'horizontal',\n ...restProps\n }: PropsWithoutRef<MultiStepFormProps>,\n ref: MultiStepFormProps['ref']\n ) => {\n const multiStepContentRef = useRef(null);\n const previousId = usePrevious(currentStepId);\n const currentStep = steps.find(step => step.id === currentStepId)!;\n const headingId = useUID();\n const descriptionId = useUID();\n const t = useI18n();\n const {\n base: { 'content-width': contentWidth }\n } = useTheme();\n\n useEffect(() => {\n if (previousId === undefined) return;\n\n if (previousId !== currentStepId) {\n const focusableElements = getFocusables(multiStepContentRef);\n\n if (focusableElements.length) focusableElements[0].focus();\n }\n }, [currentStepId, previousId]);\n\n const isSmallOrAbove = useBreakpoint('sm');\n\n const stepIndicator =\n stepIndicatorProp === 'vertical' && !isSmallOrAbove ? 'horizontal' : stepIndicatorProp;\n\n let areaDef = '';\n switch (stepIndicator) {\n case 'horizontal':\n if (heading) areaDef += '\"heading\" ';\n areaDef += '\"stepIndicator\" \"content\"';\n if (currentStep.actions) areaDef += ' \"actions\"';\n break;\n case 'vertical':\n if (heading) areaDef += '\"heading stepIndicator\" ';\n areaDef += '\"content stepIndicator\"';\n if (currentStep.actions) areaDef += ' \"actions actions\"';\n break;\n default:\n if (heading) areaDef += '\"heading\" ';\n areaDef += '\"content\"';\n if (currentStep.actions) areaDef += ' \"actions\"';\n }\n\n return (\n <Grid\n ref={ref}\n as={StyledForm}\n {...restProps}\n container={{\n cols: stepIndicator === 'vertical' ? `1fr ${contentWidth.sm}` : '1fr',\n areas: areaDef,\n gap: 3\n }}\n aria-labelledby={heading ? headingId : undefined}\n aria-describedby={currentStep.description ? descriptionId : undefined}\n >\n {(heading || steps.length > 1) && (\n <>\n {heading && (\n <Grid item={{ area: 'heading' }}>\n <Text id={headingId} variant='h3'>\n {heading}\n </Text>\n </Grid>\n )}\n {steps.length > 1 && (\n <>\n {stepIndicator === 'horizontal' && (\n <Grid\n item={{ area: 'stepIndicator' }}\n as={HorizontalFormProgress}\n steps={steps}\n currentStepId={currentStepId}\n />\n )}\n {stepIndicator === 'vertical' && (\n <Grid\n item={{ area: 'stepIndicator' }}\n as={VerticalFormProgress}\n steps={steps}\n currentStepId={currentStepId}\n />\n )}\n <VisuallyHiddenText aria-live='polite'>\n {previousId !== undefined && previousId !== currentStepId\n ? t('step_changed_to_name', [currentStep.name])\n : ''}\n </VisuallyHiddenText>\n </>\n )}\n </>\n )}\n\n <Grid item={{ area: 'content' }} container={{ gap: 3 }}>\n {currentStep.banners}\n\n {currentStep.description && (\n <HTML id={descriptionId} as='p' content={currentStep.description} />\n )}\n\n <StyledFormContent ref={multiStepContentRef}>{currentStep.content}</StyledFormContent>\n </Grid>\n {currentStep.actions && (\n <Grid item={{ area: 'actions' }}>\n <Flex container={{ justify: 'between', alignItems: 'center' }}>\n {currentStep.actions}\n </Flex>\n </Grid>\n )}\n </Grid>\n );\n }\n);\n\nexport default MultiStepForm;\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const getNumberInputTestIds: (testIdProp?: string | undefined) => import("../../utils").TestIdsRecord<readonly ["control", "plus", "minus"]>;
|
|
2
|
+
export declare const getNumberRangeTestIds: (testIdProp?: string | undefined) => import("../../utils").TestIdsRecord<readonly ["min", "max"]>;
|
|
3
|
+
//# sourceMappingURL=Number.test-ids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Number.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/Number/Number.test-ids.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,qBAAqB,iHAIvB,CAAC;AAEZ,eAAO,MAAM,qBAAqB,mGAAyD,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createTestIds } from '../../utils';
|
|
2
|
+
export const getNumberInputTestIds = createTestIds('number-input', [
|
|
3
|
+
'control',
|
|
4
|
+
'plus',
|
|
5
|
+
'minus'
|
|
6
|
+
]);
|
|
7
|
+
export const getNumberRangeTestIds = createTestIds('number-range', ['min', 'max']);
|
|
8
|
+
//# sourceMappingURL=Number.test-ids.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Number.test-ids.js","sourceRoot":"","sources":["../../../src/components/Number/Number.test-ids.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAC,cAAc,EAAE;IACjE,SAAS;IACT,MAAM;IACN,OAAO;CACC,CAAC,CAAC;AAEZ,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,KAAK,CAAU,CAAC,CAAC","sourcesContent":["import { createTestIds } from '../../utils';\n\nexport const getNumberInputTestIds = createTestIds('number-input', [\n 'control',\n 'plus',\n 'minus'\n] as const);\n\nexport const getNumberRangeTestIds = createTestIds('number-range', ['min', 'max'] as const);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberInput.d.ts","sourceRoot":"","sources":["../../../src/components/Number/NumberInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EAOlB,MAAM,OAAO,CAAC;AAQf,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"NumberInput.d.ts","sourceRoot":"","sources":["../../../src/components/Number/NumberInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EAOlB,MAAM,OAAO,CAAC;AAQf,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAY3C,OAAO,EAAE,gBAAgB,EAA6B,MAAM,qBAAqB,CAAC;AAYlF,QAAA,MAAM,WAAW,EAAE,iBAAiB,CAAC,gBAAgB,GAAG,YAAY,CA0OnE,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -6,15 +6,17 @@ import * as plusIcon from '../Icon/icons/plus.icon';
|
|
|
6
6
|
import * as minusIcon from '../Icon/icons/minus.icon';
|
|
7
7
|
import Flex from '../Flex';
|
|
8
8
|
import FormField from '../FormField';
|
|
9
|
-
import { useConfiguration, useConsolidatedRef, useI18n, useInputFormatter, useUID } from '../../hooks';
|
|
9
|
+
import { useConfiguration, useConsolidatedRef, useI18n, useInputFormatter, useTestIds, useUID } from '../../hooks';
|
|
10
10
|
import StyledInput from '../Input/Input.styles';
|
|
11
11
|
import StyledNumberInput, { StyledStepperInput } from './NumberInput.styles';
|
|
12
12
|
import { NUMBER_MAX_DECIMAL_PLACES } from './NumberInput.types';
|
|
13
13
|
import { getCleanedValue, getDecimalSign, getDecrementedValue, getFormattedValue, getIncrementedValue } from './utils';
|
|
14
|
+
import { getNumberInputTestIds } from './Number.test-ids';
|
|
14
15
|
registerIcon(minusIcon, plusIcon);
|
|
15
16
|
const NumberInput = forwardRef((props, ref) => {
|
|
16
17
|
const uid = useUID();
|
|
17
|
-
const { id = uid, status, label, labelHidden, info, required, disabled, readOnly, additionalInfo, value = '', onChange, onFocus, onBlur, onResolveSuggestion, unit, showDecimal = true, numberOfDecimals: numberOfDecimalsProp = NUMBER_MAX_DECIMAL_PLACES, showGroupSeparators = true, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER, step = 1, variant, 'aria-label': ariaLabel, autoFocus, ...restProps } = props;
|
|
18
|
+
const { testId, id = uid, status, label, labelHidden, info, required, disabled, readOnly, additionalInfo, value = '', onChange, onFocus, onBlur, onResolveSuggestion, unit, showDecimal = true, numberOfDecimals: numberOfDecimalsProp = NUMBER_MAX_DECIMAL_PLACES, showGroupSeparators = true, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER, step = 1, variant, 'aria-label': ariaLabel, autoFocus, ...restProps } = props;
|
|
19
|
+
const testIds = useTestIds(testId, getNumberInputTestIds);
|
|
18
20
|
const { locale } = useConfiguration();
|
|
19
21
|
const inputRef = useConsolidatedRef(ref);
|
|
20
22
|
const containerRef = useRef(null);
|
|
@@ -85,18 +87,18 @@ const NumberInput = forwardRef((props, ref) => {
|
|
|
85
87
|
};
|
|
86
88
|
const formattedValue = useInputFormatter(inputRef, value, formatValue, `\\p{N}${decimalSign}-`);
|
|
87
89
|
const t = useI18n();
|
|
88
|
-
const
|
|
90
|
+
const numberInput = (_jsx(Flex, { "data-testid": testIds.root, as: StyledNumberInput, hasSuggestion: status === 'pending' && !!onResolveSuggestion, container: { alignItems: 'center', wrap: 'nowrap' }, status: status, readOnly: readOnly, disabled: disabled, children: _jsx(StyledInput, { "data-testid": testIds.control, ...{ onChange: onInputChange, id, readOnly, required, disabled, status, ...restProps }, inputMode: 'numeric', ref: inputRef, value: formattedValue, onKeyDown: onKeyDown, onFocus: onInputFocusEvent, onBlur: onInputFocusEvent, "aria-label": `${ariaLabel || label}. ${unit ? t('measured_in', [unit]) : ''}`, maxLength: 16, autoFocus: autoFocus, "aria-describedby": info ? `${id}-info` : undefined }) }));
|
|
89
91
|
const onMinusClick = () => {
|
|
90
92
|
onChange?.(getDecrementedValue(value, min, max, step));
|
|
91
93
|
};
|
|
92
94
|
const onPlusClick = () => {
|
|
93
95
|
onChange?.(getIncrementedValue(value, min, max, step));
|
|
94
96
|
};
|
|
95
|
-
const
|
|
97
|
+
const stepper = (_jsxs(Flex, { as: StyledStepperInput, hasSuggestion: status === 'pending' && !!onResolveSuggestion, container: { alignItems: 'center', wrap: 'nowrap' }, status: status, readOnly: readOnly, disabled: disabled, size: formattedValue?.length, children: [_jsx(Button, { "data-testid": testIds.minus, variant: 'simple', icon: true, onClick: onMinusClick, readOnly: readOnly, disabled: disabled, tabIndex: -1, "aria-hidden": 'true', children: _jsx(Icon, { name: 'minus' }) }), _jsx(Flex, { container: { alignItems: 'center', wrap: 'nowrap', justify: 'center' }, item: { grow: 1 }, ref: containerRef, onClick: (e) => {
|
|
96
98
|
if (e.target === containerRef.current)
|
|
97
99
|
inputRef?.current?.focus();
|
|
98
|
-
}, children: _jsx(StyledInput, { ...{ onChange: onInputChange, id, readOnly, required, disabled, status, ...restProps }, inputMode: 'numeric', ref: inputRef, value: formattedValue, onKeyDown: onKeyDown, onFocus: onInputFocusEvent, onBlur: onInputFocusEvent, "aria-label": `${ariaLabel || label}. ${unit ? t('measured_in', [unit]) : ''}`, maxLength: 16, autoFocus: autoFocus, "aria-describedby": `${id}-info` }) }), _jsx(Button, { variant: 'simple', icon: true, onClick: onPlusClick, readOnly: readOnly, disabled: disabled, tabIndex: -1, "aria-hidden": 'true', children: _jsx(Icon, { name: 'plus' }) })] }));
|
|
99
|
-
const Comp = variant === 'stepper' && !readOnly ?
|
|
100
|
+
}, children: _jsx(StyledInput, { "data-testid": testIds.control, ...{ onChange: onInputChange, id, readOnly, required, disabled, status, ...restProps }, inputMode: 'numeric', ref: inputRef, value: formattedValue, onKeyDown: onKeyDown, onFocus: onInputFocusEvent, onBlur: onInputFocusEvent, "aria-label": `${ariaLabel || label}. ${unit ? t('measured_in', [unit]) : ''}`, maxLength: 16, autoFocus: autoFocus, "aria-describedby": `${id}-info` }) }), _jsx(Button, { "data-testid": testIds.plus, variant: 'simple', icon: true, onClick: onPlusClick, readOnly: readOnly, disabled: disabled, tabIndex: -1, "aria-hidden": 'true', children: _jsx(Icon, { name: 'plus' }) })] }));
|
|
101
|
+
const Comp = variant === 'stepper' && !readOnly ? stepper : numberInput;
|
|
100
102
|
return label ? (_jsx(FormField, { ...{
|
|
101
103
|
label,
|
|
102
104
|
labelHidden,
|
|
@@ -107,6 +109,7 @@ const NumberInput = forwardRef((props, ref) => {
|
|
|
107
109
|
readOnly,
|
|
108
110
|
disabled,
|
|
109
111
|
additionalInfo,
|
|
112
|
+
testId,
|
|
110
113
|
onResolveSuggestion
|
|
111
114
|
}, children: Comp })) : (Comp);
|
|
112
115
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberInput.js","sourceRoot":"","sources":["../../../src/components/Number/NumberInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAEL,UAAU,EAIV,WAAW,EACX,OAAO,EACP,MAAM,EAEP,MAAM,OAAO,CAAC;AAEf,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,SAAS,MAAM,0BAA0B,CAAC;AACtD,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EACL,gBA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,MAAM,EAAE,GAAG,SAAS,EAAE,EACvF,SAAS,EAAC,SAAS,EACnB,GAAG,EAAE,QAAQ,EACb,KAAK,EAAE,cAAc,EACrB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,iBAAiB,gBACb,GAAG,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAC5E,SAAS,EAAE,EAAE,EACb,SAAS,EAAE,SAAS,sBACF,GAAG,EAAE,OAAO,GAC9B,GACG,EACP,KAAC,MAAM,IACL,OAAO,EAAC,QAAQ,EAChB,IAAI,QACJ,OAAO,EAAE,WAAW,EACpB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,CAAC,CAAC,iBACA,MAAM,YAElB,KAAC,IAAI,IAAC,IAAI,EAAC,MAAM,GAAG,GACb,IACJ,CACR,CAAC;IAEF,MAAM,IAAI,GAAG,OAAO,KAAK,SAAS,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,eAAe,CAAC;IAEhF,OAAO,KAAK,CAAC,CAAC,CAAC,CACb,KAAC,SAAS,OACJ;YACF,KAAK;YACL,WAAW;YACX,EAAE;YACF,IAAI;YACJ,MAAM;YACN,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,cAAc;YACd,mBAAmB;SACpB,YAEA,IAAI,GACK,CACb,CAAC,CAAC,CAAC,CACF,IAAI,CACL,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC","sourcesContent":["import {\n ChangeEvent,\n forwardRef,\n FunctionComponent,\n KeyboardEvent,\n PropsWithoutRef,\n useCallback,\n useMemo,\n useRef,\n FocusEvent\n} from 'react';\n\nimport Button from '../Button';\nimport Icon, { registerIcon } from '../Icon';\nimport * as plusIcon from '../Icon/icons/plus.icon';\nimport * as minusIcon from '../Icon/icons/minus.icon';\nimport Flex from '../Flex';\nimport FormField from '../FormField';\nimport { ForwardProps } from '../../types';\nimport {\n useConfiguration,\n useConsolidatedRef,\n useI18n,\n useInputFormatter,\n useUID\n} from '../../hooks';\nimport StyledInput from '../Input/Input.styles';\n\nimport StyledNumberInput, { StyledStepperInput } from './NumberInput.styles';\nimport { NumberInputProps, NUMBER_MAX_DECIMAL_PLACES } from './NumberInput.types';\nimport {\n getCleanedValue,\n getDecimalSign,\n getDecrementedValue,\n getFormattedValue,\n getIncrementedValue\n} from './utils';\n\nregisterIcon(minusIcon, plusIcon);\n\nconst NumberInput: FunctionComponent<NumberInputProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<NumberInputProps>, ref: NumberInputProps['ref']) => {\n const uid = useUID();\n const {\n id = uid,\n status,\n label,\n labelHidden,\n info,\n required,\n disabled,\n readOnly,\n additionalInfo,\n value = '',\n onChange,\n onFocus,\n onBlur,\n onResolveSuggestion,\n unit,\n showDecimal = true,\n numberOfDecimals: numberOfDecimalsProp = NUMBER_MAX_DECIMAL_PLACES,\n showGroupSeparators = true,\n min = Number.MIN_SAFE_INTEGER,\n max = Number.MAX_SAFE_INTEGER,\n step = 1,\n variant,\n 'aria-label': ariaLabel,\n autoFocus,\n ...restProps\n } = props;\n\n const { locale } = useConfiguration();\n const inputRef = useConsolidatedRef(ref);\n const containerRef = useRef<HTMLElement>(null);\n const maximumFractionDigits = showDecimal ? numberOfDecimalsProp : 0;\n const decimalSign = useMemo(() => getDecimalSign(locale), [locale]);\n\n const formatValue = useCallback(\n number => {\n return getFormattedValue(number, locale, unit, {\n useGrouping: showGroupSeparators,\n maximumFractionDigits\n });\n },\n [locale, unit, showGroupSeparators, maximumFractionDigits]\n );\n\n const onInputChange = (e: ChangeEvent<HTMLInputElement>) => {\n const inputValue = e.target.value;\n const cleanedInputValue = getCleanedValue(inputValue, decimalSign, maximumFractionDigits);\n if (cleanedInputValue === value) return;\n onChange(cleanedInputValue);\n };\n\n const onKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {\n if (readOnly) return;\n const input = e.currentTarget;\n switch (e.key) {\n case 'ArrowUp':\n e.preventDefault();\n onChange(getIncrementedValue(value, min, max, step));\n break;\n case 'ArrowDown':\n e.preventDefault();\n onChange(getDecrementedValue(value, min, max, step));\n break;\n case decimalSign:\n if (input.value.includes(decimalSign)) {\n if (input.selectionStart && input.value.charAt(input.selectionStart) === decimalSign) {\n input.setSelectionRange(input.selectionStart + 1, input.selectionStart + 1);\n }\n e.preventDefault();\n } else if (\n input.selectionStart !== null &&\n !input.value.charAt(input.selectionStart - 1).match(/\\d/)\n ) {\n onChange(\n getCleanedValue(`${input.value}0${decimalSign}`, decimalSign, maximumFractionDigits)\n );\n e.preventDefault();\n }\n break;\n case '-':\n if (value.startsWith('-')) e.preventDefault();\n break;\n default:\n }\n };\n\n const onInputFocusEvent = (e: FocusEvent<HTMLInputElement>) => {\n let parsableValue = value;\n\n if (Number.isNaN(parseFloat(value))) {\n parsableValue = '';\n } else if (value?.endsWith('.')) {\n parsableValue = value.slice(0, -1);\n }\n\n if (e.type === 'focus') onFocus?.(parsableValue);\n else {\n if (parsableValue !== value) {\n onChange(parsableValue);\n }\n\n onBlur?.(parsableValue);\n }\n };\n\n const formattedValue = useInputFormatter(inputRef, value, formatValue, `\\\\p{N}${decimalSign}-`);\n\n const t = useI18n();\n\n const NumberInputComp = (\n <Flex\n as={StyledNumberInput}\n hasSuggestion={status === 'pending' && !!onResolveSuggestion}\n container={{ alignItems: 'center', wrap: 'nowrap' }}\n status={status}\n readOnly={readOnly}\n disabled={disabled}\n >\n <StyledInput\n {...{ onChange: onInputChange, id, readOnly, required, disabled, status, ...restProps }}\n inputMode='numeric'\n ref={inputRef}\n value={formattedValue}\n onKeyDown={onKeyDown}\n onFocus={onInputFocusEvent}\n onBlur={onInputFocusEvent}\n aria-label={`${ariaLabel || label}. ${unit ? t('measured_in', [unit]) : ''}`}\n maxLength={16}\n autoFocus={autoFocus}\n aria-describedby={info ? `${id}-info` : undefined}\n />\n </Flex>\n );\n\n const onMinusClick = () => {\n onChange?.(getDecrementedValue(value, min, max, step));\n };\n\n const onPlusClick = () => {\n onChange?.(getIncrementedValue(value, min, max, step));\n };\n\n const StepperComp = (\n <Flex\n as={StyledStepperInput}\n hasSuggestion={status === 'pending' && !!onResolveSuggestion}\n container={{ alignItems: 'center', wrap: 'nowrap' }}\n status={status}\n readOnly={readOnly}\n disabled={disabled}\n size={formattedValue?.length}\n >\n <Button\n variant='simple'\n icon\n onClick={onMinusClick}\n readOnly={readOnly}\n disabled={disabled}\n tabIndex={-1}\n aria-hidden='true'\n >\n <Icon name='minus' />\n </Button>\n <Flex\n container={{ alignItems: 'center', wrap: 'nowrap', justify: 'center' }}\n item={{ grow: 1 }}\n ref={containerRef}\n onClick={(e: MouseEvent) => {\n if (e.target === containerRef.current) inputRef?.current?.focus();\n }}\n >\n <StyledInput\n {...{ onChange: onInputChange, id, readOnly, required, disabled, status, ...restProps }}\n inputMode='numeric'\n ref={inputRef}\n value={formattedValue}\n onKeyDown={onKeyDown}\n onFocus={onInputFocusEvent}\n onBlur={onInputFocusEvent}\n aria-label={`${ariaLabel || label}. ${unit ? t('measured_in', [unit]) : ''}`}\n maxLength={16}\n autoFocus={autoFocus}\n aria-describedby={`${id}-info`}\n />\n </Flex>\n <Button\n variant='simple'\n icon\n onClick={onPlusClick}\n readOnly={readOnly}\n disabled={disabled}\n tabIndex={-1}\n aria-hidden='true'\n >\n <Icon name='plus' />\n </Button>\n </Flex>\n );\n\n const Comp = variant === 'stepper' && !readOnly ? StepperComp : NumberInputComp;\n\n return label ? (\n <FormField\n {...{\n label,\n labelHidden,\n id,\n info,\n status,\n required,\n readOnly,\n disabled,\n additionalInfo,\n onResolveSuggestion\n }}\n >\n {Comp}\n </FormField>\n ) : (\n Comp\n );\n }\n);\n\nexport default NumberInput;\n"]}
|
|
1
|
+
{"version":3,"file":"NumberInput.js","sour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AQ,EAAE,CAAC,CAAC,iBACA,MAAM,YAElB,KAAC,IAAI,IAAC,IAAI,EAAC,MAAM,GAAG,GACb,IACJ,CACR,CAAC;IAEF,MAAM,IAAI,GAAG,OAAO,KAAK,SAAS,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC;IAExE,OAAO,KAAK,CAAC,CAAC,CAAC,CACb,KAAC,SAAS,OACJ;YACF,KAAK;YACL,WAAW;YACX,EAAE;YACF,IAAI;YACJ,MAAM;YACN,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,cAAc;YACd,MAAM;YACN,mBAAmB;SACpB,YAEA,IAAI,GACK,CACb,CAAC,CAAC,CAAC,CACF,IAAI,CACL,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC","sourcesContent":["import {\n ChangeEvent,\n forwardRef,\n FunctionComponent,\n KeyboardEvent,\n PropsWithoutRef,\n useCallback,\n useMemo,\n useRef,\n FocusEvent\n} from 'react';\n\nimport Button from '../Button';\nimport Icon, { registerIcon } from '../Icon';\nimport * as plusIcon from '../Icon/icons/plus.icon';\nimport * as minusIcon from '../Icon/icons/minus.icon';\nimport Flex from '../Flex';\nimport FormField from '../FormField';\nimport { ForwardProps } from '../../types';\nimport {\n useConfiguration,\n useConsolidatedRef,\n useI18n,\n useInputFormatter,\n useTestIds,\n useUID\n} from '../../hooks';\nimport StyledInput from '../Input/Input.styles';\n\nimport StyledNumberInput, { StyledStepperInput } from './NumberInput.styles';\nimport { NumberInputProps, NUMBER_MAX_DECIMAL_PLACES } from './NumberInput.types';\nimport {\n getCleanedValue,\n getDecimalSign,\n getDecrementedValue,\n getFormattedValue,\n getIncrementedValue\n} from './utils';\nimport { getNumberInputTestIds } from './Number.test-ids';\n\nregisterIcon(minusIcon, plusIcon);\n\nconst NumberInput: FunctionComponent<NumberInputProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<NumberInputProps>, ref: NumberInputProps['ref']) => {\n const uid = useUID();\n const {\n testId,\n id = uid,\n status,\n label,\n labelHidden,\n info,\n required,\n disabled,\n readOnly,\n additionalInfo,\n value = '',\n onChange,\n onFocus,\n onBlur,\n onResolveSuggestion,\n unit,\n showDecimal = true,\n numberOfDecimals: numberOfDecimalsProp = NUMBER_MAX_DECIMAL_PLACES,\n showGroupSeparators = true,\n min = Number.MIN_SAFE_INTEGER,\n max = Number.MAX_SAFE_INTEGER,\n step = 1,\n variant,\n 'aria-label': ariaLabel,\n autoFocus,\n ...restProps\n } = props;\n\n const testIds = useTestIds(testId, getNumberInputTestIds);\n\n const { locale } = useConfiguration();\n const inputRef = useConsolidatedRef(ref);\n const containerRef = useRef<HTMLElement>(null);\n const maximumFractionDigits = showDecimal ? numberOfDecimalsProp : 0;\n const decimalSign = useMemo(() => getDecimalSign(locale), [locale]);\n\n const formatValue = useCallback(\n number => {\n return getFormattedValue(number, locale, unit, {\n useGrouping: showGroupSeparators,\n maximumFractionDigits\n });\n },\n [locale, unit, showGroupSeparators, maximumFractionDigits]\n );\n\n const onInputChange = (e: ChangeEvent<HTMLInputElement>) => {\n const inputValue = e.target.value;\n const cleanedInputValue = getCleanedValue(inputValue, decimalSign, maximumFractionDigits);\n if (cleanedInputValue === value) return;\n onChange(cleanedInputValue);\n };\n\n const onKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {\n if (readOnly) return;\n const input = e.currentTarget;\n switch (e.key) {\n case 'ArrowUp':\n e.preventDefault();\n onChange(getIncrementedValue(value, min, max, step));\n break;\n case 'ArrowDown':\n e.preventDefault();\n onChange(getDecrementedValue(value, min, max, step));\n break;\n case decimalSign:\n if (input.value.includes(decimalSign)) {\n if (input.selectionStart && input.value.charAt(input.selectionStart) === decimalSign) {\n input.setSelectionRange(input.selectionStart + 1, input.selectionStart + 1);\n }\n e.preventDefault();\n } else if (\n input.selectionStart !== null &&\n !input.value.charAt(input.selectionStart - 1).match(/\\d/)\n ) {\n onChange(\n getCleanedValue(`${input.value}0${decimalSign}`, decimalSign, maximumFractionDigits)\n );\n e.preventDefault();\n }\n break;\n case '-':\n if (value.startsWith('-')) e.preventDefault();\n break;\n default:\n }\n };\n\n const onInputFocusEvent = (e: FocusEvent<HTMLInputElement>) => {\n let parsableValue = value;\n\n if (Number.isNaN(parseFloat(value))) {\n parsableValue = '';\n } else if (value?.endsWith('.')) {\n parsableValue = value.slice(0, -1);\n }\n\n if (e.type === 'focus') onFocus?.(parsableValue);\n else {\n if (parsableValue !== value) {\n onChange(parsableValue);\n }\n\n onBlur?.(parsableValue);\n }\n };\n\n const formattedValue = useInputFormatter(inputRef, value, formatValue, `\\\\p{N}${decimalSign}-`);\n\n const t = useI18n();\n\n const numberInput = (\n <Flex\n data-testid={testIds.root}\n as={StyledNumberInput}\n hasSuggestion={status === 'pending' && !!onResolveSuggestion}\n container={{ alignItems: 'center', wrap: 'nowrap' }}\n status={status}\n readOnly={readOnly}\n disabled={disabled}\n >\n <StyledInput\n data-testid={testIds.control}\n {...{ onChange: onInputChange, id, readOnly, required, disabled, status, ...restProps }}\n inputMode='numeric'\n ref={inputRef}\n value={formattedValue}\n onKeyDown={onKeyDown}\n onFocus={onInputFocusEvent}\n onBlur={onInputFocusEvent}\n aria-label={`${ariaLabel || label}. ${unit ? t('measured_in', [unit]) : ''}`}\n maxLength={16}\n autoFocus={autoFocus}\n aria-describedby={info ? `${id}-info` : undefined}\n />\n </Flex>\n );\n\n const onMinusClick = () => {\n onChange?.(getDecrementedValue(value, min, max, step));\n };\n\n const onPlusClick = () => {\n onChange?.(getIncrementedValue(value, min, max, step));\n };\n\n const stepper = (\n <Flex\n as={StyledStepperInput}\n hasSuggestion={status === 'pending' && !!onResolveSuggestion}\n container={{ alignItems: 'center', wrap: 'nowrap' }}\n status={status}\n readOnly={readOnly}\n disabled={disabled}\n size={formattedValue?.length}\n >\n <Button\n data-testid={testIds.minus}\n variant='simple'\n icon\n onClick={onMinusClick}\n readOnly={readOnly}\n disabled={disabled}\n tabIndex={-1}\n aria-hidden='true'\n >\n <Icon name='minus' />\n </Button>\n <Flex\n container={{ alignItems: 'center', wrap: 'nowrap', justify: 'center' }}\n item={{ grow: 1 }}\n ref={containerRef}\n onClick={(e: MouseEvent) => {\n if (e.target === containerRef.current) inputRef?.current?.focus();\n }}\n >\n <StyledInput\n data-testid={testIds.control}\n {...{ onChange: onInputChange, id, readOnly, required, disabled, status, ...restProps }}\n inputMode='numeric'\n ref={inputRef}\n value={formattedValue}\n onKeyDown={onKeyDown}\n onFocus={onInputFocusEvent}\n onBlur={onInputFocusEvent}\n aria-label={`${ariaLabel || label}. ${unit ? t('measured_in', [unit]) : ''}`}\n maxLength={16}\n autoFocus={autoFocus}\n aria-describedby={`${id}-info`}\n />\n </Flex>\n <Button\n data-testid={testIds.plus}\n variant='simple'\n icon\n onClick={onPlusClick}\n readOnly={readOnly}\n disabled={disabled}\n tabIndex={-1}\n aria-hidden='true'\n >\n <Icon name='plus' />\n </Button>\n </Flex>\n );\n\n const Comp = variant === 'stepper' && !readOnly ? stepper : numberInput;\n\n return label ? (\n <FormField\n {...{\n label,\n labelHidden,\n id,\n info,\n status,\n required,\n readOnly,\n disabled,\n additionalInfo,\n testId,\n onResolveSuggestion\n }}\n >\n {Comp}\n </FormField>\n ) : (\n Comp\n );\n }\n);\n\nexport default NumberInput;\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Ref } from 'react';
|
|
2
2
|
import { FormControlProps, HandleValue } from '../FormControl';
|
|
3
|
-
import { BaseProps, NoChildrenProp } from '../../types';
|
|
4
|
-
export interface NumberProps extends BaseProps, NoChildrenProp {
|
|
3
|
+
import { BaseProps, NoChildrenProp, TestIdProp } from '../../types';
|
|
4
|
+
export interface NumberProps extends BaseProps, NoChildrenProp, TestIdProp {
|
|
5
5
|
/**
|
|
6
6
|
* Sets DOM id for the control and associates label element via 'for' attribute.
|
|
7
7
|
* If an id is not pass, a random id will be generated for any render.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberInput.types.d.ts","sourceRoot":"","sources":["../../../src/components/Number/NumberInput.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"NumberInput.types.d.ts","sourceRoot":"","sources":["../../../src/components/Number/NumberInput.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEpE,MAAM,WAAW,WAAY,SAAQ,SAAS,EAAE,cAAc,EAAE,UAAU;IACxE;;;OAGG;IACH,EAAE,CAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC5B,oDAAoD;IACpD,MAAM,CAAC,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACpC,2DAA2D;IAC3D,KAAK,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAClC;;;OAGG;IACH,WAAW,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC;IAC9C,6GAA6G;IAC7G,IAAI,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAChC,wEAAwE;IACxE,QAAQ,CAAC,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACxC,iEAAiE;IACjE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACxC,yFAAyF;IACzF,QAAQ,CAAC,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACx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AAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,kDAAkD;IAClD,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAC1D,qDAAqD;IACrD,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACzD,oDAAoD;IACpD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAC1D,8FAA8F;IAC9F,SAAS,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACtC,+FAA+F;IAC/F,OAAO,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACpC,wHAAwH;IACxH,kBAAkB,CAAC,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IACxD,yHAAyH;IACzH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IACtD,wBAAwB;IACxB,MAAM,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CAC3B;AAED,qCAAqC;AACrC,eAAO,MAAM,yBAAyB,KAAK,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberInput.types.js","sourceRoot":"","sources":["../../../src/components/Number/NumberInput.types.ts"],"names":[],"mappings":"AAmHA,qCAAqC;AACrC,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC","sourcesContent":["import { Ref } from 'react';\n\nimport { FormControlProps, HandleValue } from '../FormControl';\nimport { BaseProps, NoChildrenProp } from '../../types';\n\nexport interface NumberProps extends BaseProps, NoChildrenProp {\n /**\n * Sets DOM id for the control and associates label element via 'for' attribute.\n * If an id is not pass, a random id will be generated for any render.\n */\n id?: FormControlProps['id'];\n /** Set visual state based on a validation state. */\n status?: FormControlProps['status'];\n /** Pass a string or a fragment with an Icon and string. */\n label?: FormControlProps['label'];\n /**\n * Visually hides the label region.\n * @default false\n */\n labelHidden?: FormControlProps['labelHidden'];\n /** It is recommended to pass a simple string to offer guidance. Text will be styled based on status prop. */\n info?: FormControlProps['info'];\n /** Indicate if the field is required. The browser defaults to false. */\n required?: FormControlProps['required'];\n /** Placeholder text. The browser defaults to an empty string. */\n placeholder?: string;\n /** Disable the control. The browser defaults to false. */\n disabled?: FormControlProps['disabled'];\n /** Makes the component non editable and non clickable. The browser defaults to false. */\n readOnly?: FormControlProps['readOnly'];\n /** Sets html name attribute for the underlying control. Useful for mapping to a data field. */\n name?: FormControlProps['name'];\n /** Button when clicked will show additional information */\n additionalInfo?: FormControlProps['additionalInfo'];\n /** Defines unit of the number, like 'kg', 'miles' or '%'. */\n unit?: string;\n /**\n *\n /** Determines whether decimal places should be shown. The value is rounded if true.\n * @default true\n */\n showDecimal?: boolean;\n /** Determines the maximum number of decimal places. The value is rounded to the number of places.\n * @default variable NUMBER_MAX_DECIMAL_PLACES. Recommended minimum: 1.\n */\n numberOfDecimals?: number;\n /** Determines whether group separators should be shown.\n * @default true\n */\n showGroupSeparators?: boolean;\n /** The minimum value to accept for this input.\n * This value must be less than or equal to the value of the max attribute.\n * @default Number.MIN_SAFE_INTEGER\n */\n min?: number;\n /**\n * The maximum value to accept for this input.\n * This value must be greater than or equal to the value of the min attribute.\n * @default Number.MAX_SAFE_INTEGER\n */\n max?: number;\n /** A stepping interval to use when using up and down arrows to adjust the value.\n * @default 1\n */\n step?: number;\n /**\n * Component variation. Might be rendered as regular input or stepper.\n * @default 'default'\n */\n variant?: 'default' | 'stepper';\n /** Optional manual override for generated aria label */\n 'aria-label'?: string;\n /** Automatically focuses the input on render. */\n autoFocus?: boolean;\n}\n\nexport interface NumberInputProps extends NumberProps {\n /**\n * CurrencyInput input value.\n * Requires an onChange handler to update value.\n */\n value?: string;\n /** Callback fired when input value changes. */\n onChange: (value: string) => void;\n /** Callback fired when the component gets focus. */\n onFocus?: (value: string) => void;\n /** Callback fired when the component loses focus. */\n onBlur?: (value: string) => void;\n /** Callback fired when AI suggestion is accepted/rejected */\n onResolveSuggestion?: FormControlProps['onResolveSuggestion'];\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLInputElement>;\n}\n\nexport interface NumberRangeInputProps extends NumberProps {\n /** Range as a tuple of start and end. */\n value?: { start?: string; end?: string };\n /** Callback for any modifications to the range */\n onChange: (value: { start: string; end: string }) => void;\n /** Callback fired when the component loses focus. */\n onBlur?: (value: { start: string; end: string }) => void;\n /** Callback fired when the component gets focus. */\n onFocus?: (value: { start: string; end: string }) => void;\n /** Pass a string or a fragment with an Icon and string for first part of NumberRangeInput. */\n fromLabel?: FormControlProps['label'];\n /** Pass a string or a fragment with an Icon and string for second part of NumberRangeInput. */\n toLabel?: FormControlProps['label'];\n /** Pass an object with \"heading\" and \"content\" properties to show AdditionalInfo for first part of NumberRangeInput. */\n fromAdditionalInfo?: FormControlProps['additionalInfo'];\n /** Pass an object with \"heading\" and \"content\" properties to show AdditionalInfo for second part of NumberRangeInput. */\n toAdditionalInfo?: FormControlProps['additionalInfo'];\n /** Imperative handle */\n handle?: Ref<HandleValue>;\n}\n\n/** Maximum fraction digits is 20. */\nexport const NUMBER_MAX_DECIMAL_PLACES = 20;\n"]}
|
|
1
|
+
{"version":3,"file":"NumberInput.types.js","sourceRoot":"","sources":["../../../src/components/Number/NumberInput.types.ts"],"names":[],"mappings":"AAmHA,qCAAqC;AACrC,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC","sourcesContent":["import { Ref } from 'react';\n\nimport { FormControlProps, HandleValue } from '../FormControl';\nimport { BaseProps, NoChildrenProp, TestIdProp } from '../../types';\n\nexport interface NumberProps extends BaseProps, NoChildrenProp, TestIdProp {\n /**\n * Sets DOM id for the control and associates label element via 'for' attribute.\n * If an id is not pass, a random id will be generated for any render.\n */\n id?: FormControlProps['id'];\n /** Set visual state based on a validation state. */\n status?: FormControlProps['status'];\n /** Pass a string or a fragment with an Icon and string. */\n label?: FormControlProps['label'];\n /**\n * Visually hides the label region.\n * @default false\n */\n labelHidden?: FormControlProps['labelHidden'];\n /** It is recommended to pass a simple string to offer guidance. Text will be styled based on status prop. */\n info?: FormControlProps['info'];\n /** Indicate if the field is required. The browser defaults to false. */\n required?: FormControlProps['required'];\n /** Placeholder text. The browser defaults to an empty string. */\n placeholder?: string;\n /** Disable the control. The browser defaults to false. */\n disabled?: FormControlProps['disabled'];\n /** Makes the component non editable and non clickable. The browser defaults to false. */\n readOnly?: FormControlProps['readOnly'];\n /** Sets html name attribute for the underlying control. Useful for mapping to a data field. */\n name?: FormControlProps['name'];\n /** Button when clicked will show additional information */\n additionalInfo?: FormControlProps['additionalInfo'];\n /** Defines unit of the number, like 'kg', 'miles' or '%'. */\n unit?: string;\n /**\n *\n /** Determines whether decimal places should be shown. The value is rounded if true.\n * @default true\n */\n showDecimal?: boolean;\n /** Determines the maximum number of decimal places. The value is rounded to the number of places.\n * @default variable NUMBER_MAX_DECIMAL_PLACES. Recommended minimum: 1.\n */\n numberOfDecimals?: number;\n /** Determines whether group separators should be shown.\n * @default true\n */\n showGroupSeparators?: boolean;\n /** The minimum value to accept for this input.\n * This value must be less than or equal to the value of the max attribute.\n * @default Number.MIN_SAFE_INTEGER\n */\n min?: number;\n /**\n * The maximum value to accept for this input.\n * This value must be greater than or equal to the value of the min attribute.\n * @default Number.MAX_SAFE_INTEGER\n */\n max?: number;\n /** A stepping interval to use when using up and down arrows to adjust the value.\n * @default 1\n */\n step?: number;\n /**\n * Component variation. Might be rendered as regular input or stepper.\n * @default 'default'\n */\n variant?: 'default' | 'stepper';\n /** Optional manual override for generated aria label */\n 'aria-label'?: string;\n /** Automatically focuses the input on render. */\n autoFocus?: boolean;\n}\n\nexport interface NumberInputProps extends NumberProps {\n /**\n * CurrencyInput input value.\n * Requires an onChange handler to update value.\n */\n value?: string;\n /** Callback fired when input value changes. */\n onChange: (value: string) => void;\n /** Callback fired when the component gets focus. */\n onFocus?: (value: string) => void;\n /** Callback fired when the component loses focus. */\n onBlur?: (value: string) => void;\n /** Callback fired when AI suggestion is accepted/rejected */\n onResolveSuggestion?: FormControlProps['onResolveSuggestion'];\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLInputElement>;\n}\n\nexport interface NumberRangeInputProps extends NumberProps {\n /** Range as a tuple of start and end. */\n value?: { start?: string; end?: string };\n /** Callback for any modifications to the range */\n onChange: (value: { start: string; end: string }) => void;\n /** Callback fired when the component loses focus. */\n onBlur?: (value: { start: string; end: string }) => void;\n /** Callback fired when the component gets focus. */\n onFocus?: (value: { start: string; end: string }) => void;\n /** Pass a string or a fragment with an Icon and string for first part of NumberRangeInput. */\n fromLabel?: FormControlProps['label'];\n /** Pass a string or a fragment with an Icon and string for second part of NumberRangeInput. */\n toLabel?: FormControlProps['label'];\n /** Pass an object with \"heading\" and \"content\" properties to show AdditionalInfo for first part of NumberRangeInput. */\n fromAdditionalInfo?: FormControlProps['additionalInfo'];\n /** Pass an object with \"heading\" and \"content\" properties to show AdditionalInfo for second part of NumberRangeInput. */\n toAdditionalInfo?: FormControlProps['additionalInfo'];\n /** Imperative handle */\n handle?: Ref<HandleValue>;\n}\n\n/** Maximum fraction digits is 20. */\nexport const NUMBER_MAX_DECIMAL_PLACES = 20;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberRangeInput.d.ts","sourceRoot":"","sources":["../../../src/components/Number/NumberRangeInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAMlB,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAOhD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"NumberRangeInput.d.ts","sourceRoot":"","sources":["../../../src/components/Number/NumberRangeInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAMlB,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAOhD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAmBjE,QAAA,MAAM,gBAAgB,EAAE,iBAAiB,CAAC,qBAAqB,GAAG,YAAY,CAoK7E,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef, useCallback, useImperativeHandle, useReducer, useRef } from 'react';
|
|
3
|
-
import { useConsolidatedRef, useI18n, useFocusWithin } from '../../hooks';
|
|
3
|
+
import { useConsolidatedRef, useI18n, useFocusWithin, useTestIds } from '../../hooks';
|
|
4
4
|
import { StyledRangeInputContainer } from '../Input/Input.styles';
|
|
5
5
|
import FormField from '../FormField';
|
|
6
6
|
import Flex from '../Flex';
|
|
7
7
|
import NumberInput from './NumberInput';
|
|
8
|
+
import { getNumberRangeTestIds } from './Number.test-ids';
|
|
8
9
|
const reducer = (prevState, { type, value }) => {
|
|
9
10
|
switch (type) {
|
|
10
11
|
case 'start': {
|
|
@@ -17,7 +18,8 @@ const reducer = (prevState, { type, value }) => {
|
|
|
17
18
|
return prevState;
|
|
18
19
|
}
|
|
19
20
|
};
|
|
20
|
-
const NumberRangeInput = forwardRef(({ value = {}, onChange, onBlur, onFocus, label, fromLabel, toLabel, labelHidden, placeholder, disabled, readOnly, required, status, unit, showDecimal, numberOfDecimals, showGroupSeparators, min, max, step, variant, fromAdditionalInfo, toAdditionalInfo, autoFocus, handle, ...restProps }, ref) => {
|
|
21
|
+
const NumberRangeInput = forwardRef(({ testId, value = {}, onChange, onBlur, onFocus, label, fromLabel, toLabel, labelHidden, placeholder, disabled, readOnly, required, status, unit, showDecimal, numberOfDecimals, showGroupSeparators, min, max, step, variant, fromAdditionalInfo, toAdditionalInfo, autoFocus, handle, ...restProps }, ref) => {
|
|
22
|
+
const testIds = useTestIds(testId, getNumberRangeTestIds);
|
|
21
23
|
const t = useI18n();
|
|
22
24
|
const startValueInputRef = useRef(null);
|
|
23
25
|
const endValueInputRef = useRef(null);
|
|
@@ -59,7 +61,7 @@ const NumberRangeInput = forwardRef(({ value = {}, onChange, onBlur, onFocus, la
|
|
|
59
61
|
max,
|
|
60
62
|
variant
|
|
61
63
|
};
|
|
62
|
-
return (_jsx(FormField, { as: 'fieldset', ...restProps, ref: containerRef, container: { wrap: 'nowrap' }, labelHidden: labelHidden, labelAs: 'legend', label: label, disabled: disabled, required: required, readOnly: readOnly, status: status, children: _jsxs(Flex, { container: true, as: StyledRangeInputContainer, children: [_jsx(NumberInput, { ...commonProps, value: state.start, onChange: fromValue => {
|
|
64
|
+
return (_jsx(FormField, { testId: testIds.root, as: 'fieldset', ...restProps, ref: containerRef, container: { wrap: 'nowrap' }, labelHidden: labelHidden, labelAs: 'legend', label: label, disabled: disabled, required: required, readOnly: readOnly, status: status, children: _jsxs(Flex, { container: true, as: StyledRangeInputContainer, children: [_jsx(NumberInput, { testId: testIds.min, ...commonProps, value: state.start, onChange: fromValue => {
|
|
63
65
|
onChange({ start: fromValue, end: value.end ?? '' });
|
|
64
66
|
dispatch({
|
|
65
67
|
type: 'start',
|
|
@@ -75,7 +77,7 @@ const NumberRangeInput = forwardRef(({ value = {}, onChange, onBlur, onFocus, la
|
|
|
75
77
|
start: changedValue ?? '',
|
|
76
78
|
end: state.end
|
|
77
79
|
});
|
|
78
|
-
}, label: fromLabel, "aria-label": `${t('range_from_numeric') + (label ? ` - ${label}` : '')}`, additionalInfo: fromAdditionalInfo, autoFocus: autoFocus, ref: startValueInputRef }), _jsx(NumberInput, { ...commonProps, value: state.end, onChange: toValue => {
|
|
80
|
+
}, label: fromLabel, "aria-label": `${t('range_from_numeric') + (label ? ` - ${label}` : '')}`, additionalInfo: fromAdditionalInfo, autoFocus: autoFocus, ref: startValueInputRef }), _jsx(NumberInput, { testId: testIds.max, ...commonProps, value: state.end, onChange: toValue => {
|
|
79
81
|
onChange({ start: value.start ?? '', end: toValue });
|
|
80
82
|
dispatch({
|
|
81
83
|
type: 'end',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberRangeInput.js","sourceRoot":"","sources":["../../../src/components/Number/NumberRangeInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAGV,WAAW,EACX,mBAAmB,EACnB,UAAU,EACV,MAAM,EACP,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B,OAAO,WAAW,MAAM,eAAe,CAAC;AAMxC,MAAM,OAAO,GAAG,CAAC,SAAgB,EAAE,EAAE,IAAI,EAAE,KAAK,EAAmB,EAAS,EAAE;IAC5E,QAAQ,IAAI,EAAE;QACZ,KAAK,OAAO,CAAC,CAAC;YACZ,OAAO,EAAE,GAAG,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;SACvC;QACD,KAAK,KAAK,CAAC,CAAC;YACV,OAAO,EAAE,GAAG,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;SACrC;QACD;YACE,OAAO,SAAS,CAAC;KACpB;AACH,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAA4D,UAAU,CAC1F,CACE,EACE,KAAK,GAAG,EAAE,EACV,QAAQ,EACR,MAAM,EACN,OAAO,EACP,KAAK,EACL,SAAS,EACT,OAAO,EACP,WAAW,EACX,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,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ACH,WAAW,CAAC,OAAO,GAAG,YAAY,IAAI,EAAE,CAAC;wBACzC,QAAQ,CAAC;4BACP,KAAK,EAAE,KAAK,CAAC,KAAK;4BAClB,GAAG,EAAE,YAAY,IAAI,EAAE;yBACxB,CAAC,CAAC;oBACL,CAAC,EACD,KAAK,EAAE,OAAO,gBACF,GAAG,CAAC,CAAC,kBAAkB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EACrE,cAAc,EAAE,gBAAgB,EAChC,GAAG,EAAE,gBAAgB,GACrB,IACG,GACG,CACb,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n Ref,\n useCallback,\n useImperativeHandle,\n useReducer,\n useRef\n} from 'react';\n\nimport type { ForwardProps } from '../../types';\nimport { useConsolidatedRef, useI18n, useFocusWithin } from '../../hooks';\nimport { StyledRangeInputContainer } from '../Input/Input.styles';\nimport FormField from '../FormField';\nimport Flex from '../Flex';\n\nimport NumberInput from './NumberInput';\nimport type { NumberRangeInputProps } from './NumberInput.types';\n\ntype DateRangeAction = { type: 'start' | 'end'; value: string };\ntype State = { start: string; end: string };\n\nconst reducer = (prevState: State, { type, value }: DateRangeAction): State => {\n switch (type) {\n case 'start': {\n return { ...prevState, start: value };\n }\n case 'end': {\n return { ...prevState, end: value };\n }\n default:\n return prevState;\n }\n};\n\nconst NumberRangeInput: FunctionComponent<NumberRangeInputProps & ForwardProps> = forwardRef(\n (\n {\n value = {},\n onChange,\n onBlur,\n onFocus,\n label,\n fromLabel,\n toLabel,\n labelHidden,\n placeholder,\n disabled,\n readOnly,\n required,\n status,\n unit,\n showDecimal,\n numberOfDecimals,\n showGroupSeparators,\n min,\n max,\n step,\n variant,\n fromAdditionalInfo,\n toAdditionalInfo,\n autoFocus,\n handle,\n ...restProps\n }: NumberRangeInputProps,\n ref: Ref<HTMLDivElement>\n ) => {\n const t = useI18n();\n\n const startValueInputRef = useRef<HTMLInputElement>(null);\n const endValueInputRef = useRef<HTMLInputElement>(null);\n\n const [state, dispatch] = useReducer(reducer, {\n start: value.start ?? '',\n end: value.end ?? ''\n });\n\n // Need to keep the value in ref also, to be able to call onBlur with newest value\n const startValueRef = useRef(state.start);\n const endValueRef = useRef(state.end);\n\n const onFocusChange = useCallback(\n (focused: boolean) => {\n (focused ? onFocus : onBlur)?.({ start: startValueRef.current, end: endValueRef.current });\n },\n [onBlur, value.start, value.end]\n );\n\n const containerRef = useConsolidatedRef(ref);\n useFocusWithin([containerRef], onFocusChange);\n\n useImperativeHandle(\n handle,\n () => ({\n clear: () => {\n if (startValueInputRef.current) startValueInputRef.current.value = '';\n if (endValueInputRef.current) endValueInputRef.current.value = '';\n startValueRef.current = '';\n endValueRef.current = '';\n dispatch({ type: 'start', value: '' });\n dispatch({ type: 'end', value: '' });\n onChange({ start: '', end: '' });\n }\n }),\n [onChange]\n );\n\n const commonProps = {\n status,\n placeholder,\n readOnly,\n required,\n unit,\n showDecimal,\n numberOfDecimals,\n showGroupSeparators,\n min,\n max,\n variant\n };\n\n return (\n <FormField\n as='fieldset'\n {...restProps}\n ref={containerRef}\n container={{ wrap: 'nowrap' }}\n labelHidden={labelHidden}\n labelAs='legend'\n label={label}\n disabled={disabled}\n required={required}\n readOnly={readOnly}\n status={status}\n >\n <Flex container as={StyledRangeInputContainer}>\n <NumberInput\n {...commonProps}\n value={state.start}\n onChange={fromValue => {\n onChange({ start: fromValue, end: value.end ?? '' });\n dispatch({\n type: 'start',\n value: fromValue ?? ''\n });\n }}\n onBlur={changedValue => {\n dispatch({\n type: 'start',\n value: changedValue ?? ''\n });\n startValueRef.current = changedValue ?? '';\n onChange({\n start: changedValue ?? '',\n end: state.end\n });\n }}\n label={fromLabel}\n aria-label={`${t('range_from_numeric') + (label ? ` - ${label}` : '')}`}\n additionalInfo={fromAdditionalInfo}\n autoFocus={autoFocus}\n ref={startValueInputRef}\n />\n <NumberInput\n {...commonProps}\n value={state.end}\n onChange={toValue => {\n onChange({ start: value.start ?? '', end: toValue });\n dispatch({\n type: 'end',\n value: toValue ?? ''\n });\n }}\n onBlur={changedValue => {\n dispatch({\n type: 'end',\n value: changedValue ?? ''\n });\n endValueRef.current = changedValue ?? '';\n onChange({\n start: state.start,\n end: changedValue ?? ''\n });\n }}\n label={toLabel}\n aria-label={`${t('range_to_numeric') + (label ? ` - ${label}` : '')}`}\n additionalInfo={toAdditionalInfo}\n ref={endValueInputRef}\n />\n </Flex>\n </FormField>\n );\n }\n);\n\nexport default NumberRangeInput;\n"]}
|
|
1
|
+
{"version":3,"file":"NumberRangeInput.js","sourceRoot":"","sources":["../../../src/components/Number/NumberRangeInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAGV,WAAW,EACX,mBAAmB,EACnB,UAAU,EACV,MAAM,EACP,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACtF,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAK1D,MAAM,OAAO,GAAG,CAAC,SAAgB,EAAE,EAAE,IAAI,EAAE,KAAK,EAAmB,EAAS,EAAE;IAC5E,QAAQ,IAAI,EAAE;QACZ,KAAK,OAAO,CAAC,CAAC;YACZ,OAAO,EAAE,GAAG,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;SACvC;QACD,KAAK,KAAK,CAAC,CAAC;YACV,OAAO,EAAE,GAAG,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;SACrC;QACD;YACE,OAAO,SAAS,CAAC;K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,QAAQ,EAAE,OAAO,CAAC,EAAE;wBAClB,QAAQ,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;wBACrD,QAAQ,CAAC;4BACP,IAAI,EAAE,KAAK;4BACX,KAAK,EAAE,OAAO,IAAI,EAAE;yBACrB,CAAC,CAAC;oBACL,CAAC,EACD,MAAM,EAAE,YAAY,CAAC,EAAE;wBACrB,QAAQ,CAAC;4BACP,IAAI,EAAE,KAAK;4BACX,KAAK,EAAE,YAAY,IAAI,EAAE;yBAC1B,CAAC,CAAC;wBACH,WAAW,CAAC,OAAO,GAAG,YAAY,IAAI,EAAE,CAAC;wBACzC,QAAQ,CAAC;4BACP,KAAK,EAAE,KAAK,CAAC,KAAK;4BAClB,GAAG,EAAE,YAAY,IAAI,EAAE;yBACxB,CAAC,CAAC;oBACL,CAAC,EACD,KAAK,EAAE,OAAO,gBACF,GAAG,CAAC,CAAC,kBAAkB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EACrE,cAAc,EAAE,gBAAgB,EAChC,GAAG,EAAE,gBAAgB,GACrB,IACG,GACG,CACb,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n Ref,\n useCallback,\n useImperativeHandle,\n useReducer,\n useRef\n} from 'react';\n\nimport type { ForwardProps } from '../../types';\nimport { useConsolidatedRef, useI18n, useFocusWithin, useTestIds } from '../../hooks';\nimport { StyledRangeInputContainer } from '../Input/Input.styles';\nimport FormField from '../FormField';\nimport Flex from '../Flex';\n\nimport NumberInput from './NumberInput';\nimport type { NumberRangeInputProps } from './NumberInput.types';\nimport { getNumberRangeTestIds } from './Number.test-ids';\n\ntype DateRangeAction = { type: 'start' | 'end'; value: string };\ntype State = { start: string; end: string };\n\nconst reducer = (prevState: State, { type, value }: DateRangeAction): State => {\n switch (type) {\n case 'start': {\n return { ...prevState, start: value };\n }\n case 'end': {\n return { ...prevState, end: value };\n }\n default:\n return prevState;\n }\n};\n\nconst NumberRangeInput: FunctionComponent<NumberRangeInputProps & ForwardProps> = forwardRef(\n (\n {\n testId,\n value = {},\n onChange,\n onBlur,\n onFocus,\n label,\n fromLabel,\n toLabel,\n labelHidden,\n placeholder,\n disabled,\n readOnly,\n required,\n status,\n unit,\n showDecimal,\n numberOfDecimals,\n showGroupSeparators,\n min,\n max,\n step,\n variant,\n fromAdditionalInfo,\n toAdditionalInfo,\n autoFocus,\n handle,\n ...restProps\n }: NumberRangeInputProps,\n ref: Ref<HTMLDivElement>\n ) => {\n const testIds = useTestIds(testId, getNumberRangeTestIds);\n\n const t = useI18n();\n\n const startValueInputRef = useRef<HTMLInputElement>(null);\n const endValueInputRef = useRef<HTMLInputElement>(null);\n\n const [state, dispatch] = useReducer(reducer, {\n start: value.start ?? '',\n end: value.end ?? ''\n });\n\n // Need to keep the value in ref also, to be able to call onBlur with newest value\n const startValueRef = useRef(state.start);\n const endValueRef = useRef(state.end);\n\n const onFocusChange = useCallback(\n (focused: boolean) => {\n (focused ? onFocus : onBlur)?.({ start: startValueRef.current, end: endValueRef.current });\n },\n [onBlur, value.start, value.end]\n );\n\n const containerRef = useConsolidatedRef(ref);\n useFocusWithin([containerRef], onFocusChange);\n\n useImperativeHandle(\n handle,\n () => ({\n clear: () => {\n if (startValueInputRef.current) startValueInputRef.current.value = '';\n if (endValueInputRef.current) endValueInputRef.current.value = '';\n startValueRef.current = '';\n endValueRef.current = '';\n dispatch({ type: 'start', value: '' });\n dispatch({ type: 'end', value: '' });\n onChange({ start: '', end: '' });\n }\n }),\n [onChange]\n );\n\n const commonProps = {\n status,\n placeholder,\n readOnly,\n required,\n unit,\n showDecimal,\n numberOfDecimals,\n showGroupSeparators,\n min,\n max,\n variant\n };\n\n return (\n <FormField\n testId={testIds.root}\n as='fieldset'\n {...restProps}\n ref={containerRef}\n container={{ wrap: 'nowrap' }}\n labelHidden={labelHidden}\n labelAs='legend'\n label={label}\n disabled={disabled}\n required={required}\n readOnly={readOnly}\n status={status}\n >\n <Flex container as={StyledRangeInputContainer}>\n <NumberInput\n testId={testIds.min}\n {...commonProps}\n value={state.start}\n onChange={fromValue => {\n onChange({ start: fromValue, end: value.end ?? '' });\n dispatch({\n type: 'start',\n value: fromValue ?? ''\n });\n }}\n onBlur={changedValue => {\n dispatch({\n type: 'start',\n value: changedValue ?? ''\n });\n startValueRef.current = changedValue ?? '';\n onChange({\n start: changedValue ?? '',\n end: state.end\n });\n }}\n label={fromLabel}\n aria-label={`${t('range_from_numeric') + (label ? ` - ${label}` : '')}`}\n additionalInfo={fromAdditionalInfo}\n autoFocus={autoFocus}\n ref={startValueInputRef}\n />\n <NumberInput\n testId={testIds.max}\n {...commonProps}\n value={state.end}\n onChange={toValue => {\n onChange({ start: value.start ?? '', end: toValue });\n dispatch({\n type: 'end',\n value: toValue ?? ''\n });\n }}\n onBlur={changedValue => {\n dispatch({\n type: 'end',\n value: changedValue ?? ''\n });\n endValueRef.current = changedValue ?? '';\n onChange({\n start: state.start,\n end: changedValue ?? ''\n });\n }}\n label={toLabel}\n aria-label={`${t('range_to_numeric') + (label ? ` - ${label}` : '')}`}\n additionalInfo={toAdditionalInfo}\n ref={endValueInputRef}\n />\n </Flex>\n </FormField>\n );\n }\n);\n\nexport default NumberRangeInput;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Phone.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/Phone/Phone.test-ids.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,gHAGtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Phone.test-ids.js","sourceRoot":"","sources":["../../../src/components/Phone/Phone.test-ids.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAC,aAAa,EAAE;IAC/D,SAAS;IACT,cAAc;CACN,CAAC,CAAC","sourcesContent":["import { createTestIds } from '../../utils';\n\nexport const getPhoneInputTestIds = createTestIds('phone-input', [\n 'control',\n 'country-code'\n] as const);\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FunctionComponent, Ref } from 'react';
|
|
2
|
-
import { BaseProps, ForwardProps, NoChildrenProp } from '../../types';
|
|
2
|
+
import { BaseProps, ForwardProps, NoChildrenProp, TestIdProp } from '../../types';
|
|
3
3
|
import { FormControlProps } from '../FormControl';
|
|
4
|
-
export interface PhoneInputProps extends FormControlProps, BaseProps, NoChildrenProp {
|
|
4
|
+
export interface PhoneInputProps extends FormControlProps, BaseProps, NoChildrenProp, TestIdProp {
|
|
5
5
|
/**
|
|
6
6
|
* Display select with countries calling codes
|
|
7
7
|
* @default false
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneInput.d.ts","sourceRoot":"","sources":["../../../src/components/Phone/PhoneInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EAEjB,GAAG,EAGJ,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"PhoneInput.d.ts","sourceRoot":"","sources":["../../../src/components/Phone/PhoneInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EAEjB,GAAG,EAGJ,MAAM,OAAO,CAAC;AAWf,OAAO,EACL,SAAS,EACT,YAAY,EACZ,cAAc,EAEd,UAAU,EACX,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,gBAAgB,EAAqB,MAAM,gBAAgB,CAAC;AAWrE,MAAM,WAAW,eAAgB,SAAQ,gBAAgB,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU;IAC9F;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,+CAA+C;IAC/C,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,oDAAoD;IACpD,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,oDAAoD;IACpD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;CAC7B;AAuBD,QAAA,MAAM,UAAU,EAAE,iBAAiB,CAAC,eAAe,GAAG,YAAY,CAwIjE,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef, useCallback, useRef } from 'react';
|
|
3
3
|
import styled, { css } from 'styled-components';
|
|
4
|
-
import { useConsolidatedRef, useFocusWithin, useI18n, useInputFormatter } from '../../hooks';
|
|
4
|
+
import { useConsolidatedRef, useFocusWithin, useI18n, useInputFormatter, useTestIds } from '../../hooks';
|
|
5
5
|
import { defaultThemeProp } from '../../theme';
|
|
6
6
|
import FormField from '../FormField';
|
|
7
7
|
import { StyledFormControl } from '../FormControl';
|
|
@@ -12,6 +12,7 @@ import { StyledSelect } from '../Select/Select';
|
|
|
12
12
|
import Flex from '../Flex';
|
|
13
13
|
import callingCodes from './callingCodes';
|
|
14
14
|
import { convertToCallbackParameter, formatPhoneNumber, getPhoneNumberParts } from './utils';
|
|
15
|
+
import { getPhoneInputTestIds } from './Phone.test-ids';
|
|
15
16
|
const StyledPhoneInput = styled.div(() => {
|
|
16
17
|
return css `
|
|
17
18
|
border: 0;
|
|
@@ -30,7 +31,8 @@ const StyledPhoneInput = styled.div(() => {
|
|
|
30
31
|
});
|
|
31
32
|
StyledPhoneInput.defaultProps = defaultThemeProp;
|
|
32
33
|
const PhoneInput = forwardRef((props, ref) => {
|
|
33
|
-
const { value, id, label, labelHidden, info, status, required, readOnly, disabled, showCountryCode = false, callingCodesList = callingCodes, onChange, onBlur, onFocus, onResolveSuggestion, additionalInfo, ...restProps } = props;
|
|
34
|
+
const { testId, value, id, label, labelHidden, info, status, required, readOnly, disabled, showCountryCode = false, callingCodesList = callingCodes, onChange, onBlur, onFocus, onResolveSuggestion, additionalInfo, ...restProps } = props;
|
|
35
|
+
const testIds = useTestIds(testId, getPhoneInputTestIds);
|
|
34
36
|
const t = useI18n();
|
|
35
37
|
const [countryCode = callingCodesList[0], subscriberNumber = ''] = value
|
|
36
38
|
? getPhoneNumberParts(value, callingCodesList)
|
|
@@ -56,7 +58,7 @@ const PhoneInput = forwardRef((props, ref) => {
|
|
|
56
58
|
}, [countryCode]);
|
|
57
59
|
const formatted = useInputFormatter(inputRef, subscriberNumber, formatter);
|
|
58
60
|
const codesOptions = (_jsx(_Fragment, { children: callingCodesList.map(code => (_jsx(Option, { value: code, children: code }, code))) }));
|
|
59
|
-
const Comp = (_jsxs(StyledPhoneInput, { as: StyledFormControl, forwardedAs: Flex, container: { alignItems: 'center', wrap: 'nowrap' }, ref: containerRef, status: status, readOnly: readOnly, disabled: disabled, children: [showCountryCode && (_jsx(Select, { value: countryCode, "aria-label": t('select_country_code'), onChange: onSelectChange, required: required, status: status, readOnly: readOnly, disabled: disabled, autoComplete: 'tel-country-code', hasSuggestion: status === 'pending' && !!onResolveSuggestion, children: codesOptions })), _jsx(Input, { ...restProps, inputMode: 'tel', ref: inputRef, value: formatted, "aria-label": t('enter_a_number'), onChange: onInputChange, required: required, status: status, readOnly: readOnly, disabled: disabled, autoComplete: 'tel-national', hasSuggestion: status === 'pending' && !!onResolveSuggestion })] }));
|
|
61
|
+
const Comp = (_jsxs(StyledPhoneInput, { "data-testid": testIds.root, as: StyledFormControl, forwardedAs: Flex, container: { alignItems: 'center', wrap: 'nowrap' }, ref: containerRef, status: status, readOnly: readOnly, disabled: disabled, children: [showCountryCode && (_jsx(Select, { "data-testid": testIds.countryCode, value: countryCode, "aria-label": t('select_country_code'), onChange: onSelectChange, required: required, status: status, readOnly: readOnly, disabled: disabled, autoComplete: 'tel-country-code', hasSuggestion: status === 'pending' && !!onResolveSuggestion, children: codesOptions })), _jsx(Input, { "data-testid": testIds.control, ...restProps, inputMode: 'tel', ref: inputRef, value: formatted, "aria-label": t('enter_a_number'), onChange: onInputChange, required: required, status: status, readOnly: readOnly, disabled: disabled, autoComplete: 'tel-national', hasSuggestion: status === 'pending' && !!onResolveSuggestion })] }));
|
|
60
62
|
return label ? (_jsx(FormField, { as: 'fieldset', labelAs: 'legend', ...{
|
|
61
63
|
additionalInfo,
|
|
62
64
|
label,
|
|
@@ -66,7 +68,8 @@ const PhoneInput = forwardRef((props, ref) => {
|
|
|
66
68
|
status,
|
|
67
69
|
required,
|
|
68
70
|
disabled,
|
|
69
|
-
onResolveSuggestion
|
|
71
|
+
onResolveSuggestion,
|
|
72
|
+
testId
|
|
70
73
|
}, children: Comp })) : (Comp);
|
|
71
74
|
});
|
|
72
75
|
export default PhoneInput;
|