@equinor/eds-core-react 0.20.1 → 0.20.2-dev.20220616

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.
@@ -3172,14 +3172,19 @@ const StyledAccordionHeaderTitle = styled__default["default"].span.withConfig({
3172
3172
  displayName: "AccordionHeaderTitle__StyledAccordionHeaderTitle",
3173
3173
  componentId: "sc-g27uve-0"
3174
3174
  })(_ref => {
3175
- var _theme$entities$heade;
3175
+ var _header$states$active;
3176
3176
 
3177
3177
  let {
3178
3178
  theme,
3179
3179
  isExpanded,
3180
3180
  disabled
3181
3181
  } = _ref;
3182
- return styled.css(["flex:1;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;text-align:left;font-family:Equinor;color:", ";"], isExpanded && !disabled ? (_theme$entities$heade = theme.entities.header.states.active.typography) === null || _theme$entities$heade === void 0 ? void 0 : _theme$entities$heade.color : 'inherit');
3182
+ const {
3183
+ entities: {
3184
+ header
3185
+ }
3186
+ } = theme;
3187
+ return styled.css(["display:-webkit-box;-webkit-line-clamp:1;-webkit-box-orient:vertical;flex-grow:1;overflow:hidden;text-align:left;color:", ";"], isExpanded && !disabled ? (_header$states$active = header.states.active.typography) === null || _header$states$active === void 0 ? void 0 : _header$states$active.color : 'inherit');
3183
3188
  });
3184
3189
  const AccordionHeaderTitle = /*#__PURE__*/react.forwardRef(function AccordionHeaderTitle(_ref2, ref) {
3185
3190
  let {
@@ -3195,6 +3200,44 @@ const AccordionHeaderTitle = /*#__PURE__*/react.forwardRef(function AccordionHea
3195
3200
  });
3196
3201
  }); // AccordionHeaderTitle.displayName = 'AccordionHeaderTitle'
3197
3202
 
3203
+ const StyledAccordionHeaderActions = styled__default["default"].span.withConfig({
3204
+ displayName: "AccordionHeaderActions__StyledAccordionHeaderActions",
3205
+ componentId: "sc-klu9el-0"
3206
+ })(_ref => {
3207
+ var _header$states$active;
3208
+
3209
+ let {
3210
+ theme,
3211
+ isExpanded,
3212
+ disabled
3213
+ } = _ref;
3214
+ const {
3215
+ entities: {
3216
+ header
3217
+ }
3218
+ } = theme;
3219
+ return styled.css(["display:flex;align-items:center;justify-content:flex-end;padding-right:", ";", " color:", ";"], header.spacings.right, disabled ? styled.css({
3220
+ color: header.states.disabled.typography.color,
3221
+ cursor: 'not-allowed'
3222
+ }) : styled.css({
3223
+ color: header.typography.color,
3224
+ cursor: 'pointer'
3225
+ }), isExpanded && !disabled ? (_header$states$active = header.states.active.typography) === null || _header$states$active === void 0 ? void 0 : _header$states$active.color : 'inherit');
3226
+ });
3227
+ const AccordionHeaderActions = /*#__PURE__*/react.forwardRef(function AccordionHeaderActions(_ref2, ref) {
3228
+ let {
3229
+ isExpanded,
3230
+ disabled,
3231
+ children
3232
+ } = _ref2;
3233
+ return /*#__PURE__*/jsxRuntime.jsx(StyledAccordionHeaderActions, {
3234
+ ref: ref,
3235
+ isExpanded: isExpanded,
3236
+ disabled: disabled,
3237
+ children: children
3238
+ });
3239
+ });
3240
+
3198
3241
  const {
3199
3242
  entities: {
3200
3243
  chevron: chevronToken
@@ -3203,13 +3246,37 @@ const {
3203
3246
  const StyledAccordionHeader = styled__default["default"].div.withConfig({
3204
3247
  displayName: "AccordionHeader__StyledAccordionHeader",
3205
3248
  componentId: "sc-cu2e95-0"
3206
- })(["margin:0;padding:0;"]);
3207
- const StyledAccordionHeaderButton = styled__default["default"].button.attrs(_ref => {
3249
+ })(_ref => {
3250
+ let {
3251
+ theme,
3252
+ disabled,
3253
+ parentIndex
3254
+ } = _ref;
3255
+ const {
3256
+ entities: {
3257
+ header
3258
+ },
3259
+ border
3260
+ } = theme;
3261
+ return styled.css(["margin:0;padding:0;height:", ";box-sizing:border-box;display:flex;flex-wrap:nowrap;justify-content:space-between;background-color:", ";", " border-top:", ";", ""], header.height, header.background, edsUtils.bordersTemplate(border), parentIndex === 0 ? null : 'none', disabled ? styled.css({
3262
+ color: header.states.disabled.typography.color,
3263
+ cursor: 'not-allowed'
3264
+ }) : styled.css({
3265
+ color: header.typography.color,
3266
+ cursor: 'pointer',
3267
+ '@media (hover: hover) and (pointer: fine)': {
3268
+ ':hover': {
3269
+ background: header.states.hover.background
3270
+ }
3271
+ }
3272
+ }));
3273
+ });
3274
+ const StyledAccordionHeaderButton = styled__default["default"].button.attrs(_ref2 => {
3208
3275
  let {
3209
3276
  panelId,
3210
3277
  isExpanded,
3211
3278
  disabled
3212
- } = _ref;
3279
+ } = _ref2;
3213
3280
  return {
3214
3281
  'aria-expanded': isExpanded,
3215
3282
  'aria-controls': panelId,
@@ -3220,46 +3287,39 @@ const StyledAccordionHeaderButton = styled__default["default"].button.attrs(_ref
3220
3287
  }).withConfig({
3221
3288
  displayName: "AccordionHeader__StyledAccordionHeaderButton",
3222
3289
  componentId: "sc-cu2e95-1"
3223
- })(_ref2 => {
3290
+ })(_ref3 => {
3224
3291
  let {
3225
3292
  theme,
3226
- disabled,
3227
- parentIndex
3228
- } = _ref2;
3293
+ disabled
3294
+ } = _ref3;
3229
3295
  const {
3230
3296
  entities: {
3231
3297
  header,
3232
3298
  icon: iconToken
3233
- },
3234
- border
3299
+ }
3235
3300
  } = theme;
3236
- return styled.css(["", " ", " ", " &[data-focus-visible-added]:focus{", "}&:focus-visible{", "}border-top:", ";width:100%;background:", ";height:", ";margin:0;display:flex;align-items:center;box-sizing:border-box;", " > svg{color:", ";}"], edsUtils.typographyTemplate(header.typography), edsUtils.bordersTemplate(border), edsUtils.spacingsTemplate(header.spacings), edsUtils.outlineTemplate(header.states.focus.outline), edsUtils.outlineTemplate(header.states.focus.outline), parentIndex === 0 ? null : 'none', header.background, header.height, disabled ? styled.css({
3301
+ return styled.css(["", " ", " &[data-focus-visible-added]:focus{", "}&:focus-visible{", "}border:0;background-color:transparent;margin:0;display:flex;align-items:center;flex-grow:1;", " > svg{color:", ";}"], edsUtils.typographyTemplate(header.typography), edsUtils.spacingsTemplate(header.spacings), edsUtils.outlineTemplate(header.states.focus.outline), edsUtils.outlineTemplate(header.states.focus.outline), disabled ? styled.css({
3237
3302
  color: header.states.disabled.typography.color,
3238
3303
  cursor: 'not-allowed'
3239
3304
  }) : styled.css({
3240
3305
  color: header.typography.color,
3241
- cursor: 'pointer',
3242
- '@media (hover: hover) and (pointer: fine)': {
3243
- ':hover': {
3244
- background: header.states.hover.background
3245
- }
3246
- }
3306
+ cursor: 'pointer'
3247
3307
  }), iconToken.typography.color);
3248
3308
  });
3249
3309
  const StyledIcon$1 = styled__default["default"](Icon$1).withConfig({
3250
3310
  displayName: "AccordionHeader__StyledIcon",
3251
3311
  componentId: "sc-cu2e95-2"
3252
- })(_ref3 => {
3312
+ })(_ref4 => {
3253
3313
  let {
3254
3314
  chevronPosition
3255
- } = _ref3;
3315
+ } = _ref4;
3256
3316
  return chevronPosition === 'left' ? {
3257
3317
  marginRight: '32px'
3258
3318
  } : {
3259
3319
  marginLeft: '16px'
3260
3320
  };
3261
3321
  });
3262
- const AccordionHeader = /*#__PURE__*/react.forwardRef(function AccordionHeader(_ref4, ref) {
3322
+ const AccordionHeader = /*#__PURE__*/react.forwardRef(function AccordionHeader(_ref5, ref) {
3263
3323
  let {
3264
3324
  parentIndex,
3265
3325
  headerLevel,
@@ -3271,7 +3331,7 @@ const AccordionHeader = /*#__PURE__*/react.forwardRef(function AccordionHeader(_
3271
3331
  toggleExpanded,
3272
3332
  disabled,
3273
3333
  ...props
3274
- } = _ref4;
3334
+ } = _ref5;
3275
3335
 
3276
3336
  const handleClick = () => {
3277
3337
  if (!disabled) {
@@ -3322,14 +3382,27 @@ const AccordionHeader = /*#__PURE__*/react.forwardRef(function AccordionHeader(_
3322
3382
  });
3323
3383
  }
3324
3384
 
3385
+ if (child.type === AccordionHeaderActions) {
3386
+ return;
3387
+ }
3388
+
3325
3389
  return child;
3326
3390
  });
3391
+ const headerActions = react.Children.map(children, child => {
3392
+ if ( /*#__PURE__*/react.isValidElement(child) && child.type === AccordionHeaderActions) {
3393
+ return /*#__PURE__*/react.cloneElement(child, {
3394
+ isExpanded,
3395
+ disabled
3396
+ });
3397
+ }
3398
+ });
3327
3399
  const newChildren = [chevron, headerChildren];
3328
- return /*#__PURE__*/jsxRuntime.jsx(StyledAccordionHeader, {
3400
+ return /*#__PURE__*/jsxRuntime.jsxs(StyledAccordionHeader, {
3401
+ disabled: disabled,
3402
+ parentIndex: parentIndex,
3329
3403
  as: headerLevel,
3330
- children: /*#__PURE__*/jsxRuntime.jsx(StyledAccordionHeaderButton, {
3404
+ children: [/*#__PURE__*/jsxRuntime.jsx(StyledAccordionHeaderButton, {
3331
3405
  isExpanded: isExpanded,
3332
- parentIndex: parentIndex,
3333
3406
  disabled: disabled,
3334
3407
  panelId: panelId,
3335
3408
  onClick: handleClick,
@@ -3337,9 +3410,9 @@ const AccordionHeader = /*#__PURE__*/react.forwardRef(function AccordionHeader(_
3337
3410
  ref: ref,
3338
3411
  ...props,
3339
3412
  children: chevronPosition === 'left' ? newChildren : newChildren.reverse()
3340
- })
3413
+ }), headerActions && headerActions]
3341
3414
  });
3342
- }); // AccordionHeader.displayName = 'EdsAccordionHeader'
3415
+ });
3343
3416
 
3344
3417
  const StyledAccordionPanel = styled__default["default"].div.attrs(_ref => {
3345
3418
  let {
@@ -3387,10 +3460,12 @@ const Accordion = Accordion$1;
3387
3460
  Accordion.Item = AccordionItem;
3388
3461
  Accordion.Header = AccordionHeader;
3389
3462
  Accordion.HeaderTitle = AccordionHeaderTitle;
3463
+ Accordion.HeaderActions = AccordionHeaderActions;
3390
3464
  Accordion.Panel = AccordionPanel;
3391
3465
  Accordion.Item.displayName = 'Accordion.Item';
3392
3466
  Accordion.Header.displayName = 'Accordion.Header';
3393
3467
  Accordion.HeaderTitle.displayName = 'Accordion.HeaderTitle';
3468
+ Accordion.HeaderActions.displayName = 'Accordion.HeaderActions';
3394
3469
  Accordion.Panel.displayName = 'Accordion.Panel';
3395
3470
 
3396
3471
  const TabsContext = /*#__PURE__*/react.createContext({
@@ -9955,7 +10030,7 @@ const StyledList = styled__default["default"](List$1).withConfig({
9955
10030
  let {
9956
10031
  theme
9957
10032
  } = _ref2;
9958
- return styled.css(["background-color:", ";box-shadow:", ";", " overflow-y:auto;max-height:300px;padding:0;position:absolute;right:0;left:0;z-index:50;"], theme.background, theme.boxShadow, edsUtils.bordersTemplate(theme.border));
10033
+ return styled.css(["background-color:", ";box-shadow:", ";", " overflow-y:auto;max-height:300px;padding:0;position:absolute;right:0;left:0;z-index:1400;"], theme.background, theme.boxShadow, edsUtils.bordersTemplate(theme.border));
9959
10034
  });
9960
10035
  const StyledButton = styled__default["default"](Button).withConfig({
9961
10036
  displayName: "Autocomplete__StyledButton",
@@ -10066,7 +10141,19 @@ function AutocompleteInner(props, ref) {
10066
10141
  const [containerEl, setContainerEl] = react.useState();
10067
10142
  const isMounted = edsUtils.useIsMounted();
10068
10143
  const isControlled = Boolean(selectedOptions);
10069
- const [availableItems, setAvailableItems] = react.useState(options);
10144
+ const [inputOptions, setInputOptions] = react.useState(options);
10145
+ react.useEffect(() => {
10146
+ const availableHash = JSON.stringify(inputOptions);
10147
+ const optionsHash = JSON.stringify(options);
10148
+
10149
+ if (availableHash !== optionsHash) {
10150
+ setInputOptions(options);
10151
+ }
10152
+ }, [options, inputOptions]);
10153
+ react.useEffect(() => {
10154
+ setAvailableItems(inputOptions);
10155
+ }, [inputOptions]);
10156
+ const [availableItems, setAvailableItems] = react.useState(inputOptions);
10070
10157
  const disabledItems = react.useMemo(() => options.filter(optionDisabled), [options, optionDisabled]);
10071
10158
  const {
10072
10159
  density
@@ -10076,18 +10163,28 @@ function AutocompleteInner(props, ref) {
10076
10163
  }, multiple ? multiSelect : selectTokens);
10077
10164
  let placeholderText = placeholder;
10078
10165
  let multipleSelectionProps = {
10079
- initialSelectedItems: multiple ? initialSelectedOptions : initialSelectedOptions[0] ? [initialSelectedOptions[0]] : [],
10080
- onSelectedItemsChange: changes => {
10081
- if (onOptionsChange) {
10082
- onOptionsChange(changes);
10083
- }
10084
- }
10166
+ initialSelectedItems: multiple ? initialSelectedOptions : initialSelectedOptions[0] ? [initialSelectedOptions[0]] : []
10085
10167
  };
10086
10168
 
10087
- if (isControlled) {
10169
+ if (multiple) {
10088
10170
  multipleSelectionProps = { ...multipleSelectionProps,
10089
- selectedItems: selectedOptions
10171
+ onSelectedItemsChange: changes => {
10172
+ if (onOptionsChange) {
10173
+ const {
10174
+ selectedItems
10175
+ } = changes;
10176
+ onOptionsChange({
10177
+ selectedItems
10178
+ });
10179
+ }
10180
+ }
10090
10181
  };
10182
+
10183
+ if (isControlled) {
10184
+ multipleSelectionProps = { ...multipleSelectionProps,
10185
+ selectedItems: selectedOptions
10186
+ };
10187
+ }
10091
10188
  }
10092
10189
 
10093
10190
  const {
@@ -10206,7 +10303,17 @@ function AutocompleteInner(props, ref) {
10206
10303
 
10207
10304
  if (isControlled && !multiple) {
10208
10305
  comboBoxProps = { ...comboBoxProps,
10209
- selectedItem: selectedOptions[0]
10306
+ selectedItem: selectedOptions[0] || null,
10307
+ onSelectedItemChange: changes => {
10308
+ if (onOptionsChange) {
10309
+ const {
10310
+ selectedItem
10311
+ } = changes;
10312
+ onOptionsChange({
10313
+ selectedItems: [selectedItem]
10314
+ });
10315
+ }
10316
+ }
10210
10317
  };
10211
10318
  }
10212
10319
 
@@ -10278,8 +10385,10 @@ function AutocompleteInner(props, ref) {
10278
10385
  reset: resetCombobox
10279
10386
  } = downshift.useCombobox(comboBoxProps);
10280
10387
  react.useEffect(() => {
10281
- if (anchorRef.current) {
10388
+ if (anchorRef.current && isOpen) {
10282
10389
  setAnchorEl(anchorRef.current);
10390
+ } else {
10391
+ setAnchorEl(null);
10283
10392
  }
10284
10393
 
10285
10394
  if (isControlled) {
@@ -10290,7 +10399,16 @@ function AutocompleteInner(props, ref) {
10290
10399
  setAnchorEl(null);
10291
10400
  setContainerEl(null);
10292
10401
  };
10293
- }, [anchorRef, isControlled, isOpen, selectedOptions, setSelectedItems]);
10402
+ }, [anchorRef, isControlled, isOpen, selectedOptions, setSelectedItems]); //"Turn on" popper on load to position menu correctly and then turn it off
10403
+
10404
+ react.useEffect(() => {
10405
+ if (anchorRef.current) {
10406
+ setAnchorEl(anchorRef.current);
10407
+ setTimeout(() => {
10408
+ setAnchorEl(null);
10409
+ }, 1);
10410
+ }
10411
+ }, []);
10294
10412
  const {
10295
10413
  styles,
10296
10414
  attributes
@@ -3,9 +3,10 @@ import styled, { css } from 'styled-components';
3
3
  import { chevron_up, chevron_down } from '@equinor/eds-icons';
4
4
  import { Icon } from '../Icon/index.js';
5
5
  import { AccordionHeaderTitle } from './AccordionHeaderTitle.js';
6
+ import { AccordionHeaderActions } from './AccordionHeaderActions.js';
6
7
  import { accordion } from './Accordion.tokens.js';
7
- import { typographyTemplate, bordersTemplate, spacingsTemplate, outlineTemplate } from '@equinor/eds-utils';
8
- import { jsx } from 'react/jsx-runtime';
8
+ import { bordersTemplate, typographyTemplate, spacingsTemplate, outlineTemplate } from '@equinor/eds-utils';
9
+ import { jsx, jsxs } from 'react/jsx-runtime';
9
10
 
10
11
  const {
11
12
  entities: {
@@ -15,13 +16,37 @@ const {
15
16
  const StyledAccordionHeader = styled.div.withConfig({
16
17
  displayName: "AccordionHeader__StyledAccordionHeader",
17
18
  componentId: "sc-cu2e95-0"
18
- })(["margin:0;padding:0;"]);
19
- const StyledAccordionHeaderButton = styled.button.attrs(_ref => {
19
+ })(_ref => {
20
+ let {
21
+ theme,
22
+ disabled,
23
+ parentIndex
24
+ } = _ref;
25
+ const {
26
+ entities: {
27
+ header
28
+ },
29
+ border
30
+ } = theme;
31
+ return css(["margin:0;padding:0;height:", ";box-sizing:border-box;display:flex;flex-wrap:nowrap;justify-content:space-between;background-color:", ";", " border-top:", ";", ""], header.height, header.background, bordersTemplate(border), parentIndex === 0 ? null : 'none', disabled ? css({
32
+ color: header.states.disabled.typography.color,
33
+ cursor: 'not-allowed'
34
+ }) : css({
35
+ color: header.typography.color,
36
+ cursor: 'pointer',
37
+ '@media (hover: hover) and (pointer: fine)': {
38
+ ':hover': {
39
+ background: header.states.hover.background
40
+ }
41
+ }
42
+ }));
43
+ });
44
+ const StyledAccordionHeaderButton = styled.button.attrs(_ref2 => {
20
45
  let {
21
46
  panelId,
22
47
  isExpanded,
23
48
  disabled
24
- } = _ref;
49
+ } = _ref2;
25
50
  return {
26
51
  'aria-expanded': isExpanded,
27
52
  'aria-controls': panelId,
@@ -32,46 +57,39 @@ const StyledAccordionHeaderButton = styled.button.attrs(_ref => {
32
57
  }).withConfig({
33
58
  displayName: "AccordionHeader__StyledAccordionHeaderButton",
34
59
  componentId: "sc-cu2e95-1"
35
- })(_ref2 => {
60
+ })(_ref3 => {
36
61
  let {
37
62
  theme,
38
- disabled,
39
- parentIndex
40
- } = _ref2;
63
+ disabled
64
+ } = _ref3;
41
65
  const {
42
66
  entities: {
43
67
  header,
44
68
  icon: iconToken
45
- },
46
- border
69
+ }
47
70
  } = theme;
48
- return css(["", " ", " ", " &[data-focus-visible-added]:focus{", "}&:focus-visible{", "}border-top:", ";width:100%;background:", ";height:", ";margin:0;display:flex;align-items:center;box-sizing:border-box;", " > svg{color:", ";}"], typographyTemplate(header.typography), bordersTemplate(border), spacingsTemplate(header.spacings), outlineTemplate(header.states.focus.outline), outlineTemplate(header.states.focus.outline), parentIndex === 0 ? null : 'none', header.background, header.height, disabled ? css({
71
+ return css(["", " ", " &[data-focus-visible-added]:focus{", "}&:focus-visible{", "}border:0;background-color:transparent;margin:0;display:flex;align-items:center;flex-grow:1;", " > svg{color:", ";}"], typographyTemplate(header.typography), spacingsTemplate(header.spacings), outlineTemplate(header.states.focus.outline), outlineTemplate(header.states.focus.outline), disabled ? css({
49
72
  color: header.states.disabled.typography.color,
50
73
  cursor: 'not-allowed'
51
74
  }) : css({
52
75
  color: header.typography.color,
53
- cursor: 'pointer',
54
- '@media (hover: hover) and (pointer: fine)': {
55
- ':hover': {
56
- background: header.states.hover.background
57
- }
58
- }
76
+ cursor: 'pointer'
59
77
  }), iconToken.typography.color);
60
78
  });
61
79
  const StyledIcon = styled(Icon).withConfig({
62
80
  displayName: "AccordionHeader__StyledIcon",
63
81
  componentId: "sc-cu2e95-2"
64
- })(_ref3 => {
82
+ })(_ref4 => {
65
83
  let {
66
84
  chevronPosition
67
- } = _ref3;
85
+ } = _ref4;
68
86
  return chevronPosition === 'left' ? {
69
87
  marginRight: '32px'
70
88
  } : {
71
89
  marginLeft: '16px'
72
90
  };
73
91
  });
74
- const AccordionHeader = /*#__PURE__*/forwardRef(function AccordionHeader(_ref4, ref) {
92
+ const AccordionHeader = /*#__PURE__*/forwardRef(function AccordionHeader(_ref5, ref) {
75
93
  let {
76
94
  parentIndex,
77
95
  headerLevel,
@@ -83,7 +101,7 @@ const AccordionHeader = /*#__PURE__*/forwardRef(function AccordionHeader(_ref4,
83
101
  toggleExpanded,
84
102
  disabled,
85
103
  ...props
86
- } = _ref4;
104
+ } = _ref5;
87
105
 
88
106
  const handleClick = () => {
89
107
  if (!disabled) {
@@ -134,14 +152,27 @@ const AccordionHeader = /*#__PURE__*/forwardRef(function AccordionHeader(_ref4,
134
152
  });
135
153
  }
136
154
 
155
+ if (child.type === AccordionHeaderActions) {
156
+ return;
157
+ }
158
+
137
159
  return child;
138
160
  });
161
+ const headerActions = Children.map(children, child => {
162
+ if ( /*#__PURE__*/isValidElement(child) && child.type === AccordionHeaderActions) {
163
+ return /*#__PURE__*/cloneElement(child, {
164
+ isExpanded,
165
+ disabled
166
+ });
167
+ }
168
+ });
139
169
  const newChildren = [chevron, headerChildren];
140
- return /*#__PURE__*/jsx(StyledAccordionHeader, {
170
+ return /*#__PURE__*/jsxs(StyledAccordionHeader, {
171
+ disabled: disabled,
172
+ parentIndex: parentIndex,
141
173
  as: headerLevel,
142
- children: /*#__PURE__*/jsx(StyledAccordionHeaderButton, {
174
+ children: [/*#__PURE__*/jsx(StyledAccordionHeaderButton, {
143
175
  isExpanded: isExpanded,
144
- parentIndex: parentIndex,
145
176
  disabled: disabled,
146
177
  panelId: panelId,
147
178
  onClick: handleClick,
@@ -149,8 +180,8 @@ const AccordionHeader = /*#__PURE__*/forwardRef(function AccordionHeader(_ref4,
149
180
  ref: ref,
150
181
  ...props,
151
182
  children: chevronPosition === 'left' ? newChildren : newChildren.reverse()
152
- })
183
+ }), headerActions && headerActions]
153
184
  });
154
- }); // AccordionHeader.displayName = 'EdsAccordionHeader'
185
+ });
155
186
 
156
187
  export { AccordionHeader };
@@ -0,0 +1,43 @@
1
+ import { forwardRef } from 'react';
2
+ import styled, { css } from 'styled-components';
3
+ import { jsx } from 'react/jsx-runtime';
4
+
5
+ const StyledAccordionHeaderActions = styled.span.withConfig({
6
+ displayName: "AccordionHeaderActions__StyledAccordionHeaderActions",
7
+ componentId: "sc-klu9el-0"
8
+ })(_ref => {
9
+ var _header$states$active;
10
+
11
+ let {
12
+ theme,
13
+ isExpanded,
14
+ disabled
15
+ } = _ref;
16
+ const {
17
+ entities: {
18
+ header
19
+ }
20
+ } = theme;
21
+ return css(["display:flex;align-items:center;justify-content:flex-end;padding-right:", ";", " color:", ";"], header.spacings.right, disabled ? css({
22
+ color: header.states.disabled.typography.color,
23
+ cursor: 'not-allowed'
24
+ }) : css({
25
+ color: header.typography.color,
26
+ cursor: 'pointer'
27
+ }), isExpanded && !disabled ? (_header$states$active = header.states.active.typography) === null || _header$states$active === void 0 ? void 0 : _header$states$active.color : 'inherit');
28
+ });
29
+ const AccordionHeaderActions = /*#__PURE__*/forwardRef(function AccordionHeaderActions(_ref2, ref) {
30
+ let {
31
+ isExpanded,
32
+ disabled,
33
+ children
34
+ } = _ref2;
35
+ return /*#__PURE__*/jsx(StyledAccordionHeaderActions, {
36
+ ref: ref,
37
+ isExpanded: isExpanded,
38
+ disabled: disabled,
39
+ children: children
40
+ });
41
+ });
42
+
43
+ export { AccordionHeaderActions };
@@ -6,14 +6,19 @@ const StyledAccordionHeaderTitle = styled.span.withConfig({
6
6
  displayName: "AccordionHeaderTitle__StyledAccordionHeaderTitle",
7
7
  componentId: "sc-g27uve-0"
8
8
  })(_ref => {
9
- var _theme$entities$heade;
9
+ var _header$states$active;
10
10
 
11
11
  let {
12
12
  theme,
13
13
  isExpanded,
14
14
  disabled
15
15
  } = _ref;
16
- return css(["flex:1;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;text-align:left;font-family:Equinor;color:", ";"], isExpanded && !disabled ? (_theme$entities$heade = theme.entities.header.states.active.typography) === null || _theme$entities$heade === void 0 ? void 0 : _theme$entities$heade.color : 'inherit');
16
+ const {
17
+ entities: {
18
+ header
19
+ }
20
+ } = theme;
21
+ return css(["display:-webkit-box;-webkit-line-clamp:1;-webkit-box-orient:vertical;flex-grow:1;overflow:hidden;text-align:left;color:", ";"], isExpanded && !disabled ? (_header$states$active = header.states.active.typography) === null || _header$states$active === void 0 ? void 0 : _header$states$active.color : 'inherit');
17
22
  });
18
23
  const AccordionHeaderTitle = /*#__PURE__*/forwardRef(function AccordionHeaderTitle(_ref2, ref) {
19
24
  let {
@@ -2,16 +2,19 @@ import { Accordion as Accordion$1 } from './Accordion.js';
2
2
  import { AccordionItem } from './AccordionItem.js';
3
3
  import { AccordionHeader } from './AccordionHeader.js';
4
4
  import { AccordionHeaderTitle } from './AccordionHeaderTitle.js';
5
+ import { AccordionHeaderActions } from './AccordionHeaderActions.js';
5
6
  import { AccordionPanel } from './AccordionPanel.js';
6
7
 
7
8
  const Accordion = Accordion$1;
8
9
  Accordion.Item = AccordionItem;
9
10
  Accordion.Header = AccordionHeader;
10
11
  Accordion.HeaderTitle = AccordionHeaderTitle;
12
+ Accordion.HeaderActions = AccordionHeaderActions;
11
13
  Accordion.Panel = AccordionPanel;
12
14
  Accordion.Item.displayName = 'Accordion.Item';
13
15
  Accordion.Header.displayName = 'Accordion.Header';
14
16
  Accordion.HeaderTitle.displayName = 'Accordion.HeaderTitle';
17
+ Accordion.HeaderActions.displayName = 'Accordion.HeaderActions';
15
18
  Accordion.Panel.displayName = 'Accordion.Panel';
16
19
 
17
20
  export { Accordion };
@@ -1,4 +1,4 @@
1
- import { forwardRef, useRef, useState, useMemo, useCallback, useEffect } from 'react';
1
+ import { forwardRef, useRef, useState, useEffect, useMemo, useCallback } from 'react';
2
2
  import { createPortal } from 'react-dom';
3
3
  import { useMultipleSelection, useCombobox } from 'downshift';
4
4
  import styled, { css, ThemeProvider } from 'styled-components';
@@ -38,7 +38,7 @@ const StyledList = styled(List).withConfig({
38
38
  let {
39
39
  theme
40
40
  } = _ref2;
41
- return css(["background-color:", ";box-shadow:", ";", " overflow-y:auto;max-height:300px;padding:0;position:absolute;right:0;left:0;z-index:50;"], theme.background, theme.boxShadow, bordersTemplate(theme.border));
41
+ return css(["background-color:", ";box-shadow:", ";", " overflow-y:auto;max-height:300px;padding:0;position:absolute;right:0;left:0;z-index:1400;"], theme.background, theme.boxShadow, bordersTemplate(theme.border));
42
42
  });
43
43
  const StyledButton = styled(Button).withConfig({
44
44
  displayName: "Autocomplete__StyledButton",
@@ -149,7 +149,19 @@ function AutocompleteInner(props, ref) {
149
149
  const [containerEl, setContainerEl] = useState();
150
150
  const isMounted = useIsMounted();
151
151
  const isControlled = Boolean(selectedOptions);
152
- const [availableItems, setAvailableItems] = useState(options);
152
+ const [inputOptions, setInputOptions] = useState(options);
153
+ useEffect(() => {
154
+ const availableHash = JSON.stringify(inputOptions);
155
+ const optionsHash = JSON.stringify(options);
156
+
157
+ if (availableHash !== optionsHash) {
158
+ setInputOptions(options);
159
+ }
160
+ }, [options, inputOptions]);
161
+ useEffect(() => {
162
+ setAvailableItems(inputOptions);
163
+ }, [inputOptions]);
164
+ const [availableItems, setAvailableItems] = useState(inputOptions);
153
165
  const disabledItems = useMemo(() => options.filter(optionDisabled), [options, optionDisabled]);
154
166
  const {
155
167
  density
@@ -159,18 +171,28 @@ function AutocompleteInner(props, ref) {
159
171
  }, multiple ? multiSelect : selectTokens);
160
172
  let placeholderText = placeholder;
161
173
  let multipleSelectionProps = {
162
- initialSelectedItems: multiple ? initialSelectedOptions : initialSelectedOptions[0] ? [initialSelectedOptions[0]] : [],
163
- onSelectedItemsChange: changes => {
164
- if (onOptionsChange) {
165
- onOptionsChange(changes);
166
- }
167
- }
174
+ initialSelectedItems: multiple ? initialSelectedOptions : initialSelectedOptions[0] ? [initialSelectedOptions[0]] : []
168
175
  };
169
176
 
170
- if (isControlled) {
177
+ if (multiple) {
171
178
  multipleSelectionProps = { ...multipleSelectionProps,
172
- selectedItems: selectedOptions
179
+ onSelectedItemsChange: changes => {
180
+ if (onOptionsChange) {
181
+ const {
182
+ selectedItems
183
+ } = changes;
184
+ onOptionsChange({
185
+ selectedItems
186
+ });
187
+ }
188
+ }
173
189
  };
190
+
191
+ if (isControlled) {
192
+ multipleSelectionProps = { ...multipleSelectionProps,
193
+ selectedItems: selectedOptions
194
+ };
195
+ }
174
196
  }
175
197
 
176
198
  const {
@@ -289,7 +311,17 @@ function AutocompleteInner(props, ref) {
289
311
 
290
312
  if (isControlled && !multiple) {
291
313
  comboBoxProps = { ...comboBoxProps,
292
- selectedItem: selectedOptions[0]
314
+ selectedItem: selectedOptions[0] || null,
315
+ onSelectedItemChange: changes => {
316
+ if (onOptionsChange) {
317
+ const {
318
+ selectedItem
319
+ } = changes;
320
+ onOptionsChange({
321
+ selectedItems: [selectedItem]
322
+ });
323
+ }
324
+ }
293
325
  };
294
326
  }
295
327
 
@@ -361,8 +393,10 @@ function AutocompleteInner(props, ref) {
361
393
  reset: resetCombobox
362
394
  } = useCombobox(comboBoxProps);
363
395
  useEffect(() => {
364
- if (anchorRef.current) {
396
+ if (anchorRef.current && isOpen) {
365
397
  setAnchorEl(anchorRef.current);
398
+ } else {
399
+ setAnchorEl(null);
366
400
  }
367
401
 
368
402
  if (isControlled) {
@@ -373,7 +407,16 @@ function AutocompleteInner(props, ref) {
373
407
  setAnchorEl(null);
374
408
  setContainerEl(null);
375
409
  };
376
- }, [anchorRef, isControlled, isOpen, selectedOptions, setSelectedItems]);
410
+ }, [anchorRef, isControlled, isOpen, selectedOptions, setSelectedItems]); //"Turn on" popper on load to position menu correctly and then turn it off
411
+
412
+ useEffect(() => {
413
+ if (anchorRef.current) {
414
+ setAnchorEl(anchorRef.current);
415
+ setTimeout(() => {
416
+ setAnchorEl(null);
417
+ }, 1);
418
+ }
419
+ }, []);
377
420
  const {
378
421
  styles,
379
422
  attributes
@@ -0,0 +1,14 @@
1
+ import { HTMLAttributes } from 'react';
2
+ export declare type AccordionHeaderActionsProps = {
3
+ /** Is AccordionItem expanded */
4
+ isExpanded?: boolean;
5
+ /** Accordion item is disabled */
6
+ disabled?: boolean;
7
+ } & HTMLAttributes<HTMLSpanElement>;
8
+ declare const AccordionHeaderActions: import("react").ForwardRefExoticComponent<{
9
+ /** Is AccordionItem expanded */
10
+ isExpanded?: boolean;
11
+ /** Accordion item is disabled */
12
+ disabled?: boolean;
13
+ } & HTMLAttributes<HTMLSpanElement> & import("react").RefAttributes<HTMLSpanElement>>;
14
+ export { AccordionHeaderActions };
@@ -2,14 +2,16 @@ import { Accordion as BaseAccordion } from './Accordion';
2
2
  import { AccordionItem, AccordionItemProps } from './AccordionItem';
3
3
  import { AccordionHeader, AccordionHeaderProps } from './AccordionHeader';
4
4
  import { AccordionHeaderTitle, AccordionHeaderTitleProps } from './AccordionHeaderTitle';
5
+ import { AccordionHeaderActions, AccordionHeaderActionsProps } from './AccordionHeaderActions';
5
6
  import { AccordionPanel, AccordionPanelProps } from './AccordionPanel';
6
7
  import type { AccordionProps } from './Accordion.types';
7
8
  declare type AccordionCompoundProps = typeof BaseAccordion & {
8
9
  Item: typeof AccordionItem;
9
10
  Header: typeof AccordionHeader;
10
11
  HeaderTitle: typeof AccordionHeaderTitle;
12
+ HeaderActions: typeof AccordionHeaderActions;
11
13
  Panel: typeof AccordionPanel;
12
14
  };
13
15
  declare const Accordion: AccordionCompoundProps;
14
16
  export { Accordion };
15
- export type { AccordionProps, AccordionPanelProps, AccordionHeaderProps, AccordionHeaderTitleProps, AccordionItemProps, };
17
+ export type { AccordionProps, AccordionPanelProps, AccordionHeaderProps, AccordionHeaderTitleProps, AccordionHeaderActionsProps, AccordionItemProps, };
@@ -1,6 +1,7 @@
1
1
  import { HTMLAttributes } from 'react';
2
- import { UseMultipleSelectionProps } from 'downshift';
3
- export declare type AutocompleteChanges<T> = UseMultipleSelectionProps<T>;
2
+ export declare type AutocompleteChanges<T> = {
3
+ selectedItems: T[];
4
+ };
4
5
  export declare type AutocompleteProps<T> = {
5
6
  /** List of options to choose from */
6
7
  options: T[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/eds-core-react",
3
- "version": "0.20.1",
3
+ "version": "0.20.2-dev.20220616",
4
4
  "description": "The React implementation of the Equinor Design System",
5
5
  "sideEffects": [
6
6
  "**/*.css"
@@ -86,8 +86,8 @@
86
86
  },
87
87
  "dependencies": {
88
88
  "@babel/runtime": "^7.17.9",
89
- "@equinor/eds-icons": "0.10.0-dev.202205096",
90
- "@equinor/eds-tokens": "0.7.0-dev.202205096",
89
+ "@equinor/eds-icons": "0.11.0",
90
+ "@equinor/eds-tokens": "0.7.1",
91
91
  "@equinor/eds-utils": "0.2.2",
92
92
  "@popperjs/core": "2.9.2",
93
93
  "downshift": "^6.1.7",