@equinor/eds-core-react 0.37.0 → 0.39.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.
Files changed (38) hide show
  1. package/dist/eds-core-react.cjs +161 -78
  2. package/dist/esm/components/Autocomplete/Autocomplete.js +91 -45
  3. package/dist/esm/components/Autocomplete/Autocomplete.tokens.js +1 -1
  4. package/dist/esm/components/Button/tokens/contained.js +1 -1
  5. package/dist/esm/components/Button/tokens/contained_icon.js +1 -1
  6. package/dist/esm/components/Button/tokens/ghost.js +1 -1
  7. package/dist/esm/components/Button/tokens/icon.js +1 -1
  8. package/dist/esm/components/Button/tokens/outlined.js +1 -1
  9. package/dist/esm/components/Datepicker/DatePicker.js +13 -1
  10. package/dist/esm/components/Datepicker/DateRangePicker.js +15 -1
  11. package/dist/esm/components/Datepicker/fields/DateSegment.js +21 -3
  12. package/dist/esm/components/Datepicker/utils/context.js +6 -3
  13. package/dist/esm/components/Input/Input.tokens.js +1 -1
  14. package/dist/esm/components/InputWrapper/InputWrapper.tokens.js +1 -1
  15. package/dist/esm/components/Table/DataCell/DataCell.tokens.js +1 -1
  16. package/dist/esm/node_modules/.pnpm/{ramda@0.29.1 → ramda@0.30.0}/node_modules/ramda/es/internal/_curry1.js +0 -1
  17. package/dist/esm/node_modules/.pnpm/{ramda@0.29.1 → ramda@0.30.0}/node_modules/ramda/es/internal/_curry2.js +0 -1
  18. package/dist/esm/node_modules/.pnpm/{ramda@0.29.1 → ramda@0.30.0}/node_modules/ramda/es/internal/_curry3.js +0 -1
  19. package/dist/esm/node_modules/.pnpm/ramda@0.30.0/node_modules/ramda/es/internal/_isPlaceholder.js +7 -0
  20. package/dist/esm/node_modules/.pnpm/ramda@0.30.0/node_modules/ramda/es/internal/_placeholder.js +5 -0
  21. package/dist/esm/node_modules/.pnpm/{ramda@0.29.1 → ramda@0.30.0}/node_modules/ramda/es/mergeDeepRight.js +1 -3
  22. package/dist/esm/node_modules/.pnpm/{ramda@0.29.1 → ramda@0.30.0}/node_modules/ramda/es/mergeDeepWithKey.js +1 -3
  23. package/dist/esm/node_modules/.pnpm/{ramda@0.29.1 → ramda@0.30.0}/node_modules/ramda/es/mergeWith.js +1 -3
  24. package/dist/esm/node_modules/.pnpm/{ramda@0.29.1 → ramda@0.30.0}/node_modules/ramda/es/mergeWithKey.js +1 -3
  25. package/dist/esm/node_modules/.pnpm/{ramda@0.29.1 → ramda@0.30.0}/node_modules/ramda/es/pickBy.js +1 -3
  26. package/dist/types/components/Autocomplete/Autocomplete.d.ts +35 -16
  27. package/dist/types/components/Chip/Icon.d.ts +2 -6
  28. package/dist/types/components/Datepicker/DatePicker.d.ts +1 -0
  29. package/dist/types/components/Datepicker/DateRangePicker.d.ts +1 -0
  30. package/dist/types/components/Datepicker/calendars/CalendarWrapper.d.ts +1 -272
  31. package/dist/types/components/Datepicker/props.d.ts +6 -0
  32. package/dist/types/components/Datepicker/utils/context.d.ts +6 -1
  33. package/dist/types/components/Switch/Switch.styles.d.ts +4 -844
  34. package/package.json +14 -14
  35. package/dist/esm/node_modules/.pnpm/ramda@0.29.1/node_modules/ramda/es/internal/_isPlaceholder.js +0 -5
  36. package/dist/types/components/Datepicker/utils/timezone.d.ts +0 -1
  37. /package/dist/esm/node_modules/.pnpm/{ramda@0.29.1 → ramda@0.30.0}/node_modules/ramda/es/internal/_has.js +0 -0
  38. /package/dist/esm/node_modules/.pnpm/{ramda@0.29.1 → ramda@0.30.0}/node_modules/ramda/es/internal/_isObject.js +0 -0
@@ -172,8 +172,12 @@ const button = {
172
172
  }
173
173
  };
174
174
 
175
+ var _placeholder = {
176
+ '@@functional/placeholder': true
177
+ };
178
+
175
179
  function _isPlaceholder(a) {
176
- return a != null && typeof a === 'object' && a['@@functional/placeholder'] === true;
180
+ return a === _placeholder;
177
181
  }
178
182
 
179
183
  /**
@@ -184,7 +188,6 @@ function _isPlaceholder(a) {
184
188
  * @param {Function} fn The function to curry.
185
189
  * @return {Function} The curried function.
186
190
  */
187
-
188
191
  function _curry1(fn) {
189
192
  return function f1(a) {
190
193
  if (arguments.length === 0 || _isPlaceholder(a)) {
@@ -203,7 +206,6 @@ function _curry1(fn) {
203
206
  * @param {Function} fn The function to curry.
204
207
  * @return {Function} The curried function.
205
208
  */
206
-
207
209
  function _curry2(fn) {
208
210
  return function f2(a, b) {
209
211
  switch (arguments.length) {
@@ -231,7 +233,6 @@ function _curry2(fn) {
231
233
  * @param {Function} fn The function to curry.
232
234
  * @return {Function} The curried function.
233
235
  */
234
-
235
236
  function _curry3(fn) {
236
237
  return function f3(a, b, c) {
237
238
  switch (arguments.length) {
@@ -300,9 +301,7 @@ function _isObject(x) {
300
301
  * //=> { a: true, b: true, thing: 'bar', values: [10, 20, 15, 35] }
301
302
  * @symb R.mergeWithKey(f, { x: 1, y: 2 }, { y: 5, z: 3 }) = { x: 1, y: f('y', 2, 5), z: 3 }
302
303
  */
303
-
304
- var mergeWithKey = /*#__PURE__*/
305
- _curry3(function mergeWithKey(fn, l, r) {
304
+ var mergeWithKey = /*#__PURE__*/_curry3(function mergeWithKey(fn, l, r) {
306
305
  var result = {};
307
306
  var k;
308
307
  l = l || {};
@@ -348,9 +347,7 @@ _curry3(function mergeWithKey(fn, l, r) {
348
347
  * { b: true, c: { thing: 'bar', values: [15, 35] }});
349
348
  * //=> { a: true, b: true, c: { thing: 'bar', values: [10, 20, 15, 35] }}
350
349
  */
351
-
352
- var mergeDeepWithKey = /*#__PURE__*/
353
- _curry3(function mergeDeepWithKey(fn, lObj, rObj) {
350
+ var mergeDeepWithKey = /*#__PURE__*/_curry3(function mergeDeepWithKey(fn, lObj, rObj) {
354
351
  return mergeWithKey(function (k, lVal, rVal) {
355
352
  if (_isObject(lVal) && _isObject(rVal)) {
356
353
  return mergeDeepWithKey(fn, lVal, rVal);
@@ -381,9 +378,7 @@ _curry3(function mergeDeepWithKey(fn, lObj, rObj) {
381
378
  * { age: 40, contact: { email: 'baa@example.com' }});
382
379
  * //=> { name: 'fred', age: 40, contact: { email: 'baa@example.com' }}
383
380
  */
384
-
385
- var mergeDeepRight = /*#__PURE__*/
386
- _curry2(function mergeDeepRight(lObj, rObj) {
381
+ var mergeDeepRight = /*#__PURE__*/_curry2(function mergeDeepRight(lObj, rObj) {
387
382
  return mergeDeepWithKey(function (k, lVal, rVal) {
388
383
  return rVal;
389
384
  }, lObj, rObj);
@@ -412,9 +407,7 @@ _curry2(function mergeDeepRight(lObj, rObj) {
412
407
  * { b: true, values: [15, 35] });
413
408
  * //=> { a: true, b: true, values: [10, 20, 15, 35] }
414
409
  */
415
-
416
- var mergeWith = /*#__PURE__*/
417
- _curry3(function mergeWith(fn, l, r) {
410
+ var mergeWith = /*#__PURE__*/_curry3(function mergeWith(fn, l, r) {
418
411
  return mergeWithKey(function (_, _l, _r) {
419
412
  return fn(_l, _r);
420
413
  }, l, r);
@@ -440,9 +433,7 @@ _curry3(function mergeWith(fn, l, r) {
440
433
  * const isUpperCase = (val, key) => key.toUpperCase() === key;
441
434
  * R.pickBy(isUpperCase, {a: 1, b: 2, A: 3, B: 4}); //=> {A: 3, B: 4}
442
435
  */
443
-
444
- var pickBy = /*#__PURE__*/
445
- _curry2(function pickBy(test, obj) {
436
+ var pickBy = /*#__PURE__*/_curry2(function pickBy(test, obj) {
446
437
  var result = {};
447
438
  for (var prop in obj) {
448
439
  if (test(obj[prop], prop, obj)) {
@@ -9435,19 +9426,25 @@ const StyledList = styled__default.default(List$1).withConfig({
9435
9426
  })(({
9436
9427
  theme
9437
9428
  }) => styled.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, edsUtils.bordersTemplate(theme.border)));
9429
+ const StyledPopover = styled__default.default('div').withConfig({
9430
+ shouldForwardProp: () => true //workaround to avoid warning until popover gets added to react types
9431
+ }).withConfig({
9432
+ displayName: "Autocomplete__StyledPopover",
9433
+ componentId: "sc-yvif0e-2"
9434
+ })(["inset:unset;border:0;padding:0;margin:0;overflow:visible;&::backdrop{background-color:transparent;}"]);
9438
9435
  const HelperText = styled__default.default(TextfieldHelperText).withConfig({
9439
9436
  displayName: "Autocomplete__HelperText",
9440
- componentId: "sc-yvif0e-2"
9437
+ componentId: "sc-yvif0e-3"
9441
9438
  })(["margin-top:8px;margin-left:8px;"]);
9442
9439
  const AutocompleteNoOptions = styled__default.default(AutocompleteOption).withConfig({
9443
9440
  displayName: "Autocomplete__AutocompleteNoOptions",
9444
- componentId: "sc-yvif0e-3"
9441
+ componentId: "sc-yvif0e-4"
9445
9442
  })(({
9446
9443
  theme
9447
9444
  }) => styled.css(["color:", ";"], theme.entities.noOptions.typography.color));
9448
9445
  const StyledButton$1 = styled__default.default(Button$1).withConfig({
9449
9446
  displayName: "Autocomplete__StyledButton",
9450
- componentId: "sc-yvif0e-4"
9447
+ componentId: "sc-yvif0e-5"
9451
9448
  })(({
9452
9449
  theme: {
9453
9450
  entities: {
@@ -9531,6 +9528,23 @@ const findPrevIndex = ({
9531
9528
  }
9532
9529
  return prevIndex;
9533
9530
  };
9531
+
9532
+ /*When a user clicks the StyledList scrollbar, the input looses focus which breaks downshift
9533
+ * keyboard navigation in the list. This code returns focus to the input on mouseUp
9534
+ */
9535
+ const handleListFocus = e => {
9536
+ e.preventDefault();
9537
+ e.stopPropagation();
9538
+ window?.addEventListener('mouseup', () => {
9539
+ e.relatedTarget?.focus();
9540
+ }, {
9541
+ once: true
9542
+ });
9543
+ };
9544
+ const defaultOptionDisabled = () => false;
9545
+
9546
+ // prettier-ignore
9547
+
9534
9548
  function AutocompleteInner(props, ref) {
9535
9549
  const {
9536
9550
  options = [],
@@ -9544,12 +9558,13 @@ function AutocompleteInner(props, ref) {
9544
9558
  hideClearButton = false,
9545
9559
  onOptionsChange,
9546
9560
  onInputChange,
9547
- selectedOptions,
9561
+ selectedOptions: _selectedOptions,
9548
9562
  multiple,
9563
+ itemCompare,
9549
9564
  allowSelectAll,
9550
- initialSelectedOptions = [],
9565
+ initialSelectedOptions: _initialSelectedOptions = [],
9551
9566
  disablePortal,
9552
- optionDisabled = () => false,
9567
+ optionDisabled = defaultOptionDisabled,
9553
9568
  optionsFilter,
9554
9569
  autoWidth,
9555
9570
  placeholder,
@@ -9564,6 +9579,11 @@ function AutocompleteInner(props, ref) {
9564
9579
  variant,
9565
9580
  ...other
9566
9581
  } = props;
9582
+ const selectedOptions = _selectedOptions ? itemCompare ? options.filter(item => _selectedOptions.some(compare => itemCompare(item, compare))) : _selectedOptions : undefined;
9583
+ const initialSelectedOptions = _initialSelectedOptions ? itemCompare ? options.filter(item => _initialSelectedOptions.some(compare => itemCompare(item, compare))) : _initialSelectedOptions : undefined;
9584
+ if (disablePortal) {
9585
+ console.warn('Autocomplete "disablePortal" prop has been deprecated. Autocomplete now uses the native popover api');
9586
+ }
9567
9587
  const isControlled = Boolean(selectedOptions);
9568
9588
  const [inputOptions, setInputOptions] = react.useState(options);
9569
9589
  const [_availableItems, setAvailableItems] = react.useState(inputOptions);
@@ -9578,13 +9598,8 @@ function AutocompleteInner(props, ref) {
9578
9598
  if (showSelectAll) return [AllSymbol, ..._availableItems];
9579
9599
  return _availableItems;
9580
9600
  }, [_availableItems, showSelectAll]);
9581
- const toggleAllSelected = () => {
9582
- if (selectedItems.length === inputOptions.length) {
9583
- setSelectedItems([]);
9584
- } else {
9585
- setSelectedItems(inputOptions);
9586
- }
9587
- };
9601
+
9602
+ //issue 2304, update dataset when options are added dynamically
9588
9603
  react.useEffect(() => {
9589
9604
  const availableHash = JSON.stringify(inputOptions);
9590
9605
  const optionsHash = JSON.stringify(options);
@@ -9595,7 +9610,6 @@ function AutocompleteInner(props, ref) {
9595
9610
  react.useEffect(() => {
9596
9611
  setAvailableItems(inputOptions);
9597
9612
  }, [inputOptions]);
9598
- const disabledItems = react.useMemo(() => options.filter(optionDisabled), [options, optionDisabled]);
9599
9613
  const {
9600
9614
  density
9601
9615
  } = useEds();
@@ -9612,7 +9626,10 @@ function AutocompleteInner(props, ref) {
9612
9626
  ...multipleSelectionProps,
9613
9627
  onSelectedItemsChange: changes => {
9614
9628
  if (onOptionsChange) {
9615
- const selectedItems = changes.selectedItems.filter(item => item !== AllSymbol);
9629
+ let selectedItems = changes.selectedItems.filter(item => item !== AllSymbol);
9630
+ if (itemCompare) {
9631
+ selectedItems = inputOptions.filter(item => selectedItems.some(compare => itemCompare(item, compare)));
9632
+ }
9616
9633
  onOptionsChange({
9617
9634
  selectedItems
9618
9635
  });
@@ -9631,15 +9648,27 @@ function AutocompleteInner(props, ref) {
9631
9648
  addSelectedItem,
9632
9649
  removeSelectedItem,
9633
9650
  selectedItems,
9634
- reset: resetSelection,
9635
9651
  setSelectedItems
9636
9652
  } = downshift.useMultipleSelection(multipleSelectionProps);
9653
+ const enabledItems = react.useMemo(() => {
9654
+ const disabledItemsSet = new Set(inputOptions.filter(optionDisabled));
9655
+ return inputOptions.filter(x => !disabledItemsSet.has(x));
9656
+ }, [inputOptions, optionDisabled]);
9657
+ const selectedDisabledItemsSet = react.useMemo(() => new Set(selectedItems.filter(optionDisabled)), [selectedItems, optionDisabled]);
9658
+ const selectedEnabledItems = react.useMemo(() => selectedItems.filter(x => !selectedDisabledItemsSet.has(x)), [selectedItems, selectedDisabledItemsSet]);
9637
9659
  const allSelectedState = react.useMemo(() => {
9638
- if (!inputOptions || !selectedItems) return 'NONE';
9639
- if (inputOptions.length === selectedItems.length) return 'ALL';
9640
- if (inputOptions.length != selectedItems.length && selectedItems.length > 0) return 'SOME';
9660
+ if (!enabledItems || !selectedEnabledItems) return 'NONE';
9661
+ if (enabledItems.length === selectedEnabledItems.length) return 'ALL';
9662
+ if (enabledItems.length != selectedEnabledItems.length && selectedEnabledItems.length > 0) return 'SOME';
9641
9663
  return 'NONE';
9642
- }, [inputOptions, selectedItems]);
9664
+ }, [enabledItems, selectedEnabledItems]);
9665
+ const toggleAllSelected = () => {
9666
+ if (selectedEnabledItems.length === enabledItems.length) {
9667
+ setSelectedItems([...selectedDisabledItemsSet]);
9668
+ } else {
9669
+ setSelectedItems([...enabledItems, ...selectedDisabledItemsSet]);
9670
+ }
9671
+ };
9643
9672
  const getLabel = react.useCallback(item => {
9644
9673
  //note: non strict check for null or undefined to allow 0
9645
9674
  if (item == null) {
@@ -9698,7 +9727,14 @@ function AutocompleteInner(props, ref) {
9698
9727
  highlightedIndex,
9699
9728
  type
9700
9729
  }) {
9701
- if (type !== downshift.useCombobox.stateChangeTypes.ItemMouseMove && type !== downshift.useCombobox.stateChangeTypes.MenuMouseLeave && highlightedIndex >= 0) {
9730
+ if (type == downshift.useCombobox.stateChangeTypes.InputClick || type == downshift.useCombobox.stateChangeTypes.InputKeyDownArrowDown && !isOpen || type == downshift.useCombobox.stateChangeTypes.InputKeyDownArrowUp && !isOpen) {
9731
+ //needs delay for dropdown to render before calling scroll
9732
+ setTimeout(() => {
9733
+ rowVirtualizer.scrollToIndex(highlightedIndex, {
9734
+ align: allowSelectAll ? 'center' : 'auto'
9735
+ });
9736
+ }, 1);
9737
+ } else if (type !== downshift.useCombobox.stateChangeTypes.ItemMouseMove && type !== downshift.useCombobox.stateChangeTypes.MenuMouseLeave && highlightedIndex >= 0) {
9702
9738
  rowVirtualizer.scrollToIndex(highlightedIndex, {
9703
9739
  align: allowSelectAll ? 'center' : 'auto'
9704
9740
  });
@@ -9740,9 +9776,12 @@ function AutocompleteInner(props, ref) {
9740
9776
  ...comboBoxProps,
9741
9777
  onSelectedItemChange: changes => {
9742
9778
  if (onOptionsChange) {
9743
- const {
9779
+ let {
9744
9780
  selectedItem
9745
9781
  } = changes;
9782
+ if (itemCompare) {
9783
+ selectedItem = inputOptions.find(item => itemCompare(item, selectedItem));
9784
+ }
9746
9785
  onOptionsChange({
9747
9786
  selectedItems: selectedItem ? [selectedItem] : []
9748
9787
  });
@@ -9809,7 +9848,7 @@ function AutocompleteInner(props, ref) {
9809
9848
  }
9810
9849
  }
9811
9850
  if (multiple) {
9812
- placeholderText = typeof placeholderText !== 'undefined' ? placeholderText : `${selectedItems.length}/${options.length - disabledItems.length} selected`;
9851
+ placeholderText = typeof placeholderText !== 'undefined' ? placeholderText : `${selectedItems.length}/${inputOptions.length} selected`;
9813
9852
  comboBoxProps = {
9814
9853
  ...comboBoxProps,
9815
9854
  selectedItem: null,
@@ -9901,11 +9940,6 @@ function AutocompleteInner(props, ref) {
9901
9940
  inputValue,
9902
9941
  reset: resetCombobox
9903
9942
  } = downshift.useCombobox(comboBoxProps);
9904
- react.useEffect(() => {
9905
- if (isControlled) {
9906
- setSelectedItems(selectedOptions);
9907
- }
9908
- }, [isControlled, selectedOptions, setSelectedItems]);
9909
9943
  const {
9910
9944
  x,
9911
9945
  y,
@@ -9914,8 +9948,8 @@ function AutocompleteInner(props, ref) {
9914
9948
  strategy
9915
9949
  } = react$1.useFloating({
9916
9950
  placement: 'bottom-start',
9917
- middleware: [react$1.offset(4), react$1.flip(), react$1.shift({
9918
- padding: 8
9951
+ middleware: [react$1.offset(4), react$1.flip({
9952
+ boundary: document?.body
9919
9953
  }), react$1.size({
9920
9954
  apply({
9921
9955
  rects,
@@ -9937,25 +9971,31 @@ function AutocompleteInner(props, ref) {
9937
9971
  return react$1.autoUpdate(refs.reference.current, refs.floating.current, update);
9938
9972
  }
9939
9973
  }, [refs.reference, refs.floating, update, isOpen]);
9974
+ edsUtils.useIsomorphicLayoutEffect(() => {
9975
+ if (isOpen) {
9976
+ refs.floating.current.showPopover();
9977
+ } else {
9978
+ refs.floating.current.hidePopover();
9979
+ }
9980
+ }, [isOpen, refs.floating]);
9940
9981
  const clear = () => {
9941
9982
  resetCombobox();
9942
- resetSelection();
9983
+ //dont clear items if they are selected and disabled
9984
+ setSelectedItems([...selectedDisabledItemsSet]);
9943
9985
  setTypedInputValue('');
9944
9986
  };
9945
9987
  const showClearButton = (selectedItems.length > 0 || inputValue) && !readOnly && !hideClearButton;
9946
9988
  const showNoOptions = isOpen && !availableItems.length && noOptionsText.length > 0;
9947
9989
  const selectedItemsLabels = react.useMemo(() => selectedItems.map(getLabel), [selectedItems, getLabel]);
9948
-
9949
- //temporary fix when inside dialog. Should be replaced by popover api when it is ready
9950
- const inDialog = edsUtils.useIsInDialog(refs.domReference.current);
9951
- const optionsList = /*#__PURE__*/jsxRuntime.jsx("div", {
9990
+ const optionsList = /*#__PURE__*/jsxRuntime.jsx(StyledPopover, {
9991
+ popover: "manual",
9952
9992
  ...getFloatingProps({
9953
9993
  ref: refs.setFloating,
9994
+ onFocus: handleListFocus,
9954
9995
  style: {
9955
9996
  position: strategy,
9956
9997
  top: y || 0,
9957
- left: x || 0,
9958
- zIndex: 1500
9998
+ left: x || 0
9959
9999
  }
9960
10000
  }),
9961
10001
  children: /*#__PURE__*/jsxRuntime.jsxs(StyledList, {
@@ -10099,10 +10139,7 @@ function AutocompleteInner(props, ref) {
10099
10139
  color: variant ? tokens.variants[variant].typography.color : undefined,
10100
10140
  text: helperText,
10101
10141
  icon: helperIcon
10102
- }), disablePortal || inDialog ? optionsList : /*#__PURE__*/jsxRuntime.jsx(react$1.FloatingPortal, {
10103
- id: "eds-autocomplete-container",
10104
- children: optionsList
10105
- })]
10142
+ }), optionsList]
10106
10143
  })
10107
10144
  });
10108
10145
  }
@@ -11541,6 +11578,26 @@ const FieldWrapper = /*#__PURE__*/react.forwardRef(({
11541
11578
  InputFieldWrapper.displayName = 'InputFieldWrapper';
11542
11579
  FieldWrapper.displayName = 'FieldWrapper';
11543
11580
 
11581
+ const intl = new Intl.DateTimeFormat();
11582
+ const defaultTimezone = intl.resolvedOptions().timeZone;
11583
+ const DatePickerContext = /*#__PURE__*/react.createContext({
11584
+ timezone: defaultTimezone
11585
+ });
11586
+ const DatePickerProvider = ({
11587
+ timezone,
11588
+ formatOptions,
11589
+ children
11590
+ }) => {
11591
+ return /*#__PURE__*/jsxRuntime.jsx(DatePickerContext.Provider, {
11592
+ value: {
11593
+ timezone: timezone ?? defaultTimezone,
11594
+ formatOptions
11595
+ },
11596
+ children: children
11597
+ });
11598
+ };
11599
+ const useDatePickerContext = () => react.useContext(DatePickerContext);
11600
+
11544
11601
  const Segment = styled__default.default.div.withConfig({
11545
11602
  displayName: "DateSegment__Segment",
11546
11603
  componentId: "sc-19uidpx-0"
@@ -11555,12 +11612,29 @@ function DateSegment({
11555
11612
  segment,
11556
11613
  state
11557
11614
  }) {
11615
+ const {
11616
+ formatOptions,
11617
+ timezone
11618
+ } = useDatePickerContext();
11619
+ const formatter = reactAria.useDateFormatter(formatOptions);
11620
+ const parts = state.value ? formatter.formatToParts(state.value.toDate(timezone)) : [];
11621
+ const part = parts.find(p => p.type === segment.type);
11622
+ const value = segment.isPlaceholder || segment.type === 'literal' ? segment.text : part?.value ?? segment.text;
11623
+ const [focus, setFocus] = react.useState(false);
11558
11624
  const ref = react.useRef(null);
11559
11625
  const {
11560
11626
  segmentProps
11561
11627
  } = reactAria.useDateSegment(segment, state, ref);
11562
11628
  return /*#__PURE__*/jsxRuntime.jsx(Segment, {
11563
11629
  ...segmentProps,
11630
+ onFocus: e => {
11631
+ setFocus(true);
11632
+ segmentProps.onFocus(e);
11633
+ },
11634
+ onBlur: e => {
11635
+ setFocus(false);
11636
+ segmentProps.onBlur(e);
11637
+ },
11564
11638
  $invalid: state.isInvalid,
11565
11639
  $disabled: state.isDisabled,
11566
11640
  $placeholder: segment.isPlaceholder,
@@ -11577,7 +11651,7 @@ function DateSegment({
11577
11651
  },
11578
11652
  ref: ref,
11579
11653
  className: `segment ${segment.isPlaceholder ? 'placeholder' : ''}`,
11580
- children: segment.isPlaceholder || segment.type === 'literal' ? segment.text : segment.text.padStart(segment.type === 'year' ? 4 : 2, '0')
11654
+ children: focus ? segment.isPlaceholder || segment.type === 'literal' ? segment.text : segment.text.padStart(segment.type === 'year' ? 4 : 2, '0') : value
11581
11655
  });
11582
11656
  }
11583
11657
 
@@ -11649,23 +11723,6 @@ const DateField = /*#__PURE__*/react.forwardRef(function ({
11649
11723
  });
11650
11724
  DateField.displayName = 'DateField';
11651
11725
 
11652
- const intl = new Intl.DateTimeFormat();
11653
- const defaultTimezone = intl.resolvedOptions().timeZone;
11654
- const DatePickerContext = /*#__PURE__*/react.createContext({
11655
- timezone: defaultTimezone
11656
- });
11657
- const DatePickerProvider = ({
11658
- timezone,
11659
- children
11660
- }) => {
11661
- return /*#__PURE__*/jsxRuntime.jsx(DatePickerContext.Provider, {
11662
- value: {
11663
- timezone: timezone ?? defaultTimezone
11664
- },
11665
- children: children
11666
- });
11667
- };
11668
-
11669
11726
  const useConvertedValidationFunctions = (minValue, maxValue, isDateUnavailable, timezone) => {
11670
11727
  const tz = timezone ?? defaultTimezone;
11671
11728
  const _minValue = minValue ? date.toCalendarDate(date.fromDate(minValue, tz)) : undefined;
@@ -11755,9 +11812,15 @@ const DatePicker = /*#__PURE__*/react.forwardRef(({
11755
11812
  granularity,
11756
11813
  disabled: isDisabled,
11757
11814
  readOnly: isReadOnly,
11815
+ formatOptions,
11758
11816
  ...props
11759
11817
  }, forwardedRef) => {
11760
11818
  timezone = timezone ?? defaultTimezone;
11819
+ formatOptions = formatOptions ?? {
11820
+ year: 'numeric',
11821
+ month: '2-digit',
11822
+ day: '2-digit'
11823
+ };
11761
11824
  const [innerValue, setInnerValue] = react.useState(() => {
11762
11825
  const initialValue = value ?? defaultValue;
11763
11826
  if (initialValue) {
@@ -11833,8 +11896,14 @@ const DatePicker = /*#__PURE__*/react.forwardRef(({
11833
11896
  data: edsIcons.warning_outlined
11834
11897
  })
11835
11898
  } : undefined;
11899
+
11900
+ // innerValue is used as a fallback, especially for uncontrolled inputs, so it needs to be reset when value / defaultValue is reset
11901
+ react.useEffect(() => {
11902
+ if (!defaultValue && !value) setInnerValue(null);
11903
+ }, [defaultValue, value]);
11836
11904
  return /*#__PURE__*/jsxRuntime.jsx(DatePickerProvider, {
11837
11905
  timezone: timezone,
11906
+ formatOptions: formatOptions,
11838
11907
  children: /*#__PURE__*/jsxRuntime.jsx(FieldWrapper, {
11839
11908
  isOpen: isOpen,
11840
11909
  readonly: fieldProps.isReadOnly,
@@ -11987,11 +12056,17 @@ const DateRangePicker = /*#__PURE__*/react.forwardRef(({
11987
12056
  Header,
11988
12057
  timezone,
11989
12058
  defaultValue,
12059
+ formatOptions,
11990
12060
  disabled: isDisabled,
11991
12061
  readOnly: isReadOnly,
11992
12062
  ...props
11993
12063
  }, forwardedRef) => {
11994
12064
  timezone = timezone ?? defaultTimezone;
12065
+ formatOptions = formatOptions ?? {
12066
+ year: 'numeric',
12067
+ month: '2-digit',
12068
+ day: '2-digit'
12069
+ };
11995
12070
  const [innerValue, setInnerValue] = react.useState(() => {
11996
12071
  const initialValue = value ?? defaultValue;
11997
12072
  if (initialValue) {
@@ -12065,8 +12140,16 @@ const DateRangePicker = /*#__PURE__*/react.forwardRef(({
12065
12140
  day: '2-digit'
12066
12141
  });
12067
12142
  const valueString = formattedValue ? Object.values(formattedValue).join(' - ') : null;
12143
+
12144
+ // innerValue is used as a fallback, especially for uncontrolled inputs, so it needs to be reset when value / defaultValue is reset
12145
+ react.useEffect(() => {
12146
+ const val = defaultValue ?? value;
12147
+ if (!defaultValue && !value) setInnerValue(null);
12148
+ if (!val?.from && !val?.to) setInnerValue(null);
12149
+ }, [defaultValue, value]);
12068
12150
  return /*#__PURE__*/jsxRuntime.jsx(DatePickerProvider, {
12069
12151
  timezone: timezone,
12152
+ formatOptions: formatOptions,
12070
12153
  children: /*#__PURE__*/jsxRuntime.jsx(FieldWrapper, {
12071
12154
  isOpen: isOpen,
12072
12155
  color: state.isInvalid ? 'warning' : props.variant,