@zextras/carbonio-design-system 3.0.0 → 3.0.1-devel.1696932777043

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/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [3.0.1](https://github.com/Zextras/carbonio-design-system/compare/v3.0.0...v3.0.1) (2023-09-29)
6
+
5
7
  ## [3.0.0](https://github.com/Zextras/carbonio-design-system/compare/v2.3.0...v3.0.0) (2023-09-27)
6
8
 
7
9
 
@@ -875,7 +875,7 @@ export declare interface DropdownProps extends Omit<HTMLAttributes<HTMLDivElemen
875
875
  /** Only one component can be passed as children */
876
876
  children: React_2.ReactElement;
877
877
  /** trigger ref that can be used instead of lost children ref caused by cloneElement */
878
- triggerRef?: React_2.Ref<HTMLElement> | null;
878
+ triggerRef?: React_2.Ref<HTMLElement>;
879
879
  /** Placement of the dropdown */
880
880
  placement?: 'auto' | 'auto-start' | 'auto-end' | 'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'right' | 'right-start' | 'right-end' | 'left' | 'left-start' | 'left-end';
881
881
  /** Flag to disable the Portal implementation */
@@ -893,7 +893,7 @@ export declare interface DropdownProps extends Omit<HTMLAttributes<HTMLDivElemen
893
893
  /** Item Padding Between */
894
894
  itemPaddingBetween?: keyof DefaultTheme['sizes']['padding'];
895
895
  /** Ref assign to the dropdown list popper container */
896
- dropdownListRef?: React_2.RefObject<HTMLDivElement> | null;
896
+ dropdownListRef?: React_2.RefObject<HTMLDivElement>;
897
897
  }
898
898
 
899
899
  export declare interface DropProps {
@@ -925,6 +925,8 @@ export declare interface DSWindow {
925
925
  };
926
926
  }
927
927
 
928
+ declare type ElementType = 'listItem' | 'button' | 'list' | 'chipInputKeys' | 'chipInputSpace';
929
+
928
930
  export declare const EmailComposerInput: React_2.ForwardRefExoticComponent<EmailComposerInputProps & React_2.RefAttributes<HTMLDivElement>>;
929
931
 
930
932
  export declare interface EmailComposerInputProps extends HTMLAttributes<HTMLDivElement> {
@@ -1004,13 +1006,7 @@ export declare function generateHighlightSet(fromColorSet: Parameters<typeof gen
1004
1006
 
1005
1007
  export { getDefaultLocale }
1006
1008
 
1007
- export declare function getKeyboardPreset(type: 'listItem', callback: NativeKeyboardEventHandler, ref?: undefined, keys?: undefined, modifier?: boolean): KeyboardPreset;
1008
-
1009
- export declare function getKeyboardPreset(type: 'button', callback: NativeKeyboardEventHandler, ref?: undefined, keys?: undefined, modifier?: boolean): KeyboardPreset;
1010
-
1011
- export declare function getKeyboardPreset(type: 'list', callback: undefined, ref: React_2.RefObject<HTMLElement>, keys?: undefined, modifier?: boolean): KeyboardPreset;
1012
-
1013
- export declare function getKeyboardPreset(type: 'chipInputKeys', callback: NativeKeyboardEventHandler, ref?: undefined, keys?: string[], modifier?: boolean): KeyboardPreset;
1009
+ export declare function getKeyboardPreset(type: ElementType, callback: (e: KeyboardEvent) => void, ref?: React_2.MutableRefObject<HTMLElement | null> | undefined, keys?: string[], modifier?: boolean): KeyboardPreset;
1014
1010
 
1015
1011
  declare function getPadding(padding: PaddingStringComposition | PaddingObj): (args: {
1016
1012
  theme: DefaultTheme;
@@ -1194,7 +1190,7 @@ export declare function generateHighlightSet(fromColorSet: Parameters<typeof gen
1194
1190
 
1195
1191
  declare type KeyboardPresetObj = {
1196
1192
  type: HtmlElementKeyboardEventKey;
1197
- callback: NativeKeyboardEventHandler;
1193
+ callback: (e: KeyboardEvent) => void;
1198
1194
  keys: string[];
1199
1195
  modifier?: boolean;
1200
1196
  haveToPreventDefault?: boolean;
@@ -1469,8 +1465,6 @@ export declare function generateHighlightSet(fromColorSet: Parameters<typeof gen
1469
1465
 
1470
1466
  export declare type MultipleSelectionOnChange<T = string> = (value: Array<SelectItem<T>>) => void;
1471
1467
 
1472
- declare type NativeKeyboardEventHandler = (event: KeyboardEvent) => void;
1473
-
1474
1468
  declare type NonEmptyArray<T> = [T, ...T[]];
1475
1469
 
1476
1470
  declare type Options = {
@@ -2211,7 +2205,7 @@ export declare function generateHighlightSet(fromColorSet: Parameters<typeof gen
2211
2205
  * In order to have an event for no key, you should either provide an event with the `keys` field set
2212
2206
  * to an array with an empty key (`['']`), or not provide an event at all.
2213
2207
  */
2214
- export declare function useKeyboard(ref: React_2.RefObject<HTMLElement>, events: KeyboardPreset, registerListener?: boolean): void;
2208
+ export declare function useKeyboard(ref: React_2.RefObject<HTMLElement>, events: KeyboardPreset): void;
2215
2209
 
2216
2210
  export declare function useModal(): CreateModalFn;
2217
2211
 
@@ -7009,27 +7009,6 @@ const Spinner = /*#__PURE__*/React__namespace.default.forwardRef(function Spinne
7009
7009
  }, rest));
7010
7010
  });
7011
7011
 
7012
- /**
7013
- * This method returns `undefined`.
7014
- *
7015
- * @static
7016
- * @memberOf _
7017
- * @since 2.3.0
7018
- * @category Util
7019
- * @example
7020
- *
7021
- * _.times(2, _.noop);
7022
- * // => [undefined, undefined]
7023
- */
7024
-
7025
- function noop$1() {
7026
- // No operation performed.
7027
- }
7028
-
7029
- var noop_1 = noop$1;
7030
-
7031
- var _noop = /*@__PURE__*/getDefaultExportFromCjs(noop_1);
7032
-
7033
7012
  /**
7034
7013
  * A specialized version of `_.forEach` for arrays without support for
7035
7014
  * iteratee shorthands.
@@ -7194,167 +7173,176 @@ var _map = /*@__PURE__*/getDefaultExportFromCjs(map_1);
7194
7173
 
7195
7174
  function getFocusableElement(focusedElement, direction) {
7196
7175
  const siblingElement = focusedElement[direction];
7197
- if (!(siblingElement instanceof HTMLElement)) {
7176
+ if (!siblingElement) {
7198
7177
  return null;
7199
7178
  }
7200
7179
  if (siblingElement.tabIndex >= 0) {
7201
- return siblingElement;
7180
+ return focusedElement[direction];
7202
7181
  }
7203
7182
  return getFocusableElement(siblingElement, direction);
7204
7183
  }
7205
- function handleArrowUp(ref) {
7206
- if (ref?.current) {
7207
- const focusedElement = ref.current.querySelector('[tabindex]:focus');
7208
- if (focusedElement) {
7209
- const prevEl = getFocusableElement(focusedElement, 'previousElementSibling');
7210
- if (prevEl) {
7211
- prevEl.focus();
7184
+ function getKeyboardPreset(type, callback) {
7185
+ let ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
7186
+ let keys = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
7187
+ let modifier = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
7188
+ function handleArrowUp() {
7189
+ if (ref?.current) {
7190
+ const focusedElement = ref.current.querySelector('[tabindex]:focus');
7191
+ if (focusedElement) {
7192
+ const prevEl = getFocusableElement(focusedElement, 'previousElementSibling');
7193
+ if (prevEl) {
7194
+ prevEl.focus();
7195
+ } else {
7196
+ const lastChild = ref.current.querySelector('[tabindex]:last-child');
7197
+ lastChild && lastChild.focus();
7198
+ }
7212
7199
  } else {
7213
- const lastChild = ref.current.querySelector('[tabindex]:last-child');
7214
- lastChild && lastChild.focus();
7200
+ const firstChild = ref.current.querySelector('[tabindex]:first-child');
7201
+ firstChild && firstChild.focus();
7215
7202
  }
7216
- } else {
7217
- const firstChild = ref.current.querySelector('[tabindex]:first-child');
7218
- firstChild && firstChild.focus();
7219
7203
  }
7220
7204
  }
7221
- }
7222
- function handleArrowDown(ref) {
7223
- if (ref?.current) {
7224
- const focusedElement = ref.current.querySelector('[tabindex]:focus');
7225
- if (focusedElement) {
7226
- const nextEl = getFocusableElement(focusedElement, 'nextElementSibling');
7227
- if (nextEl) {
7228
- nextEl.focus();
7205
+ function handleArrowDown() {
7206
+ if (ref?.current) {
7207
+ const focusedElement = ref.current.querySelector('[tabindex]:focus');
7208
+ if (focusedElement) {
7209
+ const nextEl = getFocusableElement(focusedElement, 'nextElementSibling');
7210
+ if (nextEl) {
7211
+ nextEl.focus();
7212
+ } else {
7213
+ const firstChild = ref.current.querySelector('[tabindex]:first-child');
7214
+ firstChild && firstChild.focus();
7215
+ }
7229
7216
  } else {
7230
7217
  const firstChild = ref.current.querySelector('[tabindex]:first-child');
7231
7218
  firstChild && firstChild.focus();
7232
7219
  }
7233
- } else {
7234
- const firstChild = ref.current.querySelector('[tabindex]:first-child');
7235
- firstChild && firstChild.focus();
7236
7220
  }
7237
7221
  }
7238
- }
7239
- function handleEscape(ref) {
7240
- if (ref?.current) {
7241
- const focusedElement = ref.current.querySelector('[tabindex]:focus');
7242
- if (focusedElement) {
7243
- focusedElement.blur();
7222
+ function handleEscape() {
7223
+ if (ref?.current) {
7224
+ const focusedElement = ref.current.querySelector('[tabindex]:focus');
7225
+ if (focusedElement) {
7226
+ focusedElement.blur();
7227
+ }
7244
7228
  }
7245
7229
  }
7246
- }
7247
- const findFirstChildWithClick = element => {
7248
- let result = element;
7249
- while (!result?.onclick && result !== null) {
7250
- result = result.firstElementChild;
7251
- }
7252
- return result;
7253
- };
7254
- const handleEnter = ref => {
7255
- if (ref?.current) {
7256
- const focusedElement = ref.current.querySelector('[tabindex]:focus');
7257
- if (focusedElement) {
7258
- const firstChild = findFirstChildWithClick(focusedElement);
7259
- if (firstChild) {
7260
- firstChild.click();
7230
+ const findFirstChildWithClick = element => {
7231
+ let result = element;
7232
+ while (!result?.onclick && result !== null) {
7233
+ result = result.firstElementChild;
7234
+ }
7235
+ return result;
7236
+ };
7237
+ const handleEnter = () => {
7238
+ if (ref?.current) {
7239
+ const focusedElement = ref.current.querySelector('[tabindex]:focus');
7240
+ if (focusedElement) {
7241
+ const firstChild = findFirstChildWithClick(focusedElement);
7242
+ if (firstChild) {
7243
+ firstChild.click();
7244
+ }
7261
7245
  }
7262
7246
  }
7247
+ };
7248
+ function handleCtrlArrowUp() {
7249
+ if (ref?.current) {
7250
+ const firstChild = ref.current.querySelector('[tabindex]:first-child');
7251
+ firstChild && firstChild.focus();
7252
+ }
7263
7253
  }
7264
- };
7265
- function handleCtrlArrowUp(ref) {
7266
- if (ref?.current) {
7267
- const firstChild = ref.current.querySelector('[tabindex]:first-child');
7268
- firstChild && firstChild.focus();
7269
- }
7270
- }
7271
- function handleCtrlArrowDown(ref) {
7272
- if (ref?.current) {
7273
- const lastChild = ref.current.querySelector('[tabindex]:last-child');
7274
- lastChild && lastChild.focus();
7254
+ function handleCtrlArrowDown() {
7255
+ if (ref?.current) {
7256
+ const lastChild = ref.current.querySelector('[tabindex]:last-child');
7257
+ lastChild && lastChild.focus();
7258
+ }
7275
7259
  }
7276
- }
7277
- function getListItemKeyboardPreset(callback, modifier) {
7278
- return [{
7279
- type: 'keypress',
7280
- callback,
7281
- keys: ['Enter', 'NumpadEnter'],
7282
- modifier
7283
- }];
7284
- }
7285
- function getButtonKeyboardPreset(callback, modifier) {
7286
- return [{
7287
- type: 'keyup',
7288
- callback,
7289
- keys: ['Space'],
7290
- modifier
7291
- }, {
7292
- type: 'keypress',
7293
- callback: e => e.preventDefault(),
7294
- keys: ['Space'],
7295
- modifier
7296
- }, {
7297
- type: 'keypress',
7298
- callback,
7299
- keys: ['Enter', 'NumpadEnter'],
7300
- modifier
7301
- }];
7302
- }
7303
- function getListKeyboardPreset(ref, modifier) {
7304
- return [{
7305
- type: 'keydown',
7306
- callback: () => handleArrowUp(ref),
7307
- keys: ['ArrowUp'],
7308
- modifier
7309
- }, {
7310
- type: 'keydown',
7311
- callback: () => handleArrowDown(ref),
7312
- keys: ['ArrowDown'],
7313
- modifier
7314
- }, {
7315
- type: 'keydown',
7316
- callback: () => handleCtrlArrowUp(ref),
7317
- keys: ['ArrowUp'],
7318
- modifier: true
7319
- }, {
7320
- type: 'keydown',
7321
- callback: () => handleCtrlArrowDown(ref),
7322
- keys: ['ArrowDown'],
7323
- modifier: true
7324
- }, {
7325
- type: 'keydown',
7326
- callback: () => handleEscape(ref),
7327
- keys: ['Escape'],
7328
- modifier
7329
- }, {
7330
- type: 'keydown',
7331
- callback: () => handleEnter(ref),
7332
- keys: ['Enter', 'NumpadEnter'],
7333
- modifier
7334
- }];
7335
- }
7336
- function getKeyboardPreset(type) {
7337
- let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _noop;
7338
- let ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
7339
- let keys = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
7340
- let modifier = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
7260
+ const eventsArray = [];
7341
7261
  switch (type) {
7342
7262
  case 'listItem':
7343
- return getListItemKeyboardPreset(callback, modifier);
7263
+ {
7264
+ eventsArray.push({
7265
+ type: 'keypress',
7266
+ callback,
7267
+ keys: ['Enter', 'NumpadEnter'],
7268
+ modifier
7269
+ });
7270
+ break;
7271
+ }
7344
7272
  case 'button':
7345
- return getButtonKeyboardPreset(callback, modifier);
7273
+ {
7274
+ eventsArray.push({
7275
+ type: 'keyup',
7276
+ callback,
7277
+ keys: ['Space'],
7278
+ modifier
7279
+ });
7280
+ eventsArray.push({
7281
+ type: 'keypress',
7282
+ callback: e => e.preventDefault(),
7283
+ keys: ['Space'],
7284
+ modifier
7285
+ });
7286
+ eventsArray.push({
7287
+ type: 'keypress',
7288
+ callback,
7289
+ keys: ['Enter', 'NumpadEnter'],
7290
+ modifier
7291
+ });
7292
+ break;
7293
+ }
7346
7294
  case 'list':
7347
- return getListKeyboardPreset(ref, modifier);
7295
+ {
7296
+ eventsArray.push({
7297
+ type: 'keydown',
7298
+ callback: handleArrowUp,
7299
+ keys: ['ArrowUp'],
7300
+ modifier
7301
+ });
7302
+ eventsArray.push({
7303
+ type: 'keydown',
7304
+ callback: handleArrowDown,
7305
+ keys: ['ArrowDown'],
7306
+ modifier
7307
+ });
7308
+ eventsArray.push({
7309
+ type: 'keydown',
7310
+ callback: handleCtrlArrowUp,
7311
+ keys: ['ArrowUp'],
7312
+ modifier: true
7313
+ });
7314
+ eventsArray.push({
7315
+ type: 'keydown',
7316
+ callback: handleCtrlArrowDown,
7317
+ keys: ['ArrowDown'],
7318
+ modifier: true
7319
+ });
7320
+ eventsArray.push({
7321
+ type: 'keydown',
7322
+ callback: handleEscape,
7323
+ keys: ['Escape'],
7324
+ modifier
7325
+ });
7326
+ eventsArray.push({
7327
+ type: 'keydown',
7328
+ callback: handleEnter,
7329
+ keys: ['Enter', 'NumpadEnter'],
7330
+ modifier
7331
+ });
7332
+ break;
7333
+ }
7348
7334
  case 'chipInputKeys':
7349
- return [{
7350
- type: 'keypress',
7351
- callback,
7352
- keys,
7353
- modifier
7354
- }];
7355
- default:
7356
- return [];
7335
+ {
7336
+ eventsArray.push({
7337
+ type: 'keypress',
7338
+ callback,
7339
+ keys,
7340
+ modifier
7341
+ });
7342
+ break;
7343
+ }
7357
7344
  }
7345
+ return eventsArray;
7358
7346
  }
7359
7347
 
7360
7348
  /**
@@ -7365,7 +7353,6 @@ function getKeyboardPreset(type) {
7365
7353
  * to an array with an empty key (`['']`), or not provide an event at all.
7366
7354
  */
7367
7355
  function useKeyboard(ref, events) {
7368
- let registerListener = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
7369
7356
  const keyEvents = React.useMemo(() => _map(events, _ref => {
7370
7357
  let {
7371
7358
  keys,
@@ -7383,12 +7370,12 @@ function useKeyboard(ref, events) {
7383
7370
  };
7384
7371
  }), [events]);
7385
7372
  React.useEffect(() => {
7386
- const refSave = ref.current;
7387
- if (refSave && registerListener) {
7373
+ if (ref.current) {
7388
7374
  _forEach(keyEvents, (keyEvent, index) => {
7389
- refSave.addEventListener(events[index].type, keyEvent);
7375
+ ref.current && ref.current.addEventListener(events[index].type, keyEvent);
7390
7376
  });
7391
7377
  }
7378
+ const refSave = ref.current;
7392
7379
  return () => {
7393
7380
  if (refSave) {
7394
7381
  _forEach(keyEvents, (keyEvent, index) => {
@@ -7396,7 +7383,8 @@ function useKeyboard(ref, events) {
7396
7383
  });
7397
7384
  }
7398
7385
  };
7399
- }, [events, keyEvents, ref, registerListener]);
7386
+ // eslint-disable-next-line react-hooks/exhaustive-deps
7387
+ }, [events, keyEvents, ref, ref.current]);
7400
7388
  }
7401
7389
 
7402
7390
  const StyledIcon = styled__default.default(Icon).withConfig({
@@ -7638,7 +7626,6 @@ const Button$1 = /*#__PURE__*/React__namespace.default.forwardRef(function Butto
7638
7626
  buttonRef = null,
7639
7627
  ...rest
7640
7628
  } = _ref22;
7641
- const gridRef = useCombinedRefs(ref);
7642
7629
  const innerButtonRef = useCombinedRefs(buttonRef);
7643
7630
  const clickHandler = React.useCallback(e => {
7644
7631
  if (!disabled && onClick && !e.defaultPrevented) {
@@ -7657,22 +7644,11 @@ const Button$1 = /*#__PURE__*/React__namespace.default.forwardRef(function Butto
7657
7644
  type,
7658
7645
  ...rest
7659
7646
  }), [type, rest]);
7660
- const setFocusOnPrimaryButton = React.useCallback(() => {
7661
- innerButtonRef.current?.focus();
7662
- }, [innerButtonRef]);
7663
- React.useEffect(() => {
7664
- const gridElement = gridRef.current;
7665
- gridElement?.addEventListener('focus', setFocusOnPrimaryButton);
7666
- return () => {
7667
- gridElement?.removeEventListener('focus', setFocusOnPrimaryButton);
7668
- };
7669
- }, [gridRef, setFocusOnPrimaryButton]);
7670
7647
  return /*#__PURE__*/React__namespace.default.createElement(StyledGrid, {
7671
7648
  width: width,
7672
7649
  minWidth: minWidth,
7673
7650
  padding: SIZES$2[size].padding,
7674
- ref: gridRef,
7675
- tabIndex: -1
7651
+ ref: ref
7676
7652
  }, /*#__PURE__*/React__namespace.default.createElement(StyledButton, _extends({}, rest, {
7677
7653
  backgroundColor: colors.backgroundColor,
7678
7654
  color: colors.color,
@@ -8509,6 +8485,27 @@ function arrayIncludesWith$1(array, value, comparator) {
8509
8485
 
8510
8486
  var _arrayIncludesWith = arrayIncludesWith$1;
8511
8487
 
8488
+ /**
8489
+ * This method returns `undefined`.
8490
+ *
8491
+ * @static
8492
+ * @memberOf _
8493
+ * @since 2.3.0
8494
+ * @category Util
8495
+ * @example
8496
+ *
8497
+ * _.times(2, _.noop);
8498
+ * // => [undefined, undefined]
8499
+ */
8500
+
8501
+ function noop$1() {
8502
+ // No operation performed.
8503
+ }
8504
+
8505
+ var noop_1 = noop$1;
8506
+
8507
+ var _noop = /*@__PURE__*/getDefaultExportFromCjs(noop_1);
8508
+
8512
8509
  var Set$1 = _Set,
8513
8510
  noop = noop_1,
8514
8511
  setToArray$1 = _setToArray;
@@ -9776,10 +9773,6 @@ function usePrevious(value) {
9776
9773
  const INPUT_BACKGROUND_COLOR = 'gray5';
9777
9774
  const INPUT_DIVIDER_COLOR = 'gray3';
9778
9775
  const TIMERS = {
9779
- DROPDOWN: {
9780
- IS_OPEN: 1,
9781
- CLOSE_NESTED: 500
9782
- },
9783
9776
  MODAL: {
9784
9777
  DELAY_OPEN: 1
9785
9778
  }
@@ -10140,37 +10133,6 @@ var some_1 = some;
10140
10133
 
10141
10134
  var _some = /*@__PURE__*/getDefaultExportFromCjs(some_1);
10142
10135
 
10143
- /**
10144
- * Gets the first element of `array`.
10145
- *
10146
- * @static
10147
- * @memberOf _
10148
- * @since 0.1.0
10149
- * @alias first
10150
- * @category Array
10151
- * @param {Array} array The array to query.
10152
- * @returns {*} Returns the first element of `array`.
10153
- * @example
10154
- *
10155
- * _.head([1, 2, 3]);
10156
- * // => 1
10157
- *
10158
- * _.head([]);
10159
- * // => undefined
10160
- */
10161
-
10162
- function head(array) {
10163
- return (array && array.length) ? array[0] : undefined;
10164
- }
10165
-
10166
- var head_1 = head;
10167
-
10168
- var _head = /*@__PURE__*/getDefaultExportFromCjs(head_1);
10169
-
10170
- var first = head_1;
10171
-
10172
- var _first = /*@__PURE__*/getDefaultExportFromCjs(first);
10173
-
10174
10136
  const ContainerEl$2 = styled__default.default(Container).withConfig({
10175
10137
  displayName: "Dropdown__ContainerEl",
10176
10138
  componentId: "sc-1jmq2vf-0"
@@ -10260,8 +10222,7 @@ function PopperListItem(_ref3) {
10260
10222
  tabIndex: disabled ? -1 : 0,
10261
10223
  $disabled: disabled,
10262
10224
  $selectedBackgroundColor: selected ? selectedBackgroundColor : undefined,
10263
- background: selected && selectedBackgroundColor ? selectedBackgroundColor : undefined,
10264
- "data-testid": 'dropdown-item'
10225
+ background: selected && selectedBackgroundColor ? selectedBackgroundColor : undefined
10265
10226
  }, rest), customComponent || /*#__PURE__*/React__namespace.default.createElement(ListItemContent, {
10266
10227
  icon: icon,
10267
10228
  label: label,
@@ -10279,6 +10240,7 @@ function NestListItem(_ref4) {
10279
10240
  label,
10280
10241
  onClick,
10281
10242
  selected,
10243
+ open,
10282
10244
  customComponent,
10283
10245
  disabled = false,
10284
10246
  items,
@@ -10287,101 +10249,13 @@ function NestListItem(_ref4) {
10287
10249
  itemTextSize,
10288
10250
  itemPaddingBetween,
10289
10251
  keepOpen,
10290
- dropdownListRef = null,
10252
+ dropdownListRef,
10291
10253
  tooltipLabel,
10292
- onOpen,
10293
- onClose,
10294
10254
  ...rest
10295
10255
  } = _ref4;
10296
- const [open, setOpen] = React.useState(false);
10297
10256
  const itemRef = React.useRef(null);
10298
- const innerDropdownListRef = useCombinedRefs(dropdownListRef);
10299
- const closeNestedDropdownTimeoutRef = React.useRef();
10300
- React.useEffect(() => () => {
10301
- if (closeNestedDropdownTimeoutRef.current !== undefined) {
10302
- clearTimeout(closeNestedDropdownTimeoutRef.current);
10303
- }
10304
- }, []);
10305
- const openNestedDropdown = React.useCallback(() => {
10306
- if (closeNestedDropdownTimeoutRef.current !== undefined) {
10307
- clearTimeout(closeNestedDropdownTimeoutRef.current);
10308
- closeNestedDropdownTimeoutRef.current = undefined;
10309
- }
10310
- setOpen(true);
10311
- onOpen?.();
10312
- }, [onOpen]);
10313
- const closeNestedDropdown = React.useCallback(() => {
10314
- if (closeNestedDropdownTimeoutRef.current !== undefined) {
10315
- clearTimeout(closeNestedDropdownTimeoutRef.current);
10316
- closeNestedDropdownTimeoutRef.current = undefined;
10317
- }
10318
- setOpen(false);
10319
- onClose?.();
10320
- itemRef.current?.focus({
10321
- preventScroll: true
10322
- });
10323
- }, [onClose]);
10324
- const itemKeyEvents = React.useMemo(() => {
10325
- const presets = [{
10326
- type: 'keydown',
10327
- callback: openNestedDropdown,
10328
- keys: ['ArrowRight']
10329
- }];
10330
- if (onClick) {
10331
- presets.push(...getKeyboardPreset('listItem', onClick));
10332
- }
10333
- return presets;
10334
- }, [onClick, openNestedDropdown]);
10335
- useKeyboard(itemRef, itemKeyEvents);
10336
- const dropdownKeyEvents = React.useMemo(() => [{
10337
- type: 'keydown',
10338
- callback: closeNestedDropdown,
10339
- keys: ['Escape']
10340
- }, {
10341
- type: 'keydown',
10342
- callback: closeNestedDropdown,
10343
- keys: ['ArrowLeft']
10344
- }], [closeNestedDropdown]);
10345
- const [registerNestedListener, setRegisterNestedListener] = React.useState(open);
10346
- React.useEffect(() => {
10347
- let timeout;
10348
- if (open) {
10349
- timeout = setTimeout(() => {
10350
- setRegisterNestedListener(true);
10351
- }, TIMERS.DROPDOWN.IS_OPEN);
10352
- }
10353
- return () => {
10354
- setRegisterNestedListener(false);
10355
- if (timeout) {
10356
- clearTimeout(timeout);
10357
- }
10358
- };
10359
- }, [open]);
10360
- useKeyboard(innerDropdownListRef, dropdownKeyEvents, registerNestedListener);
10361
- const closeOnMouseLeave = React.useCallback(event => {
10362
- if (event.target instanceof Node) {
10363
- const eventIsOnTrigger = itemRef.current?.contains(event.target);
10364
- const eventIsOnDropdown = innerDropdownListRef.current?.contains(event.target);
10365
- if (!eventIsOnDropdown && !eventIsOnTrigger) {
10366
- if (closeNestedDropdownTimeoutRef.current === undefined) {
10367
- closeNestedDropdownTimeoutRef.current = setTimeout(() => {
10368
- closeNestedDropdown();
10369
- }, TIMERS.DROPDOWN.CLOSE_NESTED);
10370
- }
10371
- } else if (closeNestedDropdownTimeoutRef.current !== undefined) {
10372
- clearTimeout(closeNestedDropdownTimeoutRef.current);
10373
- closeNestedDropdownTimeoutRef.current = undefined;
10374
- }
10375
- }
10376
- }, [closeNestedDropdown, innerDropdownListRef]);
10377
- React.useEffect(() => {
10378
- if (open) {
10379
- window.addEventListener('mouseover', closeOnMouseLeave);
10380
- }
10381
- return () => {
10382
- window.removeEventListener('mouseover', closeOnMouseLeave);
10383
- };
10384
- }, [closeOnMouseLeave, open]);
10257
+ const keyEvents = React.useMemo(() => onClick && getKeyboardPreset('listItem', onClick) || [], [onClick]);
10258
+ useKeyboard(itemRef, keyEvents);
10385
10259
  return /*#__PURE__*/React__namespace.default.createElement(ContainerEl$2, _extends({
10386
10260
  "data-keep-open": keepOpen,
10387
10261
  ref: itemRef,
@@ -10394,9 +10268,7 @@ function NestListItem(_ref4) {
10394
10268
  onClick: disabled ? undefined : onClick,
10395
10269
  tabIndex: disabled ? undefined : 0,
10396
10270
  $disabled: disabled,
10397
- $selectedBackgroundColor: selected ? selectedBackgroundColor : undefined,
10398
- "data-testid": 'dropdown-item',
10399
- onMouseEnter: openNestedDropdown
10271
+ $selectedBackgroundColor: selected ? selectedBackgroundColor : undefined
10400
10272
  }, rest), /*#__PURE__*/React__namespace.default.createElement(Dropdown, {
10401
10273
  display: "block",
10402
10274
  items: items,
@@ -10406,7 +10278,7 @@ function NestListItem(_ref4) {
10406
10278
  itemIconSize: itemIconSize,
10407
10279
  itemTextSize: itemTextSize,
10408
10280
  itemPaddingBetween: itemPaddingBetween,
10409
- dropdownListRef: innerDropdownListRef
10281
+ dropdownListRef: dropdownListRef
10410
10282
  }, /*#__PURE__*/React__namespace.default.createElement(Container, {
10411
10283
  orientation: "horizontal",
10412
10284
  mainAlignment: "space-between",
@@ -10501,14 +10373,14 @@ const Dropdown = /*#__PURE__*/React__namespace.default.forwardRef(function Dropd
10501
10373
  onOpen,
10502
10374
  onClose,
10503
10375
  children,
10504
- triggerRef = null,
10376
+ triggerRef = /*#__PURE__*/React.createRef(),
10505
10377
  disablePortal = false,
10506
10378
  preventDefault = true,
10507
10379
  selectedBackgroundColor,
10508
10380
  itemIconSize = 'medium',
10509
10381
  itemTextSize = 'medium',
10510
10382
  itemPaddingBetween = 'small',
10511
- dropdownListRef = null,
10383
+ dropdownListRef = /*#__PURE__*/React.createRef(),
10512
10384
  ...rest
10513
10385
  } = _ref14;
10514
10386
  const {
@@ -10522,24 +10394,29 @@ const Dropdown = /*#__PURE__*/React__namespace.default.forwardRef(function Dropd
10522
10394
  const startSentinelRef = React.useRef(null);
10523
10395
  const endSentinelRef = React.useRef(null);
10524
10396
  const [position, setPosition] = React.useState(null);
10397
+ const [currentHover, setCurrentHover] = React.useState(null);
10398
+ const openPopperTimoutRef = React.useRef();
10525
10399
  const nestedDropdownsRef = React.useRef([]);
10400
+ React.useEffect(
10401
+ // clear timers on unmount
10402
+ () => () => {
10403
+ openPopperTimoutRef.current && clearTimeout(openPopperTimoutRef.current);
10404
+ }, []);
10526
10405
  React.useEffect(() => {
10527
10406
  setOpen(forceOpen);
10528
- openRef.current = forceOpen;
10529
10407
  }, [forceOpen]);
10530
10408
  const openPopper = React.useCallback(() => {
10531
10409
  setOpen(true);
10532
- openRef.current = true;
10533
- onOpen?.();
10410
+ onOpen && onOpen();
10534
10411
  }, [onOpen]);
10535
10412
  const closePopper = React.useCallback(e => {
10536
- e?.stopPropagation();
10413
+ e && e.stopPropagation();
10537
10414
  setOpen(forceOpen);
10538
- openRef.current = forceOpen;
10539
- !disableRestoreFocus && innerTriggerRef.current?.focus();
10540
- onClose?.();
10415
+ setCurrentHover(null);
10416
+ !disableRestoreFocus && innerTriggerRef.current && innerTriggerRef.current.focus();
10417
+ onClose && onClose();
10541
10418
  }, [disableRestoreFocus, forceOpen, innerTriggerRef, onClose]);
10542
- const toggleOpen = React.useCallback(e => {
10419
+ const handleClick = React.useCallback(e => {
10543
10420
  if (openRef.current) {
10544
10421
  e.preventDefault();
10545
10422
  closePopper();
@@ -10548,10 +10425,12 @@ const Dropdown = /*#__PURE__*/React__namespace.default.forwardRef(function Dropd
10548
10425
  openPopper();
10549
10426
  }
10550
10427
  }, [closePopper, disabled, openPopper]);
10428
+
10429
+ // TODO: it probably makes sense to merge this callback and the handleClick
10551
10430
  const handleLeftClick = React.useCallback(e => {
10552
- children.props.onClick?.(e);
10553
- toggleOpen(e);
10554
- }, [children.props, toggleOpen]);
10431
+ children.props.onClick && children.props.onClick(e);
10432
+ handleClick(e);
10433
+ }, [children.props, handleClick]);
10555
10434
  const handleRightClick = React.useCallback(e => {
10556
10435
  e.preventDefault();
10557
10436
  const virtualElement = {
@@ -10564,13 +10443,16 @@ const Dropdown = /*#__PURE__*/React__namespace.default.forwardRef(function Dropd
10564
10443
  left: e.clientX,
10565
10444
  x: e.clientX,
10566
10445
  y: e.clientY,
10567
- toJSON: () => ''
10446
+ toJSON: () => 'TODO' // TODO: check what this should return
10568
10447
  })
10569
10448
  };
10449
+
10570
10450
  setPosition(virtualElement);
10571
- if (!disabled && !openRef.current) {
10572
- openPopper();
10573
- }
10451
+ openPopperTimoutRef.current = setTimeout(() => {
10452
+ if (!disabled && !openRef.current) {
10453
+ openPopper();
10454
+ }
10455
+ }, 1);
10574
10456
  }, [disabled, openPopper]);
10575
10457
  const clickOutsidePopper = React.useCallback(e => {
10576
10458
  const clickedOnDropdown = dropdownRef.current && (e.target === dropdownRef.current || dropdownRef.current.contains(e.target));
@@ -10583,24 +10465,31 @@ const Dropdown = /*#__PURE__*/React__namespace.default.forwardRef(function Dropd
10583
10465
  }
10584
10466
  }, [closePopper, contextMenu, dropdownRef, innerTriggerRef]);
10585
10467
  const onStartSentinelFocus = React.useCallback(() => {
10586
- const lastChild = popperItemsRef.current?.querySelector('[tabindex]:last-child');
10587
- lastChild?.focus();
10468
+ const lastChild = popperItemsRef.current && popperItemsRef.current.querySelector('div[tabindex]:last-child');
10469
+ lastChild && lastChild.focus();
10588
10470
  }, []);
10589
10471
  const onEndSentinelFocus = React.useCallback(() => {
10590
- const firstChild = popperItemsRef.current?.querySelector('[tabindex]:first-child');
10591
- firstChild?.focus();
10472
+ const lastChild = popperItemsRef.current && popperItemsRef.current.querySelector('div[tabindex]:first-child');
10473
+ lastChild && lastChild.focus();
10592
10474
  }, []);
10593
- const triggerEvents = React.useMemo(() => handleTriggerEvents ? getKeyboardPreset('button', toggleOpen) : [], [toggleOpen, handleTriggerEvents]);
10475
+ const triggerEvents = React.useMemo(() => handleTriggerEvents ? getKeyboardPreset('button', handleClick) : [], [handleClick, handleTriggerEvents]);
10594
10476
  useKeyboard(innerTriggerRef, triggerEvents);
10595
- const listEvents = React.useMemo(() => getKeyboardPreset('list', undefined, popperItemsRef), [popperItemsRef]);
10596
- useKeyboard(popperItemsRef, listEvents, open);
10477
+
10478
+ // We need to add 'open' as dependency because we want to reattach these events each time we open the dropdown
10479
+ const listEvents = React.useMemo(() => getKeyboardPreset('list', () => undefined, popperItemsRef),
10480
+ // eslint-disable-next-line react-hooks/exhaustive-deps
10481
+ [open, popperItemsRef]);
10482
+ useKeyboard(popperItemsRef, listEvents);
10483
+ // We need to add 'open' as dependency because we want to reattach these events each time we open the dropdown
10597
10484
  const escapeEvent = React.useMemo(() => [{
10598
10485
  type: 'keydown',
10599
10486
  callback: closePopper,
10600
10487
  keys: ['Escape'],
10601
10488
  modifier: false
10602
- }], [closePopper]);
10603
- useKeyboard(dropdownRef, escapeEvent, open);
10489
+ }],
10490
+ // eslint-disable-next-line react-hooks/exhaustive-deps
10491
+ [open, closePopper]);
10492
+ useKeyboard(dropdownRef, escapeEvent);
10604
10493
  React.useLayoutEffect(() => {
10605
10494
  let popperInstance;
10606
10495
  if (open) {
@@ -10620,29 +10509,27 @@ const Dropdown = /*#__PURE__*/React__namespace.default.forwardRef(function Dropd
10620
10509
  let timeout;
10621
10510
  if (!disableAutoFocus && open) {
10622
10511
  timeout = setTimeout(() => {
10623
- const selectedItems = dropdownRef.current?.querySelectorAll('.zapp-selected');
10624
- if (selectedItems && selectedItems.length > 0) {
10625
- selectedItems[0].focus();
10626
- } else {
10627
- const firstElement = _first(popperItemsRef.current?.children);
10628
- if (firstElement instanceof HTMLElement) {
10629
- firstElement.focus();
10630
- }
10631
- }
10632
- }, TIMERS.DROPDOWN.IS_OPEN);
10512
+ const selectedItems = dropdownRef.current ? dropdownRef.current.querySelectorAll('.zapp-selected') : [];
10513
+ selectedItems.length > 0 ? selectedItems[0].focus() : popperItemsRef.current && popperItemsRef.current.children[0] && popperItemsRef.current.children[0] instanceof HTMLElement && popperItemsRef.current.children[0].focus();
10514
+ }, 1);
10633
10515
  }
10634
10516
  return () => {
10635
10517
  timeout && clearTimeout(timeout);
10636
10518
  };
10637
10519
  }, [disableAutoFocus, dropdownRef, open]);
10638
10520
  React.useEffect(() => {
10521
+ openRef.current = open;
10522
+ let timeout;
10639
10523
  if (open) {
10640
- windowObj.document.addEventListener('click', clickOutsidePopper, true);
10641
- contextMenu && windowObj.document.addEventListener('contextmenu', clickOutsidePopper, true);
10524
+ timeout = setTimeout(() => {
10525
+ windowObj.document.addEventListener('click', clickOutsidePopper, true);
10526
+ contextMenu && windowObj.document.addEventListener('contextmenu', clickOutsidePopper, true);
10527
+ }, 1);
10642
10528
  }
10643
10529
  return () => {
10644
10530
  windowObj.document.removeEventListener('click', clickOutsidePopper, true);
10645
10531
  windowObj.document.removeEventListener('contextmenu', clickOutsidePopper, true);
10532
+ timeout && clearTimeout(timeout);
10646
10533
  };
10647
10534
  }, [open, closePopper, clickOutsidePopper, contextMenu, windowObj.document]);
10648
10535
  React.useEffect(() => {
@@ -10650,23 +10537,24 @@ const Dropdown = /*#__PURE__*/React__namespace.default.forwardRef(function Dropd
10650
10537
  const startSentinelRefElement = startSentinelRef.current;
10651
10538
  const endSentinelRefElement = endSentinelRef.current;
10652
10539
  if (open && !disableAutoFocus) {
10653
- popperItemRefElement?.focus({
10540
+ popperItemRefElement && popperItemRefElement.focus({
10654
10541
  preventScroll: true
10655
10542
  });
10656
- startSentinelRefElement?.addEventListener('focus', onStartSentinelFocus);
10657
- endSentinelRefElement?.addEventListener('focus', onEndSentinelFocus);
10543
+ startSentinelRefElement && startSentinelRefElement.addEventListener('focus', onStartSentinelFocus);
10544
+ endSentinelRefElement && endSentinelRefElement.addEventListener('focus', onEndSentinelFocus);
10658
10545
  }
10659
10546
  return () => {
10660
- startSentinelRefElement?.removeEventListener('focus', onStartSentinelFocus);
10661
- endSentinelRefElement?.removeEventListener('focus', onEndSentinelFocus);
10547
+ startSentinelRefElement && startSentinelRefElement.removeEventListener('focus', onStartSentinelFocus);
10548
+ endSentinelRefElement && endSentinelRefElement.removeEventListener('focus', onEndSentinelFocus);
10662
10549
  };
10663
10550
  }, [open, startSentinelRef, endSentinelRef, onStartSentinelFocus, onEndSentinelFocus, disableAutoFocus]);
10664
10551
  const listItemClickHandler = React.useCallback((onClick, keepOpen) => event => {
10665
- onClick?.(event);
10666
- if (!multiple && !keepOpen) {
10667
- closePopper();
10668
- }
10552
+ onClick && onClick(event);
10553
+ !multiple && !keepOpen && closePopper();
10669
10554
  }, [closePopper, multiple]);
10555
+ const listItemMouseEnterHandler = React.useCallback(id => () => {
10556
+ setCurrentHover(id);
10557
+ }, []);
10670
10558
  const popperListItems = React.useMemo(() => {
10671
10559
  nestedDropdownsRef.current = [];
10672
10560
  if (items) {
@@ -10694,10 +10582,12 @@ const Dropdown = /*#__PURE__*/React__namespace.default.forwardRef(function Dropd
10694
10582
  onClick: listItemClickHandler(onClick, keepOpen),
10695
10583
  keepOpen: keepOpen,
10696
10584
  selected: selected,
10585
+ open: currentHover === id,
10697
10586
  key: id,
10698
10587
  customComponent: customComponent,
10699
10588
  disabled: itemDisabled,
10700
10589
  items: subItems,
10590
+ onMouseEnter: listItemMouseEnterHandler(id),
10701
10591
  selectedBackgroundColor: selectedBackgroundColor,
10702
10592
  itemIconSize: itemIconSize,
10703
10593
  itemTextSize: itemTextSize,
@@ -10712,6 +10602,7 @@ const Dropdown = /*#__PURE__*/React__namespace.default.forwardRef(function Dropd
10712
10602
  key: id,
10713
10603
  customComponent: customComponent,
10714
10604
  disabled: itemDisabled,
10605
+ onMouseEnter: listItemMouseEnterHandler(id),
10715
10606
  selectedBackgroundColor: selectedBackgroundColor,
10716
10607
  itemIconSize: itemIconSize,
10717
10608
  itemTextSize: itemTextSize,
@@ -10720,7 +10611,7 @@ const Dropdown = /*#__PURE__*/React__namespace.default.forwardRef(function Dropd
10720
10611
  });
10721
10612
  }
10722
10613
  return null;
10723
- }, [items, listItemClickHandler, selectedBackgroundColor, itemIconSize, itemTextSize, itemPaddingBetween]);
10614
+ }, [items, listItemClickHandler, currentHover, listItemMouseEnterHandler, selectedBackgroundColor, itemIconSize, itemTextSize, itemPaddingBetween]);
10724
10615
  const popperListPreventDefaultHandler = React.useCallback(event => {
10725
10616
  preventDefault && event.preventDefault();
10726
10617
  }, [preventDefault]);
@@ -21644,6 +21535,33 @@ var last_1 = last;
21644
21535
 
21645
21536
  var _last = /*@__PURE__*/getDefaultExportFromCjs(last_1);
21646
21537
 
21538
+ /**
21539
+ * Gets the first element of `array`.
21540
+ *
21541
+ * @static
21542
+ * @memberOf _
21543
+ * @since 0.1.0
21544
+ * @alias first
21545
+ * @category Array
21546
+ * @param {Array} array The array to query.
21547
+ * @returns {*} Returns the first element of `array`.
21548
+ * @example
21549
+ *
21550
+ * _.head([1, 2, 3]);
21551
+ * // => 1
21552
+ *
21553
+ * _.head([]);
21554
+ * // => undefined
21555
+ */
21556
+
21557
+ function head(array) {
21558
+ return (array && array.length) ? array[0] : undefined;
21559
+ }
21560
+
21561
+ var head_1 = head;
21562
+
21563
+ var _head = /*@__PURE__*/getDefaultExportFromCjs(head_1);
21564
+
21647
21565
  var baseSlice = _baseSlice,
21648
21566
  toInteger = toInteger_1;
21649
21567
 
@@ -22063,7 +21981,8 @@ const List = /*#__PURE__*/React__namespace.default.forwardRef(function ListFn(_r
22063
21981
  } = _ref6;
22064
21982
  const selecting = React.useMemo(() => _some(selected, i => !!i), [selected]);
22065
21983
  const listRef = React.useRef(null);
22066
- const keyEvents = React.useMemo(() => keyboardShortcutsIsDisabled ? [] : getKeyboardPreset('list', undefined, listRef), [listRef, keyboardShortcutsIsDisabled]);
21984
+ const useKeyboardShortcuts = () => undefined;
21985
+ const keyEvents = React.useMemo(() => keyboardShortcutsIsDisabled ? [] : getKeyboardPreset('list', useKeyboardShortcuts, listRef), [listRef, keyboardShortcutsIsDisabled]);
22067
21986
  useKeyboard(listRef, keyEvents);
22068
21987
  return /*#__PURE__*/React__namespace.default.createElement("div", {
22069
21988
  ref: listRef,
@@ -22120,7 +22039,11 @@ const BottomElement = _ref2 => {
22120
22039
  }
22121
22040
  }, [inView, onVisible]);
22122
22041
  return /*#__PURE__*/React__namespace.default.createElement("div", {
22123
- ref: ref
22042
+ ref: ref,
22043
+ style: {
22044
+ minHeight: '4px',
22045
+ minWidth: '1px'
22046
+ }
22124
22047
  });
22125
22048
  };
22126
22049
  const ListV2 = /*#__PURE__*/React__namespace.default.forwardRef(function ListV2Fn(_ref3, ref) {
@@ -22134,7 +22057,8 @@ const ListV2 = /*#__PURE__*/React__namespace.default.forwardRef(function ListV2F
22134
22057
  ...rest
22135
22058
  } = _ref3;
22136
22059
  const listRef = useCombinedRefs(ref);
22137
- const keyEvents = React.useMemo(() => keyboardShortcutsIsDisabled ? [] : getKeyboardPreset('list', undefined, listRef), [listRef, keyboardShortcutsIsDisabled]);
22060
+ const useKeyboardShortcuts = () => undefined;
22061
+ const keyEvents = React.useMemo(() => keyboardShortcutsIsDisabled ? [] : getKeyboardPreset('list', useKeyboardShortcuts, listRef), [listRef, keyboardShortcutsIsDisabled]);
22138
22062
  useKeyboard(listRef, keyEvents);
22139
22063
  const listItems = React.useMemo(() => children.map(child => /*#__PURE__*/React__namespace.default.cloneElement(child, {
22140
22064
  listRef,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zextras/carbonio-design-system",
3
- "version": "3.0.0",
3
+ "version": "3.0.1-devel.1696932777043",
4
4
  "description": "An awesome UI for Zextras Projects.",
5
5
  "main": "dist/zapp-ui.bundle.js",
6
6
  "types": "dist/zapp-ui.bundle.d.ts",