@pega/cosmos-react-core 4.0.0-dev.12.1 → 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/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/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 +2 -2
- 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 +3 -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":"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,IAA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ocusEvent\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","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,gBAAgB,EAChB,kBAAkB,EAClB,OAAO,EACP,iBAAiB,EACjB,UAAU,EACV,MAAM,EACP,MAAM,aAAa,CAAC;AACrB,OAAO,WAAW,MAAM,uBAAuB,CAAC;AAEhD,OAAO,iBAAiB,EAAE,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAoB,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,EACL,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,YAAY,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;AAElC,MAAM,WAAW,GAAuD,UAAU,CAChF,CAAC,KAAwC,EAAE,GAA4B,EAAE,EAAE;IACzE,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC;IACrB,MAAM,EACJ,MAAM,EACN,EAAE,GAAG,GAAG,EACR,MAAM,EACN,KAAK,EACL,WAAW,EACX,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,cAAc,EACd,KAAK,GAAG,EAAE,EAC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AAO,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,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,CAA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AAW,qBAAsB,SAAQ,WAAW;IACxD,yCAAyC;IACzC,KAAK,CAAC,EAAE;QAAE,KAAK,CAAC,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,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,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 } 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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AM,EAAE,OAAO,CAAC,GAAG,KACf,WAAW,EACf,KAAK,EAAE,KAAK,CAAC,GAAG,EAChB,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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneInput.js","sourceRoot":"","sources":["../../../src/components/Phone/PhoneInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAEL,UAAU,EAIV,WAAW,EACX,MAAM,EACP,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,
|
|
1
|
+
{"version":3,"file":"PhoneInput.js","sourceRoot":"","sources":["../../../src/components/Phone/PhoneInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAEL,UAAU,EAIV,WAAW,EACX,MAAM,EACP,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,EAAE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QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAC,cAAc,EAC3B,aAAa,EAAE,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,mBAAmB,GAC5D,IACe,CACpB,CAAC;IAEF,OAAO,KAAK,CAAC,CAAC,CAAC,CACb,KAAC,SAAS,IACR,EAAE,EAAC,UAAU,EACb,OAAO,EAAC,QAAQ,KACZ;YACF,cAAc;YACd,KAAK;YACL,WAAW;YACX,EAAE;YACF,IAAI;YACJ,MAAM;YACN,QAAQ;YACR,QAAQ;YACR,mBAAmB;YACnB,MAAM;SACP,YAEA,IAAI,GACK,CACb,CAAC,CAAC,CAAC,CACF,IAAI,CACL,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import {\n ChangeEvent,\n forwardRef,\n FunctionComponent,\n PropsWithoutRef,\n Ref,\n useCallback,\n useRef\n} from 'react';\nimport styled, { css } from 'styled-components';\n\nimport {\n useConsolidatedRef,\n useFocusWithin,\n useI18n,\n useInputFormatter,\n useTestIds\n} from '../../hooks';\nimport { defaultThemeProp } from '../../theme';\nimport {\n BaseProps,\n ForwardProps,\n NoChildrenProp,\n PropsWithDefaults,\n TestIdProp\n} from '../../types';\nimport FormField from '../FormField';\nimport { FormControlProps, StyledFormControl } from '../FormControl';\nimport StyledInput from '../Input/Input.styles';\nimport Select, { Option } from '../Select';\nimport Input from '../Input';\nimport { StyledSelect } from '../Select/Select';\nimport Flex from '../Flex';\n\nimport callingCodes from './callingCodes';\nimport { convertToCallbackParameter, formatPhoneNumber, getPhoneNumberParts } from './utils';\nimport { getPhoneInputTestIds } from './Phone.test-ids';\n\nexport interface PhoneInputProps extends FormControlProps, BaseProps, NoChildrenProp, TestIdProp {\n /**\n * Display select with countries calling codes\n * @default false\n */\n showCountryCode?: boolean;\n /** Changes lists of countries calling codes */\n callingCodesList?: string[];\n /** Callback fired on input value change */\n onChange?: (value: string) => void;\n /** Callback fired when the component loses focus */\n onBlur?: (value: string) => void;\n /** CCallback fired when the component gets focus */\n onFocus?: (value: string) => void;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLInputElement>;\n}\n\ntype PhoneInputPropsWithDefaults = PropsWithDefaults<PhoneInputProps>;\n\nconst StyledPhoneInput = styled.div<PhoneInputPropsWithDefaults>(() => {\n return css`\n border: 0;\n > ${StyledSelect} {\n max-width: max-content;\n border-inline-end: none;\n border-start-end-radius: 0;\n border-end-end-radius: 0;\n }\n\n > ${StyledSelect} + ${StyledInput} {\n border-start-start-radius: 0;\n border-end-start-radius: 0;\n }\n `;\n});\n\nStyledPhoneInput.defaultProps = defaultThemeProp;\n\nconst PhoneInput: FunctionComponent<PhoneInputProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<PhoneInputProps>, ref: PhoneInputProps['ref']) => {\n const {\n testId,\n value,\n id,\n label,\n labelHidden,\n info,\n status,\n required,\n readOnly,\n disabled,\n showCountryCode = false,\n callingCodesList = callingCodes,\n onChange,\n onBlur,\n onFocus,\n onResolveSuggestion,\n additionalInfo,\n ...restProps\n } = props;\n\n const testIds = useTestIds(testId, getPhoneInputTestIds);\n\n const t = useI18n();\n\n const [countryCode = callingCodesList[0], subscriberNumber = ''] = value\n ? getPhoneNumberParts(value, callingCodesList)\n : [];\n\n const onFocusChange = (focused: boolean) => {\n const callbackParam = convertToCallbackParameter(countryCode, subscriberNumber);\n if (focused) onFocus?.(callbackParam);\n else onBlur?.(callbackParam);\n };\n\n const onInputChange = (e: ChangeEvent<HTMLInputElement>) => {\n onChange?.(convertToCallbackParameter(countryCode, e.target.value));\n };\n\n const onSelectChange = (e: ChangeEvent<HTMLSelectElement>) => {\n onChange?.(convertToCallbackParameter(e.target.value, subscriberNumber));\n };\n\n const inputRef = useConsolidatedRef<HTMLInputElement>(ref);\n const containerRef = useRef<HTMLElement>(null);\n useFocusWithin([containerRef], onFocusChange);\n\n const formatter = useCallback(\n number => {\n return formatPhoneNumber(number.replace(/\\D+/g, ''), countryCode);\n },\n [countryCode]\n );\n\n const formatted = useInputFormatter(inputRef, subscriberNumber, formatter);\n\n const codesOptions = (\n <>\n {callingCodesList.map(code => (\n <Option key={code} value={code}>\n {code}\n </Option>\n ))}\n </>\n );\n\n const Comp = (\n <StyledPhoneInput\n data-testid={testIds.root}\n as={StyledFormControl}\n forwardedAs={Flex as any}\n container={{ alignItems: 'center', wrap: 'nowrap' }}\n ref={containerRef}\n status={status}\n readOnly={readOnly}\n disabled={disabled}\n >\n {showCountryCode && (\n <Select\n data-testid={testIds.countryCode}\n value={countryCode}\n aria-label={t('select_country_code')}\n onChange={onSelectChange}\n required={required}\n status={status}\n readOnly={readOnly}\n disabled={disabled}\n autoComplete='tel-country-code'\n hasSuggestion={status === 'pending' && !!onResolveSuggestion}\n >\n {codesOptions}\n </Select>\n )}\n <Input\n data-testid={testIds.control}\n {...restProps}\n inputMode='tel'\n ref={inputRef}\n value={formatted}\n aria-label={t('enter_a_number')}\n onChange={onInputChange}\n required={required}\n status={status}\n readOnly={readOnly}\n disabled={disabled}\n autoComplete='tel-national'\n hasSuggestion={status === 'pending' && !!onResolveSuggestion}\n />\n </StyledPhoneInput>\n );\n\n return label ? (\n <FormField\n as='fieldset'\n labelAs='legend'\n {...{\n additionalInfo,\n label,\n labelHidden,\n id,\n info,\n status,\n required,\n disabled,\n onResolveSuggestion,\n testId\n }}\n >\n {Comp}\n </FormField>\n ) : (\n Comp\n );\n }\n);\n\nexport default PhoneInput;\n"]}
|
|
@@ -41,6 +41,8 @@ export interface RadioCheckProps extends BaseProps, NoChildrenProp {
|
|
|
41
41
|
onKeyDown?: KeyboardEventHandler<HTMLInputElement>;
|
|
42
42
|
/** Pass a heading and content to show additional information on the field. */
|
|
43
43
|
additionalInfo?: FormControlProps['additionalInfo'];
|
|
44
|
+
/** info like error, success, warning messages */
|
|
45
|
+
info?: FormControlProps['info'];
|
|
44
46
|
/** Ref forwarded to the underlying input. */
|
|
45
47
|
ref?: Ref<HTMLInputElement>;
|
|
46
48
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AAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACpC,+FAA+F;IAC/F,IAAI,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAChC,8BAA8B;IAC9B,IAAI,EAAE,OAAO,GAAG,UAAU,CAAC;IAC3B,yEAAyE;IACzE,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,oEAAoE;IACpE,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,OAAO,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;IAC5B,4CAA4C;IAC5C,OAAO,CAAC,EAAE,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;IAC9C,8CAA8C;IAC9C,SAAS,CAAC,EAAE,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;IACnD,8EAA8E;IAC9E,cAAc,CAAC,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IACpD,iDAAiD;IACjD,IAAI,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAChC,6CAA6C;IAC7C,GAAG,CAAC,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;CAC7B;AAED,eAAO,MAAM,sBAAsB,mJAiDlC,CAAC;AAIF,eAAO,MAAM,qBAAqB,2GAiGhC,CAAC;AAIH,eAAO,MAAM,gBAAgB,qJA6C5B,CAAC;AAIF,eAAO,MAAM,oBAAoB,kKA2DhC,CAAC;AAIF,QAAA,MAAM,UAAU,EAAE,EAAE,CAAC,eAAe,GAAG,YAAY,CA0FlD,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -187,7 +187,7 @@ StyledRadioCheckCard.defaultProps = defaultThemeProp;
|
|
|
187
187
|
const RadioCheck = forwardRef((props, ref) => {
|
|
188
188
|
const uid = useUID();
|
|
189
189
|
const t = useI18n();
|
|
190
|
-
const { type, id = uid, label, required = false, disabled = false, indeterminate = false, readOnly = false, variant = 'simple', onClick, onKeyDown, status, additionalInfo, ...restProps } = props;
|
|
190
|
+
const { type, id = uid, label, required = false, disabled = false, indeterminate = false, readOnly = false, variant = 'simple', onClick, onKeyDown, status, info, additionalInfo, ...restProps } = props;
|
|
191
191
|
const isRadio = type === 'radio';
|
|
192
192
|
const card = variant === 'card';
|
|
193
193
|
const newRef = useConsolidatedRef(ref);
|
|
@@ -196,7 +196,7 @@ const RadioCheck = forwardRef((props, ref) => {
|
|
|
196
196
|
newRef.current.indeterminate = !!indeterminate;
|
|
197
197
|
}
|
|
198
198
|
}, [newRef, indeterminate, isRadio]);
|
|
199
|
-
return (_jsx(FormField, { as: card ? StyledRadioCheckCard : StyledRadioCheck, label: _jsxs(_Fragment, { children: [_jsx(StyledPseudoRadioCheck, { status: status, isRadio: isRadio, as: StyledFormControl, required: required, disabled: disabled, readOnly: readOnly }), _jsxs(_Fragment, { children: [label, readOnly && _jsx(VisuallyHiddenText, { children: ` ${t('read_only')}` })] })] }), labelAs: card ? 'div' : undefined, id: id, required: required, disabled: disabled, readOnly: readOnly, status: status, isRadioCheck: true, inline: true, labelAfter: true, additionalInfo: additionalInfo, children: _jsx(StyledRadioCheckInput, { ...restProps, id: id, type: type, required: required, disabled: disabled, readOnly: readOnly, onClick: (e) => {
|
|
199
|
+
return (_jsx(FormField, { as: card ? StyledRadioCheckCard : StyledRadioCheck, label: _jsxs(_Fragment, { children: [_jsx(StyledPseudoRadioCheck, { status: status, isRadio: isRadio, as: StyledFormControl, required: required, disabled: disabled, readOnly: readOnly }), _jsxs(_Fragment, { children: [label, readOnly && _jsx(VisuallyHiddenText, { children: ` ${t('read_only')}` })] })] }), labelAs: card ? 'div' : undefined, id: id, required: required, disabled: disabled, readOnly: readOnly, status: status, info: info, isRadioCheck: true, inline: true, labelAfter: true, additionalInfo: additionalInfo, children: _jsx(StyledRadioCheckInput, { ...restProps, id: id, type: type, required: required, disabled: disabled, readOnly: readOnly, onClick: (e) => {
|
|
200
200
|
if (readOnly)
|
|
201
201
|
e.preventDefault();
|
|
202
202
|
onClick?.(e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioCheck.js","sourceRoot":"","sources":["../../../src/components/RadioCheck/RadioCheck.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAGV,SAAS,EAMV,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE5D,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAoB,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,kBAAkB,MAAM,uBAAuB,CAAC;AA8CvD,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,GAAG,CAC9C,KAAK,CAAC,EAAE;IACN,MAAM,EACJ,KAAK,EAAE,EACL,IAAI,EAAE,EACJ,OAAO,EACP,OAAO,EAAE,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,EACrD,EACD,UAAU,EAAE,EACV,YAAY,EAAE,SAAS,EACvB,aAAa,EAAE,EACb,IAAI,EACJ,YAAY,EAAE,SAAS,EACvB,kBAAkB,EAAE,eAAe,EACnC,cAAc,EAAE,WAAW,EAC3B,cAAc,EAAE,WAAW,EAC5B,EACF,EACF,EACD,MAAM,EACP,GAAG,KAAK,CAAC;IAEV,MAAM,cAAc,GAAG,MAAM,KAAK,OAAO,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J,CAAC,CACF,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import {\n forwardRef,\n FC,\n Ref,\n useEffect,\n MouseEvent,\n KeyboardEvent,\n PropsWithoutRef,\n MouseEventHandler,\n KeyboardEventHandler\n} from 'react';\nimport styled, { css } from 'styled-components';\nimport { readableColor, hideVisually, mix } from 'polished';\n\nimport FormField from '../FormField';\nimport { FormControlProps, StyledFormControl } from '../FormControl';\nimport { defaultThemeProp } from '../../theme';\nimport { tryCatch } from '../../utils';\nimport { BaseProps, ForwardProps, NoChildrenProp } from '../../types';\nimport { useConsolidatedRef, useDirection, useI18n, useUID } from '../../hooks';\nimport { StyledLabel } from '../Label';\nimport { calculateFontSize } from '../../styles';\nimport VisuallyHiddenText from '../VisuallyHiddenText';\n\nexport interface RadioCheckProps 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 /** Pass a string or a fragment with an Icon and string. */\n label?: FormControlProps['label'];\n /** Indicate if the field is required. The browser defaults to false. */\n required?: FormControlProps['required'];\n /** Disable the control. The browser defaults to false. */\n disabled?: FormControlProps['disabled'];\n /** Makes the input non editable and non clickable. The browser defaults to false. */\n readOnly?: FormControlProps['readOnly'];\n /** Set visual state based on a validation state. */\n status?: FormControlProps['status'];\n /** Sets html name attribute for the underlying control. Useful for mapping to a data field. */\n name?: FormControlProps['name'];\n /** Sets the type of input. */\n type: 'radio' | 'checkbox';\n /** Sets checked prop via onChange when using as controlled component. */\n checked?: boolean;\n /** Initialize checked prop when using as uncontrolled component. */\n defaultChecked?: boolean;\n /**\n * Sets control to an an indeterminate state.\n * @default false\n */\n indeterminate?: boolean;\n /**\n * Controls the styling of the RadioCheck.\n * @default 'simple'\n */\n variant?: 'simple' | 'card';\n /** Callback function for onClick events. */\n onClick?: MouseEventHandler<HTMLInputElement>;\n /** Callback function for onKeyDown events. */\n onKeyDown?: KeyboardEventHandler<HTMLInputElement>;\n /** Pass a heading and content to show additional information on the field. */\n additionalInfo?: FormControlProps['additionalInfo'];\n /** Ref forwarded to the underlying input. */\n ref?: Ref<HTMLInputElement>;\n}\n\nexport const StyledPseudoRadioCheck = styled.div<Pick<RadioCheckProps, 'readOnly' | 'status'>>(\n props => {\n const {\n theme: {\n base: {\n spacing,\n palette: { 'primary-background': primaryBackground }\n },\n components: {\n 'form-field': formField,\n 'radio-check': {\n size,\n 'touch-size': touchSize,\n 'background-color': backgroundColor,\n 'border-color': borderColor,\n 'border-width': borderWidth\n }\n }\n },\n status\n } = props;\n\n const useBorderColor = status === 'error' ? formField.error['status-color'] : borderColor;\n const useBackgroundColor =\n status && formField[status]\n ? tryCatch(() => mix(0.8, primaryBackground, formField[status]['status-color']))\n : backgroundColor;\n\n return css`\n display: flex;\n flex-shrink: 0;\n position: relative;\n width: ${size};\n height: ${size};\n margin-inline-end: ${spacing};\n border: ${borderWidth} solid ${useBorderColor};\n background-color: ${useBackgroundColor};\n\n @media (pointer: coarse) {\n width: ${touchSize};\n height: ${touchSize};\n }\n\n &::after {\n content: '';\n display: none;\n }\n `;\n }\n);\n\nStyledPseudoRadioCheck.defaultProps = defaultThemeProp;\n\nexport const StyledRadioCheckInput = styled.input(props => {\n const {\n disabled,\n theme: {\n base: { 'border-radius': baseBorderRadius },\n components: {\n 'form-control': {\n ':focus': { 'box-shadow': shadow, 'border-color': focusBorderColor },\n ':read-only': { 'background-color': readOnlyBackgroundColor }\n },\n 'radio-check': {\n ':checked': {\n 'background-color': checkedBackgroundColor,\n 'border-color': checkedBorderColor\n }\n },\n checkbox: { 'border-radius': checkRadius },\n 'radio-button': { 'border-radius': radioRadius }\n }\n }\n } = props;\n\n const backgroundColor = props.readOnly ? readOnlyBackgroundColor : checkedBackgroundColor;\n const foreground = tryCatch(() => readableColor(backgroundColor));\n\n const prcSelector = `+ ${StyledLabel} ${StyledPseudoRadioCheck}`;\n const { ltr } = useDirection();\n\n return css`\n ${hideVisually}\n\n ${!disabled &&\n css`\n &:focus ${prcSelector} {\n box-shadow: ${shadow};\n border-color: ${focusBorderColor};\n }\n `}\n\n &:checked\n ${prcSelector},\n &:checked:disabled\n ${prcSelector},\n &[type='checkbox']:indeterminate\n ${prcSelector},\n &[type='checkbox']:indeterminate:disabled\n ${prcSelector} {\n border-color: ${props.readOnly ? 'inherit' : checkedBorderColor};\n background-color: ${backgroundColor};\n\n &::after {\n display: block;\n }\n }\n\n &[type='radio'] ${prcSelector}, &[type='radio'] ${prcSelector}::after {\n border-radius: ${radioRadius};\n }\n\n &[type='radio'] ${prcSelector}::after {\n margin: auto;\n width: 100%;\n height: 100%;\n background-color: ${foreground};\n transform: scale(0.4);\n }\n\n &[type='checkbox'] ${prcSelector} {\n border-radius: min(calc(${baseBorderRadius} * ${checkRadius}), 0.25rem);\n }\n\n &[type='checkbox']:not(:indeterminate) ${prcSelector} {\n &::after {\n width: 40%;\n height: 75%;\n ${ltr\n ? css`\n transform: rotate(45deg) translate(50%, -30%);\n `\n : css`\n transform: rotate(45deg) translate(-50%, 30%);\n `}\n border-right: 0.15em solid ${foreground};\n border-bottom: 0.15em solid ${foreground};\n }\n }\n\n &[type='checkbox']:indeterminate ${prcSelector} {\n display: flex;\n &::after {\n width: 90%;\n height: 0.15em;\n margin: auto;\n background-color: ${foreground};\n }\n }\n `;\n});\n\nStyledRadioCheckInput.defaultProps = defaultThemeProp;\n\nexport const StyledRadioCheck = styled.div<Pick<RadioCheckProps, 'disabled' | 'readOnly'>>(\n props => {\n const {\n disabled,\n readOnly,\n theme: {\n base,\n components: {\n 'radio-check': {\n label: { color: labelColor, 'font-weight': labelFontWeight }\n },\n 'form-control': {\n ':hover': { 'border-color': hoverBorderColor }\n }\n }\n }\n } = props;\n\n const fontSize = calculateFontSize(base['font-size'], base['font-scale']);\n\n return css`\n > ${StyledLabel} {\n cursor: pointer;\n display: flex;\n align-items: center;\n font-weight: ${labelFontWeight};\n word-break: break-word;\n font-size: ${fontSize.s};\n color: ${labelColor};\n margin: 0;\n min-height: ${base['hit-area']['mouse-min']};\n\n @media (pointer: coarse) {\n min-height: ${base['hit-area']['finger-min']};\n }\n }\n\n ${!(disabled || readOnly) &&\n css`\n &:not(:focus-within) > ${StyledLabel}:hover ${StyledPseudoRadioCheck} {\n border-color: ${hoverBorderColor};\n }\n `}\n `;\n }\n);\n\nStyledRadioCheck.defaultProps = defaultThemeProp;\n\nexport const StyledRadioCheckCard = styled.label<\n Pick<RadioCheckProps, 'disabled' | 'readOnly' | 'status'>\n>(\n ({\n disabled,\n readOnly,\n status,\n theme: {\n base: { palette, shadow, spacing },\n components: {\n card,\n 'form-field': formField,\n 'radio-check': { label },\n 'form-control': {\n ':hover': { 'border-color': hoverBorderColor }\n }\n }\n }\n }) => {\n const useBorderColor =\n status === 'error' ? formField.error['status-color'] : palette['border-line'];\n\n return css`\n min-width: min-content;\n align-items: start;\n cursor: pointer;\n background-color: ${card.background};\n border-radius: ${card['border-radius']};\n border: 0.0625rem solid ${useBorderColor};\n padding: ${spacing};\n\n ${disabled &&\n css`\n cursor: not-allowed;\n `}\n\n ${!(disabled || readOnly) &&\n css`\n :hover:not(:focus-within) {\n border-color: ${hoverBorderColor};\n ${StyledLabel} ${StyledPseudoRadioCheck} {\n border-color: ${hoverBorderColor};\n }\n }\n\n :focus-within {\n box-shadow: ${shadow.focus};\n border-color: transparent;\n }\n `}\n\n > ${StyledLabel} {\n display: grid;\n grid-template-columns: auto 1fr;\n color: ${label.color};\n font-weight: ${label['font-weight']};\n }\n `;\n }\n);\n\nStyledRadioCheckCard.defaultProps = defaultThemeProp;\n\nconst RadioCheck: FC<RadioCheckProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<RadioCheckProps>, ref: RadioCheckProps['ref']) => {\n const uid = useUID();\n const t = useI18n();\n\n const {\n type,\n id = uid,\n label,\n required = false,\n disabled = false,\n indeterminate = false,\n readOnly = false,\n variant = 'simple',\n onClick,\n onKeyDown,\n status,\n additionalInfo,\n ...restProps\n } = props;\n\n const isRadio = type === 'radio';\n const card = variant === 'card';\n const newRef = useConsolidatedRef(ref);\n\n useEffect(() => {\n if (!isRadio && newRef.current) {\n newRef.current.indeterminate = !!indeterminate;\n }\n }, [newRef, indeterminate, isRadio]);\n\n return (\n <FormField\n as={card ? StyledRadioCheckCard : StyledRadioCheck}\n label={\n <>\n <StyledPseudoRadioCheck\n status={status}\n isRadio={isRadio}\n as={StyledFormControl}\n required={required}\n disabled={disabled}\n readOnly={readOnly}\n />\n <>\n {label}\n {readOnly && <VisuallyHiddenText>{` ${t('read_only')}`}</VisuallyHiddenText>}\n </>\n </>\n }\n labelAs={card ? 'div' : undefined}\n id={id}\n required={required}\n disabled={disabled}\n readOnly={readOnly}\n status={status}\n isRadioCheck\n inline\n labelAfter\n additionalInfo={additionalInfo}\n >\n <StyledRadioCheckInput\n {...restProps}\n id={id}\n type={type}\n required={required}\n disabled={disabled}\n readOnly={readOnly}\n onClick={(e: MouseEvent<HTMLInputElement>) => {\n if (readOnly) e.preventDefault();\n\n onClick?.(e);\n }}\n onKeyDown={(e: KeyboardEvent<HTMLInputElement>) => {\n if (type === 'checkbox' && readOnly && e.key === ' ') {\n e.preventDefault();\n }\n if (type === 'radio' && readOnly && e.key.includes('Arrow')) {\n e.preventDefault();\n }\n\n onKeyDown?.(e);\n }}\n ref={newRef}\n />\n </FormField>\n );\n }\n);\n\nexport default RadioCheck;\n"]}
|
|
1
|
+
{"version":3,"file":"RadioCheck.js","sourceRoot":"","sources":["../../../src/components/RadioCheck/RadioCheck.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAGV,SAAS,EAMV,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE5D,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAoB,iBAAiB,EAAE,MAA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ClB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,EACV,YAAY,QACZ,MAAM,QACN,UAAU,QACV,cAAc,EAAE,cAAc,YAE9B,KAAC,qBAAqB,OAChB,SAAS,EACb,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,CAAC,CAA+B,EAAE,EAAE;gBAC3C,IAAI,QAAQ;oBAAE,CAAC,CAAC,cAAc,EAAE,CAAC;gBAEjC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;YACf,CAAC,EACD,SAAS,EAAE,CAAC,CAAkC,EAAE,EAAE;gBAChD,IAAI,IAAI,KAAK,UAAU,IAAI,QAAQ,IAAI,CAAC,CAAC,GAAG,KAAK,GAAG,EAAE;oBACpD,CAAC,CAAC,cAAc,EAAE,CAAC;iBACpB;gBACD,IAAI,IAAI,KAAK,OAAO,IAAI,QAAQ,IAAI,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;oBAC3D,CAAC,CAAC,cAAc,EAAE,CAAC;iBACpB;gBAED,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;YACjB,CAAC,EACD,GAAG,EAAE,MAAM,GACX,GACQ,CACb,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import {\n forwardRef,\n FC,\n Ref,\n useEffect,\n MouseEvent,\n KeyboardEvent,\n PropsWithoutRef,\n MouseEventHandler,\n KeyboardEventHandler\n} from 'react';\nimport styled, { css } from 'styled-components';\nimport { readableColor, hideVisually, mix } from 'polished';\n\nimport FormField from '../FormField';\nimport { FormControlProps, StyledFormControl } from '../FormControl';\nimport { defaultThemeProp } from '../../theme';\nimport { tryCatch } from '../../utils';\nimport { BaseProps, ForwardProps, NoChildrenProp } from '../../types';\nimport { useConsolidatedRef, useDirection, useI18n, useUID } from '../../hooks';\nimport { StyledLabel } from '../Label';\nimport { calculateFontSize } from '../../styles';\nimport VisuallyHiddenText from '../VisuallyHiddenText';\n\nexport interface RadioCheckProps 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 /** Pass a string or a fragment with an Icon and string. */\n label?: FormControlProps['label'];\n /** Indicate if the field is required. The browser defaults to false. */\n required?: FormControlProps['required'];\n /** Disable the control. The browser defaults to false. */\n disabled?: FormControlProps['disabled'];\n /** Makes the input non editable and non clickable. The browser defaults to false. */\n readOnly?: FormControlProps['readOnly'];\n /** Set visual state based on a validation state. */\n status?: FormControlProps['status'];\n /** Sets html name attribute for the underlying control. Useful for mapping to a data field. */\n name?: FormControlProps['name'];\n /** Sets the type of input. */\n type: 'radio' | 'checkbox';\n /** Sets checked prop via onChange when using as controlled component. */\n checked?: boolean;\n /** Initialize checked prop when using as uncontrolled component. */\n defaultChecked?: boolean;\n /**\n * Sets control to an an indeterminate state.\n * @default false\n */\n indeterminate?: boolean;\n /**\n * Controls the styling of the RadioCheck.\n * @default 'simple'\n */\n variant?: 'simple' | 'card';\n /** Callback function for onClick events. */\n onClick?: MouseEventHandler<HTMLInputElement>;\n /** Callback function for onKeyDown events. */\n onKeyDown?: KeyboardEventHandler<HTMLInputElement>;\n /** Pass a heading and content to show additional information on the field. */\n additionalInfo?: FormControlProps['additionalInfo'];\n /** info like error, success, warning messages */\n info?: FormControlProps['info'];\n /** Ref forwarded to the underlying input. */\n ref?: Ref<HTMLInputElement>;\n}\n\nexport const StyledPseudoRadioCheck = styled.div<Pick<RadioCheckProps, 'readOnly' | 'status'>>(\n props => {\n const {\n theme: {\n base: {\n spacing,\n palette: { 'primary-background': primaryBackground }\n },\n components: {\n 'form-field': formField,\n 'radio-check': {\n size,\n 'touch-size': touchSize,\n 'background-color': backgroundColor,\n 'border-color': borderColor,\n 'border-width': borderWidth\n }\n }\n },\n status\n } = props;\n\n const useBorderColor = status === 'error' ? formField.error['status-color'] : borderColor;\n const useBackgroundColor =\n status && formField[status]\n ? tryCatch(() => mix(0.8, primaryBackground, formField[status]['status-color']))\n : backgroundColor;\n\n return css`\n display: flex;\n flex-shrink: 0;\n position: relative;\n width: ${size};\n height: ${size};\n margin-inline-end: ${spacing};\n border: ${borderWidth} solid ${useBorderColor};\n background-color: ${useBackgroundColor};\n\n @media (pointer: coarse) {\n width: ${touchSize};\n height: ${touchSize};\n }\n\n &::after {\n content: '';\n display: none;\n }\n `;\n }\n);\n\nStyledPseudoRadioCheck.defaultProps = defaultThemeProp;\n\nexport const StyledRadioCheckInput = styled.input(props => {\n const {\n disabled,\n theme: {\n base: { 'border-radius': baseBorderRadius },\n components: {\n 'form-control': {\n ':focus': { 'box-shadow': shadow, 'border-color': focusBorderColor },\n ':read-only': { 'background-color': readOnlyBackgroundColor }\n },\n 'radio-check': {\n ':checked': {\n 'background-color': checkedBackgroundColor,\n 'border-color': checkedBorderColor\n }\n },\n checkbox: { 'border-radius': checkRadius },\n 'radio-button': { 'border-radius': radioRadius }\n }\n }\n } = props;\n\n const backgroundColor = props.readOnly ? readOnlyBackgroundColor : checkedBackgroundColor;\n const foreground = tryCatch(() => readableColor(backgroundColor));\n\n const prcSelector = `+ ${StyledLabel} ${StyledPseudoRadioCheck}`;\n const { ltr } = useDirection();\n\n return css`\n ${hideVisually}\n\n ${!disabled &&\n css`\n &:focus ${prcSelector} {\n box-shadow: ${shadow};\n border-color: ${focusBorderColor};\n }\n `}\n\n &:checked\n ${prcSelector},\n &:checked:disabled\n ${prcSelector},\n &[type='checkbox']:indeterminate\n ${prcSelector},\n &[type='checkbox']:indeterminate:disabled\n ${prcSelector} {\n border-color: ${props.readOnly ? 'inherit' : checkedBorderColor};\n background-color: ${backgroundColor};\n\n &::after {\n display: block;\n }\n }\n\n &[type='radio'] ${prcSelector}, &[type='radio'] ${prcSelector}::after {\n border-radius: ${radioRadius};\n }\n\n &[type='radio'] ${prcSelector}::after {\n margin: auto;\n width: 100%;\n height: 100%;\n background-color: ${foreground};\n transform: scale(0.4);\n }\n\n &[type='checkbox'] ${prcSelector} {\n border-radius: min(calc(${baseBorderRadius} * ${checkRadius}), 0.25rem);\n }\n\n &[type='checkbox']:not(:indeterminate) ${prcSelector} {\n &::after {\n width: 40%;\n height: 75%;\n ${ltr\n ? css`\n transform: rotate(45deg) translate(50%, -30%);\n `\n : css`\n transform: rotate(45deg) translate(-50%, 30%);\n `}\n border-right: 0.15em solid ${foreground};\n border-bottom: 0.15em solid ${foreground};\n }\n }\n\n &[type='checkbox']:indeterminate ${prcSelector} {\n display: flex;\n &::after {\n width: 90%;\n height: 0.15em;\n margin: auto;\n background-color: ${foreground};\n }\n }\n `;\n});\n\nStyledRadioCheckInput.defaultProps = defaultThemeProp;\n\nexport const StyledRadioCheck = styled.div<Pick<RadioCheckProps, 'disabled' | 'readOnly'>>(\n props => {\n const {\n disabled,\n readOnly,\n theme: {\n base,\n components: {\n 'radio-check': {\n label: { color: labelColor, 'font-weight': labelFontWeight }\n },\n 'form-control': {\n ':hover': { 'border-color': hoverBorderColor }\n }\n }\n }\n } = props;\n\n const fontSize = calculateFontSize(base['font-size'], base['font-scale']);\n\n return css`\n > ${StyledLabel} {\n cursor: pointer;\n display: flex;\n align-items: center;\n font-weight: ${labelFontWeight};\n word-break: break-word;\n font-size: ${fontSize.s};\n color: ${labelColor};\n margin: 0;\n min-height: ${base['hit-area']['mouse-min']};\n\n @media (pointer: coarse) {\n min-height: ${base['hit-area']['finger-min']};\n }\n }\n\n ${!(disabled || readOnly) &&\n css`\n &:not(:focus-within) > ${StyledLabel}:hover ${StyledPseudoRadioCheck} {\n border-color: ${hoverBorderColor};\n }\n `}\n `;\n }\n);\n\nStyledRadioCheck.defaultProps = defaultThemeProp;\n\nexport const StyledRadioCheckCard = styled.label<\n Pick<RadioCheckProps, 'disabled' | 'readOnly' | 'status'>\n>(\n ({\n disabled,\n readOnly,\n status,\n theme: {\n base: { palette, shadow, spacing },\n components: {\n card,\n 'form-field': formField,\n 'radio-check': { label },\n 'form-control': {\n ':hover': { 'border-color': hoverBorderColor }\n }\n }\n }\n }) => {\n const useBorderColor =\n status === 'error' ? formField.error['status-color'] : palette['border-line'];\n\n return css`\n min-width: min-content;\n align-items: start;\n cursor: pointer;\n background-color: ${card.background};\n border-radius: ${card['border-radius']};\n border: 0.0625rem solid ${useBorderColor};\n padding: ${spacing};\n\n ${disabled &&\n css`\n cursor: not-allowed;\n `}\n\n ${!(disabled || readOnly) &&\n css`\n :hover:not(:focus-within) {\n border-color: ${hoverBorderColor};\n ${StyledLabel} ${StyledPseudoRadioCheck} {\n border-color: ${hoverBorderColor};\n }\n }\n\n :focus-within {\n box-shadow: ${shadow.focus};\n border-color: transparent;\n }\n `}\n\n > ${StyledLabel} {\n display: grid;\n grid-template-columns: auto 1fr;\n color: ${label.color};\n font-weight: ${label['font-weight']};\n }\n `;\n }\n);\n\nStyledRadioCheckCard.defaultProps = defaultThemeProp;\n\nconst RadioCheck: FC<RadioCheckProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<RadioCheckProps>, ref: RadioCheckProps['ref']) => {\n const uid = useUID();\n const t = useI18n();\n\n const {\n type,\n id = uid,\n label,\n required = false,\n disabled = false,\n indeterminate = false,\n readOnly = false,\n variant = 'simple',\n onClick,\n onKeyDown,\n status,\n info,\n additionalInfo,\n ...restProps\n } = props;\n\n const isRadio = type === 'radio';\n const card = variant === 'card';\n const newRef = useConsolidatedRef(ref);\n\n useEffect(() => {\n if (!isRadio && newRef.current) {\n newRef.current.indeterminate = !!indeterminate;\n }\n }, [newRef, indeterminate, isRadio]);\n\n return (\n <FormField\n as={card ? StyledRadioCheckCard : StyledRadioCheck}\n label={\n <>\n <StyledPseudoRadioCheck\n status={status}\n isRadio={isRadio}\n as={StyledFormControl}\n required={required}\n disabled={disabled}\n readOnly={readOnly}\n />\n <>\n {label}\n {readOnly && <VisuallyHiddenText>{` ${t('read_only')}`}</VisuallyHiddenText>}\n </>\n </>\n }\n labelAs={card ? 'div' : undefined}\n id={id}\n required={required}\n disabled={disabled}\n readOnly={readOnly}\n status={status}\n info={info}\n isRadioCheck\n inline\n labelAfter\n additionalInfo={additionalInfo}\n >\n <StyledRadioCheckInput\n {...restProps}\n id={id}\n type={type}\n required={required}\n disabled={disabled}\n readOnly={readOnly}\n onClick={(e: MouseEvent<HTMLInputElement>) => {\n if (readOnly) e.preventDefault();\n\n onClick?.(e);\n }}\n onKeyDown={(e: KeyboardEvent<HTMLInputElement>) => {\n if (type === 'checkbox' && readOnly && e.key === ' ') {\n e.preventDefault();\n }\n if (type === 'radio' && readOnly && e.key.includes('Arrow')) {\n e.preventDefault();\n }\n\n onKeyDown?.(e);\n }}\n ref={newRef}\n />\n </FormField>\n );\n }\n);\n\nexport default RadioCheck;\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FunctionComponent, Ref, ReactNode, ChangeEventHandler } from 'react';
|
|
2
|
-
import { Action, ForwardProps } from '../../types';
|
|
2
|
+
import { Action, BaseProps, ForwardProps, TestIdProp } from '../../types';
|
|
3
3
|
import { FormControlProps } from '../FormControl';
|
|
4
|
-
export interface SelectProps {
|
|
4
|
+
export interface SelectProps extends BaseProps, TestIdProp {
|
|
5
5
|
/** Pass Options components as children to render the options of the Select list. */
|
|
6
6
|
children: ReactNode;
|
|
7
7
|
/** Called when an Option is chosen within the list. */
|