@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":"Select.d.ts","sourceRoot":"","sources":["../../../src/components/Select/Select.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAEjB,GAAG,EACH,SAAS,EACT,kBAAkB,EAEnB,MAAM,OAAO,CAAC;AAIf,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Select.d.ts","sourceRoot":"","sources":["../../../src/components/Select/Select.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAEjB,GAAG,EACH,SAAS,EACT,kBAAkB,EAEnB,MAAM,OAAO,CAAC;AAIf,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE1E,OAAO,EAAqB,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAMrE,MAAM,WAAW,WAAY,SAAQ,SAAS,EAAE,UAAU;IACxD,oFAAoF;IACpF,QAAQ,EAAE,SAAS,CAAC;IACpB,uDAAuD;IACvD,QAAQ,CAAC,EAAE,kBAAkB,CAAC,iBAAiB,CAAC,CAAC;IACjD,6DAA6D;IAC7D,mBAAmB,CAAC,EAAE,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;IAC9D;;;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,uCAAuC;IACvC,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;;;OAGG;IACH,KAAK,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAClC,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACxC,qFAAqF;IACrF,QAAQ,CAAC,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACxC,+FAA+F;IAC/F,IAAI,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAChC,kFAAkF;IAClF,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,8EAA8E;IAC9E,cAAc,CAAC,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IACpD,mCAAmC;IACnC,GAAG,CAAC,EAAE,GAAG,CAAC,iBAAiB,CAAC,CAAC;CAC9B;AAED,eAAO,MAAM,YAAY;YAA2B,OAAO;cAAY,OAAO;SAiD5E,CAAC;AAIH,QAAA,MAAM,MAAM,EAAE,iBAAiB,CAAC,WAAW,GAAG,YAAY,CAqFzD,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -4,8 +4,9 @@ import styled, { css } from 'styled-components';
|
|
|
4
4
|
import { defaultThemeProp } from '../../theme';
|
|
5
5
|
import FormField from '../FormField';
|
|
6
6
|
import { StyledFormControl } from '../FormControl';
|
|
7
|
-
import { useDirection, useI18n, useUID } from '../../hooks';
|
|
7
|
+
import { useDirection, useI18n, useTestIds, useUID } from '../../hooks';
|
|
8
8
|
import VisuallyHiddenText from '../VisuallyHiddenText';
|
|
9
|
+
import { getSelectTestIds } from './Select.test-ids';
|
|
9
10
|
export const StyledSelect = styled.select(props => {
|
|
10
11
|
const { readOnly } = props;
|
|
11
12
|
const { base, components: { 'form-control': { 'foreground-color': fg }, select } } = props.theme;
|
|
@@ -53,8 +54,9 @@ StyledSelect.defaultProps = defaultThemeProp;
|
|
|
53
54
|
const Select = forwardRef((props, ref) => {
|
|
54
55
|
const uid = useUID();
|
|
55
56
|
const t = useI18n();
|
|
56
|
-
const { additionalInfo, children, id = uid, label, labelHidden, info, status, required = false, disabled = false, readOnly = false, actions, onResolveSuggestion, ...restProps } = props;
|
|
57
|
-
const
|
|
57
|
+
const { testId, additionalInfo, children, id = uid, label, labelHidden, info, status, required = false, disabled = false, readOnly = false, actions, onResolveSuggestion, ...restProps } = props;
|
|
58
|
+
const testIds = useTestIds(testId, getSelectTestIds);
|
|
59
|
+
const Comp = (_jsx(StyledFormControl, { "data-testid": testIds.control, ...restProps, as: StyledSelect, hasSuggestion: status === 'pending' && !!onResolveSuggestion, id: id, status: status, required: required, disabled: disabled, label: label, readOnly: readOnly, ref: ref, onMouseDown: readOnly
|
|
58
60
|
? (e) => {
|
|
59
61
|
e.preventDefault();
|
|
60
62
|
}
|
|
@@ -66,6 +68,7 @@ const Select = forwardRef((props, ref) => {
|
|
|
66
68
|
}
|
|
67
69
|
: undefined, children: children }));
|
|
68
70
|
return label ? (_jsx(FormField, { ...{
|
|
71
|
+
testId: testIds.root,
|
|
69
72
|
label: (_jsxs(_Fragment, { children: [label, readOnly && _jsx(VisuallyHiddenText, { children: ` ${t('read_only')}` })] })),
|
|
70
73
|
labelHidden,
|
|
71
74
|
id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Select.js","sourceRoot":"","sources":["../../../src/components/Select/Select.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAOX,MAAM,OAAO,CAAC;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C,CAAC,SAAS,YAGd,QAAQ,GACS,CACrB,CAAC;IAEF,OAAO,KAAK,CAAC,CAAC,CAAC,CACb,KAAC,SAAS,OACJ;YACF,KAAK,EAAE,CACL,8BACG,KAAK,EACL,QAAQ,IAAI,KAAC,kBAAkB,cAAE,IAAI,CAAC,CAAC,WAAW,CAAC,EAAE,GAAsB,IAC3E,CACJ;YACD,WAAW;YACX,EAAE;YACF,IAAI;YACJ,MAAM;YACN,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,OAAO;YACP,mBAAmB;YACnB,cAAc;SACf,YAEA,IAAI,GACK,CACb,CAAC,CAAC,CAAC,CACF,IAAI,CACL,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,MAAM,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n PropsWithoutRef,\n Ref,\n ReactNode,\n ChangeEventHandler,\n MouseEvent\n} from 'react';\nimport styled, { css } from 'styled-components';\n\nimport { defaultThemeProp } from '../../theme';\nimport { Action, ForwardProps } from '../../types';\nimport FormField from '../FormField';\nimport { StyledFormControl, FormControlProps } from '../FormControl';\nimport { useDirection, useI18n, useUID } from '../../hooks';\nimport VisuallyHiddenText from '../VisuallyHiddenText';\n\nexport interface SelectProps {\n /** Pass Options components as children to render the options of the Select list. */\n children: ReactNode;\n /** Called when an Option is chosen within the list. */\n onChange?: ChangeEventHandler<HTMLSelectElement>;\n /** Callback fired when AI suggestion is accepted/rejected */\n onResolveSuggestion?: FormControlProps['onResolveSuggestion'];\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 /** Visually hides the label region. */\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 /**\n * Creates a controlled input and sets the value. Requires an onChange handler to update value.\n * value + onChange is the recommended method per React team.\n */\n value?: FormControlProps['value'];\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 /** Sets html name attribute for the underlying control. Useful for mapping to a data field. */\n name?: FormControlProps['name'];\n /** Pass an array of Action objects to append button(s) inline with the Select. */\n actions?: Action[];\n /** Pass a heading and content to show additional information on the field. */\n additionalInfo?: FormControlProps['additionalInfo'];\n /** A ref to the select element. */\n ref?: Ref<HTMLSelectElement>;\n}\n\nexport const StyledSelect = styled.select<{ status: boolean; readOnly: boolean }>(props => {\n const { readOnly } = props;\n const {\n base,\n components: {\n 'form-control': { 'foreground-color': fg },\n select\n }\n } = props.theme;\n const foreground = encodeURIComponent(fg);\n const { rtl } = useDirection();\n\n return css`\n appearance: none;\n -webkit-appearance: none;\n overflow-x: hidden;\n text-overflow: ellipsis;\n width: 100%;\n height: ${select.height};\n min-height: ${base['hit-area']['mouse-min']};\n padding-inline-start: ${select.padding};\n padding-inline-end: calc(4 * ${base.spacing});\n\n /* cSpell:disable-next-line */\n background-image: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 25 25' fill='${foreground}'%3E%3Cpath d='M12.1476563,16.5726562 C12.1476563,16.5726562 3.2875,9.72421875 3.2875,9.72421875 C3.2875,9.72421875 3.14375,9.58046875 3.14375,9.58046875 C3.04765625,9.3890625 3,9.19765625 3,9.00546875 C3,9.00546875 3,9.00546875 3,9.00546875 C3,8.33515625 3.33515625,8 3.9578125,8 C3.9578125,8 3.9578125,8 3.9578125,8 C4.1015625,8 4.29296875,8.09609375 4.628125,8.2390625 C4.628125,8.2390625 4.628125,8.2390625 4.628125,8.2390625 C4.628125,8.2390625 12.8179688,14.2257813 12.8179688,14.2257813 C12.8179688,14.2257813 21.103125,8.19140625 21.103125,8.19140625 C21.3421875,8.04765625 21.534375,8 21.678125,8 C21.678125,8 21.678125,8 21.678125,8 C22.3007813,8 22.6359375,8.33515625 22.6359375,9.00546875 C22.6359375,9.00546875 22.6359375,9.00546875 22.6359375,9.00546875 C22.6359375,9.196875 22.5882813,9.38828125 22.4921875,9.58046875 C22.4921875,9.58046875 22.4921875,9.58046875 22.4921875,9.58046875 C22.4921875,9.58046875 22.3484375,9.72421875 22.3484375,9.72421875 C22.3484375,9.72421875 13.4882812,16.525 13.4882812,16.525 C13.296875,16.7164063 13.0570312,16.8125 12.8179688,16.8125 C12.8179688,16.8125 12.8179688,16.8125 12.8179688,16.8125 C12.5789062,16.8125 12.3867188,16.7164062 12.1476563,16.5734375 C12.1476563,16.5734375 12.1476563,16.5734375 12.1476563,16.5734375 L12.1476563,16.5726562 Z'/%3E%3C/svg%3E\");\n background-repeat: no-repeat;\n background-size: calc(2 * ${base.spacing}) auto;\n background-position: ${rtl ? base.spacing : `calc(100% - ${base.spacing}) `} 60%;\n border-width: ${select['border-width']};\n border-radius: calc(${base['border-radius']} * ${select['border-radius']});\n\n ${readOnly &&\n css`\n background-image: none;\n `}\n\n ${!props.status &&\n css`\n border-color: ${select['border-color']};\n `}\n\n &::-ms-expand {\n display: none;\n }\n\n @media (pointer: coarse) {\n min-height: ${base['hit-area']['finger-min']};\n }\n `;\n});\n\nStyledSelect.defaultProps = defaultThemeProp;\n\nconst Select: FunctionComponent<SelectProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<SelectProps>, ref: SelectProps['ref']) => {\n const uid = useUID();\n const t = useI18n();\n\n const {\n additionalInfo,\n children,\n id = uid,\n label,\n labelHidden,\n info,\n status,\n required = false,\n disabled = false,\n readOnly = false,\n actions,\n onResolveSuggestion,\n ...restProps\n } = props;\n\n const Comp = (\n <StyledFormControl\n {...restProps}\n as={StyledSelect}\n hasSuggestion={status === 'pending' && !!onResolveSuggestion}\n id={id}\n status={status}\n required={required}\n disabled={disabled}\n label={label}\n readOnly={readOnly}\n ref={ref}\n onMouseDown={\n readOnly\n ? (e: MouseEvent<HTMLSelectElement>) => {\n e.preventDefault();\n }\n : undefined\n }\n onKeyDown={\n readOnly\n ? (e: KeyboardEvent) => {\n // TODO: Consideration is needed for key modifiers, e.g. \"ctrl p\"\n if (!['Escape', 'Tab', 'Space'].includes(e.key)) e.preventDefault();\n }\n : undefined\n }\n >\n {children}\n </StyledFormControl>\n );\n\n return label ? (\n <FormField\n {...{\n label: (\n <>\n {label}\n {readOnly && <VisuallyHiddenText>{` ${t('read_only')}`}</VisuallyHiddenText>}\n </>\n ),\n labelHidden,\n id,\n info,\n status,\n required,\n disabled,\n readOnly,\n actions,\n onResolveSuggestion,\n additionalInfo\n }}\n >\n {Comp}\n </FormField>\n ) : (\n Comp\n );\n }\n);\n\nexport default Select;\n"]}
|
|
1
|
+
{"version":3,"file":"Select.js","sourceRoot":"","sources":["../../../src/components/Select/Select.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAOX,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAoB,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,kBAAkB,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AA2CrD,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAyC,KAAK,CAAC,EAAE;IACxF,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAC3B,MAAM,EACJ,IAAI,EACJ,UAAU,EAAE,EACV,cAAc,EAAE,EAAE,kBAA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CAAC,CAAC,CACF,IAAI,CACL,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,MAAM,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n PropsWithoutRef,\n Ref,\n ReactNode,\n ChangeEventHandler,\n MouseEvent\n} from 'react';\nimport styled, { css } from 'styled-components';\n\nimport { defaultThemeProp } from '../../theme';\nimport { Action, BaseProps, ForwardProps, TestIdProp } from '../../types';\nimport FormField from '../FormField';\nimport { StyledFormControl, FormControlProps } from '../FormControl';\nimport { useDirection, useI18n, useTestIds, useUID } from '../../hooks';\nimport VisuallyHiddenText from '../VisuallyHiddenText';\n\nimport { getSelectTestIds } from './Select.test-ids';\n\nexport interface SelectProps extends BaseProps, TestIdProp {\n /** Pass Options components as children to render the options of the Select list. */\n children: ReactNode;\n /** Called when an Option is chosen within the list. */\n onChange?: ChangeEventHandler<HTMLSelectElement>;\n /** Callback fired when AI suggestion is accepted/rejected */\n onResolveSuggestion?: FormControlProps['onResolveSuggestion'];\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 /** Visually hides the label region. */\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 /**\n * Creates a controlled input and sets the value. Requires an onChange handler to update value.\n * value + onChange is the recommended method per React team.\n */\n value?: FormControlProps['value'];\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 /** Sets html name attribute for the underlying control. Useful for mapping to a data field. */\n name?: FormControlProps['name'];\n /** Pass an array of Action objects to append button(s) inline with the Select. */\n actions?: Action[];\n /** Pass a heading and content to show additional information on the field. */\n additionalInfo?: FormControlProps['additionalInfo'];\n /** A ref to the select element. */\n ref?: Ref<HTMLSelectElement>;\n}\n\nexport const StyledSelect = styled.select<{ status: boolean; readOnly: boolean }>(props => {\n const { readOnly } = props;\n const {\n base,\n components: {\n 'form-control': { 'foreground-color': fg },\n select\n }\n } = props.theme;\n const foreground = encodeURIComponent(fg);\n const { rtl } = useDirection();\n\n return css`\n appearance: none;\n -webkit-appearance: none;\n overflow-x: hidden;\n text-overflow: ellipsis;\n width: 100%;\n height: ${select.height};\n min-height: ${base['hit-area']['mouse-min']};\n padding-inline-start: ${select.padding};\n padding-inline-end: calc(4 * ${base.spacing});\n\n /* cSpell:disable-next-line */\n background-image: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 25 25' fill='${foreground}'%3E%3Cpath d='M12.1476563,16.5726562 C12.1476563,16.5726562 3.2875,9.72421875 3.2875,9.72421875 C3.2875,9.72421875 3.14375,9.58046875 3.14375,9.58046875 C3.04765625,9.3890625 3,9.19765625 3,9.00546875 C3,9.00546875 3,9.00546875 3,9.00546875 C3,8.33515625 3.33515625,8 3.9578125,8 C3.9578125,8 3.9578125,8 3.9578125,8 C4.1015625,8 4.29296875,8.09609375 4.628125,8.2390625 C4.628125,8.2390625 4.628125,8.2390625 4.628125,8.2390625 C4.628125,8.2390625 12.8179688,14.2257813 12.8179688,14.2257813 C12.8179688,14.2257813 21.103125,8.19140625 21.103125,8.19140625 C21.3421875,8.04765625 21.534375,8 21.678125,8 C21.678125,8 21.678125,8 21.678125,8 C22.3007813,8 22.6359375,8.33515625 22.6359375,9.00546875 C22.6359375,9.00546875 22.6359375,9.00546875 22.6359375,9.00546875 C22.6359375,9.196875 22.5882813,9.38828125 22.4921875,9.58046875 C22.4921875,9.58046875 22.4921875,9.58046875 22.4921875,9.58046875 C22.4921875,9.58046875 22.3484375,9.72421875 22.3484375,9.72421875 C22.3484375,9.72421875 13.4882812,16.525 13.4882812,16.525 C13.296875,16.7164063 13.0570312,16.8125 12.8179688,16.8125 C12.8179688,16.8125 12.8179688,16.8125 12.8179688,16.8125 C12.5789062,16.8125 12.3867188,16.7164062 12.1476563,16.5734375 C12.1476563,16.5734375 12.1476563,16.5734375 12.1476563,16.5734375 L12.1476563,16.5726562 Z'/%3E%3C/svg%3E\");\n background-repeat: no-repeat;\n background-size: calc(2 * ${base.spacing}) auto;\n background-position: ${rtl ? base.spacing : `calc(100% - ${base.spacing}) `} 60%;\n border-width: ${select['border-width']};\n border-radius: calc(${base['border-radius']} * ${select['border-radius']});\n\n ${readOnly &&\n css`\n background-image: none;\n `}\n\n ${!props.status &&\n css`\n border-color: ${select['border-color']};\n `}\n\n &::-ms-expand {\n display: none;\n }\n\n @media (pointer: coarse) {\n min-height: ${base['hit-area']['finger-min']};\n }\n `;\n});\n\nStyledSelect.defaultProps = defaultThemeProp;\n\nconst Select: FunctionComponent<SelectProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<SelectProps>, ref: SelectProps['ref']) => {\n const uid = useUID();\n const t = useI18n();\n\n const {\n testId,\n additionalInfo,\n children,\n id = uid,\n label,\n labelHidden,\n info,\n status,\n required = false,\n disabled = false,\n readOnly = false,\n actions,\n onResolveSuggestion,\n ...restProps\n } = props;\n\n const testIds = useTestIds(testId, getSelectTestIds);\n\n const Comp = (\n <StyledFormControl\n data-testid={testIds.control}\n {...restProps}\n as={StyledSelect}\n hasSuggestion={status === 'pending' && !!onResolveSuggestion}\n id={id}\n status={status}\n required={required}\n disabled={disabled}\n label={label}\n readOnly={readOnly}\n ref={ref}\n onMouseDown={\n readOnly\n ? (e: MouseEvent<HTMLSelectElement>) => {\n e.preventDefault();\n }\n : undefined\n }\n onKeyDown={\n readOnly\n ? (e: KeyboardEvent) => {\n // TODO: Consideration is needed for key modifiers, e.g. \"ctrl p\"\n if (!['Escape', 'Tab', 'Space'].includes(e.key)) e.preventDefault();\n }\n : undefined\n }\n >\n {children}\n </StyledFormControl>\n );\n\n return label ? (\n <FormField\n {...{\n testId: testIds.root,\n label: (\n <>\n {label}\n {readOnly && <VisuallyHiddenText>{` ${t('read_only')}`}</VisuallyHiddenText>}\n </>\n ),\n labelHidden,\n id,\n info,\n status,\n required,\n disabled,\n readOnly,\n actions,\n onResolveSuggestion,\n additionalInfo\n }}\n >\n {Comp}\n </FormField>\n ) : (\n Comp\n );\n }\n);\n\nexport default Select;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Select.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/Select/Select.test-ids.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,gGAAgD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Select.test-ids.js","sourceRoot":"","sources":["../../../src/components/Select/Select.test-ids.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAC,QAAQ,EAAE,CAAC,SAAS,CAAU,CAAC,CAAC","sourcesContent":["import { createTestIds } from '../../utils';\n\nexport const getSelectTestIds = createTestIds('select', ['control'] as const);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Slider.d.ts","sourceRoot":"","sources":["../../../src/components/Slider/Slider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAUlB,MAAM,OAAO,CAAC;AAOf,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,OAAO,WAAW,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Slider.d.ts","sourceRoot":"","sources":["../../../src/components/Slider/Slider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAUlB,MAAM,OAAO,CAAC;AAOf,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,OAAO,WAAW,MAAM,gBAAgB,CAAC;AAazC,QAAA,MAAM,MAAM,EAAE,iBAAiB,CAAC,WAAW,GAAG,YAAY,CA8OzD,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useEffect, useRef, useState, forwardRef } from 'react';
|
|
3
3
|
import { NumberInput } from '../Number';
|
|
4
|
-
import { useConsolidatedRef, useDirection, useUID } from '../../hooks';
|
|
4
|
+
import { useConsolidatedRef, useDirection, useTestIds, useUID } from '../../hooks';
|
|
5
5
|
import FormField from '../FormField';
|
|
6
6
|
import Flex from '../Flex';
|
|
7
7
|
import Grid from '../Grid';
|
|
@@ -9,9 +9,11 @@ import { cap } from '../../utils';
|
|
|
9
9
|
import { StyledSlider, StyledTrack, StyledThumb, StyledSliderTrackWrapper, StyledBar, StyledPreview } from './Slider.styles';
|
|
10
10
|
import { calculateValueLength, getNearestValue } from './utils';
|
|
11
11
|
import SliderTicks from './SliderTicks';
|
|
12
|
+
import { getSliderTestIds } from './Slider.test-ids';
|
|
12
13
|
const Slider = forwardRef((props, ref) => {
|
|
13
14
|
const uid = useUID();
|
|
14
|
-
const { id = uid, required, status, info, label, labelHidden, min = 0, max = 100, step = 1, value = min, orientation = 'horizontal', preview, disabled = false, readOnly = false, showInput = true, showProgress, ticks = {}, onChange, autoFocus, onDragStart, onDragEnd: onDragEndProp, ...restProps } = props;
|
|
15
|
+
const { testId, id = uid, required, status, info, label, labelHidden, min = 0, max = 100, step = 1, value = min, orientation = 'horizontal', preview, disabled = false, readOnly = false, showInput = true, showProgress, ticks = {}, onChange, autoFocus, onDragStart, onDragEnd: onDragEndProp, ...restProps } = props;
|
|
16
|
+
const testIds = useTestIds(testId, getSliderTestIds);
|
|
15
17
|
const thumbRef = useConsolidatedRef(ref);
|
|
16
18
|
const trackRef = useRef(null);
|
|
17
19
|
const [inDrag, setInDrag] = useState(false);
|
|
@@ -100,7 +102,7 @@ const Slider = forwardRef((props, ref) => {
|
|
|
100
102
|
thumbRef.current?.focus();
|
|
101
103
|
}, [autoFocus]);
|
|
102
104
|
const percentage = ((Number(value) - min) / (max - min)) * 100;
|
|
103
|
-
const Comp = (_jsxs(Flex, { ...restProps, as: StyledSlider, container: {
|
|
105
|
+
const Comp = (_jsxs(Flex, { "data-testid": testIds.root, ...restProps, as: StyledSlider, container: {
|
|
104
106
|
alignItems: 'start',
|
|
105
107
|
direction: orientation === 'horizontal' ? 'row' : 'column'
|
|
106
108
|
}, orientation: orientation, ...{ status, disabled, readOnly }, style: {
|
|
@@ -113,8 +115,8 @@ const Slider = forwardRef((props, ref) => {
|
|
|
113
115
|
setInDrag(true);
|
|
114
116
|
e.preventDefault(); // Prevent dispatching mouse events as some browser may do that
|
|
115
117
|
onDragStart?.();
|
|
116
|
-
}, "aria-valuemin": min, "aria-valuemax": max, "aria-valuenow": value, "aria-orientation": orientation, "aria-readonly": readOnly || undefined, "aria-disabled": disabled || undefined, id: id, "aria-label": label?.toString(), "aria-describedby": `${id}-info`, "aria-controls": `${id}-value` })] }), Object.keys(ticks).length > 0 && (_jsx(SliderTicks, { ticks: ticks, min: min, max: max, step: step, orientation: orientation, onClick: setValue }))] }), showInput && !preview && (_jsx(NumberInput, { id: `${id}-value`, status: status, min: min, max: max, step: step, value: inputValue, onChange: setInputValue, onBlur: v => setValue(getNearestValue(Number(v), min, max, step)), size: calculateValueLength(min, max, step), readOnly: readOnly, disabled: disabled, "aria-label": label?.toString() })), preview && (_jsx(StyledPreview, { id: `${id}-value`, value: value.toString(), size: calculateValueLength(min, max, step) }))] }));
|
|
117
|
-
return label ? (_jsx(FormField, { ...{ label, labelHidden, id, info, status, required, disabled }, children: Comp })) : (Comp);
|
|
118
|
+
}, "aria-valuemin": min, "aria-valuemax": max, "aria-valuenow": value, "aria-orientation": orientation, "aria-readonly": readOnly || undefined, "aria-disabled": disabled || undefined, id: id, "aria-label": label?.toString(), "aria-describedby": `${id}-info`, "aria-controls": `${id}-value` })] }), Object.keys(ticks).length > 0 && (_jsx(SliderTicks, { ticks: ticks, min: min, max: max, step: step, orientation: orientation, onClick: setValue }))] }), showInput && !preview && (_jsx(NumberInput, { "data-testid": testIds.control, id: `${id}-value`, status: status, min: min, max: max, step: step, value: inputValue, onChange: setInputValue, onBlur: v => setValue(getNearestValue(Number(v), min, max, step)), size: calculateValueLength(min, max, step), readOnly: readOnly, disabled: disabled, "aria-label": label?.toString() })), preview && (_jsx(StyledPreview, { id: `${id}-value`, value: value.toString(), size: calculateValueLength(min, max, step) }))] }));
|
|
119
|
+
return label ? (_jsx(FormField, { ...{ label, labelHidden, id, info, status, required, disabled, testId }, children: Comp })) : (Comp);
|
|
118
120
|
});
|
|
119
121
|
export default Slider;
|
|
120
122
|
//# sourceMappingURL=Slider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Slider.js","sourceRoot":"","sources":["../../../src/components/Slider/Slider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAIL,WAAW,EACX,SAAS,EACT,MAAM,EACN,QAAQ,EAER,UAAU,EAGX,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAGlC,OAAO,EACL,YAAY,EACZ,WAAW,EACX,WAAW,EACX,wBAAwB,EACxB,SAAS,EACT,aAAa,EACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC,MAAM,MAAM,G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,EAAE,QAAQ,GACjB,CACH,IACI,EACN,SAAS,IAAI,CAAC,OAAO,IAAI,CACxB,KAAC,WAAW,IACV,EAAE,EAAE,GAAG,EAAE,QAAQ,EACjB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,aAAa,EACvB,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,EACjE,IAAI,EAAE,oBAAoB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,EAC1C,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,gBACN,KAAK,EAAE,QAAQ,EAAE,GAC7B,CACH,EACA,OAAO,IAAI,CACV,KAAC,aAAa,IACZ,EAAE,EAAE,GAAG,EAAE,QAAQ,EACjB,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE,EACvB,IAAI,EAAE,oBAAoB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,GAC1C,CACH,IACI,CACR,CAAC;IAEF,OAAO,KAAK,CAAC,CAAC,CAAC,CACb,KAAC,SAAS,OAAK,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,YACxE,IAAI,GACK,CACb,CAAC,CAAC,CAAC,CACF,IAAI,CACL,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,MAAM,CAAC","sourcesContent":["import {\n KeyboardEvent,\n FunctionComponent,\n PropsWithoutRef,\n useCallback,\n useEffect,\n useRef,\n useState,\n CSSProperties,\n forwardRef,\n Ref,\n TouchEvent as ReactTouchEvent\n} from 'react';\n\nimport { NumberInput } from '../Number';\nimport { useConsolidatedRef, useDirection, useUID } from '../../hooks';\nimport FormField from '../FormField';\nimport Flex from '../Flex';\nimport Grid from '../Grid';\nimport { ForwardProps } from '../../types';\nimport { cap } from '../../utils';\n\nimport SliderProps from './Slider.types';\nimport {\n StyledSlider,\n StyledTrack,\n StyledThumb,\n StyledSliderTrackWrapper,\n StyledBar,\n StyledPreview\n} from './Slider.styles';\nimport { calculateValueLength, getNearestValue } from './utils';\nimport SliderTicks from './SliderTicks';\n\nconst Slider: FunctionComponent<SliderProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<SliderProps>, ref: Ref<HTMLDivElement>) => {\n const uid = useUID();\n const {\n id = uid,\n required,\n status,\n info,\n label,\n labelHidden,\n min = 0,\n max = 100,\n step = 1,\n value = min,\n orientation = 'horizontal',\n preview,\n disabled = false,\n readOnly = false,\n showInput = true,\n showProgress,\n ticks = {},\n onChange,\n autoFocus,\n onDragStart,\n onDragEnd: onDragEndProp,\n ...restProps\n } = props;\n\n const thumbRef = useConsolidatedRef<HTMLDivElement>(ref);\n const trackRef = useRef<HTMLDivElement>(null);\n const [inDrag, setInDrag] = useState(false);\n const [inputValue, setInputValue] = useState(value.toString());\n\n const setValue = useCallback(\n (newValue: number) => {\n if (disabled || readOnly) return;\n const normalizedValue = Math.min(Math.max(newValue, min), max);\n\n setInputValue(normalizedValue.toString());\n onChange(normalizedValue);\n },\n [disabled, readOnly, onChange]\n );\n\n const { start, end } = useDirection();\n\n const moveThumb = useCallback(\n (e: MouseEvent | TouchEvent) => {\n if (disabled || readOnly) return;\n if (trackRef.current) {\n const track = trackRef.current.getBoundingClientRect();\n const { clientX, clientY } = 'touches' in e ? e.touches[0] : e;\n const newPosition =\n orientation === 'horizontal'\n ? (clientX - track[start]) / (track[end] - track[start])\n : (clientY - track.bottom) / (track.top - track.bottom);\n\n const normalizedValue = Math.min(Math.max(min + (max - min) * newPosition, min), max);\n setValue(getNearestValue(normalizedValue, min, max, step));\n }\n thumbRef.current?.focus();\n },\n [disabled, readOnly, step, min, max, setValue, start, end]\n );\n\n const onThumbKeyDown = useCallback(\n (e: KeyboardEvent<HTMLDivElement>) => {\n if (\n [\n 'ArrowDown',\n 'ArrowUp',\n 'ArrowLeft',\n 'ArrowRight',\n 'PageUp',\n 'PageDown',\n 'Home',\n 'End'\n ].includes(e.key)\n )\n e.preventDefault();\n\n switch (e.key) {\n case 'ArrowDown':\n case `Arrow${cap(start)}`:\n setValue(value - step);\n break;\n case 'ArrowUp':\n case `Arrow${cap(end)}`:\n setValue(value + step);\n break;\n case 'PageUp':\n setValue(value + 10 * step);\n break;\n case 'PageDown':\n setValue(value - 10 * step);\n break;\n case 'Home':\n setValue(min);\n break;\n case 'End':\n setValue(max);\n break;\n default:\n }\n },\n [setValue, value, step, start, end]\n );\n\n useEffect(() => {\n const onDragEnd = () => {\n setInDrag(false);\n if (inDrag) onDragEndProp?.();\n };\n\n document.addEventListener('mouseup', onDragEnd);\n document.addEventListener('touchend', onDragEnd);\n document.addEventListener('touchcancel', onDragEnd);\n if (inDrag) {\n document.addEventListener('mousemove', moveThumb);\n document.addEventListener('touchmove', moveThumb);\n }\n\n return () => {\n document.removeEventListener('mouseup', onDragEnd);\n document.removeEventListener('touchend', onDragEnd);\n document.removeEventListener('touchcancel', onDragEnd);\n document.removeEventListener('mousemove', moveThumb);\n document.removeEventListener('touchmove', moveThumb);\n };\n }, [inDrag, moveThumb, onDragEndProp]);\n\n useEffect(() => {\n if (autoFocus) thumbRef.current?.focus();\n }, [autoFocus]);\n\n const percentage = ((Number(value) - min) / (max - min)) * 100;\n\n const Comp = (\n <Flex\n {...restProps}\n as={StyledSlider}\n container={{\n alignItems: 'start',\n direction: orientation === 'horizontal' ? 'row' : 'column'\n }}\n orientation={orientation}\n {...{ status, disabled, readOnly }}\n style={\n {\n '--slider-value': `${percentage}%`,\n userSelect: inDrag ? 'none' : 'auto'\n } as CSSProperties\n }\n >\n <Grid as={StyledSliderTrackWrapper} container>\n <Flex\n as={StyledTrack}\n ref={trackRef}\n onMouseDown={moveThumb}\n container={{ alignItems: 'center', justify: 'center' }}\n >\n <StyledBar showProgress={showProgress} />\n <StyledThumb\n ref={thumbRef}\n role='slider'\n tabIndex={0}\n onKeyDown={onThumbKeyDown}\n onMouseDown={() => {\n setInDrag(true);\n onDragStart?.();\n }}\n onTouchStart={(e: ReactTouchEvent<HTMLDivElement>) => {\n setInDrag(true);\n e.preventDefault(); // Prevent dispatching mouse events as some browser may do that\n onDragStart?.();\n }}\n aria-valuemin={min}\n aria-valuemax={max}\n aria-valuenow={value}\n aria-orientation={orientation}\n aria-readonly={readOnly || undefined}\n aria-disabled={disabled || undefined}\n id={id}\n aria-label={label?.toString()}\n aria-describedby={`${id}-info`}\n aria-controls={`${id}-value`}\n />\n </Flex>\n {Object.keys(ticks).length > 0 && (\n <SliderTicks\n ticks={ticks}\n min={min}\n max={max}\n step={step}\n orientation={orientation}\n onClick={setValue}\n />\n )}\n </Grid>\n {showInput && !preview && (\n <NumberInput\n id={`${id}-value`}\n status={status}\n min={min}\n max={max}\n step={step}\n value={inputValue}\n onChange={setInputValue}\n onBlur={v => setValue(getNearestValue(Number(v), min, max, step))}\n size={calculateValueLength(min, max, step)}\n readOnly={readOnly}\n disabled={disabled}\n aria-label={label?.toString()}\n />\n )}\n {preview && (\n <StyledPreview\n id={`${id}-value`}\n value={value.toString()}\n size={calculateValueLength(min, max, step)}\n />\n )}\n </Flex>\n );\n\n return label ? (\n <FormField {...{ label, labelHidden, id, info, status, required, disabled }}>\n {Comp}\n </FormField>\n ) : (\n Comp\n );\n }\n);\n\nexport default Slider;\n"]}
|
|
1
|
+
{"version":3,"file":"Slider.js","sourceRoot":"","sources":["../../../src/components/Slider/Slider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAIL,WAAW,EACX,SAAS,EACT,MAAM,EACN,QAAQ,EAER,UAAU,EAGX,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,U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,EAAE,QAAQ,EACjB,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE,EACvB,IAAI,EAAE,oBAAoB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,GAC1C,CACH,IACI,CACR,CAAC;IAEF,OAAO,KAAK,CAAC,CAAC,CAAC,CACb,KAAC,SAAS,OAAK,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,YAChF,IAAI,GACK,CACb,CAAC,CAAC,CAAC,CACF,IAAI,CACL,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,MAAM,CAAC","sourcesContent":["import {\n KeyboardEvent,\n FunctionComponent,\n PropsWithoutRef,\n useCallback,\n useEffect,\n useRef,\n useState,\n CSSProperties,\n forwardRef,\n Ref,\n TouchEvent as ReactTouchEvent\n} from 'react';\n\nimport { NumberInput } from '../Number';\nimport { useConsolidatedRef, useDirection, useTestIds, useUID } from '../../hooks';\nimport FormField from '../FormField';\nimport Flex from '../Flex';\nimport Grid from '../Grid';\nimport { ForwardProps } from '../../types';\nimport { cap } from '../../utils';\n\nimport SliderProps from './Slider.types';\nimport {\n StyledSlider,\n StyledTrack,\n StyledThumb,\n StyledSliderTrackWrapper,\n StyledBar,\n StyledPreview\n} from './Slider.styles';\nimport { calculateValueLength, getNearestValue } from './utils';\nimport SliderTicks from './SliderTicks';\nimport { getSliderTestIds } from './Slider.test-ids';\n\nconst Slider: FunctionComponent<SliderProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<SliderProps>, ref: Ref<HTMLDivElement>) => {\n const uid = useUID();\n const {\n testId,\n id = uid,\n required,\n status,\n info,\n label,\n labelHidden,\n min = 0,\n max = 100,\n step = 1,\n value = min,\n orientation = 'horizontal',\n preview,\n disabled = false,\n readOnly = false,\n showInput = true,\n showProgress,\n ticks = {},\n onChange,\n autoFocus,\n onDragStart,\n onDragEnd: onDragEndProp,\n ...restProps\n } = props;\n\n const testIds = useTestIds(testId, getSliderTestIds);\n\n const thumbRef = useConsolidatedRef<HTMLDivElement>(ref);\n const trackRef = useRef<HTMLDivElement>(null);\n const [inDrag, setInDrag] = useState(false);\n const [inputValue, setInputValue] = useState(value.toString());\n\n const setValue = useCallback(\n (newValue: number) => {\n if (disabled || readOnly) return;\n const normalizedValue = Math.min(Math.max(newValue, min), max);\n\n setInputValue(normalizedValue.toString());\n onChange(normalizedValue);\n },\n [disabled, readOnly, onChange]\n );\n\n const { start, end } = useDirection();\n\n const moveThumb = useCallback(\n (e: MouseEvent | TouchEvent) => {\n if (disabled || readOnly) return;\n if (trackRef.current) {\n const track = trackRef.current.getBoundingClientRect();\n const { clientX, clientY } = 'touches' in e ? e.touches[0] : e;\n const newPosition =\n orientation === 'horizontal'\n ? (clientX - track[start]) / (track[end] - track[start])\n : (clientY - track.bottom) / (track.top - track.bottom);\n\n const normalizedValue = Math.min(Math.max(min + (max - min) * newPosition, min), max);\n setValue(getNearestValue(normalizedValue, min, max, step));\n }\n thumbRef.current?.focus();\n },\n [disabled, readOnly, step, min, max, setValue, start, end]\n );\n\n const onThumbKeyDown = useCallback(\n (e: KeyboardEvent<HTMLDivElement>) => {\n if (\n [\n 'ArrowDown',\n 'ArrowUp',\n 'ArrowLeft',\n 'ArrowRight',\n 'PageUp',\n 'PageDown',\n 'Home',\n 'End'\n ].includes(e.key)\n )\n e.preventDefault();\n\n switch (e.key) {\n case 'ArrowDown':\n case `Arrow${cap(start)}`:\n setValue(value - step);\n break;\n case 'ArrowUp':\n case `Arrow${cap(end)}`:\n setValue(value + step);\n break;\n case 'PageUp':\n setValue(value + 10 * step);\n break;\n case 'PageDown':\n setValue(value - 10 * step);\n break;\n case 'Home':\n setValue(min);\n break;\n case 'End':\n setValue(max);\n break;\n default:\n }\n },\n [setValue, value, step, start, end]\n );\n\n useEffect(() => {\n const onDragEnd = () => {\n setInDrag(false);\n if (inDrag) onDragEndProp?.();\n };\n\n document.addEventListener('mouseup', onDragEnd);\n document.addEventListener('touchend', onDragEnd);\n document.addEventListener('touchcancel', onDragEnd);\n if (inDrag) {\n document.addEventListener('mousemove', moveThumb);\n document.addEventListener('touchmove', moveThumb);\n }\n\n return () => {\n document.removeEventListener('mouseup', onDragEnd);\n document.removeEventListener('touchend', onDragEnd);\n document.removeEventListener('touchcancel', onDragEnd);\n document.removeEventListener('mousemove', moveThumb);\n document.removeEventListener('touchmove', moveThumb);\n };\n }, [inDrag, moveThumb, onDragEndProp]);\n\n useEffect(() => {\n if (autoFocus) thumbRef.current?.focus();\n }, [autoFocus]);\n\n const percentage = ((Number(value) - min) / (max - min)) * 100;\n\n const Comp = (\n <Flex\n data-testid={testIds.root}\n {...restProps}\n as={StyledSlider}\n container={{\n alignItems: 'start',\n direction: orientation === 'horizontal' ? 'row' : 'column'\n }}\n orientation={orientation}\n {...{ status, disabled, readOnly }}\n style={\n {\n '--slider-value': `${percentage}%`,\n userSelect: inDrag ? 'none' : 'auto'\n } as CSSProperties\n }\n >\n <Grid as={StyledSliderTrackWrapper} container>\n <Flex\n as={StyledTrack}\n ref={trackRef}\n onMouseDown={moveThumb}\n container={{ alignItems: 'center', justify: 'center' }}\n >\n <StyledBar showProgress={showProgress} />\n <StyledThumb\n ref={thumbRef}\n role='slider'\n tabIndex={0}\n onKeyDown={onThumbKeyDown}\n onMouseDown={() => {\n setInDrag(true);\n onDragStart?.();\n }}\n onTouchStart={(e: ReactTouchEvent<HTMLDivElement>) => {\n setInDrag(true);\n e.preventDefault(); // Prevent dispatching mouse events as some browser may do that\n onDragStart?.();\n }}\n aria-valuemin={min}\n aria-valuemax={max}\n aria-valuenow={value}\n aria-orientation={orientation}\n aria-readonly={readOnly || undefined}\n aria-disabled={disabled || undefined}\n id={id}\n aria-label={label?.toString()}\n aria-describedby={`${id}-info`}\n aria-controls={`${id}-value`}\n />\n </Flex>\n {Object.keys(ticks).length > 0 && (\n <SliderTicks\n ticks={ticks}\n min={min}\n max={max}\n step={step}\n orientation={orientation}\n onClick={setValue}\n />\n )}\n </Grid>\n {showInput && !preview && (\n <NumberInput\n data-testid={testIds.control}\n id={`${id}-value`}\n status={status}\n min={min}\n max={max}\n step={step}\n value={inputValue}\n onChange={setInputValue}\n onBlur={v => setValue(getNearestValue(Number(v), min, max, step))}\n size={calculateValueLength(min, max, step)}\n readOnly={readOnly}\n disabled={disabled}\n aria-label={label?.toString()}\n />\n )}\n {preview && (\n <StyledPreview\n id={`${id}-value`}\n value={value.toString()}\n size={calculateValueLength(min, max, step)}\n />\n )}\n </Flex>\n );\n\n return label ? (\n <FormField {...{ label, labelHidden, id, info, status, required, disabled, testId }}>\n {Comp}\n </FormField>\n ) : (\n Comp\n );\n }\n);\n\nexport default Slider;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Slider.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/Slider/Slider.test-ids.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,gGAAgD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Slider.test-ids.js","sourceRoot":"","sources":["../../../src/components/Slider/Slider.test-ids.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAC,QAAQ,EAAE,CAAC,SAAS,CAAU,CAAC,CAAC","sourcesContent":["import { createTestIds } from '../../utils';\n\nexport const getSliderTestIds = createTestIds('slider', ['control'] as const);\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BaseProps, NoChildrenProp } from '../../types';
|
|
1
|
+
import { BaseProps, NoChildrenProp, TestIdProp } from '../../types';
|
|
2
2
|
import { FormControlProps } from '../FormControl';
|
|
3
|
-
export default interface SliderProps extends BaseProps, NoChildrenProp {
|
|
3
|
+
export default interface SliderProps extends BaseProps, NoChildrenProp, TestIdProp {
|
|
4
4
|
/**
|
|
5
5
|
* Sets DOM id for the control and associates label element via 'for' attribute.
|
|
6
6
|
* If an id is not pass, a random id will be generated for any render.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Slider.types.d.ts","sourceRoot":"","sources":["../../../src/components/Slider/Slider.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Slider.types.d.ts","sourceRoot":"","sources":["../../../src/components/Slider/Slider.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,MAAM,CAAC,OAAO,WAAW,WAAY,SAAQ,SAAS,EAAE,cAAc,EAAE,UAAU;IAChF;;;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,uCAAuC;IACvC,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;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACxC,qFAAqF;IACrF,QAAQ,CAAC,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACxC,+FAA+F;IAC/F,IAAI,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAChC,2DAA2D;IAC3D,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,WAAW,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC;IACxC;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,KAAK,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAClC;;;OAGG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Slider.types.js","sourceRoot":"","sources":["../../../src/components/Slider/Slider.types.ts"],"names":[],"mappings":"","sourcesContent":["import { BaseProps, NoChildrenProp } from '../../types';\nimport { FormControlProps } from '../FormControl';\n\nexport default interface SliderProps 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 /** Visually hides the label region. */\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 /**\n * Creates a controlled input and sets the value. Requires an onChange handler to update value.\n * value + onChange is the recommended method per React team.\n */\n value: number;\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 /** Sets html name attribute for the underlying control. Useful for mapping to a data field. */\n name?: FormControlProps['name'];\n /** Will automatically focus the thumb on render if true */\n autoFocus?: boolean;\n /**\n * Minimum value.\n * @default 0\n */\n min?: number;\n /**\n * Maximum value.\n * @default 100\n */\n max?: number;\n /**\n * Step value.\n * @default 1\n */\n step?: number;\n /**\n * Slider orientation.\n * @default 'horizontal'\n */\n orientation?: 'vertical' | 'horizontal';\n /**\n * Show slider color progress bar.\n * @default false\n */\n showProgress?: boolean;\n /**\n * Show current value.\n * @default false\n */\n preview?: boolean;\n /**\n * Display input to provide value.\n * @default true\n */\n showInput?: boolean;\n /**\n * Display defined ticks.\n */\n ticks?: { [key: number]: string };\n /**\n * On change callback.\n * @param value new input value\n */\n onChange: (value: number) => void;\n /**\n * Called when the user starts dragging the slider thumb.\n */\n onDragStart?: () => void;\n /**\n * Called when the user stops dragging the slider thumb.\n */\n onDragEnd?: () => void;\n}\n\nexport interface TickDefinition {\n start: number;\n end: number;\n value: number;\n label: string;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Slider.types.js","sourceRoot":"","sources":["../../../src/components/Slider/Slider.types.ts"],"names":[],"mappings":"","sourcesContent":["import { BaseProps, NoChildrenProp, TestIdProp } from '../../types';\nimport { FormControlProps } from '../FormControl';\n\nexport default interface SliderProps 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 /** Visually hides the label region. */\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 /**\n * Creates a controlled input and sets the value. Requires an onChange handler to update value.\n * value + onChange is the recommended method per React team.\n */\n value: number;\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 /** Sets html name attribute for the underlying control. Useful for mapping to a data field. */\n name?: FormControlProps['name'];\n /** Will automatically focus the thumb on render if true */\n autoFocus?: boolean;\n /**\n * Minimum value.\n * @default 0\n */\n min?: number;\n /**\n * Maximum value.\n * @default 100\n */\n max?: number;\n /**\n * Step value.\n * @default 1\n */\n step?: number;\n /**\n * Slider orientation.\n * @default 'horizontal'\n */\n orientation?: 'vertical' | 'horizontal';\n /**\n * Show slider color progress bar.\n * @default false\n */\n showProgress?: boolean;\n /**\n * Show current value.\n * @default false\n */\n preview?: boolean;\n /**\n * Display input to provide value.\n * @default true\n */\n showInput?: boolean;\n /**\n * Display defined ticks.\n */\n ticks?: { [key: number]: string };\n /**\n * On change callback.\n * @param value new input value\n */\n onChange: (value: number) => void;\n /**\n * Called when the user starts dragging the slider thumb.\n */\n onDragStart?: () => void;\n /**\n * Called when the user stops dragging the slider thumb.\n */\n onDragEnd?: () => void;\n}\n\nexport interface TickDefinition {\n start: number;\n end: number;\n value: number;\n label: string;\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FunctionComponent, ReactNode, Ref, ElementType } from 'react';
|
|
2
2
|
import { GridContainerProps } from '../Grid';
|
|
3
|
-
import { ForwardProps, NoChildrenProp } from '../../types';
|
|
4
|
-
export interface SummaryItemProps extends NoChildrenProp {
|
|
3
|
+
import { ForwardProps, NoChildrenProp, TestIdProp } from '../../types';
|
|
4
|
+
export interface SummaryItemProps extends NoChildrenProp, TestIdProp {
|
|
5
5
|
/** Region for the primary information. */
|
|
6
6
|
primary: NonNullable<ReactNode>;
|
|
7
7
|
/** Region for displaying supporting metadata. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SummaryItem.d.ts","sourceRoot":"","sources":["../../../src/components/SummaryItem/SummaryItem.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,GAAG,EAA+B,WAAW,EAAE,MAAM,OAAO,CAAC;AAGpG,OAAa,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"SummaryItem.d.ts","sourceRoot":"","sources":["../../../src/components/SummaryItem/SummaryItem.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,GAAG,EAA+B,WAAW,EAAE,MAAM,OAAO,CAAC;AAGpG,OAAa,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAMvE,MAAM,WAAW,gBAAiB,SAAQ,cAAc,EAAE,UAAU;IAClE,0CAA0C;IAC1C,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAChC,iDAAiD;IACjD,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,8DAA8D;IAC9D,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,oDAAoD;IACpD,OAAO,CAAC,EAAE,SAAS,CAAC;IAEpB,SAAS,CAAC,EAAE,kBAAkB,CAAC;IAC/B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IACvC,yDAAyD;IACzD,EAAE,CAAC,EAAE,WAAW,CAAC;IACjB,+BAA+B;IAC/B,GAAG,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CACxB;AAED,eAAO,MAAM,YAAY,yGAOxB,CAAC;AAIF,eAAO,MAAM,aAAa;;uBAEL,gBAAgB,CAAC,kBAAkB,CAAC;SAkBvD,CAAC;AAIH,eAAO,MAAM,eAAe;uBACP,gBAAgB,CAAC,kBAAkB,CAAC;SAYvD,CAAC;AAEH,eAAO,MAAM,wBAAwB,yGAEpC,CAAC;AAEF,eAAO,MAAM,iBAAiB,yGAAe,CAAC;AAgB9C,QAAA,MAAM,WAAW,EAAE,iBAAiB,CAAC,gBAAgB,GAAG,YAAY,CAqEnE,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -4,6 +4,8 @@ import styled, { css } from 'styled-components';
|
|
|
4
4
|
import Grid from '../Grid';
|
|
5
5
|
import { defaultThemeProp } from '../../theme';
|
|
6
6
|
import { StyledProgressRing } from '../Progress';
|
|
7
|
+
import { useTestIds } from '../../hooks';
|
|
8
|
+
import { getSummaryItemTestIds } from './SummaryItem.test-ids';
|
|
7
9
|
export const StyledVisual = styled.div `
|
|
8
10
|
> ${StyledProgressRing}, img {
|
|
9
11
|
display: block;
|
|
@@ -54,13 +56,14 @@ const getColumns = ({ visual, actions }) => {
|
|
|
54
56
|
const getAreas = ({ secondary, visual, actions }) => {
|
|
55
57
|
return `"${visual ? 'visual ' : ''}primary${actions ? ' actions' : ''}"${secondary ? `\n"${visual ? 'visual ' : ''}secondary${actions ? ' actions' : ''}"` : ''}`;
|
|
56
58
|
};
|
|
57
|
-
const SummaryItem = forwardRef(({ visual, primary, secondary, actions, container, overflowStrategy = 'wrap', as, ...restProps }, ref) => {
|
|
58
|
-
|
|
59
|
+
const SummaryItem = forwardRef(({ testId, visual, primary, secondary, actions, container, overflowStrategy = 'wrap', as, ...restProps }, ref) => {
|
|
60
|
+
const testIds = useTestIds(testId, getSummaryItemTestIds);
|
|
61
|
+
return (_jsxs(Grid, { "data-testid": testIds.root, ...restProps, ref: ref, container: {
|
|
59
62
|
cols: getColumns({ visual, actions }),
|
|
60
63
|
colGap: 2,
|
|
61
64
|
areas: getAreas({ secondary, visual, actions }),
|
|
62
65
|
...container
|
|
63
|
-
}, as: StyledSummaryItem, forwardedAs: as, children: [visual && (_jsx(Grid, { as: StyledVisual, item: { area: 'visual', alignSelf: 'center' }, children: visual })), _jsx(StyledPrimary, { item: { area: 'primary', alignSelf: secondary ? 'end' : 'center' }, isString: typeof primary === 'string', overflowStrategy: overflowStrategy, children: primary }), secondary && (_jsx(StyledSecondary, { item: { area: 'secondary', alignSelf: 'start' }, overflowStrategy: overflowStrategy, children: secondary })), actions && (_jsx(Grid, { as: StyledSummaryItemActions, item: { area: 'actions', alignSelf: 'center' }, children: actions }))] }));
|
|
66
|
+
}, as: StyledSummaryItem, forwardedAs: as, children: [visual && (_jsx(Grid, { "data-testid": testIds.visual, as: StyledVisual, item: { area: 'visual', alignSelf: 'center' }, children: visual })), _jsx(StyledPrimary, { "data-testid": testIds.primary, item: { area: 'primary', alignSelf: secondary ? 'end' : 'center' }, isString: typeof primary === 'string', overflowStrategy: overflowStrategy, children: primary }), secondary && (_jsx(StyledSecondary, { "data-testid": testIds.secondary, item: { area: 'secondary', alignSelf: 'start' }, overflowStrategy: overflowStrategy, children: secondary })), actions && (_jsx(Grid, { "data-testid": testIds.actions, as: StyledSummaryItemActions, item: { area: 'actions', alignSelf: 'center' }, children: actions }))] }));
|
|
64
67
|
});
|
|
65
68
|
export default SummaryItem;
|
|
66
69
|
//# sourceMappingURL=SummaryItem.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SummaryItem.js","sourceRoot":"","sources":["../../../src/components/SummaryItem/SummaryItem.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAqC,UAAU,EAAgC,MAAM,OAAO,CAAC;AACpG,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,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AC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC","sourcesContent":["import { FunctionComponent, ReactNode, Ref, forwardRef, PropsWithoutRef, ElementType } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport Grid, { GridContainerProps } from '../Grid';\nimport { defaultThemeProp } from '../../theme';\nimport { ForwardProps, NoChildrenProp, TestIdProp } from '../../types';\nimport { StyledProgressRing } from '../Progress';\nimport { useTestIds } from '../../hooks';\n\nimport { getSummaryItemTestIds } from './SummaryItem.test-ids';\n\nexport interface SummaryItemProps extends NoChildrenProp, TestIdProp {\n /** Region for the primary information. */\n primary: NonNullable<ReactNode>;\n /** Region for displaying supporting metadata. */\n secondary?: ReactNode;\n /** Region for an Avatar, Icon, or other supporting visual. */\n visual?: ReactNode;\n /** Region for adding Actions, Buttons, or Links. */\n actions?: ReactNode;\n /* Override the default Grid container props on SummaryItem. */\n container?: GridContainerProps;\n /**\n * Determines how the text within primary and secondary fields should handle overflow.\n * @default \"wrap\"\n */\n overflowStrategy?: 'wrap' | 'ellipsis';\n /** HTML tag to render the SummaryItem's element with. */\n as?: ElementType;\n /** Ref for the SummaryItem. */\n ref?: Ref<HTMLElement>;\n}\n\nexport const StyledVisual = styled.div`\n > ${StyledProgressRing}, img {\n display: block;\n object-fit: cover;\n width: 2rem;\n height: 2rem;\n }\n`;\n\nStyledVisual.defaultProps = defaultThemeProp;\n\nexport const StyledPrimary = styled(Grid)<{\n isString?: boolean;\n overflowStrategy?: SummaryItemProps['overflowStrategy'];\n}>(({ theme, isString, overflowStrategy }) => {\n return css`\n ${overflowStrategy === 'ellipsis'\n ? css`\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n `\n : css`\n word-break: break-word;\n `}\n\n ${isString &&\n css`\n font-weight: ${theme.base['font-weight']['semi-bold']};\n `}\n `;\n});\n\nStyledPrimary.defaultProps = defaultThemeProp;\n\nexport const StyledSecondary = styled(Grid)<{\n overflowStrategy?: SummaryItemProps['overflowStrategy'];\n}>(({ overflowStrategy }) => {\n return css`\n ${overflowStrategy === 'ellipsis'\n ? css`\n overflow: hidden;\n text-overflow: ellipsis;\n `\n : css`\n word-break: break-word;\n `}\n `;\n});\n\nexport const StyledSummaryItemActions = styled.div`\n white-space: nowrap;\n`;\n\nexport const StyledSummaryItem = styled.div``;\n\nconst getColumns = ({ visual, actions }: Pick<SummaryItemProps, 'visual' | 'actions'>) => {\n return `${visual ? 'auto ' : ''}minmax(0, 1fr)${actions ? ' auto' : ''}`;\n};\n\nconst getAreas = ({\n secondary,\n visual,\n actions\n}: Pick<SummaryItemProps, 'secondary' | 'visual' | 'actions'>) => {\n return `\"${visual ? 'visual ' : ''}primary${actions ? ' actions' : ''}\"${\n secondary ? `\\n\"${visual ? 'visual ' : ''}secondary${actions ? ' actions' : ''}\"` : ''\n }`;\n};\n\nconst SummaryItem: FunctionComponent<SummaryItemProps & ForwardProps> = forwardRef(\n (\n {\n testId,\n visual,\n primary,\n secondary,\n actions,\n container,\n overflowStrategy = 'wrap',\n as,\n ...restProps\n }: PropsWithoutRef<SummaryItemProps>,\n ref: SummaryItemProps['ref']\n ) => {\n const testIds = useTestIds(testId, getSummaryItemTestIds);\n\n return (\n <Grid\n data-testid={testIds.root}\n {...restProps}\n ref={ref}\n container={{\n cols: getColumns({ visual, actions }),\n colGap: 2,\n areas: getAreas({ secondary, visual, actions }),\n ...container\n }}\n as={StyledSummaryItem}\n forwardedAs={as}\n >\n {visual && (\n <Grid\n data-testid={testIds.visual}\n as={StyledVisual}\n item={{ area: 'visual', alignSelf: 'center' }}\n >\n {visual}\n </Grid>\n )}\n <StyledPrimary\n data-testid={testIds.primary}\n item={{ area: 'primary', alignSelf: secondary ? 'end' : 'center' }}\n isString={typeof primary === 'string'}\n overflowStrategy={overflowStrategy}\n >\n {primary}\n </StyledPrimary>\n {secondary && (\n <StyledSecondary\n data-testid={testIds.secondary}\n item={{ area: 'secondary', alignSelf: 'start' }}\n overflowStrategy={overflowStrategy}\n >\n {secondary}\n </StyledSecondary>\n )}\n {actions && (\n <Grid\n data-testid={testIds.actions}\n as={StyledSummaryItemActions}\n item={{ area: 'actions', alignSelf: 'center' }}\n >\n {actions}\n </Grid>\n )}\n </Grid>\n );\n }\n);\n\nexport default SummaryItem;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SummaryItem.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/SummaryItem/SummaryItem.test-ids.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,qBAAqB,kIAKvB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SummaryItem.test-ids.js","sourceRoot":"","sources":["../../../src/components/SummaryItem/SummaryItem.test-ids.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAC,cAAc,EAAE;IACjE,SAAS;IACT,WAAW;IACX,QAAQ;IACR,SAAS;CACD,CAAC,CAAC","sourcesContent":["import { createTestIds } from '../../utils';\n\nexport const getSummaryItemTestIds = createTestIds('summary-item', [\n 'primary',\n 'secondary',\n 'visual',\n 'actions'\n] as const);\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FC, ChangeEventHandler } from 'react';
|
|
2
|
-
import { ForwardProps, NoChildrenProp } from '../../types';
|
|
2
|
+
import { BaseProps, ForwardProps, NoChildrenProp, TestIdProp } from '../../types';
|
|
3
3
|
import { FormControlProps } from '../FormControl';
|
|
4
|
-
export interface TextAreaProps extends FormControlProps, NoChildrenProp {
|
|
4
|
+
export interface TextAreaProps extends FormControlProps, BaseProps, NoChildrenProp, TestIdProp {
|
|
5
5
|
/** Minimum length of characters that can be input. */
|
|
6
6
|
minLength?: number;
|
|
7
7
|
/** Maximum length of characters that can be input. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextArea.d.ts","sourceRoot":"","sources":["../../../src/components/TextArea/TextArea.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,EAAE,EAOF,kBAAkB,EAEnB,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"TextArea.d.ts","sourceRoot":"","sources":["../../../src/components/TextArea/TextArea.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,EAAE,EAOF,kBAAkB,EAEnB,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAElF,OAAO,EAAE,gBAAgB,EAAqB,MAAM,gBAAgB,CAAC;AAQrE,MAAM,WAAW,aAAc,SAAQ,gBAAgB,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU;IAC5F,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;CACpD;AAED,QAAA,MAAM,QAAQ,EAAE,EAAE,CAAC,aAAa,GAAG,YAAY,CAqH9C,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -3,13 +3,15 @@ import { forwardRef, useCallback, useState, useEffect } from 'react';
|
|
|
3
3
|
import FormField from '../FormField';
|
|
4
4
|
import { StyledFormControl } from '../FormControl';
|
|
5
5
|
import { hasProp } from '../../utils';
|
|
6
|
-
import { useAutoResize, useConsolidatedRef, useI18n, useUID } from '../../hooks';
|
|
6
|
+
import { useAutoResize, useConsolidatedRef, useI18n, useTestIds, useUID } from '../../hooks';
|
|
7
7
|
import Text from '../Text';
|
|
8
8
|
import StyledTextArea from './TextArea.styles';
|
|
9
|
+
import { getTextAreaTestIds } from './TextArea.test-ids';
|
|
9
10
|
const TextArea = forwardRef((props, ref) => {
|
|
10
11
|
const uid = useUID();
|
|
11
|
-
const { additionalInfo, id = uid, value, defaultValue, required = false, disabled = false, readOnly = false, label, labelHidden, info, status, resizable = false, autoResize = false, maxLength, displayCharCount = false, hardStop = true, onChange: onChangeProp, onResolveSuggestion, ...restProps } = props;
|
|
12
|
+
const { testId, additionalInfo, id = uid, value, defaultValue, required = false, disabled = false, readOnly = false, label, labelHidden, info, status, resizable = false, autoResize = false, maxLength, displayCharCount = false, hardStop = true, onChange: onChangeProp, onResolveSuggestion, ...restProps } = props;
|
|
12
13
|
const t = useI18n();
|
|
14
|
+
const testIds = useTestIds(testId, getTextAreaTestIds);
|
|
13
15
|
const [textAreaRef, resizeTextArea] = useAutoResize(undefined, 100);
|
|
14
16
|
const consolidatedRef = useConsolidatedRef(textAreaRef, ref);
|
|
15
17
|
const [charCount, setCharCount] = useState(0);
|
|
@@ -37,6 +39,7 @@ const TextArea = forwardRef((props, ref) => {
|
|
|
37
39
|
}
|
|
38
40
|
}, [onChangeProp, resizeTextArea, hardStop, maxLength]);
|
|
39
41
|
const Comp = (_jsx(StyledFormControl, { ...{
|
|
42
|
+
'data-testid': testIds.control,
|
|
40
43
|
ref: autoResize ? consolidatedRef : ref,
|
|
41
44
|
id,
|
|
42
45
|
required,
|
|
@@ -52,6 +55,7 @@ const TextArea = forwardRef((props, ref) => {
|
|
|
52
55
|
as: StyledTextArea
|
|
53
56
|
} }));
|
|
54
57
|
return label || displayCharCount ? (_jsx(FormField, { ...{
|
|
58
|
+
testId: testIds.root,
|
|
55
59
|
additionalInfo,
|
|
56
60
|
label,
|
|
57
61
|
labelHidden,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextArea.js","sourceRoot":"","sources":["../../../src/components/TextArea/TextArea.tsx"],"names":[],"mappings":";AAAA,OAAO,EAGL,UAAU,EAGV,WAAW,EACX,QAAQ,EAER,SAAS,EACV,MAAM,OAAO,CAAC;AAGf,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAoB,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"TextArea.js","sourceRoot":"","sources":["../../../src/components/TextArea/TextArea.tsx"],"names":[],"mappings":";AAAA,OAAO,EAGL,UAAU,EAGV,WAAW,EACX,QAAQ,EAER,SAAS,EACV,MAAM,OAAO,CAAC;AAGf,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAoB,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC7F,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AA8BzD,MAAM,QAAQ,GAAqC,UAAU,CAC3D,CAAC,KAAqC,EAAE,GAA6B,EAAE,EAAE;IACvE,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC;IACrB,MAAM,EACJ,MAAM,EACN,cAAc,EACd,EAAE,GAAG,GAAG,EACR,KAAK,EACL,YAAY,EACZ,QAAQ,GAAG,KAAK,EAChB,QAAQ,GAAG,KAAK,EAChB,QAAQ,GAAG,KAAK,EAChB,KAAK,EACL,WAAW,EACX,IAAI,EACJ,MAAM,EACN,SA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AAI,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,YAE1E,SAAS,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,SAAS,IAAI,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,GACnE,CACR,CAAC,CAAC,CAAC,SAAS;YACf,QAAQ;YACR,QAAQ;YACR,mBAAmB;SACpB,YAEA,IAAI,GACK,CACb,CAAC,CAAC,CAAC,CACF,IAAI,CACL,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["import {\n FC,\n Ref,\n forwardRef,\n PropsWithoutRef,\n ChangeEvent,\n useCallback,\n useState,\n ChangeEventHandler,\n useEffect\n} from 'react';\n\nimport { BaseProps, ForwardProps, NoChildrenProp, TestIdProp } from '../../types';\nimport FormField from '../FormField';\nimport { FormControlProps, StyledFormControl } from '../FormControl';\nimport { hasProp } from '../../utils';\nimport { useAutoResize, useConsolidatedRef, useI18n, useTestIds, useUID } from '../../hooks';\nimport Text from '../Text';\n\nimport StyledTextArea from './TextArea.styles';\nimport { getTextAreaTestIds } from './TextArea.test-ids';\n\nexport interface TextAreaProps extends FormControlProps, BaseProps, NoChildrenProp, TestIdProp {\n /** Minimum length of characters that can be input. */\n minLength?: number;\n /** Maximum length of characters that can be input. */\n maxLength?: number;\n /**\n * Allows the user to resize the Text Area.\n * @default false\n */\n resizable?: boolean;\n /**\n * Enables the Text Area to resize itself automatically.\n * @default false\n */\n autoResize?: boolean;\n /**\n * Display a live character count in relation to the maxLength.\n * @default false\n */\n displayCharCount?: boolean;\n /**\n * Allow or disallow a value beyond the maxLength.\n * @default true\n */\n hardStop?: boolean;\n onChange?: ChangeEventHandler<HTMLTextAreaElement>;\n}\n\nconst TextArea: FC<TextAreaProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<TextAreaProps>, ref: Ref<HTMLTextAreaElement>) => {\n const uid = useUID();\n const {\n testId,\n additionalInfo,\n id = uid,\n value,\n defaultValue,\n required = false,\n disabled = false,\n readOnly = false,\n label,\n labelHidden,\n info,\n status,\n resizable = false,\n autoResize = false,\n maxLength,\n displayCharCount = false,\n hardStop = true,\n onChange: onChangeProp,\n onResolveSuggestion,\n ...restProps\n } = props;\n const t = useI18n();\n\n const testIds = useTestIds(testId, getTextAreaTestIds);\n\n const [textAreaRef, resizeTextArea] = useAutoResize<HTMLTextAreaElement>(undefined, 100);\n const consolidatedRef = useConsolidatedRef(textAreaRef, ref);\n const [charCount, setCharCount] = useState(0);\n\n const controlProp: {\n value?: string;\n defaultValue?: string;\n } = {};\n\n useEffect(() => {\n if ('value' in props) {\n setCharCount(props.value ? props.value.length : 0);\n } else if ('defaultValue' in props) {\n setCharCount(props.defaultValue ? props.defaultValue.length : 0);\n }\n }, [props]);\n\n // Conditionally render component as controlled/uncontrolled\n if (hasProp(props, 'value')) {\n controlProp.value = value ?? '';\n } else if (hasProp(props, 'defaultValue')) {\n controlProp.defaultValue = defaultValue ?? '';\n }\n\n const onChange = useCallback(\n (e: ChangeEvent<HTMLTextAreaElement>) => {\n if (!hardStop || maxLength === undefined || e.target.value.length <= maxLength) {\n onChangeProp?.(e);\n setCharCount(e.target.value.length);\n resizeTextArea();\n }\n },\n [onChangeProp, resizeTextArea, hardStop, maxLength]\n );\n\n const Comp = (\n <StyledFormControl\n {...{\n 'data-testid': testIds.control,\n ref: autoResize ? consolidatedRef : ref,\n id,\n required,\n disabled,\n status,\n readOnly,\n resizable,\n maxLength: hardStop ? maxLength : undefined,\n hasSuggestion: status === 'pending' && !!onResolveSuggestion,\n ...controlProp,\n ...restProps,\n onChange,\n as: StyledTextArea\n }}\n />\n );\n\n return label || displayCharCount ? (\n <FormField\n {...{\n testId: testIds.root,\n additionalInfo,\n label,\n labelHidden,\n id,\n readOnly,\n info,\n status,\n charLimitDisplay:\n displayCharCount && typeof maxLength === 'number' ? (\n <Text\n readOnly={readOnly}\n variant='secondary'\n aria-live={maxLength >= 0 && maxLength - charCount <= 20 ? 'polite' : 'off'}\n >\n {maxLength >= 0 ? t('x_of_y', [charCount || '0', maxLength]) : charCount}\n </Text>\n ) : undefined,\n required,\n disabled,\n onResolveSuggestion\n }}\n >\n {Comp}\n </FormField>\n ) : (\n Comp\n );\n }\n);\n\nexport default TextArea;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextArea.test-ids.d.ts","sourceRoot":"","sources":["../../../src/components/TextArea/TextArea.test-ids.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,gGAAmD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextArea.test-ids.js","sourceRoot":"","sources":["../../../src/components/TextArea/TextArea.test-ids.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC,SAAS,CAAU,CAAC,CAAC","sourcesContent":["import { createTestIds } from '../../utils';\n\nexport const getTextAreaTestIds = createTestIds('text-area', ['control'] as const);\n"]}
|
package/lib/hooks/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export { default as useOuterEvent } from './useOuterEvent';
|
|
|
24
24
|
export { default as usePrevious } from './usePrevious';
|
|
25
25
|
export { default as useScrollStick } from './useScrollStick';
|
|
26
26
|
export { default as useScrollToggle } from './useScrollToggle';
|
|
27
|
+
export { default as useTestIds } from './useTestIds';
|
|
27
28
|
export { default as useTheme } from './useTheme';
|
|
28
29
|
export { default as useToaster } from './useToaster';
|
|
29
30
|
export { default as useTransitionState } from './useTransitionState';
|
package/lib/hooks/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,IAAI,mBAAmB,EAC9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EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,OAAO,IAAI,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AACrF,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC"}
|
package/lib/hooks/index.js
CHANGED
|
@@ -24,6 +24,7 @@ export { default as useOuterEvent } from './useOuterEvent';
|
|
|
24
24
|
export { default as usePrevious } from './usePrevious';
|
|
25
25
|
export { default as useScrollStick } from './useScrollStick';
|
|
26
26
|
export { default as useScrollToggle } from './useScrollToggle';
|
|
27
|
+
export { default as useTestIds } from './useTestIds';
|
|
27
28
|
export { default as useTheme } from './useTheme';
|
|
28
29
|
export { default as useToaster } from './useToaster';
|
|
29
30
|
export { default as useTransitionState } from './useTransitionState';
|