@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.
- 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/index.d.ts +7 -4
- package/dist/index.js +7 -4
- 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/nebula.css +1 -1
- package/package.json +1 -1
- 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/index.ts +7 -4
- 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/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Part of **[Ream](https://github.com/C9up/ream)** — a Rust-powered, AdonisJS-co
|
|
|
8
8
|
|
|
9
9
|
shadcn/ui is React. [Aurora](https://github.com/C9up/aurora) is a tagged-template DOM runtime with signals and no build step. nebula is the shadcn component set — the same markup, the same Tailwind classes, the same behaviour — written for Aurora.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Seventy-four components across four atomic layers, plus the headless behaviour layer Radix would otherwise provide. Every component in shadcn's registry has a counterpart; several are deliberately narrower, and the [parity section](#parity-with-shadcn) says exactly which.
|
|
12
12
|
|
|
13
13
|
## Installation
|
|
14
14
|
|
|
@@ -82,7 +82,7 @@ Several of those are narrower than what they replace — see [parity with shadcn
|
|
|
82
82
|
|
|
83
83
|
Checked against shadcn's published component list, not from memory. Every one of its components has a counterpart here — including the conversational set (`Bubble`, `Message`, `MessageScroller`, `Attachment`, `Marker`), `NativeSelect` and `Questionnaire` — and the ~40 simple ones are faithful down to the class strings, the variants and the ARIA attributes.
|
|
84
84
|
|
|
85
|
-
Two of shadcn's entries have no direct counterpart on purpose. `DirectionProvider` is React context
|
|
85
|
+
Two of shadcn's entries have no direct counterpart on purpose. `DirectionProvider` is React context. Aurora has context, and these components use it, but the direction belongs on `<html dir>` — what it was really buying is [RTL support](#right-to-left), which is handled in the placement engine instead. `Form` has been folded into `Field` upstream; nebula ships both, with `Form` binding Aurora's own form controller. The components shadcn builds by wrapping a third-party library are reimplementations, and they are narrower. Stated plainly, because "complete port" would not be true:
|
|
86
86
|
|
|
87
87
|
| Component | shadcn | nebula |
|
|
88
88
|
| --- | --- | --- |
|
|
@@ -90,7 +90,7 @@ Two of shadcn's entries have no direct counterpart on purpose. `DirectionProvide
|
|
|
90
90
|
| DataTable | TanStack Table (column grouping, virtualisation, pinning, faceted filters, server-side) | sort, filter, page, select — in memory |
|
|
91
91
|
| Sidebar | ~15 parts | the parts that are not re-skinned atoms — see below |
|
|
92
92
|
| Carousel | embla (loop, autoplay, N slides per view) | scroll-snap, one slide per view, no loop or autoplay |
|
|
93
|
-
| Toaster |
|
|
93
|
+
| Toaster | Base UI's manager (display priority, anchored toasts, typed payload) — or sonner, with six positions | five variants, promise toasts, update and dedup by id, action, `onClose`, pause on hover, four corners |
|
|
94
94
|
| Resizable | arbitrary nesting, persisted layouts, collapse-to-zero | two panes, one handle |
|
|
95
95
|
| Combobox | single, multi-select and creatable recipes | single-select |
|
|
96
96
|
| ScrollArea | scrollbars redrawn by Radix | native scrollbars, styled |
|
|
@@ -98,7 +98,7 @@ Two of shadcn's entries have no direct counterpart on purpose. `DirectionProvide
|
|
|
98
98
|
| Questionnaire | branching logic, validation schemas | linear steps; single, multiple, freeform, skippable |
|
|
99
99
|
| Bubble / Message | rich composition slots | the parts nebula's own layout needs |
|
|
100
100
|
|
|
101
|
-
Two API-wide differences, both consequences of the runtime rather than choices about scope: there is no `asChild` (a compiled template has no element to clone), and compound components take data rather than children (Aurora has
|
|
101
|
+
Two API-wide differences, both consequences of the runtime rather than choices about scope: there is no `asChild` (a compiled template has no element to clone), and compound components take data rather than children (Aurora's context lives on a stack during setup, so a part passed as a lazy slot is built after that frame has popped — see below).
|
|
102
102
|
|
|
103
103
|
**The Sidebar deserves its own note**, because porting it part-for-part would have fought the atomic taxonomy rather than following it. `SidebarInput`, `SidebarSeparator` and `SidebarMenuSkeleton` are the existing `Input`, `Separator` and `Skeleton` atoms with a prefix — redeclaring them would break the composition rule the whole library is organised on. `SidebarProvider` is React context, and nebula's sidebar owns its own shared signal instead. `SidebarInset` is the content column beside the rail, which is `AppShell`, a template. What was genuinely missing and has been added: `SidebarMenuSub`, `SidebarMenuSubItem`, `SidebarMenuAction`, a badge slot, and tooltips when the rail is collapsed.
|
|
104
104
|
|
|
@@ -194,11 +194,11 @@ resources/pages/
|
|
|
194
194
|
The rule is composition, not complexity. Slider is an atom though it is interactive, because it is one input. Card is a molecule though it is trivial, because it assembles parts.
|
|
195
195
|
|
|
196
196
|
<details>
|
|
197
|
-
<summary><strong>All
|
|
197
|
+
<summary><strong>All 74 components</strong></summary>
|
|
198
198
|
|
|
199
|
-
**atoms (
|
|
199
|
+
**atoms (22)** — AccessibleIcon, AspectRatio, Avatar, Badge, Button, Checkbox, Image, Input, Kbd, Label, Marker, NativeSelect, Progress, ScrollArea, Separator, Skeleton, Slider, Spinner, Switch, Textarea, Toggle, VisuallyHidden
|
|
200
200
|
|
|
201
|
-
**molecules (
|
|
201
|
+
**molecules (23)** — Accordion, Alert, Attachment, Breadcrumb, Bubble, ButtonGroup, Card, Collapsible, Empty, Field, InputGroup, InputOTP, Item, Message, Pagination, Picture, RadioGroup, Resizable, Table, Tabs, ToggleGroup, Toolbar, Typography
|
|
202
202
|
|
|
203
203
|
**organisms (26)** — AlertDialog, Calendar, Carousel, Chart, Combobox, Command, CommandDialog, ContextMenu, DataTable, DatePicker, DateRangePicker, Dialog, Drawer, DropdownMenu, Form, HoverCard, Menubar, MessageScroller, NavigationMenu, Popover, Questionnaire, Select, Sheet, Sidebar, Toaster, Tooltip
|
|
204
204
|
|
|
@@ -217,7 +217,9 @@ shadcn composes through React context:
|
|
|
217
217
|
</Tabs>
|
|
218
218
|
```
|
|
219
219
|
|
|
220
|
-
Aurora
|
|
220
|
+
Aurora **does** have context — `createContext` / `provide` / `inject` — and these components use it: `Tabs` provides a `TabsApi` that `TabsTrigger` and `TabsContent` inject. What they do not do is take their parts as children.
|
|
221
|
+
|
|
222
|
+
Context here lives on a stack during a component's **setup**, which is synchronous. A part handed in as a `Slot` thunk is built later, by the renderer, when that frame has already popped — so the shadcn shape, where a child reads the parent it was nested inside, cannot read anything. Taking data keeps every part built during setup, while the context is still there. So compound components take data:
|
|
221
223
|
|
|
222
224
|
```ts
|
|
223
225
|
Tabs({
|
|
@@ -273,7 +275,7 @@ The headless layer is most of this package, and it is where shadcn's behaviour a
|
|
|
273
275
|
## Development
|
|
274
276
|
|
|
275
277
|
```bash
|
|
276
|
-
pnpm test #
|
|
278
|
+
pnpm test # 593 unit tests
|
|
277
279
|
pnpm typecheck
|
|
278
280
|
pnpm lint
|
|
279
281
|
pnpm registry # regenerate registry.json from the source tree
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
import { type Slot } from "../lib/children.js";
|
|
16
|
+
import { type Reactive } from "../lib/props.js";
|
|
17
|
+
export interface AccessibleIconProps {
|
|
18
|
+
/** The icon. Hidden from the accessibility tree. */
|
|
19
|
+
children?: Slot;
|
|
20
|
+
/** What the icon means, in words. */
|
|
21
|
+
label: Reactive<string>;
|
|
22
|
+
class?: Reactive<string>;
|
|
23
|
+
}
|
|
24
|
+
export declare const AccessibleIcon: (props?: AccessibleIconProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
import { component, html } from "@c9up/aurora";
|
|
16
|
+
import { slot } from "../lib/children.js";
|
|
17
|
+
import { cn } from "../lib/cn.js";
|
|
18
|
+
import { read } from "../lib/props.js";
|
|
19
|
+
import { VisuallyHidden } from "./VisuallyHidden.js";
|
|
20
|
+
export const AccessibleIcon = component((props) => {
|
|
21
|
+
return html `<span
|
|
22
|
+
data-slot="accessible-icon"
|
|
23
|
+
class="${() => cn("contents", read(props.class))}"
|
|
24
|
+
><span aria-hidden="true" class="contents">${slot(props.children)}</span>${VisuallyHidden({
|
|
25
|
+
children: () => read(props.label),
|
|
26
|
+
})}</span>`;
|
|
27
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
import { type Slot } from "../lib/children.js";
|
|
23
|
+
import { type Reactive } from "../lib/props.js";
|
|
24
|
+
export interface VisuallyHiddenProps {
|
|
25
|
+
children?: Slot;
|
|
26
|
+
/** Reveal it once focused — for a skip link. Default `false`. */
|
|
27
|
+
focusable?: boolean;
|
|
28
|
+
class?: Reactive<string>;
|
|
29
|
+
}
|
|
30
|
+
export declare const VisuallyHidden: (props?: VisuallyHiddenProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
import { component, html } from "@c9up/aurora";
|
|
23
|
+
import { slot } from "../lib/children.js";
|
|
24
|
+
import { cn } from "../lib/cn.js";
|
|
25
|
+
import { read } from "../lib/props.js";
|
|
26
|
+
/** Tailwind's own `sr-only`, plus its counterpart for the focusable case. */
|
|
27
|
+
const HIDDEN = "sr-only";
|
|
28
|
+
const FOCUSABLE = "sr-only focus-within:not-sr-only focus:not-sr-only";
|
|
29
|
+
export const VisuallyHidden = component((props) => {
|
|
30
|
+
const base = props.focusable === true ? FOCUSABLE : HIDDEN;
|
|
31
|
+
return html `<span
|
|
32
|
+
data-slot="visually-hidden"
|
|
33
|
+
class="${() => cn(base, read(props.class))}"
|
|
34
|
+
>${slot(props.children)}</span>`;
|
|
35
|
+
});
|
package/dist/atoms/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* a molecule despite being simpler than Slider, because it assembles parts.
|
|
12
12
|
* Slider is an atom despite being interactive, because it is one input.
|
|
13
13
|
*/
|
|
14
|
+
export { AccessibleIcon, type AccessibleIconProps, } from "./AccessibleIcon.js";
|
|
14
15
|
export { AspectRatio, type AspectRatioProps } from "./AspectRatio.js";
|
|
15
16
|
export { Avatar, AvatarBadge, type AvatarBadgeProps, AvatarFallback, type AvatarFallbackProps, AvatarGroup, AvatarGroupCount, type AvatarGroupProps, AvatarImage, type AvatarImageProps, type AvatarProps, } from "./Avatar.js";
|
|
16
17
|
export { Badge, type BadgeProps, type BadgeVariants, badgeVariants, } from "./Badge.js";
|
|
@@ -31,3 +32,4 @@ export { Spinner, type SpinnerProps } from "./Spinner.js";
|
|
|
31
32
|
export { Switch, type SwitchProps, switchTrackClasses } from "./Switch.js";
|
|
32
33
|
export { Textarea, type TextareaProps, textareaClasses } from "./Textarea.js";
|
|
33
34
|
export { Toggle, type ToggleProps, type ToggleVariants, toggleVariants, } from "./Toggle.js";
|
|
35
|
+
export { VisuallyHidden, type VisuallyHiddenProps, } from "./VisuallyHidden.js";
|
package/dist/atoms/index.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* a molecule despite being simpler than Slider, because it assembles parts.
|
|
12
12
|
* Slider is an atom despite being interactive, because it is one input.
|
|
13
13
|
*/
|
|
14
|
+
export { AccessibleIcon, } from "./AccessibleIcon.js";
|
|
14
15
|
export { AspectRatio } from "./AspectRatio.js";
|
|
15
16
|
export { Avatar, AvatarBadge, AvatarFallback, AvatarGroup, AvatarGroupCount, AvatarImage, } from "./Avatar.js";
|
|
16
17
|
export { Badge, badgeVariants, } from "./Badge.js";
|
|
@@ -31,3 +32,4 @@ export { Spinner } from "./Spinner.js";
|
|
|
31
32
|
export { Switch, switchTrackClasses } from "./Switch.js";
|
|
32
33
|
export { Textarea, textareaClasses } from "./Textarea.js";
|
|
33
34
|
export { Toggle, toggleVariants, } from "./Toggle.js";
|
|
35
|
+
export { VisuallyHidden, } from "./VisuallyHidden.js";
|
package/dist/index.d.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/dist/index.js
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
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
import { type ButtonProps } from "../atoms/Button.js";
|
|
22
|
+
import { type Slot } from "../lib/children.js";
|
|
23
|
+
import { type Reactive } from "../lib/props.js";
|
|
24
|
+
export interface ToolbarProps {
|
|
25
|
+
children?: Slot;
|
|
26
|
+
/** Which arrows move focus. Default `"horizontal"`, as a toolbar reads. */
|
|
27
|
+
orientation?: "horizontal" | "vertical";
|
|
28
|
+
/** Wrap from the last control back to the first. Default `true`. */
|
|
29
|
+
loop?: boolean;
|
|
30
|
+
/** Announced name — a page with two toolbars needs to tell them apart. */
|
|
31
|
+
label?: Reactive<string>;
|
|
32
|
+
class?: Reactive<string>;
|
|
33
|
+
}
|
|
34
|
+
export declare const Toolbar: (props?: ToolbarProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
35
|
+
export interface ToolbarButtonProps extends ButtonProps {
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A control inside the bar.
|
|
39
|
+
*
|
|
40
|
+
* `Button` with the defaults a toolbar wants — ghost, small — so a row of them
|
|
41
|
+
* reads as a bar rather than as six primary actions competing for attention.
|
|
42
|
+
* Nothing else: a plain `Button` dropped in the bar navigates identically,
|
|
43
|
+
* which is the point of finding items by focusability.
|
|
44
|
+
*/
|
|
45
|
+
export declare const ToolbarButton: (props?: ToolbarButtonProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
46
|
+
export interface ToolbarSeparatorProps {
|
|
47
|
+
class?: Reactive<string>;
|
|
48
|
+
}
|
|
49
|
+
/** A boundary between groups of controls, announced as one. */
|
|
50
|
+
export declare const ToolbarSeparator: (props?: ToolbarSeparatorProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
import { component, html, onMount, onUnmount, uid } from "@c9up/aurora";
|
|
22
|
+
import { Button } from "../atoms/Button.js";
|
|
23
|
+
import { Separator } from "../atoms/Separator.js";
|
|
24
|
+
import { slot } from "../lib/children.js";
|
|
25
|
+
import { cn } from "../lib/cn.js";
|
|
26
|
+
import { read } from "../lib/props.js";
|
|
27
|
+
import { FOCUSABLE_SELECTOR } from "../primitives/focusable.js";
|
|
28
|
+
import { rovingFocus } from "../primitives/rovingFocus.js";
|
|
29
|
+
export const Toolbar = component((props) => {
|
|
30
|
+
const orientation = props.orientation ?? "horizontal";
|
|
31
|
+
const barId = uid("toolbar");
|
|
32
|
+
let group;
|
|
33
|
+
onMount(() => {
|
|
34
|
+
group = rovingFocus({
|
|
35
|
+
container: () => document.getElementById(barId),
|
|
36
|
+
itemSelector: FOCUSABLE_SELECTOR,
|
|
37
|
+
orientation,
|
|
38
|
+
loop: props.loop !== false,
|
|
39
|
+
});
|
|
40
|
+
// The controls exist by now; without this none of them carries
|
|
41
|
+
// `tabindex="0"` and the bar cannot be reached by Tab at all.
|
|
42
|
+
group.sync();
|
|
43
|
+
});
|
|
44
|
+
onUnmount(() => group?.destroy());
|
|
45
|
+
return html `<div
|
|
46
|
+
data-slot="toolbar"
|
|
47
|
+
id="${barId}"
|
|
48
|
+
role="toolbar"
|
|
49
|
+
aria-orientation="${orientation}"
|
|
50
|
+
aria-label="${() => read(props.label) ?? ""}"
|
|
51
|
+
class="${() => cn("flex items-center gap-1", orientation === "vertical" ? "flex-col" : "flex-row", read(props.class))}"
|
|
52
|
+
>${slot(props.children)}</div>`;
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* A control inside the bar.
|
|
56
|
+
*
|
|
57
|
+
* `Button` with the defaults a toolbar wants — ghost, small — so a row of them
|
|
58
|
+
* reads as a bar rather than as six primary actions competing for attention.
|
|
59
|
+
* Nothing else: a plain `Button` dropped in the bar navigates identically,
|
|
60
|
+
* which is the point of finding items by focusability.
|
|
61
|
+
*/
|
|
62
|
+
export const ToolbarButton = component((props) => Button({ variant: "ghost", size: "sm", ...props }));
|
|
63
|
+
/** A boundary between groups of controls, announced as one. */
|
|
64
|
+
export const ToolbarSeparator = component((props) => {
|
|
65
|
+
return Separator({
|
|
66
|
+
orientation: "vertical",
|
|
67
|
+
decorative: false,
|
|
68
|
+
class: () => cn("mx-1 h-6 self-center", read(props.class)),
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -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
|
export { Accordion, AccordionContent, type AccordionContentProps, AccordionItem, type AccordionItemProps, type AccordionProps, AccordionTrigger, type AccordionTriggerProps, } from "./Accordion.js";
|
|
18
19
|
export { Alert, AlertDescription, type AlertProps, AlertTitle, type AlertVariants, alertVariants, } from "./Alert.js";
|
|
@@ -35,4 +36,5 @@ export { ResizableHandle, type ResizableHandleProps, ResizablePanel, ResizablePa
|
|
|
35
36
|
export { Table, TableBody, TableCaption, TableCell, type TableCellProps, TableFooter, TableHead, TableHeader, type TableProps, TableRow, type TableRowProps, } from "./Table.js";
|
|
36
37
|
export { Tabs, TabsContent, type TabsContentProps, TabsList, type TabsListProps, type TabsListVariants, type TabsProps, TabsTrigger, type TabsTriggerProps, tabsListVariants, } from "./Tabs.js";
|
|
37
38
|
export { ToggleGroup, ToggleGroupItem, type ToggleGroupItemProps, type ToggleGroupProps, } from "./ToggleGroup.js";
|
|
39
|
+
export { Toolbar, ToolbarButton, type ToolbarButtonProps, type ToolbarProps, ToolbarSeparator, type ToolbarSeparatorProps, } from "./Toolbar.js";
|
|
38
40
|
export { Blockquote, H1, H2, H3, H4, InlineCode, Large, Lead, List, Muted, P, Small, type TypographyProps, } from "./Typography.js";
|
package/dist/molecules/index.js
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
|
export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "./Accordion.js";
|
|
18
19
|
export { Alert, AlertDescription, AlertTitle, alertVariants, } from "./Alert.js";
|
|
@@ -35,4 +36,5 @@ export { ResizableHandle, ResizablePanel, ResizablePanelGroup, } from "./Resizab
|
|
|
35
36
|
export { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, } from "./Table.js";
|
|
36
37
|
export { Tabs, TabsContent, TabsList, TabsTrigger, tabsListVariants, } from "./Tabs.js";
|
|
37
38
|
export { ToggleGroup, ToggleGroupItem, } from "./ToggleGroup.js";
|
|
39
|
+
export { Toolbar, ToolbarButton, ToolbarSeparator, } from "./Toolbar.js";
|
|
38
40
|
export { Blockquote, H1, H2, H3, H4, InlineCode, Large, Lead, List, Muted, P, Small, } from "./Typography.js";
|
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Toaster — transient notifications.
|
|
3
3
|
*
|
|
4
|
-
* shadcn
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* shadcn ships two: `sonner`, which wraps a third-party library, and `toast`,
|
|
5
|
+
* its own, built on Base UI. nebula keeps it in-house with zero dependencies
|
|
6
|
+
* and follows the SECOND — the shape is the same: one region mounted once near
|
|
7
|
+
* the app root, and a `toast` object callable from anywhere with no reference
|
|
8
|
+
* to it.
|
|
9
|
+
*
|
|
10
|
+
* NAMED DEVIATIONS from Base UI's manager, all deliberate:
|
|
11
|
+
*
|
|
12
|
+
* - `show` / `dismiss` / `variant` / `duration` rather than `add` / `close` /
|
|
13
|
+
* `type` / `timeout`. `variant` is what every other nebula component calls
|
|
14
|
+
* this (Button, Alert, Badge), and renaming it here alone would make the
|
|
15
|
+
* package less consistent with itself than with Base UI.
|
|
16
|
+
* - `variant` keeps `warning`, which Base UI's `type` does not have.
|
|
17
|
+
* - No `priority` (display ordering), `data` (typed payload for a React render
|
|
18
|
+
* prop — a `Child` already covers it) or `positionerProps` (anchored toasts).
|
|
19
|
+
* - No `updateKey`. It exists to make React replay an animation without
|
|
20
|
+
* remounting; `update` here replaces the entry, and aurora re-renders it.
|
|
7
21
|
*
|
|
8
22
|
* That decoupling is the whole design. A queue in module state, a signal the
|
|
9
23
|
* region subscribes to, and `toast.error(…)` works from a route handler's
|
|
@@ -23,20 +37,51 @@
|
|
|
23
37
|
*/
|
|
24
38
|
import type { Child } from "../lib/children.js";
|
|
25
39
|
import { type Reactive } from "../lib/props.js";
|
|
26
|
-
export type ToastVariant = "default" | "success" | "error" | "warning";
|
|
40
|
+
export type ToastVariant = "default" | "success" | "error" | "warning" | "loading";
|
|
41
|
+
/**
|
|
42
|
+
* A toast's identity. A number when `show` minted it, a string when the caller
|
|
43
|
+
* supplied one — which is what makes `update` and deduplication possible, and
|
|
44
|
+
* how {@link toast.promise} turns one toast from loading into its outcome.
|
|
45
|
+
*/
|
|
46
|
+
export type ToastId = number | string;
|
|
27
47
|
export interface ToastOptions {
|
|
28
48
|
title: Child;
|
|
29
49
|
description?: Child;
|
|
30
50
|
variant?: ToastVariant;
|
|
31
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Milliseconds on screen. `0` keeps it until dismissed.
|
|
53
|
+
*
|
|
54
|
+
* Left out, it comes from the variant: an error stays twice as long because
|
|
55
|
+
* the user has to read it and often act on it, and a `loading` toast does not
|
|
56
|
+
* leave on its own at all — it is waiting for an outcome.
|
|
57
|
+
*/
|
|
32
58
|
duration?: number;
|
|
33
59
|
action?: {
|
|
34
60
|
label: string;
|
|
35
61
|
onClick: () => void;
|
|
36
62
|
};
|
|
63
|
+
/**
|
|
64
|
+
* A stable id. Showing a toast under an id that is already on screen UPDATES
|
|
65
|
+
* it instead of stacking another — so "you are offline", raised on every
|
|
66
|
+
* failed request, is one toast rather than nine.
|
|
67
|
+
*/
|
|
68
|
+
id?: string;
|
|
69
|
+
/** Called once the toast leaves, however it left. */
|
|
70
|
+
onClose?: () => void;
|
|
37
71
|
}
|
|
38
|
-
declare function dismiss(id:
|
|
39
|
-
declare function show(options: ToastOptions):
|
|
72
|
+
declare function dismiss(id: ToastId): void;
|
|
73
|
+
declare function show(options: ToastOptions): ToastId;
|
|
74
|
+
/**
|
|
75
|
+
* Change a toast that is already on screen. No-op if it has gone.
|
|
76
|
+
*
|
|
77
|
+
* The countdown is recomputed, because that is the part a caller would not
|
|
78
|
+
* think to ask for and always wants: a `loading` toast has no timer at all, so
|
|
79
|
+
* turning it into a success without rescheduling would leave it on screen for
|
|
80
|
+
* good. Which is exactly what {@link toast.promise} does to it.
|
|
81
|
+
*/
|
|
82
|
+
declare function update(id: ToastId, patch: Partial<ToastOptions>): void;
|
|
83
|
+
/** What a `promise` stage says: just a title, or the whole toast. */
|
|
84
|
+
export type ToastMessage = Child | Omit<ToastOptions, "id" | "variant">;
|
|
40
85
|
/**
|
|
41
86
|
* Raise a toast. Returns its id, which `dismiss` accepts.
|
|
42
87
|
*
|
|
@@ -44,10 +89,33 @@ declare function show(options: ToastOptions): number;
|
|
|
44
89
|
*/
|
|
45
90
|
export declare const toast: {
|
|
46
91
|
show: typeof show;
|
|
92
|
+
update: typeof update;
|
|
47
93
|
dismiss: typeof dismiss;
|
|
48
|
-
success: (title: Child, description?: Child) =>
|
|
49
|
-
error: (title: Child, description?: Child) =>
|
|
50
|
-
warning: (title: Child, description?: Child) =>
|
|
94
|
+
success: (title: Child, description?: Child) => ToastId;
|
|
95
|
+
error: (title: Child, description?: Child) => ToastId;
|
|
96
|
+
warning: (title: Child, description?: Child) => ToastId;
|
|
97
|
+
loading: (title: Child, description?: Child) => ToastId;
|
|
98
|
+
/**
|
|
99
|
+
* One toast for the whole life of an async call: waiting, then the outcome.
|
|
100
|
+
*
|
|
101
|
+
* ```ts
|
|
102
|
+
* await toast.promise(save(form), {
|
|
103
|
+
* loading: 'Saving…',
|
|
104
|
+
* success: (saved) => `Saved ${saved.name}`,
|
|
105
|
+
* error: (reason) => ({ title: 'Could not save', description: String(reason) }),
|
|
106
|
+
* })
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* Returns the SAME promise it was given, rejection included. It reports, it
|
|
110
|
+
* does not handle: swallowing the rejection here would turn a failed call
|
|
111
|
+
* into a red toast and nothing else, with the caller's own error path never
|
|
112
|
+
* running.
|
|
113
|
+
*/
|
|
114
|
+
promise<T>(work: Promise<T>, messages: {
|
|
115
|
+
loading: ToastMessage;
|
|
116
|
+
success: ToastMessage | ((value: T) => ToastMessage);
|
|
117
|
+
error: ToastMessage | ((reason: unknown) => ToastMessage);
|
|
118
|
+
}): Promise<T>;
|
|
51
119
|
/** Clear everything — on navigation, say. */
|
|
52
120
|
clear(): void;
|
|
53
121
|
};
|