@c9up/nebula 0.2.1 → 0.2.2

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 (40) hide show
  1. package/README.md +11 -9
  2. package/dist/atoms/AccessibleIcon.d.ts +24 -0
  3. package/dist/atoms/AccessibleIcon.js +27 -0
  4. package/dist/atoms/VisuallyHidden.d.ts +30 -0
  5. package/dist/atoms/VisuallyHidden.js +35 -0
  6. package/dist/atoms/index.d.ts +2 -0
  7. package/dist/atoms/index.js +2 -0
  8. package/dist/index.d.ts +7 -4
  9. package/dist/index.js +7 -4
  10. package/dist/molecules/Toolbar.d.ts +50 -0
  11. package/dist/molecules/Toolbar.js +70 -0
  12. package/dist/molecules/index.d.ts +7 -5
  13. package/dist/molecules/index.js +7 -5
  14. package/dist/organisms/Toaster.d.ts +78 -10
  15. package/dist/organisms/Toaster.js +146 -20
  16. package/dist/organisms/index.d.ts +1 -1
  17. package/dist/primitives/direction.d.ts +38 -0
  18. package/dist/primitives/direction.js +57 -0
  19. package/dist/primitives/floating.js +1 -12
  20. package/dist/primitives/focusable.d.ts +10 -0
  21. package/dist/primitives/focusable.js +10 -1
  22. package/dist/primitives/index.d.ts +2 -1
  23. package/dist/primitives/index.js +2 -1
  24. package/dist/primitives/rovingFocus.js +14 -7
  25. package/nebula.css +1 -1
  26. package/package.json +1 -1
  27. package/registry.json +63 -0
  28. package/src/atoms/AccessibleIcon.ts +39 -0
  29. package/src/atoms/VisuallyHidden.ts +45 -0
  30. package/src/atoms/index.ts +8 -0
  31. package/src/index.ts +7 -4
  32. package/src/molecules/Toolbar.ts +100 -0
  33. package/src/molecules/index.ts +14 -5
  34. package/src/organisms/Toaster.ts +207 -33
  35. package/src/organisms/index.ts +2 -0
  36. package/src/primitives/direction.ts +61 -0
  37. package/src/primitives/floating.ts +2 -12
  38. package/src/primitives/focusable.ts +10 -1
  39. package/src/primitives/index.ts +7 -0
  40. package/src/primitives/rovingFocus.ts +18 -5
@@ -25,6 +25,8 @@
25
25
  * has to find an offset parent, and gets it wrong the moment one appears.
26
26
  */
27
27
 
28
+ import { isRightToLeft } from "./direction.js";
29
+
28
30
  export type Side = "top" | "right" | "bottom" | "left";
29
31
  export type Align = "start" | "center" | "end";
30
32
  export type Placement = Side | `${Side}-${Align}`;
@@ -456,18 +458,6 @@ export function autoPosition(
456
458
  };
457
459
  }
458
460
 
459
- /**
460
- * Is this element laid out right to left?
461
- *
462
- * The computed style rather than the `dir` attribute, so an element inheriting
463
- * the direction from `<html dir="rtl">` is answered correctly without every
464
- * anchor having to carry the attribute itself.
465
- */
466
- function isRightToLeft(element: HTMLElement): boolean {
467
- if (typeof getComputedStyle !== "function") return false;
468
- return getComputedStyle(element).direction === "rtl";
469
- }
470
-
471
461
  /**
472
462
  * Watch elements for size changes, where the platform supports it.
473
463
  *
@@ -13,7 +13,16 @@
13
13
  * styles rather than trusting the markup.
14
14
  */
15
15
 
16
- const FOCUSABLE_SELECTOR = [
16
+ /**
17
+ * The standard tabbable set.
18
+ *
19
+ * Exported because a composite widget that navigates "whatever controls are in
20
+ * here" — a toolbar — needs the same definition, and a second copy next door
21
+ * is how the two drift into disagreeing about `summary` or `contenteditable`.
22
+ * It is a selector, not an answer: `isFocusable` below is still what decides,
23
+ * because a selector cannot see `display: none` or a collapsed `<details>`.
24
+ */
25
+ export const FOCUSABLE_SELECTOR = [
17
26
  "a[href]",
18
27
  "area[href]",
19
28
  "button:not([disabled])",
@@ -18,6 +18,12 @@ export {
18
18
  type ControllableOptions,
19
19
  controllable,
20
20
  } from "./controllable.js";
21
+ export {
22
+ type Direction,
23
+ directionOf,
24
+ forward,
25
+ isRightToLeft,
26
+ } from "./direction.js";
21
27
  export {
22
28
  type DismissableLayer,
23
29
  type DismissableOptions,
@@ -43,6 +49,7 @@ export {
43
49
  floatingSurface,
44
50
  } from "./floatingSurface.js";
45
51
  export {
52
+ FOCUSABLE_SELECTOR,
46
53
  firstFocusable,
47
54
  focusableWithin,
48
55
  focusSilently,
@@ -19,6 +19,7 @@
19
19
  * which is not a budget worth optimising against correctness.
20
20
  */
21
21
 
22
+ import { forward } from "./direction.js";
22
23
  import { focusSilently, isVisible } from "./focusable.js";
23
24
 
24
25
  export type Orientation = "vertical" | "horizontal" | "both";
@@ -132,7 +133,7 @@ export function rovingFocus(options: RovingFocusOptions): RovingFocus {
132
133
  // A modifier means the user is talking to the browser, not the widget.
133
134
  if (event.altKey || event.ctrlKey || event.metaKey) return;
134
135
 
135
- const direction = directionFor(event.key, orientation);
136
+ const direction = directionFor(event.key, orientation, container);
136
137
  if (direction !== 0) {
137
138
  event.preventDefault();
138
139
  move(direction);
@@ -177,15 +178,27 @@ export function rovingFocus(options: RovingFocusOptions): RovingFocus {
177
178
  };
178
179
  }
179
180
 
180
- /** `-1` for previous, `+1` for next, `0` when the key is not ours. */
181
- function directionFor(key: string, orientation: Orientation): number {
181
+ /**
182
+ * `-1` for previous, `+1` for next, `0` when the key is not ours.
183
+ *
184
+ * The horizontal pair is mirrored in a right-to-left group: ArrowRight means
185
+ * the key to the right, and in an RTL list the item to the right is the
186
+ * PREVIOUS one. Vertical never mirrors — `dir` does not turn a page upside
187
+ * down.
188
+ */
189
+ function directionFor(
190
+ key: string,
191
+ orientation: Orientation,
192
+ container: HTMLElement,
193
+ ): number {
182
194
  const vertical = orientation === "vertical" || orientation === "both";
183
195
  const horizontal = orientation === "horizontal" || orientation === "both";
184
196
 
185
197
  if (vertical && key === "ArrowDown") return 1;
186
198
  if (vertical && key === "ArrowUp") return -1;
187
- if (horizontal && key === "ArrowRight") return 1;
188
- if (horizontal && key === "ArrowLeft") return -1;
199
+ if (horizontal && (key === "ArrowRight" || key === "ArrowLeft")) {
200
+ return forward(key, container);
201
+ }
189
202
  return 0;
190
203
  }
191
204