@via-profit/ui-kit 0.10.0 → 0.11.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 (47) hide show
  1. package/Badge/BadgeBase.d.ts +8 -3
  2. package/Badge/BadgeBase.js +5 -6
  3. package/Badge/BadgeContainer.d.ts +8 -0
  4. package/Badge/BadgeContainer.js +148 -10
  5. package/Badge/BadgeDeleteButton.d.ts +4 -4
  6. package/Badge/BadgeDeleteButton.js +5 -4
  7. package/Badge/BadgeDeleteIcon.d.ts +4 -0
  8. package/Badge/BadgeDeleteIcon.js +9 -0
  9. package/Badge/BadgeOutlined.js +2 -2
  10. package/Badge/BadgeStandard.js +2 -2
  11. package/Badge/BadgeStyled.d.ts +2 -5
  12. package/Badge/BadgeStyled.js +4 -163
  13. package/Badge/index.d.ts +3 -4
  14. package/Badge/index.js +17 -3
  15. package/CHANGELOG.md +18 -0
  16. package/DatePicker/index.js +3 -1
  17. package/HintPopover/index.js +1 -1
  18. package/Menu/MenuContainer.js +5 -3
  19. package/Selectbox/SelectboxMenu.js +1 -1
  20. package/ThemeProvider/tokens.d.ts +1 -1
  21. package/ThemeProvider/tokens.js +1 -1
  22. package/Toast/ToastContainer.d.ts +5 -3
  23. package/Toast/ToastContainer.js +1 -1
  24. package/Toast/ToastItem.d.ts +2 -2
  25. package/Toast/ToastItem.js +11 -1
  26. package/Toast/index.d.ts +1 -1
  27. package/Toast/store.d.ts +15 -0
  28. package/Toast/store.js +5 -1
  29. package/esm/Badge/BadgeBase.js +5 -6
  30. package/esm/Badge/BadgeContainer.js +148 -10
  31. package/esm/Badge/BadgeDeleteButton.js +5 -4
  32. package/esm/Badge/BadgeDeleteIcon.js +4 -0
  33. package/esm/Badge/BadgeOutlined.js +2 -2
  34. package/esm/Badge/BadgeStandard.js +2 -2
  35. package/esm/Badge/BadgeStyled.js +2 -163
  36. package/esm/Badge/index.js +17 -3
  37. package/esm/DatePicker/index.js +3 -1
  38. package/esm/HintPopover/index.js +1 -1
  39. package/esm/Menu/MenuContainer.js +5 -3
  40. package/esm/Selectbox/SelectboxMenu.js +1 -1
  41. package/esm/ThemeProvider/tokens.js +1 -1
  42. package/esm/Toast/ToastContainer.js +2 -2
  43. package/esm/Toast/ToastItem.js +12 -2
  44. package/esm/Toast/store.js +4 -0
  45. package/esm/utils/TabManager.js +1 -1
  46. package/package.json +6 -1
  47. package/utils/TabManager.js +1 -1
@@ -35,7 +35,7 @@ const HintPopover = props => {
35
35
  const onKeyDown = (event) => {
36
36
  if (event.key === 'Escape') {
37
37
  setOpen(false);
38
- button === null || button === void 0 ? void 0 : button.focus();
38
+ button === null || button === void 0 ? void 0 : button.focus({ preventScroll: true });
39
39
  }
40
40
  };
41
41
  document.addEventListener('keydown', onKeyDown);
@@ -247,10 +247,11 @@ const MenuContainer = React.forwardRef((props, ref) => {
247
247
  if (!isOpen) {
248
248
  // The menu is already closed by the parent, so onRequestClose must not be called again
249
249
  dispatch(actionSetmenuState({ markedIndex: -1, hoveredIndex: -1 }));
250
- // Otherwise the focus is lost together with the unmounted list
250
+ // Otherwise the focus is lost together with the unmounted list.
251
+ // Without the scroll: an anchor in a sticky header is scrolled to its place in the document
251
252
  if (hasFocusRef.current) {
252
253
  hasFocusRef.current = false;
253
- (_a = lastAnchorRef.current) === null || _a === void 0 ? void 0 : _a.focus();
254
+ (_a = lastAnchorRef.current) === null || _a === void 0 ? void 0 : _a.focus({ preventScroll: true });
254
255
  }
255
256
  return;
256
257
  }
@@ -265,7 +266,8 @@ const MenuContainer = React.forwardRef((props, ref) => {
265
266
  var _a;
266
267
  scrollToFirstSelected();
267
268
  if (autofocus) {
268
- (_a = menuListRef.current) === null || _a === void 0 ? void 0 : _a.focus();
269
+ // The list is already placed by the popper: focusing must not scroll the page
270
+ (_a = menuListRef.current) === null || _a === void 0 ? void 0 : _a.focus({ preventScroll: true });
269
271
  }
270
272
  }, 15);
271
273
  }, [isOpen, autofocus, dispatch, scrollToFirstSelected]);
@@ -21,7 +21,7 @@ const SelectboxMenu = React.forwardRef((props, ref) => {
21
21
  if (onRequestClose) {
22
22
  onRequestClose(evt);
23
23
  }
24
- anchorElement === null || anchorElement === void 0 ? void 0 : anchorElement.focus();
24
+ anchorElement === null || anchorElement === void 0 ? void 0 : anchorElement.focus({ preventScroll: true });
25
25
  }
26
26
  }, [onRequestClose, anchorElement]);
27
27
  return (React.createElement(Menu, Object.assign({ ref: ref, offset: 0, anchorPos: anchorPos, multiple: multiple, items: items, value: value, isOpen: isOpen && items.length > 0, autofocus: true, anchorElement: anchorElement, closeOutsideClick: false, getOptionSelected: getOptionSelected, onSelectItem: handleSelectItem, closeOnSelect: !multiple, onRequestClose: handleRequestClose }, restMenuProps), ({ index, item }, itemProps) => children({ index, item: item }, itemProps)));
@@ -46,7 +46,7 @@ export const CONTROL_LINE_HEIGHT = '1.2em';
46
46
  */
47
47
  export const BORDER_WIDTH = '0.0625em';
48
48
  /**
49
- * The border of the buttons. The standard and the plain buttons have no border:
49
+ * The border of the buttons. The standard, plain and soft buttons have no border:
50
50
  * their padding is larger by this width, so all the variants have the same size
51
51
  */
52
52
  export const CONTROL_BORDER = BORDER_WIDTH;
@@ -7,7 +7,7 @@ import Icon from './ToastIcon';
7
7
  import CloseButton from './ToastCloseButton';
8
8
  import Action from './ToastAction';
9
9
  import ToastItem from './ToastItem';
10
- import { toastStore } from './store';
10
+ import { toastStore, TOAST_DEFAULT_AUTO_CLOSE, } from './store';
11
11
  const POSITIONS = [
12
12
  'top-left',
13
13
  'top-center',
@@ -84,7 +84,7 @@ const useWindowFocused = () => {
84
84
  return isFocused;
85
85
  };
86
86
  const ToastContainer = props => {
87
- const { containerId, position = 'top-right', autoClose = 5000, limit, closeButton = true, closeButtonLabel = 'Close', closeOnClick = true, pauseOnHover = true, pauseOnFocusLoss = true, newestOnTop = false, hotkey = 'F8', label = 'Notifications', zIndex, overrides, } = props;
87
+ const { containerId, position = 'top-right', autoClose = TOAST_DEFAULT_AUTO_CLOSE, limit, closeButton = true, closeButtonLabel = 'Close', closeOnClick = true, pauseOnHover = true, pauseOnFocusLoss = true, newestOnTop = false, hotkey = 'F8', label = 'Notifications', zIndex, overrides, } = props;
88
88
  const theme = useTheme();
89
89
  const allToasts = React.useSyncExternalStore(toastStore.subscribe, toastStore.getSnapshot, toastStore.getServerSnapshot);
90
90
  const toasts = React.useMemo(() => allToasts.filter(item => item.containerId === containerId), [allToasts, containerId]);
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import styled from '@emotion/styled';
3
3
  import { TOAST_ANIMATION_MS } from './ToastCard';
4
- import { toast as toastApi, toastStore } from './store';
4
+ import { toast as toastApi, toastStore, TOAST_DEFAULT_AUTO_CLOSE, } from './store';
5
5
  const Body = styled.div `
6
6
  flex: 1;
7
7
  min-width: 0;
@@ -23,12 +23,22 @@ const Actions = styled.div `
23
23
  * The clicks on these elements are actions, not the click on the toast
24
24
  */
25
25
  const INTERACTIVE = 'a, button, input, select, textarea, label, summary, [role="button"], [contenteditable="true"]';
26
+ /**
27
+ * The `autoClose` of the toast type: the own value of the type, then `default`, then 5000
28
+ */
29
+ const getAutoClose = (autoClose, type) => {
30
+ var _a, _b;
31
+ if (typeof autoClose === 'number' || autoClose === false) {
32
+ return autoClose;
33
+ }
34
+ return (_b = (_a = autoClose[type]) !== null && _a !== void 0 ? _a : autoClose.default) !== null && _b !== void 0 ? _b : TOAST_DEFAULT_AUTO_CLOSE;
35
+ };
26
36
  const ToastItem = props => {
27
37
  var _a, _b, _c, _d, _e;
28
38
  const { toast, position, defaults, components, isWindowFocused } = props;
29
39
  const { toastId, content, type = 'default', isLoading = false, description, actions, icon, onClick, onOpen, isClosing, version, } = toast;
30
40
  // The loading toast waits for `toast.update`: it can not be closed by the timer or by the click
31
- const autoClose = isLoading ? false : ((_a = toast.autoClose) !== null && _a !== void 0 ? _a : defaults.autoClose);
41
+ const autoClose = isLoading ? false : ((_a = toast.autoClose) !== null && _a !== void 0 ? _a : getAutoClose(defaults.autoClose, type));
32
42
  const closeButton = isLoading ? false : ((_b = toast.closeButton) !== null && _b !== void 0 ? _b : defaults.closeButton);
33
43
  const closeOnClick = isLoading ? false : ((_c = toast.closeOnClick) !== null && _c !== void 0 ? _c : defaults.closeOnClick);
34
44
  const pauseOnHover = (_d = toast.pauseOnHover) !== null && _d !== void 0 ? _d : defaults.pauseOnHover;
@@ -9,6 +9,10 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
+ /**
13
+ * The time to close the toast when `autoClose` does not set one
14
+ */
15
+ export const TOAST_DEFAULT_AUTO_CLOSE = 5000;
12
16
  let toasts = [];
13
17
  const listeners = new Set();
14
18
  let idCounter = 0;
@@ -76,7 +76,7 @@ class TabManager {
76
76
  __classPrivateFieldSet(this, _TabManager_stack, __classPrivateFieldGet(this, _TabManager_stack, "f").filter(stackElem => {
77
77
  const founded = stackElem.container === container;
78
78
  if (founded && revertBackFocus && stackElem.lastFocused instanceof HTMLElement) {
79
- stackElem.lastFocused.focus();
79
+ stackElem.lastFocused.focus({ preventScroll: true });
80
80
  }
81
81
  return !founded;
82
82
  }), "f");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@via-profit/ui-kit",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "UI Kit",
5
5
  "repository": {
6
6
  "type": "git",
@@ -150,6 +150,11 @@
150
150
  "import": "./esm/Badge/BadgeDeleteButton.js",
151
151
  "require": "./Badge/BadgeDeleteButton.js"
152
152
  },
153
+ "./Badge/BadgeDeleteIcon": {
154
+ "types": "./Badge/BadgeDeleteIcon.d.ts",
155
+ "import": "./esm/Badge/BadgeDeleteIcon.js",
156
+ "require": "./Badge/BadgeDeleteIcon.js"
157
+ },
153
158
  "./Badge/BadgeDot": {
154
159
  "types": "./Badge/BadgeDot.d.ts",
155
160
  "import": "./esm/Badge/BadgeDot.js",
@@ -78,7 +78,7 @@ class TabManager {
78
78
  __classPrivateFieldSet(this, _TabManager_stack, __classPrivateFieldGet(this, _TabManager_stack, "f").filter(stackElem => {
79
79
  const founded = stackElem.container === container;
80
80
  if (founded && revertBackFocus && stackElem.lastFocused instanceof HTMLElement) {
81
- stackElem.lastFocused.focus();
81
+ stackElem.lastFocused.focus({ preventScroll: true });
82
82
  }
83
83
  return !founded;
84
84
  }), "f");