@mdbase-dev/ui 0.1.0-beta.155 → 0.1.0-beta.157

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/README.md +1 -1
  2. package/css/collections.css +5 -100
  3. package/css/controls.css +35 -36
  4. package/css/feedback.css +6 -6
  5. package/css/motion.css +50 -26
  6. package/css/palette.css +32 -55
  7. package/css/toast.css +11 -6
  8. package/css/tokens.css +14 -25
  9. package/dist/AppSwitcher.js +18 -30
  10. package/dist/CommandPalette.d.ts +9 -2
  11. package/dist/CommandPalette.js +203 -167
  12. package/dist/ConfirmDialog.d.ts +18 -0
  13. package/dist/ConfirmDialog.js +74 -0
  14. package/dist/Dialog.d.ts +8 -8
  15. package/dist/Dialog.js +90 -25
  16. package/dist/Feedback.js +24 -56
  17. package/dist/FeedbackMarkup.d.ts +2 -1
  18. package/dist/FeedbackMarkup.js +9 -2
  19. package/dist/Menu.d.ts +28 -0
  20. package/dist/Menu.js +64 -0
  21. package/dist/Select.js +6 -2
  22. package/dist/SelectList.js +2 -1
  23. package/dist/Toaster.d.ts +18 -1
  24. package/dist/Toaster.js +132 -50
  25. package/dist/brand.js +5 -3
  26. package/dist/collections/CollectionSwitcher.d.ts +2 -3
  27. package/dist/collections/CollectionSwitcher.js +14 -173
  28. package/dist/collections/copy.js +4 -4
  29. package/dist/collections/dialogs.d.ts +9 -4
  30. package/dist/collections/dialogs.js +84 -87
  31. package/dist/collections/parts.d.ts +0 -9
  32. package/dist/collections/parts.js +5 -77
  33. package/dist/locales/de/messages.json +1 -1
  34. package/dist/locales/en/messages.json +1 -1
  35. package/dist/locales/es/messages.json +1 -1
  36. package/dist/locales/fr/messages.json +1 -1
  37. package/dist/locales/it/messages.json +1 -1
  38. package/dist/locales/ja/messages.json +1 -1
  39. package/dist/locales/ko/messages.json +1 -1
  40. package/dist/locales/pt/messages.json +1 -1
  41. package/dist/locales/ru/messages.json +1 -1
  42. package/dist/locales/zh/messages.json +1 -1
  43. package/dist/overlay.d.ts +4 -0
  44. package/dist/overlay.js +23 -0
  45. package/dist/popover.d.ts +6 -1
  46. package/dist/popover.js +22 -16
  47. package/package.json +14 -2
@@ -0,0 +1,4 @@
1
+ export declare function useOverlay<Element extends HTMLElement>(open: boolean): {
2
+ ref: import("react").RefObject<Element | null>;
3
+ present: boolean;
4
+ };
@@ -0,0 +1,23 @@
1
+ import { useLayoutEffect, useRef, useState } from "react";
2
+ export function useOverlay(open) {
3
+ const ref = useRef(null);
4
+ const [retained, setRetained] = useState(open);
5
+ useLayoutEffect(() => {
6
+ if (open) {
7
+ setRetained(true);
8
+ return;
9
+ }
10
+ // The resolved transition duration is always in seconds, whatever a build does to the token.
11
+ const duration = ref.current ? parseFloat(getComputedStyle(ref.current).transitionDuration) * 1000 : 0;
12
+ if (!duration) {
13
+ setRetained(false);
14
+ return;
15
+ }
16
+ const timeout = setTimeout(() => setRetained(false), duration);
17
+ return () => clearTimeout(timeout);
18
+ }, [open]);
19
+ return {
20
+ ref,
21
+ present: open || retained
22
+ };
23
+ }
package/dist/popover.d.ts CHANGED
@@ -28,6 +28,11 @@ export declare function anchoredPlacement(trigger: Box, popover: Size, viewport:
28
28
  */
29
29
  export declare function useSelectPopover(open: boolean, triggerRef: RefObject<HTMLElement | null>, listRef: RefObject<HTMLElement | null>, onDismiss: () => void): void;
30
30
  export interface MenuPopoverOptions {
31
+ readonly point?: {
32
+ readonly left: number;
33
+ readonly top: number;
34
+ } | undefined;
35
+ readonly open?: boolean;
31
36
  /** Preferred width; narrow viewports shrink it. Omit it to leave the width to CSS. */
32
37
  readonly width?: number | undefined;
33
38
  /** Which edge of the trigger the menu lines up with. */
@@ -41,7 +46,7 @@ export interface MenuPopoverOptions {
41
46
  * Keeps a mounted menu in the top layer beside its trigger. It closes on an outside press,
42
47
  * Escape (returning focus to the trigger), Tab or a resize.
43
48
  */
44
- export declare function useMenuPopover(menuRef: RefObject<HTMLElement | null>, triggerRef: RefObject<HTMLElement | null>, onClose: (refocus: boolean) => void, { width, align, focus, busy }: MenuPopoverOptions): void;
49
+ export declare function useMenuPopover(menuRef: RefObject<HTMLElement | null>, triggerRef: RefObject<HTMLElement | null>, onClose: (refocus: boolean) => void, { open, width, align, focus, busy, point }: MenuPopoverOptions): void;
45
50
  /**
46
51
  * Arrow keys, Home and End move between a menu's enabled items. From a text field inside the
47
52
  * menu (a filter), Home and End stay in the field and the arrows enter the list.
package/dist/popover.js CHANGED
@@ -40,9 +40,6 @@ function place(trigger, popover, options) {
40
40
  function showInTopLayer(element) {
41
41
  if (typeof element.showPopover === "function") element.showPopover();
42
42
  }
43
- function hideFromTopLayer(element) {
44
- if (typeof element.hidePopover === "function" && element.matches(":popover-open")) element.hidePopover();
45
- }
46
43
  function onScreen(element) {
47
44
  const box = element.getBoundingClientRect();
48
45
  return box.width > 0 && box.bottom > 0 && box.top < window.innerHeight && box.right > 0 && box.left < window.innerWidth;
@@ -64,9 +61,6 @@ export function useSelectPopover(open, triggerRef, listRef, onDismiss) {
64
61
  list.focus({
65
62
  preventScroll: true
66
63
  });
67
- return () => {
68
- hideFromTopLayer(list);
69
- };
70
64
  }, [open, triggerRef, listRef]);
71
65
  useEffect(() => {
72
66
  const list = listRef.current;
@@ -100,20 +94,26 @@ export function useSelectPopover(open, triggerRef, listRef, onDismiss) {
100
94
  * Escape (returning focus to the trigger), Tab or a resize.
101
95
  */
102
96
  export function useMenuPopover(menuRef, triggerRef, onClose, {
97
+ open = true,
103
98
  width,
104
99
  align = "start",
105
- focus = '[aria-checked="true"], [role^="menuitem"]',
106
- busy = false
100
+ focus = '[aria-checked="true"], [role^="menuitem"]:not(:disabled)',
101
+ busy = false,
102
+ point
107
103
  }) {
108
104
  const close = useEffectEvent(onClose);
109
105
  const locked = useEffectEvent(() => busy);
110
106
  useLayoutEffect(() => {
111
107
  const menu = menuRef.current;
112
108
  const trigger = triggerRef.current;
113
- if (!menu || !trigger) return undefined;
109
+ if (!menu || !trigger || !open) return undefined;
114
110
  showInTopLayer(menu);
115
111
  if (width !== undefined) menu.style.width = `${Math.min(width, window.innerWidth - 16)}px`;
116
- place(trigger, menu, {
112
+ if (point) {
113
+ const bounds = menu.getBoundingClientRect();
114
+ menu.style.left = `${Math.max(8, Math.min(point.left, window.innerWidth - bounds.width - 8))}px`;
115
+ menu.style.top = `${Math.max(8, Math.min(point.top, window.innerHeight - bounds.height - 8))}px`;
116
+ } else place(trigger, menu, {
117
117
  gap: 6,
118
118
  align,
119
119
  matchWidth: false
@@ -121,11 +121,9 @@ export function useMenuPopover(menuRef, triggerRef, onClose, {
121
121
  (menu.querySelector(focus) ?? menu).focus({
122
122
  preventScroll: true
123
123
  });
124
- return () => {
125
- hideFromTopLayer(menu);
126
- };
127
- }, [menuRef, triggerRef, width, align, focus]);
124
+ }, [menuRef, triggerRef, width, align, focus, open, point]);
128
125
  useEffect(() => {
126
+ if (!open) return;
129
127
  const onPointerDown = event => {
130
128
  const target = event.target;
131
129
  if (target && !locked() && !menuRef.current?.contains(target) && !triggerRef.current?.contains(target)) {
@@ -142,15 +140,20 @@ export function useMenuPopover(menuRef, triggerRef, onClose, {
142
140
  }
143
141
  };
144
142
  const onResize = () => close(false);
143
+ const onScroll = event => {
144
+ if (point && !menuRef.current?.contains(event.target)) close(false);
145
+ };
145
146
  document.addEventListener("pointerdown", onPointerDown, true);
146
147
  document.addEventListener("keydown", onKeyDown, true);
147
148
  window.addEventListener("resize", onResize);
149
+ document.addEventListener("scroll", onScroll, true);
148
150
  return () => {
149
151
  document.removeEventListener("pointerdown", onPointerDown, true);
150
152
  document.removeEventListener("keydown", onKeyDown, true);
151
153
  window.removeEventListener("resize", onResize);
154
+ document.removeEventListener("scroll", onScroll, true);
152
155
  };
153
- }, [menuRef, triggerRef]);
156
+ }, [menuRef, triggerRef, open, point]);
154
157
  }
155
158
  /**
156
159
  * Arrow keys, Home and End move between a menu's enabled items. From a text field inside the
@@ -158,7 +161,7 @@ export function useMenuPopover(menuRef, triggerRef, onClose, {
158
161
  */
159
162
  export function moveMenuFocus(event, menu) {
160
163
  if (!menu || !["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) return;
161
- const items = [...menu.querySelectorAll('[role^="menuitem"]:not(:disabled)')];
164
+ const items = [...menu.querySelectorAll('[role^="menuitem"]:not(:disabled):not([aria-disabled="true"])')];
162
165
  const inField = document.activeElement instanceof HTMLInputElement && menu.contains(document.activeElement);
163
166
  if (inField && (event.key === "Home" || event.key === "End")) return;
164
167
  event.preventDefault();
@@ -167,4 +170,7 @@ export function moveMenuFocus(event, menu) {
167
170
  items[next]?.focus({
168
171
  preventScroll: true
169
172
  });
173
+ items[next]?.scrollIntoView?.({
174
+ block: "nearest"
175
+ });
170
176
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdbase-dev/ui",
3
- "version": "0.1.0-beta.155",
3
+ "version": "0.1.0-beta.157",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -64,6 +64,18 @@
64
64
  "types": "./dist/CollectionModeControl.d.ts",
65
65
  "import": "./dist/CollectionModeControl.js"
66
66
  },
67
+ "./confirm-dialog": {
68
+ "types": "./dist/ConfirmDialog.d.ts",
69
+ "import": "./dist/ConfirmDialog.js"
70
+ },
71
+ "./menu": {
72
+ "types": "./dist/Menu.d.ts",
73
+ "import": "./dist/Menu.js"
74
+ },
75
+ "./overlay": {
76
+ "types": "./dist/overlay.d.ts",
77
+ "import": "./dist/overlay.js"
78
+ },
67
79
  "./dialog": {
68
80
  "types": "./dist/Dialog.d.ts",
69
81
  "import": "./dist/Dialog.js"
@@ -174,6 +186,6 @@
174
186
  "typecheck": "node scripts/compile-catalogues.mjs && tsc -p tsconfig.json --noEmit"
175
187
  },
176
188
  "mdbaseRelease": {
177
- "commit": "091d912babeacbba88661f7ce4b96081658376af"
189
+ "commit": "493d29ca2a3494c5d59677e8b83e309b44a28c31"
178
190
  }
179
191
  }