@c9up/nebula 0.2.0 → 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.
- package/README.md +11 -9
- package/dist/atoms/AccessibleIcon.d.ts +24 -0
- package/dist/atoms/AccessibleIcon.js +27 -0
- package/dist/atoms/VisuallyHidden.d.ts +30 -0
- package/dist/atoms/VisuallyHidden.js +35 -0
- package/dist/atoms/index.d.ts +2 -0
- package/dist/atoms/index.js +2 -0
- package/dist/configure.d.ts +6 -0
- package/dist/configure.js +4 -22
- package/dist/index.d.ts +7 -4
- package/dist/index.js +7 -4
- package/dist/lib/id.d.ts +13 -29
- package/dist/lib/id.js +13 -39
- package/dist/molecules/Toolbar.d.ts +50 -0
- package/dist/molecules/Toolbar.js +70 -0
- package/dist/molecules/index.d.ts +7 -5
- package/dist/molecules/index.js +7 -5
- package/dist/organisms/Toaster.d.ts +78 -10
- package/dist/organisms/Toaster.js +146 -20
- package/dist/organisms/index.d.ts +1 -1
- package/dist/primitives/direction.d.ts +38 -0
- package/dist/primitives/direction.js +57 -0
- package/dist/primitives/floating.js +1 -12
- package/dist/primitives/focusable.d.ts +10 -0
- package/dist/primitives/focusable.js +10 -1
- package/dist/primitives/index.d.ts +2 -1
- package/dist/primitives/index.js +2 -1
- package/dist/primitives/rovingFocus.js +14 -7
- package/dist/stubs.d.ts +13 -0
- package/dist/stubs.js +14 -0
- package/nebula.css +1 -1
- package/package.json +4 -3
- package/registry.json +63 -0
- package/src/atoms/AccessibleIcon.ts +39 -0
- package/src/atoms/VisuallyHidden.ts +45 -0
- package/src/atoms/index.ts +8 -0
- package/src/configure.ts +10 -23
- package/src/index.ts +7 -4
- package/src/lib/id.ts +11 -39
- package/src/molecules/Toolbar.ts +100 -0
- package/src/molecules/index.ts +14 -5
- package/src/organisms/Toaster.ts +207 -33
- package/src/organisms/index.ts +2 -0
- package/src/primitives/direction.ts +61 -0
- package/src/primitives/floating.ts +2 -12
- package/src/primitives/focusable.ts +10 -1
- package/src/primitives/index.ts +7 -0
- package/src/primitives/rovingFocus.ts +18 -5
- package/src/stubs.ts +16 -0
- package/stubs/config/nebula.stub +21 -0
package/registry.json
CHANGED
|
@@ -4,6 +4,20 @@
|
|
|
4
4
|
"homepage": "https://github.com/C9up/nebula",
|
|
5
5
|
"layout": "mirror",
|
|
6
6
|
"items": [
|
|
7
|
+
{
|
|
8
|
+
"name": "accessible-icon",
|
|
9
|
+
"title": "AccessibleIcon",
|
|
10
|
+
"layer": "atoms",
|
|
11
|
+
"files": [
|
|
12
|
+
"atoms/AccessibleIcon.ts",
|
|
13
|
+
"lib/children.ts",
|
|
14
|
+
"lib/cn.ts",
|
|
15
|
+
"lib/props.ts"
|
|
16
|
+
],
|
|
17
|
+
"dependencies": [
|
|
18
|
+
"visually-hidden"
|
|
19
|
+
]
|
|
20
|
+
},
|
|
7
21
|
{
|
|
8
22
|
"name": "accordion",
|
|
9
23
|
"title": "Accordion",
|
|
@@ -15,6 +29,7 @@
|
|
|
15
29
|
"lib/id.ts",
|
|
16
30
|
"lib/props.ts",
|
|
17
31
|
"molecules/Accordion.ts",
|
|
32
|
+
"primitives/direction.ts",
|
|
18
33
|
"primitives/focusable.ts",
|
|
19
34
|
"primitives/rovingFocus.ts"
|
|
20
35
|
],
|
|
@@ -46,6 +61,7 @@
|
|
|
46
61
|
"lib/props.ts",
|
|
47
62
|
"organisms/AlertDialog.ts",
|
|
48
63
|
"primitives/controllable.ts",
|
|
64
|
+
"primitives/direction.ts",
|
|
49
65
|
"primitives/dismissable.ts",
|
|
50
66
|
"primitives/floating.ts",
|
|
51
67
|
"primitives/focusTrap.ts",
|
|
@@ -280,6 +296,7 @@
|
|
|
280
296
|
"lib/props.ts",
|
|
281
297
|
"organisms/Combobox.ts",
|
|
282
298
|
"primitives/controllable.ts",
|
|
299
|
+
"primitives/direction.ts",
|
|
283
300
|
"primitives/dismissable.ts",
|
|
284
301
|
"primitives/floating.ts",
|
|
285
302
|
"primitives/floatingSurface.ts",
|
|
@@ -319,6 +336,7 @@
|
|
|
319
336
|
"lib/props.ts",
|
|
320
337
|
"organisms/CommandDialog.ts",
|
|
321
338
|
"primitives/controllable.ts",
|
|
339
|
+
"primitives/direction.ts",
|
|
322
340
|
"primitives/dismissable.ts",
|
|
323
341
|
"primitives/floating.ts",
|
|
324
342
|
"primitives/focusTrap.ts",
|
|
@@ -345,6 +363,7 @@
|
|
|
345
363
|
"lib/motion.ts",
|
|
346
364
|
"lib/props.ts",
|
|
347
365
|
"organisms/ContextMenu.ts",
|
|
366
|
+
"primitives/direction.ts",
|
|
348
367
|
"primitives/dismissable.ts",
|
|
349
368
|
"primitives/floating.ts",
|
|
350
369
|
"primitives/floatingSurface.ts",
|
|
@@ -389,6 +408,7 @@
|
|
|
389
408
|
"lib/props.ts",
|
|
390
409
|
"organisms/DatePicker.ts",
|
|
391
410
|
"primitives/controllable.ts",
|
|
411
|
+
"primitives/direction.ts",
|
|
392
412
|
"primitives/dismissable.ts",
|
|
393
413
|
"primitives/floating.ts",
|
|
394
414
|
"primitives/floatingSurface.ts",
|
|
@@ -414,6 +434,7 @@
|
|
|
414
434
|
"lib/props.ts",
|
|
415
435
|
"organisms/DateRangePicker.ts",
|
|
416
436
|
"primitives/controllable.ts",
|
|
437
|
+
"primitives/direction.ts",
|
|
417
438
|
"primitives/dismissable.ts",
|
|
418
439
|
"primitives/floating.ts",
|
|
419
440
|
"primitives/floatingSurface.ts",
|
|
@@ -441,6 +462,7 @@
|
|
|
441
462
|
"lib/props.ts",
|
|
442
463
|
"organisms/Dialog.ts",
|
|
443
464
|
"primitives/controllable.ts",
|
|
465
|
+
"primitives/direction.ts",
|
|
444
466
|
"primitives/dismissable.ts",
|
|
445
467
|
"primitives/floating.ts",
|
|
446
468
|
"primitives/focusTrap.ts",
|
|
@@ -466,6 +488,7 @@
|
|
|
466
488
|
"lib/props.ts",
|
|
467
489
|
"organisms/Drawer.ts",
|
|
468
490
|
"primitives/controllable.ts",
|
|
491
|
+
"primitives/direction.ts",
|
|
469
492
|
"primitives/dismissable.ts",
|
|
470
493
|
"primitives/floating.ts",
|
|
471
494
|
"primitives/focusTrap.ts",
|
|
@@ -492,6 +515,7 @@
|
|
|
492
515
|
"lib/props.ts",
|
|
493
516
|
"organisms/DropdownMenu.ts",
|
|
494
517
|
"primitives/controllable.ts",
|
|
518
|
+
"primitives/direction.ts",
|
|
495
519
|
"primitives/dismissable.ts",
|
|
496
520
|
"primitives/floating.ts",
|
|
497
521
|
"primitives/floatingSurface.ts",
|
|
@@ -563,6 +587,7 @@
|
|
|
563
587
|
"lib/props.ts",
|
|
564
588
|
"organisms/HoverCard.ts",
|
|
565
589
|
"primitives/controllable.ts",
|
|
590
|
+
"primitives/direction.ts",
|
|
566
591
|
"primitives/dismissable.ts",
|
|
567
592
|
"primitives/floating.ts",
|
|
568
593
|
"primitives/floatingSurface.ts",
|
|
@@ -689,6 +714,7 @@
|
|
|
689
714
|
"lib/motion.ts",
|
|
690
715
|
"lib/props.ts",
|
|
691
716
|
"organisms/Menubar.ts",
|
|
717
|
+
"primitives/direction.ts",
|
|
692
718
|
"primitives/dismissable.ts",
|
|
693
719
|
"primitives/floating.ts",
|
|
694
720
|
"primitives/floatingSurface.ts",
|
|
@@ -757,6 +783,7 @@
|
|
|
757
783
|
"lib/motion.ts",
|
|
758
784
|
"lib/props.ts",
|
|
759
785
|
"organisms/NavigationMenu.ts",
|
|
786
|
+
"primitives/direction.ts",
|
|
760
787
|
"primitives/dismissable.ts",
|
|
761
788
|
"primitives/floating.ts",
|
|
762
789
|
"primitives/floatingSurface.ts",
|
|
@@ -807,6 +834,7 @@
|
|
|
807
834
|
"lib/props.ts",
|
|
808
835
|
"organisms/Popover.ts",
|
|
809
836
|
"primitives/controllable.ts",
|
|
837
|
+
"primitives/direction.ts",
|
|
810
838
|
"primitives/dismissable.ts",
|
|
811
839
|
"primitives/floating.ts",
|
|
812
840
|
"primitives/floatingSurface.ts",
|
|
@@ -900,6 +928,7 @@
|
|
|
900
928
|
"lib/props.ts",
|
|
901
929
|
"organisms/Select.ts",
|
|
902
930
|
"primitives/controllable.ts",
|
|
931
|
+
"primitives/direction.ts",
|
|
903
932
|
"primitives/dismissable.ts",
|
|
904
933
|
"primitives/floating.ts",
|
|
905
934
|
"primitives/floatingSurface.ts",
|
|
@@ -946,6 +975,7 @@
|
|
|
946
975
|
"lib/props.ts",
|
|
947
976
|
"organisms/Sheet.ts",
|
|
948
977
|
"primitives/controllable.ts",
|
|
978
|
+
"primitives/direction.ts",
|
|
949
979
|
"primitives/dismissable.ts",
|
|
950
980
|
"primitives/floating.ts",
|
|
951
981
|
"primitives/focusTrap.ts",
|
|
@@ -1050,6 +1080,7 @@
|
|
|
1050
1080
|
"lib/id.ts",
|
|
1051
1081
|
"lib/props.ts",
|
|
1052
1082
|
"molecules/Tabs.ts",
|
|
1083
|
+
"primitives/direction.ts",
|
|
1053
1084
|
"primitives/focusable.ts",
|
|
1054
1085
|
"primitives/rovingFocus.ts"
|
|
1055
1086
|
],
|
|
@@ -1077,6 +1108,7 @@
|
|
|
1077
1108
|
"lib/motion.ts",
|
|
1078
1109
|
"lib/props.ts",
|
|
1079
1110
|
"organisms/Toaster.ts",
|
|
1111
|
+
"primitives/direction.ts",
|
|
1080
1112
|
"primitives/floating.ts"
|
|
1081
1113
|
],
|
|
1082
1114
|
"dependencies": []
|
|
@@ -1108,6 +1140,24 @@
|
|
|
1108
1140
|
"toggle"
|
|
1109
1141
|
]
|
|
1110
1142
|
},
|
|
1143
|
+
{
|
|
1144
|
+
"name": "toolbar",
|
|
1145
|
+
"title": "Toolbar",
|
|
1146
|
+
"layer": "molecules",
|
|
1147
|
+
"files": [
|
|
1148
|
+
"lib/children.ts",
|
|
1149
|
+
"lib/cn.ts",
|
|
1150
|
+
"lib/props.ts",
|
|
1151
|
+
"molecules/Toolbar.ts",
|
|
1152
|
+
"primitives/direction.ts",
|
|
1153
|
+
"primitives/focusable.ts",
|
|
1154
|
+
"primitives/rovingFocus.ts"
|
|
1155
|
+
],
|
|
1156
|
+
"dependencies": [
|
|
1157
|
+
"button",
|
|
1158
|
+
"separator"
|
|
1159
|
+
]
|
|
1160
|
+
},
|
|
1111
1161
|
{
|
|
1112
1162
|
"name": "tooltip",
|
|
1113
1163
|
"title": "Tooltip",
|
|
@@ -1119,6 +1169,7 @@
|
|
|
1119
1169
|
"lib/motion.ts",
|
|
1120
1170
|
"lib/props.ts",
|
|
1121
1171
|
"organisms/Tooltip.ts",
|
|
1172
|
+
"primitives/direction.ts",
|
|
1122
1173
|
"primitives/dismissable.ts",
|
|
1123
1174
|
"primitives/floating.ts",
|
|
1124
1175
|
"primitives/floatingSurface.ts",
|
|
@@ -1141,6 +1192,18 @@
|
|
|
1141
1192
|
"molecules/Typography.ts"
|
|
1142
1193
|
],
|
|
1143
1194
|
"dependencies": []
|
|
1195
|
+
},
|
|
1196
|
+
{
|
|
1197
|
+
"name": "visually-hidden",
|
|
1198
|
+
"title": "VisuallyHidden",
|
|
1199
|
+
"layer": "atoms",
|
|
1200
|
+
"files": [
|
|
1201
|
+
"atoms/VisuallyHidden.ts",
|
|
1202
|
+
"lib/children.ts",
|
|
1203
|
+
"lib/cn.ts",
|
|
1204
|
+
"lib/props.ts"
|
|
1205
|
+
],
|
|
1206
|
+
"dependencies": []
|
|
1144
1207
|
}
|
|
1145
1208
|
]
|
|
1146
1209
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AccessibleIcon — an icon with a name only a screen reader hears.
|
|
3
|
+
*
|
|
4
|
+
* An icon on its own is a picture of a word. Sighted users read the picture;
|
|
5
|
+
* a screen reader reads nothing at all, because an `<svg>` with no label is
|
|
6
|
+
* announced as nothing — which is how a delete button becomes an unlabelled
|
|
7
|
+
* button in the middle of a row of unlabelled buttons.
|
|
8
|
+
*
|
|
9
|
+
* Two halves, and both matter. The icon is marked `aria-hidden` so its own
|
|
10
|
+
* internals — a `<title>`, a stray `<text>` — are not announced on top of the
|
|
11
|
+
* label; the label is visually hidden text beside it. `aria-label` on the
|
|
12
|
+
* parent would do for a plain string, but it does not survive translation
|
|
13
|
+
* tooling the way real text does, and it cannot carry markup.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { component, html } from "@c9up/aurora";
|
|
17
|
+
import { type Slot, slot } from "../lib/children.js";
|
|
18
|
+
import { cn } from "../lib/cn.js";
|
|
19
|
+
import { type Reactive, read } from "../lib/props.js";
|
|
20
|
+
import { VisuallyHidden } from "./VisuallyHidden.js";
|
|
21
|
+
|
|
22
|
+
export interface AccessibleIconProps {
|
|
23
|
+
/** The icon. Hidden from the accessibility tree. */
|
|
24
|
+
children?: Slot;
|
|
25
|
+
/** What the icon means, in words. */
|
|
26
|
+
label: Reactive<string>;
|
|
27
|
+
class?: Reactive<string>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const AccessibleIcon = component<AccessibleIconProps>((props) => {
|
|
31
|
+
return html`<span
|
|
32
|
+
data-slot="accessible-icon"
|
|
33
|
+
class="${() => cn("contents", read(props.class))}"
|
|
34
|
+
><span aria-hidden="true" class="contents">${slot(props.children)}</span>${VisuallyHidden(
|
|
35
|
+
{
|
|
36
|
+
children: () => read(props.label),
|
|
37
|
+
},
|
|
38
|
+
)}</span>`;
|
|
39
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VisuallyHidden — text for a screen reader and nothing else.
|
|
3
|
+
*
|
|
4
|
+
* Not `display: none`, which removes it from the accessibility tree as well,
|
|
5
|
+
* and not `opacity: 0`, which keeps it taking space. The clip rectangle is the
|
|
6
|
+
* one technique that leaves the node announced and unrendered, and it is
|
|
7
|
+
* fiddly enough that hand-writing it in each component is how one of them ends
|
|
8
|
+
* up subtly wrong.
|
|
9
|
+
*
|
|
10
|
+
* Its main job is the label a sighted user does not need: a dialog whose title
|
|
11
|
+
* is a logo, an icon button, a table caption. `aria-label` covers some of
|
|
12
|
+
* those, but not the ones where the content is real markup — a heading that a
|
|
13
|
+
* `aria-labelledby` has to point at, for instance.
|
|
14
|
+
*
|
|
15
|
+
* `focusable` keeps it hidden until it is tabbed to, which is what a skip link
|
|
16
|
+
* needs: invisible in the layout, and visible the moment it has focus.
|
|
17
|
+
*
|
|
18
|
+
* Always a `<span>`. Radix takes an `asChild` here so a hidden heading can be
|
|
19
|
+
* a real `<h2>`; aurora's template parser fixes the tag at compile time, so
|
|
20
|
+
* the equivalent is to put this inside the heading rather than to become one.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { component, html } from "@c9up/aurora";
|
|
24
|
+
import { type Slot, slot } from "../lib/children.js";
|
|
25
|
+
import { cn } from "../lib/cn.js";
|
|
26
|
+
import { type Reactive, read } from "../lib/props.js";
|
|
27
|
+
|
|
28
|
+
export interface VisuallyHiddenProps {
|
|
29
|
+
children?: Slot;
|
|
30
|
+
/** Reveal it once focused — for a skip link. Default `false`. */
|
|
31
|
+
focusable?: boolean;
|
|
32
|
+
class?: Reactive<string>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Tailwind's own `sr-only`, plus its counterpart for the focusable case. */
|
|
36
|
+
const HIDDEN = "sr-only";
|
|
37
|
+
const FOCUSABLE = "sr-only focus-within:not-sr-only focus:not-sr-only";
|
|
38
|
+
|
|
39
|
+
export const VisuallyHidden = component<VisuallyHiddenProps>((props) => {
|
|
40
|
+
const base = props.focusable === true ? FOCUSABLE : HIDDEN;
|
|
41
|
+
return html`<span
|
|
42
|
+
data-slot="visually-hidden"
|
|
43
|
+
class="${() => cn(base, read(props.class))}"
|
|
44
|
+
>${slot(props.children)}</span>`;
|
|
45
|
+
});
|
package/src/atoms/index.ts
CHANGED
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
* Slider is an atom despite being interactive, because it is one input.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
+
export {
|
|
16
|
+
AccessibleIcon,
|
|
17
|
+
type AccessibleIconProps,
|
|
18
|
+
} from "./AccessibleIcon.js";
|
|
15
19
|
export { AspectRatio, type AspectRatioProps } from "./AspectRatio.js";
|
|
16
20
|
export {
|
|
17
21
|
Avatar,
|
|
@@ -82,3 +86,7 @@ export {
|
|
|
82
86
|
type ToggleVariants,
|
|
83
87
|
toggleVariants,
|
|
84
88
|
} from "./Toggle.js";
|
|
89
|
+
export {
|
|
90
|
+
VisuallyHidden,
|
|
91
|
+
type VisuallyHiddenProps,
|
|
92
|
+
} from "./VisuallyHidden.js";
|
package/src/configure.ts
CHANGED
|
@@ -21,6 +21,7 @@ import { resolve } from "node:path";
|
|
|
21
21
|
import { adapterFor, isAdapterName } from "./adapters/index.js";
|
|
22
22
|
import type { GeneratedFile } from "./adapters/types.js";
|
|
23
23
|
import { type AdapterName, resolveConfig } from "./config.js";
|
|
24
|
+
import { stubsRoot } from "./stubs.js";
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* The subset of the CLI's codemods this hook uses.
|
|
@@ -38,33 +39,17 @@ interface Codemods {
|
|
|
38
39
|
): Promise<void>;
|
|
39
40
|
/** Appends to `reamrc.commands` — the channel for package-shipped commands. */
|
|
40
41
|
registerCommand(importPath: string): Promise<void>;
|
|
42
|
+
makeUsingStub(
|
|
43
|
+
stubsRoot: string,
|
|
44
|
+
stubPath: string,
|
|
45
|
+
state?: Record<string, string | number | boolean>,
|
|
46
|
+
options?: { force?: boolean },
|
|
47
|
+
): Promise<{ path: string; contents: string }>;
|
|
41
48
|
}
|
|
42
49
|
|
|
43
50
|
/** Flags forwarded from `ream add` / `ream configure`, as the CLI encodes them. */
|
|
44
51
|
type Flags = Record<string, string[] | undefined>;
|
|
45
52
|
|
|
46
|
-
function configFile(adapter: AdapterName): string {
|
|
47
|
-
return `import { defineConfig } from '@c9up/nebula'
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* nebula — component registry and style adapter.
|
|
51
|
-
*
|
|
52
|
-
* Changing \`adapter\` and re-running \`ream configure @c9up/nebula\` swaps the
|
|
53
|
-
* CSS engine. The components themselves are untouched: all three adapters
|
|
54
|
-
* consume the same class names.
|
|
55
|
-
*/
|
|
56
|
-
export default defineConfig({
|
|
57
|
-
adapter: '${adapter}',
|
|
58
|
-
paths: {
|
|
59
|
-
// Where \`ream nebula:add\` copies components. The atomic layers live under it.
|
|
60
|
-
components: 'resources/pages',
|
|
61
|
-
css: 'resources/css/app.css',
|
|
62
|
-
output: 'public/app.css',
|
|
63
|
-
},
|
|
64
|
-
})
|
|
65
|
-
`;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
53
|
/**
|
|
69
54
|
* Read the adapter from the forwarded flags.
|
|
70
55
|
*
|
|
@@ -91,7 +76,9 @@ export async function configure(
|
|
|
91
76
|
const adapter = adapterFor(name);
|
|
92
77
|
const config = resolveConfig({ adapter: name });
|
|
93
78
|
|
|
94
|
-
await codemods.
|
|
79
|
+
await codemods.makeUsingStub(stubsRoot, "config/nebula.stub", {
|
|
80
|
+
adapter: name,
|
|
81
|
+
});
|
|
95
82
|
|
|
96
83
|
// `reamrc.commands` is the channel Ream provides for commands a package
|
|
97
84
|
// ships, which directory discovery cannot see. `ream` forwards any
|
package/src/index.ts
CHANGED
|
@@ -13,10 +13,13 @@
|
|
|
13
13
|
* icons are inlined, and the date maths is `Date` and `Intl`.
|
|
14
14
|
*
|
|
15
15
|
* **Compound components take data, not children.** shadcn composes through
|
|
16
|
-
* React context — `<Tabs><TabsList><TabsTrigger>`. Aurora has
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* React context — `<Tabs><TabsList><TabsTrigger>`. Aurora has context too, and
|
|
17
|
+
* these components use it; what they do not do is take their parts as children.
|
|
18
|
+
* Context here lives on a stack during a component's SETUP, so a part handed in
|
|
19
|
+
* as a `Slot` thunk is built later, once that frame has popped, and reads
|
|
20
|
+
* nothing. An `items` array and named slots keep every part built while the
|
|
21
|
+
* context is still there. The rendered markup is unchanged, which means shadcn's
|
|
22
|
+
* CSS and its examples still read across.
|
|
20
23
|
*
|
|
21
24
|
* **The atomic layer is a property of the component.** An atom renders its own
|
|
22
25
|
* markup and composes nothing from nebula; a molecule assembles atoms or owns
|
package/src/lib/id.ts
CHANGED
|
@@ -1,44 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Stable element ids.
|
|
2
|
+
* Stable element ids — aurora's counter, re-exported.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* It was nebula's own, and that was the bug: aurora resets its sequence at the
|
|
5
|
+
* start of each render pass (`renderPage` server-side, `hydrate` in the
|
|
6
|
+
* browser), and a second counter living here saw none of those resets. A
|
|
7
|
+
* long-lived server therefore shipped `tooltip-trigger-14` while the browser,
|
|
8
|
+
* hydrating from zero, minted `tooltip-trigger-1` and looked it up — so
|
|
9
|
+
* `byId` answered `null`, `floatingSurface` had no anchor, and the tooltip
|
|
10
|
+
* never opened although its mount hook had run and its trigger was wired.
|
|
9
11
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* server and in the browser for the same tree, which is what makes the ids
|
|
13
|
-
* survive hydration — the same property React's `useId` relies on.
|
|
14
|
-
*
|
|
15
|
-
* `resetIds()` exists for the server: a long-lived process renders many
|
|
16
|
-
* requests, and without a reset the counter climbs forever and every response
|
|
17
|
-
* ships different markup, defeating any HTML cache. Call it once per render
|
|
18
|
-
* pass, before the tree is built.
|
|
12
|
+
* Every id nebula mints has to come from the same counter aurora resets; the
|
|
13
|
+
* names are kept so nothing importing them has to change.
|
|
19
14
|
*/
|
|
20
15
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
/** Mint an id unique within this render pass. */
|
|
24
|
-
export function uid(prefix = "nebula"): string {
|
|
25
|
-
counter += 1;
|
|
26
|
-
return `${prefix}-${counter}`;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** Restart the sequence. Call once per SSR render, before building the tree. */
|
|
30
|
-
export function resetIds(): void {
|
|
31
|
-
counter = 0;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Look an element up by the id a component minted for it.
|
|
36
|
-
*
|
|
37
|
-
* Returns `null` off the DOM (SSR) or before mount rather than throwing, so
|
|
38
|
-
* callers can run the same code in both environments. Every consumer inside
|
|
39
|
-
* nebula is in `onMount`, where the node is live.
|
|
40
|
-
*/
|
|
41
|
-
export function byId(id: string): HTMLElement | null {
|
|
42
|
-
if (typeof document === "undefined") return null;
|
|
43
|
-
return document.getElementById(id);
|
|
44
|
-
}
|
|
16
|
+
export { byId, resetIds, uid } from "@c9up/aurora";
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Toolbar — a row of controls that behaves as one tab stop.
|
|
3
|
+
*
|
|
4
|
+
* Radix ships this as a primitive and shadcn styles no equivalent, which is
|
|
5
|
+
* why it is easy to miss: a page builds a `<div class="flex gap-2">` full of
|
|
6
|
+
* buttons and it looks right. What it is not is navigable. Eleven buttons in a
|
|
7
|
+
* formatting bar are eleven presses of Tab to get past, and a keyboard user
|
|
8
|
+
* reaching the content below pays for every one of them.
|
|
9
|
+
*
|
|
10
|
+
* The WAI-ARIA toolbar pattern says: one tab stop, arrows move inside it. That
|
|
11
|
+
* is `rovingFocus`, which nebula already owns for menus and tab lists — the
|
|
12
|
+
* only thing a toolbar adds is `role="toolbar"`, the orientation, and a
|
|
13
|
+
* separator that is announced as one.
|
|
14
|
+
*
|
|
15
|
+
* The items are whatever the caller puts in — `Button`, `Toggle`, a `Select`
|
|
16
|
+
* trigger, a plain `<a>` — found by the same tabbable selector the focus trap
|
|
17
|
+
* uses. No marker attribute to remember: a control that a keyboard could
|
|
18
|
+
* reach on its own is a control the arrows reach here, and one that could not
|
|
19
|
+
* was never in the tab order to begin with.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { component, html, onMount, onUnmount, uid } from "@c9up/aurora";
|
|
23
|
+
import { Button, type ButtonProps } from "../atoms/Button.js";
|
|
24
|
+
import { Separator } from "../atoms/Separator.js";
|
|
25
|
+
import { type Slot, slot } from "../lib/children.js";
|
|
26
|
+
import { cn } from "../lib/cn.js";
|
|
27
|
+
import { type Reactive, read } from "../lib/props.js";
|
|
28
|
+
import { FOCUSABLE_SELECTOR } from "../primitives/focusable.js";
|
|
29
|
+
import { type RovingFocus, rovingFocus } from "../primitives/rovingFocus.js";
|
|
30
|
+
|
|
31
|
+
export interface ToolbarProps {
|
|
32
|
+
children?: Slot;
|
|
33
|
+
/** Which arrows move focus. Default `"horizontal"`, as a toolbar reads. */
|
|
34
|
+
orientation?: "horizontal" | "vertical";
|
|
35
|
+
/** Wrap from the last control back to the first. Default `true`. */
|
|
36
|
+
loop?: boolean;
|
|
37
|
+
/** Announced name — a page with two toolbars needs to tell them apart. */
|
|
38
|
+
label?: Reactive<string>;
|
|
39
|
+
class?: Reactive<string>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const Toolbar = component<ToolbarProps>((props) => {
|
|
43
|
+
const orientation = props.orientation ?? "horizontal";
|
|
44
|
+
const barId = uid("toolbar");
|
|
45
|
+
let group: RovingFocus | undefined;
|
|
46
|
+
|
|
47
|
+
onMount(() => {
|
|
48
|
+
group = rovingFocus({
|
|
49
|
+
container: () => document.getElementById(barId),
|
|
50
|
+
itemSelector: FOCUSABLE_SELECTOR,
|
|
51
|
+
orientation,
|
|
52
|
+
loop: props.loop !== false,
|
|
53
|
+
});
|
|
54
|
+
// The controls exist by now; without this none of them carries
|
|
55
|
+
// `tabindex="0"` and the bar cannot be reached by Tab at all.
|
|
56
|
+
group.sync();
|
|
57
|
+
});
|
|
58
|
+
onUnmount(() => group?.destroy());
|
|
59
|
+
|
|
60
|
+
return html`<div
|
|
61
|
+
data-slot="toolbar"
|
|
62
|
+
id="${barId}"
|
|
63
|
+
role="toolbar"
|
|
64
|
+
aria-orientation="${orientation}"
|
|
65
|
+
aria-label="${() => read(props.label) ?? ""}"
|
|
66
|
+
class="${() =>
|
|
67
|
+
cn(
|
|
68
|
+
"flex items-center gap-1",
|
|
69
|
+
orientation === "vertical" ? "flex-col" : "flex-row",
|
|
70
|
+
read(props.class),
|
|
71
|
+
)}"
|
|
72
|
+
>${slot(props.children)}</div>`;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
export interface ToolbarButtonProps extends ButtonProps {}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A control inside the bar.
|
|
79
|
+
*
|
|
80
|
+
* `Button` with the defaults a toolbar wants — ghost, small — so a row of them
|
|
81
|
+
* reads as a bar rather than as six primary actions competing for attention.
|
|
82
|
+
* Nothing else: a plain `Button` dropped in the bar navigates identically,
|
|
83
|
+
* which is the point of finding items by focusability.
|
|
84
|
+
*/
|
|
85
|
+
export const ToolbarButton = component<ToolbarButtonProps>((props) =>
|
|
86
|
+
Button({ variant: "ghost", size: "sm", ...props }),
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
export interface ToolbarSeparatorProps {
|
|
90
|
+
class?: Reactive<string>;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** A boundary between groups of controls, announced as one. */
|
|
94
|
+
export const ToolbarSeparator = component<ToolbarSeparatorProps>((props) => {
|
|
95
|
+
return Separator({
|
|
96
|
+
orientation: "vertical",
|
|
97
|
+
decorative: false,
|
|
98
|
+
class: () => cn("mx-1 h-6 self-center", read(props.class)),
|
|
99
|
+
});
|
|
100
|
+
});
|
package/src/molecules/index.ts
CHANGED
|
@@ -8,11 +8,12 @@
|
|
|
8
8
|
* organisms.
|
|
9
9
|
*
|
|
10
10
|
* Compound components are data-driven — `Accordion({ items: [...] })`, not
|
|
11
|
-
* `<Accordion><AccordionItem>`.
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
11
|
+
* `<Accordion><AccordionItem>`. Not for want of context: Aurora has it and these
|
|
12
|
+
* components use it. It lives on a stack during SETUP, so a part passed as a
|
|
13
|
+
* `Slot` thunk is built after that frame has popped and has nothing to read —
|
|
14
|
+
* which is exactly the shape `<Accordion><AccordionItem>` would need. Data keeps
|
|
15
|
+
* every part built while the context is there. The rendered markup is unchanged,
|
|
16
|
+
* so shadcn's CSS and its examples still read across.
|
|
16
17
|
*/
|
|
17
18
|
|
|
18
19
|
export {
|
|
@@ -206,6 +207,14 @@ export {
|
|
|
206
207
|
type ToggleGroupItemProps,
|
|
207
208
|
type ToggleGroupProps,
|
|
208
209
|
} from "./ToggleGroup.js";
|
|
210
|
+
export {
|
|
211
|
+
Toolbar,
|
|
212
|
+
ToolbarButton,
|
|
213
|
+
type ToolbarButtonProps,
|
|
214
|
+
type ToolbarProps,
|
|
215
|
+
ToolbarSeparator,
|
|
216
|
+
type ToolbarSeparatorProps,
|
|
217
|
+
} from "./Toolbar.js";
|
|
209
218
|
export {
|
|
210
219
|
Blockquote,
|
|
211
220
|
H1,
|