@equinor/eds-core-react 0.44.0 → 0.45.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.
@@ -9663,7 +9663,8 @@ function AutocompleteInner(props, ref) {
9663
9663
  onInputChange,
9664
9664
  selectedOptions: _selectedOptions,
9665
9665
  multiple,
9666
- itemCompare,
9666
+ itemToKey: _itemToKey,
9667
+ itemCompare: _itemCompare,
9667
9668
  allowSelectAll,
9668
9669
  initialSelectedOptions: _initialSelectedOptions = [],
9669
9670
  optionDisabled = defaultOptionDisabled,
@@ -9682,6 +9683,20 @@ function AutocompleteInner(props, ref) {
9682
9683
  onClear,
9683
9684
  ...other
9684
9685
  } = props;
9686
+ const itemCompare = react.useMemo(() => {
9687
+ if (_itemCompare && _itemToKey) {
9688
+ console.error('Error: Specifying both itemCompare and itemToKey. itemCompare is deprecated, while itemToKey should be used instead of it. Please only use one.');
9689
+ return _itemCompare;
9690
+ }
9691
+ if (_itemToKey) {
9692
+ return (o1, o2) => _itemToKey(o1) === _itemToKey(o2);
9693
+ }
9694
+ return _itemCompare;
9695
+ }, [_itemCompare, _itemToKey]);
9696
+ const itemToKey = react.useCallback(item => {
9697
+ console.log(`item is`, item);
9698
+ return _itemToKey ? _itemToKey(item) : item;
9699
+ }, [_itemToKey]);
9685
9700
 
9686
9701
  // MARK: initializing data/setup
9687
9702
  const selectedOptions = _selectedOptions ? itemCompare ? options.filter(item => _selectedOptions.some(compare => itemCompare(item, compare))) : _selectedOptions : undefined;
@@ -9722,6 +9737,7 @@ function AutocompleteInner(props, ref) {
9722
9737
  const tokens = token();
9723
9738
  let placeholderText = placeholder;
9724
9739
  let multipleSelectionProps = {
9740
+ itemToKey,
9725
9741
  initialSelectedItems: multiple ? initialSelectedOptions : initialSelectedOptions[0] ? [initialSelectedOptions[0]] : []
9726
9742
  };
9727
9743
  if (multiple) {
@@ -9824,6 +9840,7 @@ function AutocompleteInner(props, ref) {
9824
9840
  isItemDisabled(item) {
9825
9841
  return optionDisabled(item);
9826
9842
  },
9843
+ itemToKey,
9827
9844
  itemToString: getLabel,
9828
9845
  onInputValueChange: ({
9829
9846
  inputValue
@@ -11884,7 +11901,8 @@ const DateFieldSegments = /*#__PURE__*/react.forwardRef((props, ref) => {
11884
11901
  return /*#__PURE__*/jsxRuntime.jsx("div", {
11885
11902
  ...fieldProps,
11886
11903
  style: {
11887
- display: 'flex'
11904
+ display: 'flex',
11905
+ fontFamily: 'Equinor, Arial, sans-serif'
11888
11906
  },
11889
11907
  ref: ref,
11890
11908
  children: state.segments.map((segment, i) => /*#__PURE__*/jsxRuntime.jsx(DateSegment, {
@@ -11964,7 +11982,10 @@ const Toggle = ({
11964
11982
  showClearButton,
11965
11983
  readonly
11966
11984
  }) => {
11967
- return readonly || disabled ? null : /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
11985
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
11986
+ style: {
11987
+ visibility: readonly || disabled ? 'hidden' : 'visible'
11988
+ },
11968
11989
  children: [showClearButton && /*#__PURE__*/jsxRuntime.jsx(StyledButton, {
11969
11990
  disabled: disabled,
11970
11991
  variant: 'ghost_icon',
@@ -12006,12 +12027,14 @@ const getCalendarDate = (value, timezone, showTimeInput = false) => {
12006
12027
 
12007
12028
  const useGetLocale = locale => {
12008
12029
  const {
12009
- locale: externalLocale
12030
+ locale: currentLocale
12010
12031
  } = reactAria.useLocale();
12011
- // react-aria defaults to navigator.language if no locale is provided. If these are equal, we override by using the system default locale
12012
- const defaultLocale = typeof navigator !== 'undefined' && navigator.language || 'en-US';
12013
- const fallbackLocale = new Intl.DateTimeFormat().resolvedOptions().locale;
12014
- return locale ?? (externalLocale === defaultLocale ? undefined : externalLocale) ?? fallbackLocale;
12032
+ // Priority:
12033
+ // 1. Explicitly passed locale prop
12034
+ // 2. Locale from I18nProvider
12035
+ // 3. Fallback to browser's default
12036
+ const browserLocale = new Intl.DateTimeFormat().resolvedOptions().locale;
12037
+ return locale ?? currentLocale ?? browserLocale;
12015
12038
  };
12016
12039
 
12017
12040
  const DatePicker = /*#__PURE__*/react.forwardRef(({
@@ -1,4 +1,4 @@
1
- import { forwardRef, useState, useRef, useMemo, useEffect, useCallback } from 'react';
1
+ import { forwardRef, useMemo, useCallback, useState, useRef, useEffect } from 'react';
2
2
  import { useMultipleSelection, useCombobox } from 'downshift';
3
3
  import { useVirtualizer } from '@tanstack/react-virtual';
4
4
  import styled, { css, ThemeProvider } from 'styled-components';
@@ -169,7 +169,8 @@ function AutocompleteInner(props, ref) {
169
169
  onInputChange,
170
170
  selectedOptions: _selectedOptions,
171
171
  multiple,
172
- itemCompare,
172
+ itemToKey: _itemToKey,
173
+ itemCompare: _itemCompare,
173
174
  allowSelectAll,
174
175
  initialSelectedOptions: _initialSelectedOptions = [],
175
176
  optionDisabled = defaultOptionDisabled,
@@ -188,6 +189,20 @@ function AutocompleteInner(props, ref) {
188
189
  onClear,
189
190
  ...other
190
191
  } = props;
192
+ const itemCompare = useMemo(() => {
193
+ if (_itemCompare && _itemToKey) {
194
+ console.error('Error: Specifying both itemCompare and itemToKey. itemCompare is deprecated, while itemToKey should be used instead of it. Please only use one.');
195
+ return _itemCompare;
196
+ }
197
+ if (_itemToKey) {
198
+ return (o1, o2) => _itemToKey(o1) === _itemToKey(o2);
199
+ }
200
+ return _itemCompare;
201
+ }, [_itemCompare, _itemToKey]);
202
+ const itemToKey = useCallback(item => {
203
+ console.log(`item is`, item);
204
+ return _itemToKey ? _itemToKey(item) : item;
205
+ }, [_itemToKey]);
191
206
 
192
207
  // MARK: initializing data/setup
193
208
  const selectedOptions = _selectedOptions ? itemCompare ? options.filter(item => _selectedOptions.some(compare => itemCompare(item, compare))) : _selectedOptions : undefined;
@@ -228,6 +243,7 @@ function AutocompleteInner(props, ref) {
228
243
  const tokens = token();
229
244
  let placeholderText = placeholder;
230
245
  let multipleSelectionProps = {
246
+ itemToKey,
231
247
  initialSelectedItems: multiple ? initialSelectedOptions : initialSelectedOptions[0] ? [initialSelectedOptions[0]] : []
232
248
  };
233
249
  if (multiple) {
@@ -330,6 +346,7 @@ function AutocompleteInner(props, ref) {
330
346
  isItemDisabled(item) {
331
347
  return optionDisabled(item);
332
348
  },
349
+ itemToKey,
333
350
  itemToString: getLabel,
334
351
  onInputValueChange: ({
335
352
  inputValue
@@ -26,7 +26,8 @@ const DateFieldSegments = /*#__PURE__*/forwardRef((props, ref) => {
26
26
  return /*#__PURE__*/jsx("div", {
27
27
  ...fieldProps,
28
28
  style: {
29
- display: 'flex'
29
+ display: 'flex',
30
+ fontFamily: 'Equinor, Arial, sans-serif'
30
31
  },
31
32
  ref: ref,
32
33
  children: state.segments.map((segment, i) => /*#__PURE__*/jsx(DateSegment, {
@@ -3,7 +3,7 @@ import { close } from '@equinor/eds-icons';
3
3
  import { Button } from '../../Button/Button.js';
4
4
  import styled from 'styled-components';
5
5
  import { filterDOMProps } from '@react-aria/utils';
6
- import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
6
+ import { jsxs, jsx } from 'react/jsx-runtime';
7
7
 
8
8
  const StyledButton = styled(Button).withConfig({
9
9
  displayName: "Toggle__StyledButton",
@@ -24,7 +24,10 @@ const Toggle = ({
24
24
  showClearButton,
25
25
  readonly
26
26
  }) => {
27
- return readonly || disabled ? null : /*#__PURE__*/jsxs(Fragment, {
27
+ return /*#__PURE__*/jsxs("div", {
28
+ style: {
29
+ visibility: readonly || disabled ? 'hidden' : 'visible'
30
+ },
28
31
  children: [showClearButton && /*#__PURE__*/jsx(StyledButton, {
29
32
  disabled: disabled,
30
33
  variant: 'ghost_icon',
@@ -2,12 +2,14 @@ import { useLocale } from 'react-aria';
2
2
 
3
3
  const useGetLocale = locale => {
4
4
  const {
5
- locale: externalLocale
5
+ locale: currentLocale
6
6
  } = useLocale();
7
- // react-aria defaults to navigator.language if no locale is provided. If these are equal, we override by using the system default locale
8
- const defaultLocale = typeof navigator !== 'undefined' && navigator.language || 'en-US';
9
- const fallbackLocale = new Intl.DateTimeFormat().resolvedOptions().locale;
10
- return locale ?? (externalLocale === defaultLocale ? undefined : externalLocale) ?? fallbackLocale;
7
+ // Priority:
8
+ // 1. Explicitly passed locale prop
9
+ // 2. Locale from I18nProvider
10
+ // 3. Fallback to browser's default
11
+ const browserLocale = new Intl.DateTimeFormat().resolvedOptions().locale;
12
+ return locale ?? currentLocale ?? browserLocale;
11
13
  };
12
14
 
13
15
  export { useGetLocale };
@@ -84,6 +84,11 @@ export type AutocompleteProps<T> = {
84
84
  */
85
85
  dropdownHeight?: number;
86
86
  /**
87
+ * Method that is used to select a key that can be used for comparing items. If omitted, objects are matched by reference.
88
+ */
89
+ itemToKey?: (value: T | null) => unknown;
90
+ /**
91
+ * @deprecated since version 0.45.0 - use itemToKey instead
87
92
  * Method that is used to compare objects by value. If omitted, objects are matched by reference.
88
93
  */
89
94
  itemCompare?: (value: T, compare: T) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/eds-core-react",
3
- "version": "0.44.0",
3
+ "version": "0.45.0",
4
4
  "description": "The React implementation of the Equinor Design System",
5
5
  "sideEffects": [
6
6
  "**/*.css"
@@ -46,7 +46,7 @@
46
46
  "@storybook/react-vite": "^8.4.7",
47
47
  "@testing-library/dom": "^10.4.0",
48
48
  "@testing-library/jest-dom": "^6.6.3",
49
- "@testing-library/react": "16.1.0",
49
+ "@testing-library/react": "16.3.0",
50
50
  "@testing-library/user-event": "14.5.2",
51
51
  "@types/jest": "^29.5.14",
52
52
  "@types/ramda": "^0.30.2",
@@ -68,9 +68,9 @@
68
68
  "rollup-plugin-postcss": "^4.0.2",
69
69
  "rollup-preserve-directives": "^1.1.3",
70
70
  "storybook": "^8.4.7",
71
- "styled-components": "6.1.13",
71
+ "styled-components": "6.1.17",
72
72
  "tsc-watch": "^6.2.1",
73
- "typescript": "^5.7.2"
73
+ "typescript": "^5.8.2"
74
74
  },
75
75
  "peerDependencies": {
76
76
  "react": ">=16.8",
@@ -78,7 +78,7 @@
78
78
  "styled-components": ">=5.1"
79
79
  },
80
80
  "dependencies": {
81
- "@babel/runtime": "^7.26.0",
81
+ "@babel/runtime": "^7.26.10",
82
82
  "@floating-ui/react": "^0.27.2",
83
83
  "@internationalized/date": "^3.6.0",
84
84
  "@react-aria/utils": "^3.26.0",
@@ -89,8 +89,8 @@
89
89
  "downshift": "9.0.8",
90
90
  "react-aria": "^3.36.0",
91
91
  "@equinor/eds-icons": "^0.22.0",
92
- "@equinor/eds-tokens": "0.9.2",
93
- "@equinor/eds-utils": "0.8.6"
92
+ "@equinor/eds-utils": "0.8.7",
93
+ "@equinor/eds-tokens": "0.9.2"
94
94
  },
95
95
  "scripts": {
96
96
  "build": "rollup -c --bundleConfigAsCjs && tsc -p tsconfig.build.json",