@equinor/eds-core-react 0.37.0 → 0.38.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/dist/eds-core-react.cjs +145 -74
- package/dist/esm/components/Autocomplete/Autocomplete.js +75 -41
- package/dist/esm/components/Autocomplete/Autocomplete.tokens.js +1 -1
- package/dist/esm/components/Button/tokens/contained.js +1 -1
- package/dist/esm/components/Button/tokens/contained_icon.js +1 -1
- package/dist/esm/components/Button/tokens/ghost.js +1 -1
- package/dist/esm/components/Button/tokens/icon.js +1 -1
- package/dist/esm/components/Button/tokens/outlined.js +1 -1
- package/dist/esm/components/Datepicker/DatePicker.js +13 -1
- package/dist/esm/components/Datepicker/DateRangePicker.js +15 -1
- package/dist/esm/components/Datepicker/fields/DateSegment.js +21 -3
- package/dist/esm/components/Datepicker/utils/context.js +6 -3
- package/dist/esm/components/Input/Input.tokens.js +1 -1
- package/dist/esm/components/InputWrapper/InputWrapper.tokens.js +1 -1
- package/dist/esm/components/Table/DataCell/DataCell.tokens.js +1 -1
- package/dist/esm/node_modules/.pnpm/{ramda@0.29.1 → ramda@0.30.0}/node_modules/ramda/es/internal/_curry1.js +0 -1
- package/dist/esm/node_modules/.pnpm/{ramda@0.29.1 → ramda@0.30.0}/node_modules/ramda/es/internal/_curry2.js +0 -1
- package/dist/esm/node_modules/.pnpm/{ramda@0.29.1 → ramda@0.30.0}/node_modules/ramda/es/internal/_curry3.js +0 -1
- package/dist/esm/node_modules/.pnpm/ramda@0.30.0/node_modules/ramda/es/internal/_isPlaceholder.js +7 -0
- package/dist/esm/node_modules/.pnpm/ramda@0.30.0/node_modules/ramda/es/internal/_placeholder.js +5 -0
- package/dist/esm/node_modules/.pnpm/{ramda@0.29.1 → ramda@0.30.0}/node_modules/ramda/es/mergeDeepRight.js +1 -3
- package/dist/esm/node_modules/.pnpm/{ramda@0.29.1 → ramda@0.30.0}/node_modules/ramda/es/mergeDeepWithKey.js +1 -3
- package/dist/esm/node_modules/.pnpm/{ramda@0.29.1 → ramda@0.30.0}/node_modules/ramda/es/mergeWith.js +1 -3
- package/dist/esm/node_modules/.pnpm/{ramda@0.29.1 → ramda@0.30.0}/node_modules/ramda/es/mergeWithKey.js +1 -3
- package/dist/esm/node_modules/.pnpm/{ramda@0.29.1 → ramda@0.30.0}/node_modules/ramda/es/pickBy.js +1 -3
- package/dist/types/components/Autocomplete/Autocomplete.d.ts +27 -16
- package/dist/types/components/Chip/Icon.d.ts +2 -6
- package/dist/types/components/Datepicker/DatePicker.d.ts +1 -0
- package/dist/types/components/Datepicker/DateRangePicker.d.ts +1 -0
- package/dist/types/components/Datepicker/calendars/CalendarWrapper.d.ts +1 -272
- package/dist/types/components/Datepicker/props.d.ts +6 -0
- package/dist/types/components/Datepicker/utils/context.d.ts +6 -1
- package/dist/types/components/Switch/Switch.styles.d.ts +4 -844
- package/package.json +13 -13
- package/dist/esm/node_modules/.pnpm/ramda@0.29.1/node_modules/ramda/es/internal/_isPlaceholder.js +0 -5
- package/dist/types/components/Datepicker/utils/timezone.d.ts +0 -1
- /package/dist/esm/node_modules/.pnpm/{ramda@0.29.1 → ramda@0.30.0}/node_modules/ramda/es/internal/_has.js +0 -0
- /package/dist/esm/node_modules/.pnpm/{ramda@0.29.1 → ramda@0.30.0}/node_modules/ramda/es/internal/_isObject.js +0 -0
|
@@ -8,12 +8,12 @@ import { Icon } from '../Icon/index.js';
|
|
|
8
8
|
import { Progress } from '../Progress/index.js';
|
|
9
9
|
import { close, arrow_drop_up, arrow_drop_down } from '@equinor/eds-icons';
|
|
10
10
|
import { multiSelect, selectTokens } from './Autocomplete.tokens.js';
|
|
11
|
-
import { bordersTemplate, useToken, useIsomorphicLayoutEffect
|
|
11
|
+
import { bordersTemplate, useToken, useIsomorphicLayoutEffect } from '@equinor/eds-utils';
|
|
12
12
|
import { AutocompleteOption } from './Option.js';
|
|
13
|
-
import { useFloating, offset, flip,
|
|
13
|
+
import { useFloating, offset, flip, size, useInteractions, autoUpdate } from '@floating-ui/react';
|
|
14
14
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
15
|
-
import pickBy from '../../node_modules/.pnpm/ramda@0.
|
|
16
|
-
import mergeWith from '../../node_modules/.pnpm/ramda@0.
|
|
15
|
+
import pickBy from '../../node_modules/.pnpm/ramda@0.30.0/node_modules/ramda/es/pickBy.js';
|
|
16
|
+
import mergeWith from '../../node_modules/.pnpm/ramda@0.30.0/node_modules/ramda/es/mergeWith.js';
|
|
17
17
|
import { HelperText as TextfieldHelperText } from '../InputWrapper/HelperText/HelperText.js';
|
|
18
18
|
import { useEds } from '../EdsProvider/eds.context.js';
|
|
19
19
|
import { Label } from '../Label/Label.js';
|
|
@@ -30,19 +30,25 @@ const StyledList = styled(List).withConfig({
|
|
|
30
30
|
})(({
|
|
31
31
|
theme
|
|
32
32
|
}) => css(["background-color:", ";box-shadow:", ";", " overflow-y:auto;overflow-x:hidden;padding:0;display:grid;@supports (-moz-appearance:none){scrollbar-width:thin;}"], theme.background, theme.boxShadow, bordersTemplate(theme.border)));
|
|
33
|
+
const StyledPopover = styled('div').withConfig({
|
|
34
|
+
shouldForwardProp: () => true //workaround to avoid warning until popover gets added to react types
|
|
35
|
+
}).withConfig({
|
|
36
|
+
displayName: "Autocomplete__StyledPopover",
|
|
37
|
+
componentId: "sc-yvif0e-2"
|
|
38
|
+
})(["inset:unset;border:0;padding:0;margin:0;overflow:visible;"]);
|
|
33
39
|
const HelperText = styled(TextfieldHelperText).withConfig({
|
|
34
40
|
displayName: "Autocomplete__HelperText",
|
|
35
|
-
componentId: "sc-yvif0e-
|
|
41
|
+
componentId: "sc-yvif0e-3"
|
|
36
42
|
})(["margin-top:8px;margin-left:8px;"]);
|
|
37
43
|
const AutocompleteNoOptions = styled(AutocompleteOption).withConfig({
|
|
38
44
|
displayName: "Autocomplete__AutocompleteNoOptions",
|
|
39
|
-
componentId: "sc-yvif0e-
|
|
45
|
+
componentId: "sc-yvif0e-4"
|
|
40
46
|
})(({
|
|
41
47
|
theme
|
|
42
48
|
}) => css(["color:", ";"], theme.entities.noOptions.typography.color));
|
|
43
49
|
const StyledButton = styled(Button).withConfig({
|
|
44
50
|
displayName: "Autocomplete__StyledButton",
|
|
45
|
-
componentId: "sc-yvif0e-
|
|
51
|
+
componentId: "sc-yvif0e-5"
|
|
46
52
|
})(({
|
|
47
53
|
theme: {
|
|
48
54
|
entities: {
|
|
@@ -126,6 +132,20 @@ const findPrevIndex = ({
|
|
|
126
132
|
}
|
|
127
133
|
return prevIndex;
|
|
128
134
|
};
|
|
135
|
+
|
|
136
|
+
/*When a user clicks the StyledList scrollbar, the input looses focus which breaks downshift
|
|
137
|
+
* keyboard navigation in the list. This code returns focus to the input on mouseUp
|
|
138
|
+
*/
|
|
139
|
+
const handleListFocus = e => {
|
|
140
|
+
e.preventDefault();
|
|
141
|
+
e.stopPropagation();
|
|
142
|
+
window?.addEventListener('mouseup', () => {
|
|
143
|
+
e.relatedTarget?.focus();
|
|
144
|
+
}, {
|
|
145
|
+
once: true
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
const defaultOptionDisabled = () => false;
|
|
129
149
|
function AutocompleteInner(props, ref) {
|
|
130
150
|
const {
|
|
131
151
|
options = [],
|
|
@@ -144,7 +164,7 @@ function AutocompleteInner(props, ref) {
|
|
|
144
164
|
allowSelectAll,
|
|
145
165
|
initialSelectedOptions = [],
|
|
146
166
|
disablePortal,
|
|
147
|
-
optionDisabled =
|
|
167
|
+
optionDisabled = defaultOptionDisabled,
|
|
148
168
|
optionsFilter,
|
|
149
169
|
autoWidth,
|
|
150
170
|
placeholder,
|
|
@@ -159,6 +179,9 @@ function AutocompleteInner(props, ref) {
|
|
|
159
179
|
variant,
|
|
160
180
|
...other
|
|
161
181
|
} = props;
|
|
182
|
+
if (disablePortal) {
|
|
183
|
+
console.warn('Autocomplete "disablePortal" prop has been deprecated. Autocomplete now uses the native popover api');
|
|
184
|
+
}
|
|
162
185
|
const isControlled = Boolean(selectedOptions);
|
|
163
186
|
const [inputOptions, setInputOptions] = useState(options);
|
|
164
187
|
const [_availableItems, setAvailableItems] = useState(inputOptions);
|
|
@@ -173,13 +196,8 @@ function AutocompleteInner(props, ref) {
|
|
|
173
196
|
if (showSelectAll) return [AllSymbol, ..._availableItems];
|
|
174
197
|
return _availableItems;
|
|
175
198
|
}, [_availableItems, showSelectAll]);
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
setSelectedItems([]);
|
|
179
|
-
} else {
|
|
180
|
-
setSelectedItems(inputOptions);
|
|
181
|
-
}
|
|
182
|
-
};
|
|
199
|
+
|
|
200
|
+
//issue 2304, update dataset when options are added dynamically
|
|
183
201
|
useEffect(() => {
|
|
184
202
|
const availableHash = JSON.stringify(inputOptions);
|
|
185
203
|
const optionsHash = JSON.stringify(options);
|
|
@@ -190,7 +208,6 @@ function AutocompleteInner(props, ref) {
|
|
|
190
208
|
useEffect(() => {
|
|
191
209
|
setAvailableItems(inputOptions);
|
|
192
210
|
}, [inputOptions]);
|
|
193
|
-
const disabledItems = useMemo(() => options.filter(optionDisabled), [options, optionDisabled]);
|
|
194
211
|
const {
|
|
195
212
|
density
|
|
196
213
|
} = useEds();
|
|
@@ -226,15 +243,27 @@ function AutocompleteInner(props, ref) {
|
|
|
226
243
|
addSelectedItem,
|
|
227
244
|
removeSelectedItem,
|
|
228
245
|
selectedItems,
|
|
229
|
-
reset: resetSelection,
|
|
230
246
|
setSelectedItems
|
|
231
247
|
} = useMultipleSelection(multipleSelectionProps);
|
|
248
|
+
const enabledItems = useMemo(() => {
|
|
249
|
+
const disabledItemsSet = new Set(inputOptions.filter(optionDisabled));
|
|
250
|
+
return inputOptions.filter(x => !disabledItemsSet.has(x));
|
|
251
|
+
}, [inputOptions, optionDisabled]);
|
|
252
|
+
const selectedDisabledItemsSet = useMemo(() => new Set(selectedItems.filter(optionDisabled)), [selectedItems, optionDisabled]);
|
|
253
|
+
const selectedEnabledItems = useMemo(() => selectedItems.filter(x => !selectedDisabledItemsSet.has(x)), [selectedItems, selectedDisabledItemsSet]);
|
|
232
254
|
const allSelectedState = useMemo(() => {
|
|
233
|
-
if (!
|
|
234
|
-
if (
|
|
235
|
-
if (
|
|
255
|
+
if (!enabledItems || !selectedEnabledItems) return 'NONE';
|
|
256
|
+
if (enabledItems.length === selectedEnabledItems.length) return 'ALL';
|
|
257
|
+
if (enabledItems.length != selectedEnabledItems.length && selectedEnabledItems.length > 0) return 'SOME';
|
|
236
258
|
return 'NONE';
|
|
237
|
-
}, [
|
|
259
|
+
}, [enabledItems, selectedEnabledItems]);
|
|
260
|
+
const toggleAllSelected = () => {
|
|
261
|
+
if (selectedEnabledItems.length === enabledItems.length) {
|
|
262
|
+
setSelectedItems([...selectedDisabledItemsSet]);
|
|
263
|
+
} else {
|
|
264
|
+
setSelectedItems([...enabledItems, ...selectedDisabledItemsSet]);
|
|
265
|
+
}
|
|
266
|
+
};
|
|
238
267
|
const getLabel = useCallback(item => {
|
|
239
268
|
//note: non strict check for null or undefined to allow 0
|
|
240
269
|
if (item == null) {
|
|
@@ -293,7 +322,14 @@ function AutocompleteInner(props, ref) {
|
|
|
293
322
|
highlightedIndex,
|
|
294
323
|
type
|
|
295
324
|
}) {
|
|
296
|
-
if (type
|
|
325
|
+
if (type == useCombobox.stateChangeTypes.InputClick || type == useCombobox.stateChangeTypes.InputKeyDownArrowDown && !isOpen || type == useCombobox.stateChangeTypes.InputKeyDownArrowUp && !isOpen) {
|
|
326
|
+
//needs delay for dropdown to render before calling scroll
|
|
327
|
+
setTimeout(() => {
|
|
328
|
+
rowVirtualizer.scrollToIndex(highlightedIndex, {
|
|
329
|
+
align: allowSelectAll ? 'center' : 'auto'
|
|
330
|
+
});
|
|
331
|
+
}, 1);
|
|
332
|
+
} else if (type !== useCombobox.stateChangeTypes.ItemMouseMove && type !== useCombobox.stateChangeTypes.MenuMouseLeave && highlightedIndex >= 0) {
|
|
297
333
|
rowVirtualizer.scrollToIndex(highlightedIndex, {
|
|
298
334
|
align: allowSelectAll ? 'center' : 'auto'
|
|
299
335
|
});
|
|
@@ -404,7 +440,7 @@ function AutocompleteInner(props, ref) {
|
|
|
404
440
|
}
|
|
405
441
|
}
|
|
406
442
|
if (multiple) {
|
|
407
|
-
placeholderText = typeof placeholderText !== 'undefined' ? placeholderText : `${selectedItems.length}/${
|
|
443
|
+
placeholderText = typeof placeholderText !== 'undefined' ? placeholderText : `${selectedItems.length}/${inputOptions.length} selected`;
|
|
408
444
|
comboBoxProps = {
|
|
409
445
|
...comboBoxProps,
|
|
410
446
|
selectedItem: null,
|
|
@@ -496,11 +532,6 @@ function AutocompleteInner(props, ref) {
|
|
|
496
532
|
inputValue,
|
|
497
533
|
reset: resetCombobox
|
|
498
534
|
} = useCombobox(comboBoxProps);
|
|
499
|
-
useEffect(() => {
|
|
500
|
-
if (isControlled) {
|
|
501
|
-
setSelectedItems(selectedOptions);
|
|
502
|
-
}
|
|
503
|
-
}, [isControlled, selectedOptions, setSelectedItems]);
|
|
504
535
|
const {
|
|
505
536
|
x,
|
|
506
537
|
y,
|
|
@@ -509,8 +540,8 @@ function AutocompleteInner(props, ref) {
|
|
|
509
540
|
strategy
|
|
510
541
|
} = useFloating({
|
|
511
542
|
placement: 'bottom-start',
|
|
512
|
-
middleware: [offset(4), flip(
|
|
513
|
-
|
|
543
|
+
middleware: [offset(4), flip({
|
|
544
|
+
boundary: document?.body
|
|
514
545
|
}), size({
|
|
515
546
|
apply({
|
|
516
547
|
rects,
|
|
@@ -532,25 +563,31 @@ function AutocompleteInner(props, ref) {
|
|
|
532
563
|
return autoUpdate(refs.reference.current, refs.floating.current, update);
|
|
533
564
|
}
|
|
534
565
|
}, [refs.reference, refs.floating, update, isOpen]);
|
|
566
|
+
useIsomorphicLayoutEffect(() => {
|
|
567
|
+
if (isOpen) {
|
|
568
|
+
refs.floating.current.showPopover();
|
|
569
|
+
} else {
|
|
570
|
+
refs.floating.current.hidePopover();
|
|
571
|
+
}
|
|
572
|
+
}, [isOpen, refs.floating]);
|
|
535
573
|
const clear = () => {
|
|
536
574
|
resetCombobox();
|
|
537
|
-
|
|
575
|
+
//dont clear items if they are selected and disabled
|
|
576
|
+
setSelectedItems([...selectedDisabledItemsSet]);
|
|
538
577
|
setTypedInputValue('');
|
|
539
578
|
};
|
|
540
579
|
const showClearButton = (selectedItems.length > 0 || inputValue) && !readOnly && !hideClearButton;
|
|
541
580
|
const showNoOptions = isOpen && !availableItems.length && noOptionsText.length > 0;
|
|
542
581
|
const selectedItemsLabels = useMemo(() => selectedItems.map(getLabel), [selectedItems, getLabel]);
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
const inDialog = useIsInDialog(refs.domReference.current);
|
|
546
|
-
const optionsList = /*#__PURE__*/jsx("div", {
|
|
582
|
+
const optionsList = /*#__PURE__*/jsx(StyledPopover, {
|
|
583
|
+
popover: "manual",
|
|
547
584
|
...getFloatingProps({
|
|
548
585
|
ref: refs.setFloating,
|
|
586
|
+
onFocus: handleListFocus,
|
|
549
587
|
style: {
|
|
550
588
|
position: strategy,
|
|
551
589
|
top: y || 0,
|
|
552
|
-
left: x || 0
|
|
553
|
-
zIndex: 1500
|
|
590
|
+
left: x || 0
|
|
554
591
|
}
|
|
555
592
|
}),
|
|
556
593
|
children: /*#__PURE__*/jsxs(StyledList, {
|
|
@@ -694,10 +731,7 @@ function AutocompleteInner(props, ref) {
|
|
|
694
731
|
color: variant ? tokens.variants[variant].typography.color : undefined,
|
|
695
732
|
text: helperText,
|
|
696
733
|
icon: helperIcon
|
|
697
|
-
}),
|
|
698
|
-
id: "eds-autocomplete-container",
|
|
699
|
-
children: optionsList
|
|
700
|
-
})]
|
|
734
|
+
}), optionsList]
|
|
701
735
|
})
|
|
702
736
|
});
|
|
703
737
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { tokens } from '@equinor/eds-tokens';
|
|
2
|
-
import mergeDeepRight from '../../node_modules/.pnpm/ramda@0.
|
|
2
|
+
import mergeDeepRight from '../../node_modules/.pnpm/ramda@0.30.0/node_modules/ramda/es/mergeDeepRight.js';
|
|
3
3
|
|
|
4
4
|
const {
|
|
5
5
|
typography,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { tokens } from '@equinor/eds-tokens';
|
|
2
2
|
import { button } from './button.js';
|
|
3
|
-
import mergeDeepRight from '../../../node_modules/.pnpm/ramda@0.
|
|
3
|
+
import mergeDeepRight from '../../../node_modules/.pnpm/ramda@0.30.0/node_modules/ramda/es/mergeDeepRight.js';
|
|
4
4
|
|
|
5
5
|
const {
|
|
6
6
|
colors: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { tokens } from '@equinor/eds-tokens';
|
|
2
2
|
import { primary as primary$1, secondary as secondary$1, danger as danger$1 } from './contained.js';
|
|
3
|
-
import mergeDeepRight from '../../../node_modules/.pnpm/ramda@0.
|
|
3
|
+
import mergeDeepRight from '../../../node_modules/.pnpm/ramda@0.30.0/node_modules/ramda/es/mergeDeepRight.js';
|
|
4
4
|
|
|
5
5
|
const {
|
|
6
6
|
clickbounds: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { tokens } from '@equinor/eds-tokens';
|
|
2
2
|
import { button } from './button.js';
|
|
3
|
-
import mergeDeepRight from '../../../node_modules/.pnpm/ramda@0.
|
|
3
|
+
import mergeDeepRight from '../../../node_modules/.pnpm/ramda@0.30.0/node_modules/ramda/es/mergeDeepRight.js';
|
|
4
4
|
|
|
5
5
|
const {
|
|
6
6
|
colors: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { tokens } from '@equinor/eds-tokens';
|
|
2
2
|
import { button } from './button.js';
|
|
3
|
-
import mergeDeepRight from '../../../node_modules/.pnpm/ramda@0.
|
|
3
|
+
import mergeDeepRight from '../../../node_modules/.pnpm/ramda@0.30.0/node_modules/ramda/es/mergeDeepRight.js';
|
|
4
4
|
|
|
5
5
|
const {
|
|
6
6
|
colors: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { tokens } from '@equinor/eds-tokens';
|
|
2
2
|
import { button } from './button.js';
|
|
3
|
-
import mergeDeepRight from '../../../node_modules/.pnpm/ramda@0.
|
|
3
|
+
import mergeDeepRight from '../../../node_modules/.pnpm/ramda@0.30.0/node_modules/ramda/es/mergeDeepRight.js';
|
|
4
4
|
|
|
5
5
|
const {
|
|
6
6
|
colors: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { forwardRef, useState, useRef, useCallback } from 'react';
|
|
1
|
+
import { forwardRef, useState, useRef, useCallback, useEffect } from 'react';
|
|
2
2
|
import { Calendar } from './calendars/Calendar.js';
|
|
3
3
|
import { DateField } from './fields/DateField.js';
|
|
4
4
|
import { warning_outlined, calendar } from '@equinor/eds-icons';
|
|
@@ -29,9 +29,15 @@ const DatePicker = /*#__PURE__*/forwardRef(({
|
|
|
29
29
|
granularity,
|
|
30
30
|
disabled: isDisabled,
|
|
31
31
|
readOnly: isReadOnly,
|
|
32
|
+
formatOptions,
|
|
32
33
|
...props
|
|
33
34
|
}, forwardedRef) => {
|
|
34
35
|
timezone = timezone ?? defaultTimezone;
|
|
36
|
+
formatOptions = formatOptions ?? {
|
|
37
|
+
year: 'numeric',
|
|
38
|
+
month: '2-digit',
|
|
39
|
+
day: '2-digit'
|
|
40
|
+
};
|
|
35
41
|
const [innerValue, setInnerValue] = useState(() => {
|
|
36
42
|
const initialValue = value ?? defaultValue;
|
|
37
43
|
if (initialValue) {
|
|
@@ -107,8 +113,14 @@ const DatePicker = /*#__PURE__*/forwardRef(({
|
|
|
107
113
|
data: warning_outlined
|
|
108
114
|
})
|
|
109
115
|
} : undefined;
|
|
116
|
+
|
|
117
|
+
// innerValue is used as a fallback, especially for uncontrolled inputs, so it needs to be reset when value / defaultValue is reset
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (!defaultValue && !value) setInnerValue(null);
|
|
120
|
+
}, [defaultValue, value]);
|
|
110
121
|
return /*#__PURE__*/jsx(DatePickerProvider, {
|
|
111
122
|
timezone: timezone,
|
|
123
|
+
formatOptions: formatOptions,
|
|
112
124
|
children: /*#__PURE__*/jsx(FieldWrapper, {
|
|
113
125
|
isOpen: isOpen,
|
|
114
126
|
readonly: fieldProps.isReadOnly,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { forwardRef, useState, useRef, useCallback } from 'react';
|
|
1
|
+
import { forwardRef, useState, useRef, useCallback, useEffect } from 'react';
|
|
2
2
|
import { RangeCalendar } from './calendars/RangeCalendar.js';
|
|
3
3
|
import { warning_outlined, calendar_date_range } from '@equinor/eds-icons';
|
|
4
4
|
import { useConvertedValidationFunctions } from './utils/useConvertedValidationFunctions.js';
|
|
@@ -25,11 +25,17 @@ const DateRangePicker = /*#__PURE__*/forwardRef(({
|
|
|
25
25
|
Header,
|
|
26
26
|
timezone,
|
|
27
27
|
defaultValue,
|
|
28
|
+
formatOptions,
|
|
28
29
|
disabled: isDisabled,
|
|
29
30
|
readOnly: isReadOnly,
|
|
30
31
|
...props
|
|
31
32
|
}, forwardedRef) => {
|
|
32
33
|
timezone = timezone ?? defaultTimezone;
|
|
34
|
+
formatOptions = formatOptions ?? {
|
|
35
|
+
year: 'numeric',
|
|
36
|
+
month: '2-digit',
|
|
37
|
+
day: '2-digit'
|
|
38
|
+
};
|
|
33
39
|
const [innerValue, setInnerValue] = useState(() => {
|
|
34
40
|
const initialValue = value ?? defaultValue;
|
|
35
41
|
if (initialValue) {
|
|
@@ -103,8 +109,16 @@ const DateRangePicker = /*#__PURE__*/forwardRef(({
|
|
|
103
109
|
day: '2-digit'
|
|
104
110
|
});
|
|
105
111
|
const valueString = formattedValue ? Object.values(formattedValue).join(' - ') : null;
|
|
112
|
+
|
|
113
|
+
// innerValue is used as a fallback, especially for uncontrolled inputs, so it needs to be reset when value / defaultValue is reset
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
const val = defaultValue ?? value;
|
|
116
|
+
if (!defaultValue && !value) setInnerValue(null);
|
|
117
|
+
if (!val?.from && !val?.to) setInnerValue(null);
|
|
118
|
+
}, [defaultValue, value]);
|
|
106
119
|
return /*#__PURE__*/jsx(DatePickerProvider, {
|
|
107
120
|
timezone: timezone,
|
|
121
|
+
formatOptions: formatOptions,
|
|
108
122
|
children: /*#__PURE__*/jsx(FieldWrapper, {
|
|
109
123
|
isOpen: isOpen,
|
|
110
124
|
color: state.isInvalid ? 'warning' : props.variant,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { useRef } from 'react';
|
|
2
|
-
import { useDateSegment } from 'react-aria';
|
|
1
|
+
import { useState, useRef } from 'react';
|
|
2
|
+
import { useDateFormatter, useDateSegment } from 'react-aria';
|
|
3
3
|
import styled from 'styled-components';
|
|
4
4
|
import { tokens } from '@equinor/eds-tokens';
|
|
5
|
+
import { useDatePickerContext } from '../utils/context.js';
|
|
5
6
|
import { jsx } from 'react/jsx-runtime';
|
|
6
7
|
|
|
7
8
|
const Segment = styled.div.withConfig({
|
|
@@ -18,12 +19,29 @@ function DateSegment({
|
|
|
18
19
|
segment,
|
|
19
20
|
state
|
|
20
21
|
}) {
|
|
22
|
+
const {
|
|
23
|
+
formatOptions,
|
|
24
|
+
timezone
|
|
25
|
+
} = useDatePickerContext();
|
|
26
|
+
const formatter = useDateFormatter(formatOptions);
|
|
27
|
+
const parts = state.value ? formatter.formatToParts(state.value.toDate(timezone)) : [];
|
|
28
|
+
const part = parts.find(p => p.type === segment.type);
|
|
29
|
+
const value = part?.value ?? segment.text;
|
|
30
|
+
const [focus, setFocus] = useState(false);
|
|
21
31
|
const ref = useRef(null);
|
|
22
32
|
const {
|
|
23
33
|
segmentProps
|
|
24
34
|
} = useDateSegment(segment, state, ref);
|
|
25
35
|
return /*#__PURE__*/jsx(Segment, {
|
|
26
36
|
...segmentProps,
|
|
37
|
+
onFocus: e => {
|
|
38
|
+
setFocus(true);
|
|
39
|
+
segmentProps.onFocus(e);
|
|
40
|
+
},
|
|
41
|
+
onBlur: e => {
|
|
42
|
+
setFocus(false);
|
|
43
|
+
segmentProps.onBlur(e);
|
|
44
|
+
},
|
|
27
45
|
$invalid: state.isInvalid,
|
|
28
46
|
$disabled: state.isDisabled,
|
|
29
47
|
$placeholder: segment.isPlaceholder,
|
|
@@ -40,7 +58,7 @@ function DateSegment({
|
|
|
40
58
|
},
|
|
41
59
|
ref: ref,
|
|
42
60
|
className: `segment ${segment.isPlaceholder ? 'placeholder' : ''}`,
|
|
43
|
-
children: segment.isPlaceholder || segment.type === 'literal' ? segment.text : segment.text.padStart(segment.type === 'year' ? 4 : 2, '0')
|
|
61
|
+
children: focus ? segment.isPlaceholder || segment.type === 'literal' ? segment.text : segment.text.padStart(segment.type === 'year' ? 4 : 2, '0') : value
|
|
44
62
|
});
|
|
45
63
|
}
|
|
46
64
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext } from 'react';
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
3
|
|
|
4
4
|
const intl = new Intl.DateTimeFormat();
|
|
@@ -8,14 +8,17 @@ const DatePickerContext = /*#__PURE__*/createContext({
|
|
|
8
8
|
});
|
|
9
9
|
const DatePickerProvider = ({
|
|
10
10
|
timezone,
|
|
11
|
+
formatOptions,
|
|
11
12
|
children
|
|
12
13
|
}) => {
|
|
13
14
|
return /*#__PURE__*/jsx(DatePickerContext.Provider, {
|
|
14
15
|
value: {
|
|
15
|
-
timezone: timezone ?? defaultTimezone
|
|
16
|
+
timezone: timezone ?? defaultTimezone,
|
|
17
|
+
formatOptions
|
|
16
18
|
},
|
|
17
19
|
children: children
|
|
18
20
|
});
|
|
19
21
|
};
|
|
22
|
+
const useDatePickerContext = () => useContext(DatePickerContext);
|
|
20
23
|
|
|
21
|
-
export { DatePickerProvider, defaultTimezone };
|
|
24
|
+
export { DatePickerProvider, defaultTimezone, useDatePickerContext };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { tokens } from '@equinor/eds-tokens';
|
|
2
|
-
import mergeDeepRight from '../../node_modules/.pnpm/ramda@0.
|
|
2
|
+
import mergeDeepRight from '../../node_modules/.pnpm/ramda@0.30.0/node_modules/ramda/es/mergeDeepRight.js';
|
|
3
3
|
|
|
4
4
|
const {
|
|
5
5
|
colors: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { tokens } from '@equinor/eds-tokens';
|
|
2
|
-
import mergeDeepRight from '../../node_modules/.pnpm/ramda@0.
|
|
2
|
+
import mergeDeepRight from '../../node_modules/.pnpm/ramda@0.30.0/node_modules/ramda/es/mergeDeepRight.js';
|
|
3
3
|
|
|
4
4
|
const {
|
|
5
5
|
colors: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { tokens } from '@equinor/eds-tokens';
|
|
2
|
-
import mergeDeepRight from '../../../node_modules/.pnpm/ramda@0.
|
|
2
|
+
import mergeDeepRight from '../../../node_modules/.pnpm/ramda@0.30.0/node_modules/ramda/es/mergeDeepRight.js';
|
|
3
3
|
|
|
4
4
|
const {
|
|
5
5
|
typography: {
|
|
@@ -22,9 +22,7 @@ import mergeDeepWithKey from './mergeDeepWithKey.js';
|
|
|
22
22
|
* { age: 40, contact: { email: 'baa@example.com' }});
|
|
23
23
|
* //=> { name: 'fred', age: 40, contact: { email: 'baa@example.com' }}
|
|
24
24
|
*/
|
|
25
|
-
|
|
26
|
-
var mergeDeepRight = /*#__PURE__*/
|
|
27
|
-
_curry2(function mergeDeepRight(lObj, rObj) {
|
|
25
|
+
var mergeDeepRight = /*#__PURE__*/_curry2(function mergeDeepRight(lObj, rObj) {
|
|
28
26
|
return mergeDeepWithKey(function (k, lVal, rVal) {
|
|
29
27
|
return rVal;
|
|
30
28
|
}, lObj, rObj);
|
|
@@ -30,9 +30,7 @@ import mergeWithKey from './mergeWithKey.js';
|
|
|
30
30
|
* { b: true, c: { thing: 'bar', values: [15, 35] }});
|
|
31
31
|
* //=> { a: true, b: true, c: { thing: 'bar', values: [10, 20, 15, 35] }}
|
|
32
32
|
*/
|
|
33
|
-
|
|
34
|
-
var mergeDeepWithKey = /*#__PURE__*/
|
|
35
|
-
_curry3(function mergeDeepWithKey(fn, lObj, rObj) {
|
|
33
|
+
var mergeDeepWithKey = /*#__PURE__*/_curry3(function mergeDeepWithKey(fn, lObj, rObj) {
|
|
36
34
|
return mergeWithKey(function (k, lVal, rVal) {
|
|
37
35
|
if (_isObject(lVal) && _isObject(rVal)) {
|
|
38
36
|
return mergeDeepWithKey(fn, lVal, rVal);
|
package/dist/esm/node_modules/.pnpm/{ramda@0.29.1 → ramda@0.30.0}/node_modules/ramda/es/mergeWith.js
RENAMED
|
@@ -24,9 +24,7 @@ import mergeWithKey from './mergeWithKey.js';
|
|
|
24
24
|
* { b: true, values: [15, 35] });
|
|
25
25
|
* //=> { a: true, b: true, values: [10, 20, 15, 35] }
|
|
26
26
|
*/
|
|
27
|
-
|
|
28
|
-
var mergeWith = /*#__PURE__*/
|
|
29
|
-
_curry3(function mergeWith(fn, l, r) {
|
|
27
|
+
var mergeWith = /*#__PURE__*/_curry3(function mergeWith(fn, l, r) {
|
|
30
28
|
return mergeWithKey(function (_, _l, _r) {
|
|
31
29
|
return fn(_l, _r);
|
|
32
30
|
}, l, r);
|
|
@@ -26,9 +26,7 @@ import _has from './internal/_has.js';
|
|
|
26
26
|
* //=> { a: true, b: true, thing: 'bar', values: [10, 20, 15, 35] }
|
|
27
27
|
* @symb R.mergeWithKey(f, { x: 1, y: 2 }, { y: 5, z: 3 }) = { x: 1, y: f('y', 2, 5), z: 3 }
|
|
28
28
|
*/
|
|
29
|
-
|
|
30
|
-
var mergeWithKey = /*#__PURE__*/
|
|
31
|
-
_curry3(function mergeWithKey(fn, l, r) {
|
|
29
|
+
var mergeWithKey = /*#__PURE__*/_curry3(function mergeWithKey(fn, l, r) {
|
|
32
30
|
var result = {};
|
|
33
31
|
var k;
|
|
34
32
|
l = l || {};
|
package/dist/esm/node_modules/.pnpm/{ramda@0.29.1 → ramda@0.30.0}/node_modules/ramda/es/pickBy.js
RENAMED
|
@@ -20,9 +20,7 @@ import _curry2 from './internal/_curry2.js';
|
|
|
20
20
|
* const isUpperCase = (val, key) => key.toUpperCase() === key;
|
|
21
21
|
* R.pickBy(isUpperCase, {a: 1, b: 2, A: 3, B: 4}); //=> {A: 3, B: 4}
|
|
22
22
|
*/
|
|
23
|
-
|
|
24
|
-
var pickBy = /*#__PURE__*/
|
|
25
|
-
_curry2(function pickBy(test, obj) {
|
|
23
|
+
var pickBy = /*#__PURE__*/_curry2(function pickBy(test, obj) {
|
|
26
24
|
var result = {};
|
|
27
25
|
for (var prop in obj) {
|
|
28
26
|
if (test(obj[prop], prop, obj)) {
|