@c9up/nebula 0.2.1 → 0.2.3
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/Checkbox.d.ts +1 -1
- package/dist/atoms/Checkbox.js +1 -1
- package/dist/atoms/Input.d.ts +5 -0
- package/dist/atoms/Input.js +1 -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/lib/children.d.ts +13 -8
- package/dist/lib/children.js +5 -0
- package/dist/molecules/Breadcrumb.d.ts +11 -2
- package/dist/molecules/Breadcrumb.js +2 -2
- package/dist/molecules/InputOTP.d.ts +2 -0
- package/dist/molecules/InputOTP.js +3 -1
- package/dist/molecules/Pagination.d.ts +34 -2
- package/dist/molecules/Pagination.js +15 -6
- package/dist/molecules/PieceMap.d.ts +72 -0
- package/dist/molecules/PieceMap.js +78 -0
- package/dist/molecules/Resizable.d.ts +2 -0
- package/dist/molecules/Resizable.js +1 -1
- package/dist/molecules/Toolbar.d.ts +50 -0
- package/dist/molecules/Toolbar.js +70 -0
- package/dist/molecules/index.d.ts +10 -7
- package/dist/molecules/index.js +8 -5
- package/dist/organisms/Calendar.d.ts +13 -0
- package/dist/organisms/Calendar.js +2 -2
- package/dist/organisms/Carousel.d.ts +8 -0
- package/dist/organisms/Carousel.js +8 -5
- package/dist/organisms/DataTable.d.ts +23 -1
- package/dist/organisms/DataTable.js +57 -27
- package/dist/organisms/DatePicker.d.ts +7 -0
- package/dist/organisms/DatePicker.js +2 -1
- package/dist/organisms/DateRangePicker.d.ts +2 -0
- package/dist/organisms/DateRangePicker.js +2 -1
- package/dist/organisms/Dialog.d.ts +13 -3
- package/dist/organisms/Dialog.js +12 -5
- package/dist/organisms/Questionnaire.d.ts +4 -0
- package/dist/organisms/Questionnaire.js +5 -2
- package/dist/organisms/Select.d.ts +23 -4
- package/dist/organisms/Select.js +115 -15
- package/dist/organisms/Sheet.d.ts +2 -0
- package/dist/organisms/Sheet.js +2 -1
- package/dist/organisms/Sidebar.d.ts +6 -0
- package/dist/organisms/Sidebar.js +9 -4
- package/dist/organisms/Toaster.d.ts +80 -10
- package/dist/organisms/Toaster.js +152 -24
- package/dist/organisms/index.d.ts +3 -3
- package/dist/organisms/index.js +1 -1
- package/dist/primitives/direction.d.ts +38 -0
- package/dist/primitives/direction.js +57 -0
- package/dist/primitives/floating.js +25 -13
- 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/templates/SettingsLayout.d.ts +2 -0
- package/dist/templates/SettingsLayout.js +1 -1
- package/nebula.css +1 -1
- package/package.json +3 -3
- package/registry.json +76 -0
- package/src/atoms/AccessibleIcon.ts +39 -0
- package/src/atoms/Checkbox.ts +1 -1
- package/src/atoms/Input.ts +6 -0
- package/src/atoms/VisuallyHidden.ts +45 -0
- package/src/atoms/index.ts +8 -0
- package/src/index.ts +7 -4
- package/src/lib/children.ts +15 -7
- package/src/molecules/Breadcrumb.ts +15 -4
- package/src/molecules/InputOTP.ts +7 -1
- package/src/molecules/Pagination.ts +50 -8
- package/src/molecules/PieceMap.ts +136 -0
- package/src/molecules/Resizable.ts +3 -1
- package/src/molecules/Toolbar.ts +100 -0
- package/src/molecules/index.ts +28 -5
- package/src/organisms/Calendar.ts +16 -2
- package/src/organisms/Carousel.ts +17 -5
- package/src/organisms/DataTable.ts +95 -30
- package/src/organisms/DatePicker.ts +10 -2
- package/src/organisms/DateRangePicker.ts +4 -2
- package/src/organisms/Dialog.ts +17 -5
- package/src/organisms/Questionnaire.ts +10 -2
- package/src/organisms/Select.ts +137 -16
- package/src/organisms/Sheet.ts +5 -1
- package/src/organisms/Sidebar.ts +15 -4
- package/src/organisms/Toaster.ts +215 -37
- package/src/organisms/index.ts +9 -1
- package/src/primitives/direction.ts +61 -0
- package/src/primitives/floating.ts +29 -13
- package/src/primitives/focusable.ts +10 -1
- package/src/primitives/index.ts +7 -0
- package/src/primitives/rovingFocus.ts +18 -5
- package/src/templates/SettingsLayout.ts +3 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PieceMap — a transfer drawn as one small square per piece.
|
|
3
|
+
*
|
|
4
|
+
* What a torrent client shows under a download: each square is a piece of the
|
|
5
|
+
* whole, coloured by where it stands — here, missing, on its way, taken from a
|
|
6
|
+
* peer. A progress bar says how much; the map says *which*, and that is what
|
|
7
|
+
* a stalled run, a missing layer or a peer serving one half shows at a glance.
|
|
8
|
+
*
|
|
9
|
+
* The states are the caller's, not a fixed set. A download, a replication and
|
|
10
|
+
* a backup do not have the same ones, so the component takes a string type of
|
|
11
|
+
* its own and a class per state — `tones` — and paints nothing it was not
|
|
12
|
+
* told about. The legend reads the same `tones`, so a square and its key can
|
|
13
|
+
* never drift apart.
|
|
14
|
+
*
|
|
15
|
+
* Pieces come in groups: each group after the first is set off by a rule — a
|
|
16
|
+
* torrent's files, an image's layers. A flat map is one group.
|
|
17
|
+
*
|
|
18
|
+
* A generic function rather than `component<P>`, as DataTable: `State` has to
|
|
19
|
+
* stay open so `tones` is checked against the caller's own states.
|
|
20
|
+
*
|
|
21
|
+
* With a `label`, the map is one image to assistive technology and the label
|
|
22
|
+
* is what it says ("12 of 40 pieces"): a screen reader walking hundreds of
|
|
23
|
+
* squares one by one learns nothing the sentence does not. Each square keeps
|
|
24
|
+
* its `title` for the pointer.
|
|
25
|
+
*/
|
|
26
|
+
import { html } from "@c9up/aurora";
|
|
27
|
+
import { cn } from "../lib/cn.js";
|
|
28
|
+
import { cva } from "../lib/cva.js";
|
|
29
|
+
import { read } from "../lib/props.js";
|
|
30
|
+
export const pieceVariants = cva("inline-block shrink-0 rounded-[2px]", {
|
|
31
|
+
variants: {
|
|
32
|
+
size: {
|
|
33
|
+
sm: "size-2",
|
|
34
|
+
default: "size-2.5",
|
|
35
|
+
lg: "size-3",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
defaultVariants: { size: "default" },
|
|
39
|
+
});
|
|
40
|
+
export function PieceMap(props) {
|
|
41
|
+
return html `<div
|
|
42
|
+
data-slot="piece-map"
|
|
43
|
+
role="${() => (read(props.label) === undefined ? undefined : "img")}"
|
|
44
|
+
aria-label="${() => read(props.label)}"
|
|
45
|
+
class="${() => cn("flex flex-wrap gap-1", read(props.class))}"
|
|
46
|
+
>
|
|
47
|
+
${() => read(props.groups).map((pieces, index) => html `<span
|
|
48
|
+
data-slot="piece-map-group"
|
|
49
|
+
class="${cn("flex flex-wrap gap-0.5", index > 0 && "border-border border-s ps-1")}"
|
|
50
|
+
>
|
|
51
|
+
${pieces.map((piece) => html `<span
|
|
52
|
+
data-slot="piece"
|
|
53
|
+
data-state="${piece.state}"
|
|
54
|
+
title="${piece.title}"
|
|
55
|
+
class="${cn(pieceVariants({ size: read(props.size) }), props.tones[piece.state])}"
|
|
56
|
+
></span>`)}
|
|
57
|
+
</span>`)}
|
|
58
|
+
</div>`;
|
|
59
|
+
}
|
|
60
|
+
/** What the squares' colours mean. */
|
|
61
|
+
export function PieceMapLegend(props) {
|
|
62
|
+
// A space after each key: the gap between them is only drawn, and without
|
|
63
|
+
// one their labels run together for a screen reader and a copy.
|
|
64
|
+
return html `<p
|
|
65
|
+
data-slot="piece-map-legend"
|
|
66
|
+
class="${() => cn("text-muted-foreground flex flex-wrap gap-x-4 gap-y-1 text-xs", read(props.class))}"
|
|
67
|
+
>
|
|
68
|
+
${props.children}
|
|
69
|
+
${props.items.map((item) => html `<span class="inline-flex items-center gap-1.5"
|
|
70
|
+
><span
|
|
71
|
+
aria-hidden="true"
|
|
72
|
+
data-state="${item.state}"
|
|
73
|
+
class="${() => cn(pieceVariants({ size: read(props.size) }), props.tones[item.state])}"
|
|
74
|
+
></span
|
|
75
|
+
>${item.label}</span
|
|
76
|
+
> `)}
|
|
77
|
+
</p>`;
|
|
78
|
+
}
|
|
@@ -50,6 +50,8 @@ export declare const ResizablePanel: (props?: ResizablePanelProps | undefined) =
|
|
|
50
50
|
export interface ResizableHandleProps {
|
|
51
51
|
/** Show the grip dots. */
|
|
52
52
|
withHandle?: boolean;
|
|
53
|
+
/** The separator's accessible name. Default `"Resize panes"`. */
|
|
54
|
+
label?: string;
|
|
53
55
|
class?: Reactive<string>;
|
|
54
56
|
}
|
|
55
57
|
/**
|
|
@@ -148,7 +148,7 @@ export const ResizableHandle = component((props) => {
|
|
|
148
148
|
aria-valuemin="${group.min}"
|
|
149
149
|
aria-valuemax="${group.max}"
|
|
150
150
|
aria-valuenow="${() => Math.round(group.size())}"
|
|
151
|
-
aria-label="Resize panes"
|
|
151
|
+
aria-label="${props.label ?? "Resize panes"}"
|
|
152
152
|
class="${() => cn("bg-border relative flex shrink-0 items-center justify-center outline-none", "focus-visible:ring-ring focus-visible:ring-1 focus-visible:ring-offset-1", group.horizontal ? "w-px cursor-col-resize" : "h-px cursor-row-resize", read(props.class))}"
|
|
153
153
|
@pointerdown="${onPointerDown}"
|
|
154
154
|
@keydown="${onKeyDown}"
|
|
@@ -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,16 +8,17 @@
|
|
|
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";
|
|
19
20
|
export { Attachment, type AttachmentProps, formatBytes, } from "./Attachment.js";
|
|
20
|
-
export { Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, type BreadcrumbLinkProps, BreadcrumbList, BreadcrumbPage, type BreadcrumbProps, BreadcrumbSeparator, } from "./Breadcrumb.js";
|
|
21
|
+
export { Breadcrumb, BreadcrumbEllipsis, type BreadcrumbEllipsisProps, BreadcrumbItem, BreadcrumbLink, type BreadcrumbLinkProps, BreadcrumbList, type BreadcrumbNavProps, BreadcrumbPage, type BreadcrumbProps, BreadcrumbSeparator, } from "./Breadcrumb.js";
|
|
21
22
|
export { Bubble, type BubbleProps, type BubbleReaction, type BubbleVariants, bubbleVariants, } from "./Bubble.js";
|
|
22
23
|
export { ButtonGroup, type ButtonGroupProps, ButtonGroupSeparator, ButtonGroupText, } from "./ButtonGroup.js";
|
|
23
24
|
export { Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, type CardProps, CardTitle, } from "./Card.js";
|
|
@@ -28,11 +29,13 @@ export { InputGroup, InputGroupAddon, type InputGroupAddonProps, InputGroupButto
|
|
|
28
29
|
export { InputOTP, InputOTPGroup, type InputOTPGroupProps, type InputOTPProps, InputOTPSeparator, type InputOTPSeparatorProps, InputOTPSlot, type InputOTPSlotProps, } from "./InputOTP.js";
|
|
29
30
|
export { Item, ItemActions, ItemContent, ItemDescription, ItemGroup, ItemMedia, type ItemProps, ItemSeparator, ItemTitle, type ItemVariants, itemVariants, } from "./Item.js";
|
|
30
31
|
export { Message, type MessageProps } from "./Message.js";
|
|
31
|
-
export { type PageSlot, Pagination, PaginationContent, PaginationEllipsis, type PaginationEllipsisProps, PaginationItem, PaginationLink, type PaginationLinkProps, PaginationNext, PaginationPrevious, type PaginationProps, type PaginationStepProps, pageWindow, } from "./Pagination.js";
|
|
32
|
+
export { type PageSlot, Pagination, PaginationContent, PaginationEllipsis, type PaginationEllipsisProps, PaginationItem, type PaginationLabels, PaginationLink, type PaginationLinkProps, type PaginationNavProps, PaginationNext, PaginationPrevious, type PaginationProps, type PaginationStepProps, pageWindow, } from "./Pagination.js";
|
|
32
33
|
export { Picture, type PictureProps } from "./Picture.js";
|
|
34
|
+
export { type Piece, PieceMap, PieceMapLegend, type PieceMapLegendItem, type PieceMapLegendProps, type PieceMapProps, type PieceVariants, pieceVariants, } from "./PieceMap.js";
|
|
33
35
|
export { RadioGroup, RadioGroupItem, type RadioGroupItemProps, type RadioGroupProps, } from "./RadioGroup.js";
|
|
34
36
|
export { ResizableHandle, type ResizableHandleProps, ResizablePanel, ResizablePanelGroup, type ResizablePanelGroupProps, type ResizablePanelProps, } from "./Resizable.js";
|
|
35
37
|
export { Table, TableBody, TableCaption, TableCell, type TableCellProps, TableFooter, TableHead, TableHeader, type TableProps, TableRow, type TableRowProps, } from "./Table.js";
|
|
36
38
|
export { Tabs, TabsContent, type TabsContentProps, TabsList, type TabsListProps, type TabsListVariants, type TabsProps, TabsTrigger, type TabsTriggerProps, tabsListVariants, } from "./Tabs.js";
|
|
37
39
|
export { ToggleGroup, ToggleGroupItem, type ToggleGroupItemProps, type ToggleGroupProps, } from "./ToggleGroup.js";
|
|
40
|
+
export { Toolbar, ToolbarButton, type ToolbarButtonProps, type ToolbarProps, ToolbarSeparator, type ToolbarSeparatorProps, } from "./Toolbar.js";
|
|
38
41
|
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";
|
|
@@ -30,9 +31,11 @@ export { Item, ItemActions, ItemContent, ItemDescription, ItemGroup, ItemMedia,
|
|
|
30
31
|
export { Message } from "./Message.js";
|
|
31
32
|
export { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, pageWindow, } from "./Pagination.js";
|
|
32
33
|
export { Picture } from "./Picture.js";
|
|
34
|
+
export { PieceMap, PieceMapLegend, pieceVariants, } from "./PieceMap.js";
|
|
33
35
|
export { RadioGroup, RadioGroupItem, } from "./RadioGroup.js";
|
|
34
36
|
export { ResizableHandle, ResizablePanel, ResizablePanelGroup, } from "./Resizable.js";
|
|
35
37
|
export { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, } from "./Table.js";
|
|
36
38
|
export { Tabs, TabsContent, TabsList, TabsTrigger, tabsListVariants, } from "./Tabs.js";
|
|
37
39
|
export { ToggleGroup, ToggleGroupItem, } from "./ToggleGroup.js";
|
|
40
|
+
export { Toolbar, ToolbarButton, ToolbarSeparator, } from "./Toolbar.js";
|
|
38
41
|
export { Blockquote, H1, H2, H3, H4, InlineCode, Large, Lead, List, Muted, P, Small, } from "./Typography.js";
|
|
@@ -28,6 +28,18 @@ export interface DateRange {
|
|
|
28
28
|
readonly from: Date;
|
|
29
29
|
readonly to?: Date;
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* The words the calendar writes itself — react-day-picker's `labels`.
|
|
33
|
+
*
|
|
34
|
+
* Month and weekday names come from `Intl` in `locale`; these two do not, and
|
|
35
|
+
* a screen reader would read them in English in the middle of a French page.
|
|
36
|
+
*/
|
|
37
|
+
export interface CalendarLabels {
|
|
38
|
+
/** The previous-month arrow. Default `"Previous month"`. */
|
|
39
|
+
previousMonth: string;
|
|
40
|
+
/** The next-month arrow. Default `"Next month"`. */
|
|
41
|
+
nextMonth: string;
|
|
42
|
+
}
|
|
31
43
|
export interface CalendarProps {
|
|
32
44
|
/**
|
|
33
45
|
* `"range"` picks a span in two clicks. Default `"single"`.
|
|
@@ -54,6 +66,7 @@ export interface CalendarProps {
|
|
|
54
66
|
/** `0` Sunday, `1` Monday. Defaults to the locale's own first day. */
|
|
55
67
|
weekStartsOn?: number;
|
|
56
68
|
locale?: string;
|
|
69
|
+
labels?: Partial<CalendarLabels>;
|
|
57
70
|
class?: Reactive<string>;
|
|
58
71
|
/** `"single"` mode. */
|
|
59
72
|
onValueChange?: (date: Date) => void;
|
|
@@ -268,7 +268,7 @@ export const Calendar = component((props) => {
|
|
|
268
268
|
<div class="flex items-center justify-between pb-4">
|
|
269
269
|
<button
|
|
270
270
|
type="button"
|
|
271
|
-
aria-label="Previous month"
|
|
271
|
+
aria-label="${props.labels?.previousMonth ?? "Previous month"}"
|
|
272
272
|
class="${buttonVariants({ variant: "outline", size: "icon", class: "size-7" })}"
|
|
273
273
|
@click="${() => month(addMonths(month(), -1))}"
|
|
274
274
|
>${ChevronLeftIcon({ class: "size-4" })}</button>
|
|
@@ -277,7 +277,7 @@ export const Calendar = component((props) => {
|
|
|
277
277
|
</div>
|
|
278
278
|
<button
|
|
279
279
|
type="button"
|
|
280
|
-
aria-label="Next month"
|
|
280
|
+
aria-label="${props.labels?.nextMonth ?? "Next month"}"
|
|
281
281
|
class="${buttonVariants({ variant: "outline", size: "icon", class: "size-7" })}"
|
|
282
282
|
@click="${() => month(addMonths(month(), 1))}"
|
|
283
283
|
>${ChevronRightIcon({ class: "size-4" })}</button>
|
|
@@ -21,6 +21,8 @@ import { type Reactive } from "../lib/props.js";
|
|
|
21
21
|
export interface CarouselProps {
|
|
22
22
|
/** Announced before the slides. */
|
|
23
23
|
label?: string;
|
|
24
|
+
/** What a screen reader calls the region. Default `"carousel"`. */
|
|
25
|
+
roleDescription?: string;
|
|
24
26
|
orientation?: "horizontal" | "vertical";
|
|
25
27
|
class?: Reactive<string>;
|
|
26
28
|
children?: Parts;
|
|
@@ -34,6 +36,10 @@ export interface CarouselContentProps {
|
|
|
34
36
|
export declare const CarouselContent: (props?: CarouselContentProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
35
37
|
export interface CarouselItemProps {
|
|
36
38
|
children?: Slot;
|
|
39
|
+
/** What a screen reader calls one slide. Default `"slide"`. */
|
|
40
|
+
roleDescription?: string;
|
|
41
|
+
/** The slide's name from its position. Default `"3 of 7"`. */
|
|
42
|
+
label?: (position: number, count: number) => string;
|
|
37
43
|
class?: Reactive<string>;
|
|
38
44
|
}
|
|
39
45
|
/**
|
|
@@ -45,6 +51,8 @@ export interface CarouselItemProps {
|
|
|
45
51
|
*/
|
|
46
52
|
export declare const CarouselItem: (props?: CarouselItemProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
47
53
|
export interface CarouselButtonProps {
|
|
54
|
+
/** The arrow's accessible name. Default `"Previous slide"` / `"Next slide"`. */
|
|
55
|
+
label?: string;
|
|
48
56
|
class?: Reactive<string>;
|
|
49
57
|
}
|
|
50
58
|
export declare const CarouselPrevious: (props?: CarouselButtonProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
@@ -97,7 +97,7 @@ export const Carousel = component((props) => {
|
|
|
97
97
|
return html `<div
|
|
98
98
|
data-slot="carousel"
|
|
99
99
|
role="region"
|
|
100
|
-
aria-roledescription="carousel"
|
|
100
|
+
aria-roledescription="${props.roleDescription ?? "carousel"}"
|
|
101
101
|
aria-label="${props.label ?? "Carousel"}"
|
|
102
102
|
class="${() => cn("relative", read(props.class))}"
|
|
103
103
|
@keydown="${onKeyDown}"
|
|
@@ -126,18 +126,21 @@ export const CarouselItem = component((props) => {
|
|
|
126
126
|
return html `<div
|
|
127
127
|
data-slot="carousel-item"
|
|
128
128
|
role="group"
|
|
129
|
-
aria-roledescription="slide"
|
|
130
|
-
aria-label="${() =>
|
|
129
|
+
aria-roledescription="${props.roleDescription ?? "slide"}"
|
|
130
|
+
aria-label="${() => (props.label ?? slideOf)(position, carousel.slideCount())}"
|
|
131
131
|
class="${() => cn("min-w-0 shrink-0 grow-0 basis-full snap-start", read(props.class))}"
|
|
132
132
|
>${slot(props.children)}</div>`;
|
|
133
133
|
});
|
|
134
|
+
function slideOf(position, count) {
|
|
135
|
+
return `${position} of ${count}`;
|
|
136
|
+
}
|
|
134
137
|
const arrowClasses = "absolute size-8 rounded-full";
|
|
135
138
|
export const CarouselPrevious = component((props) => {
|
|
136
139
|
const carousel = inject(CarouselContext);
|
|
137
140
|
return html `<button
|
|
138
141
|
type="button"
|
|
139
142
|
data-slot="carousel-previous"
|
|
140
|
-
aria-label="Previous slide"
|
|
143
|
+
aria-label="${props.label ?? "Previous slide"}"
|
|
141
144
|
?disabled="${() => carousel.atStart()}"
|
|
142
145
|
class="${() => cn(buttonVariants({ variant: "outline", size: "icon" }), arrowClasses, carousel.horizontal
|
|
143
146
|
? "top-1/2 -left-12 -translate-y-1/2"
|
|
@@ -150,7 +153,7 @@ export const CarouselNext = component((props) => {
|
|
|
150
153
|
return html `<button
|
|
151
154
|
type="button"
|
|
152
155
|
data-slot="carousel-next"
|
|
153
|
-
aria-label="Next slide"
|
|
156
|
+
aria-label="${props.label ?? "Next slide"}"
|
|
154
157
|
?disabled="${() => carousel.atEnd()}"
|
|
155
158
|
class="${() => cn(buttonVariants({ variant: "outline", size: "icon" }), arrowClasses, carousel.horizontal
|
|
156
159
|
? "top-1/2 -right-12 -translate-y-1/2"
|
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import { type TemplateResult } from "@c9up/aurora";
|
|
23
23
|
import type { Child } from "../lib/children.js";
|
|
24
|
+
import { type Reactive } from "../lib/props.js";
|
|
25
|
+
import { type PaginationLabels } from "../molecules/Pagination.js";
|
|
24
26
|
export interface Column<Row> {
|
|
25
27
|
key: string;
|
|
26
28
|
header: Child;
|
|
@@ -33,16 +35,36 @@ export interface Column<Row> {
|
|
|
33
35
|
}
|
|
34
36
|
export interface DataTableProps<Row> {
|
|
35
37
|
columns: readonly Column<Row>[];
|
|
36
|
-
|
|
38
|
+
/**
|
|
39
|
+
* The rows, or an accessor for rows that change. An accessor must return the
|
|
40
|
+
* same array until the data changes — a new one per read counts as new data
|
|
41
|
+
* on every read, as it does for TanStack's `data`.
|
|
42
|
+
*/
|
|
43
|
+
rows: Reactive<readonly Row[]>;
|
|
37
44
|
/** Stable identity per row — used for selection and as the render key. */
|
|
38
45
|
rowKey: (row: Row) => string;
|
|
39
46
|
/** Rows per page. Omit to show everything. */
|
|
40
47
|
pageSize?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Go back to the first page when the rows change. Default `true`, as
|
|
50
|
+
* TanStack's `autoResetPageIndex`: the page was chosen in data that is
|
|
51
|
+
* gone. Turn it off for rows refreshed in place, such as a polled list.
|
|
52
|
+
* Sorting and the filter always survive a change.
|
|
53
|
+
*/
|
|
54
|
+
autoResetPage?: boolean;
|
|
41
55
|
/** Show a filter box. Provide `filterMatch` to say what it searches. */
|
|
42
56
|
filterPlaceholder?: string;
|
|
57
|
+
/** The filter box's accessible name. Defaults to the placeholder. */
|
|
58
|
+
filterLabel?: string;
|
|
43
59
|
filterMatch?: (row: Row, query: string) => boolean;
|
|
44
60
|
/** Add a checkbox column. */
|
|
45
61
|
selectable?: boolean;
|
|
62
|
+
/** The header checkbox's accessible name. Default `"Select all rows on this page"`. */
|
|
63
|
+
selectAllLabel?: string;
|
|
64
|
+
/** A row checkbox's accessible name. Default `"Select row <key>"`. */
|
|
65
|
+
selectRowLabel?: (row: Row) => string;
|
|
66
|
+
/** The pager's words — see `PaginationLabels`. */
|
|
67
|
+
paginationLabels?: Partial<PaginationLabels>;
|
|
46
68
|
onSelectionChange?: (keys: readonly string[]) => void;
|
|
47
69
|
emptyMessage?: Child;
|
|
48
70
|
class?: string;
|
|
@@ -19,18 +19,23 @@
|
|
|
19
19
|
* The little chevron says which column is sorted to anyone who can see it; the
|
|
20
20
|
* attribute is what says it to everyone else.
|
|
21
21
|
*/
|
|
22
|
-
import { html, signal } from "@c9up/aurora";
|
|
22
|
+
import { each, html, memo, signal, } from "@c9up/aurora";
|
|
23
23
|
import { Checkbox } from "../atoms/Checkbox.js";
|
|
24
24
|
import { Input } from "../atoms/Input.js";
|
|
25
25
|
import { cn } from "../lib/cn.js";
|
|
26
26
|
import { ChevronDownIcon, ChevronsUpDownIcon, ChevronUpIcon, } from "../lib/icons.js";
|
|
27
|
-
import {
|
|
27
|
+
import { read } from "../lib/props.js";
|
|
28
|
+
import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, pageWindow, paginationLabels, } from "../molecules/Pagination.js";
|
|
28
29
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "../molecules/Table.js";
|
|
29
30
|
export function DataTable(props) {
|
|
30
31
|
const sortKey = signal(undefined);
|
|
31
32
|
const sortDirection = signal("asc");
|
|
32
33
|
const query = signal("");
|
|
33
|
-
|
|
34
|
+
/**
|
|
35
|
+
* The page, and the rows it was chosen in. Derived rather than reset by an
|
|
36
|
+
* effect: when the rows are no longer those, the page reads as the first.
|
|
37
|
+
*/
|
|
38
|
+
const page = signal({ number: 1, of: read(props.rows) });
|
|
34
39
|
const selected = signal([]);
|
|
35
40
|
function readCell(row, column) {
|
|
36
41
|
if (column.cell !== undefined)
|
|
@@ -44,10 +49,20 @@ export function DataTable(props) {
|
|
|
44
49
|
return typeof value === "number" ? value : String(value ?? "");
|
|
45
50
|
}
|
|
46
51
|
function filtered() {
|
|
52
|
+
const rows = read(props.rows);
|
|
47
53
|
const needle = query().trim().toLowerCase();
|
|
48
54
|
if (needle === "" || props.filterMatch === undefined)
|
|
49
|
-
return
|
|
50
|
-
return
|
|
55
|
+
return rows;
|
|
56
|
+
return rows.filter((row) => props.filterMatch?.(row, needle) === true);
|
|
57
|
+
}
|
|
58
|
+
function pageNumber() {
|
|
59
|
+
const { number, of } = page();
|
|
60
|
+
if (props.autoResetPage !== false && of !== read(props.rows))
|
|
61
|
+
return 1;
|
|
62
|
+
return number;
|
|
63
|
+
}
|
|
64
|
+
function goToPage(number) {
|
|
65
|
+
page({ number, of: read(props.rows) });
|
|
51
66
|
}
|
|
52
67
|
function sorted() {
|
|
53
68
|
const key = sortKey();
|
|
@@ -79,10 +94,12 @@ export function DataTable(props) {
|
|
|
79
94
|
return rows;
|
|
80
95
|
// Clamp: filtering down to fewer pages while on the last one would
|
|
81
96
|
// otherwise show an empty table with no way back.
|
|
82
|
-
const current = Math.min(
|
|
97
|
+
const current = Math.min(pageNumber(), pageCount());
|
|
83
98
|
const from = (current - 1) * props.pageSize;
|
|
84
99
|
return rows.slice(from, from + props.pageSize);
|
|
85
100
|
}
|
|
101
|
+
/** Whether the body shows the empty row — read apart, so the list survives. */
|
|
102
|
+
const isEmpty = memo(() => visible().length === 0);
|
|
86
103
|
function toggleSort(column) {
|
|
87
104
|
if (column.sortable === false)
|
|
88
105
|
return;
|
|
@@ -145,10 +162,11 @@ export function DataTable(props) {
|
|
|
145
162
|
: Input({
|
|
146
163
|
type: "search",
|
|
147
164
|
placeholder: props.filterPlaceholder ?? "Filter…",
|
|
165
|
+
label: props.filterLabel ?? props.filterPlaceholder ?? "Filter…",
|
|
148
166
|
class: "max-w-sm",
|
|
149
167
|
onInput: (value) => {
|
|
150
168
|
query(value);
|
|
151
|
-
|
|
169
|
+
goToPage(1);
|
|
152
170
|
},
|
|
153
171
|
})}
|
|
154
172
|
${Table({
|
|
@@ -160,7 +178,7 @@ export function DataTable(props) {
|
|
|
160
178
|
? TableHead({
|
|
161
179
|
class: "w-10",
|
|
162
180
|
children: Checkbox({
|
|
163
|
-
label: "Select all rows on this page",
|
|
181
|
+
label: props.selectAllLabel ?? "Select all rows on this page",
|
|
164
182
|
checked: () => {
|
|
165
183
|
const keys = visible().map(props.rowKey);
|
|
166
184
|
return (keys.length > 0 &&
|
|
@@ -189,19 +207,18 @@ export function DataTable(props) {
|
|
|
189
207
|
}),
|
|
190
208
|
}),
|
|
191
209
|
TableBody({
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
})
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
},
|
|
210
|
+
// Rows by key: a re-read, a sort or a page change keeps the rows
|
|
211
|
+
// that stay, with their open menus and focus. The body itself only
|
|
212
|
+
// switches between the list and the empty row.
|
|
213
|
+
children: () => isEmpty()
|
|
214
|
+
? TableRow({
|
|
215
|
+
children: TableCell({
|
|
216
|
+
colspan: columnCount,
|
|
217
|
+
class: "h-24 text-center",
|
|
218
|
+
children: props.emptyMessage ?? "No results.",
|
|
219
|
+
}),
|
|
220
|
+
})
|
|
221
|
+
: each(visible, props.rowKey, renderRow),
|
|
205
222
|
}),
|
|
206
223
|
],
|
|
207
224
|
})}
|
|
@@ -215,22 +232,26 @@ export function DataTable(props) {
|
|
|
215
232
|
* current one and the gaps between — and the parts render that list.
|
|
216
233
|
*/
|
|
217
234
|
function renderPagination() {
|
|
218
|
-
const current = () => Math.min(
|
|
235
|
+
const current = () => Math.min(pageNumber(), pageCount());
|
|
219
236
|
const go = (target) => () => {
|
|
220
|
-
|
|
237
|
+
goToPage(Math.min(Math.max(target, 1), pageCount()));
|
|
221
238
|
};
|
|
239
|
+
const word = (key) => props.paginationLabels?.[key] ?? paginationLabels[key];
|
|
222
240
|
return Pagination({
|
|
241
|
+
"aria-label": word("navigation"),
|
|
223
242
|
children: () => PaginationContent({
|
|
224
243
|
children: [
|
|
225
244
|
PaginationItem({
|
|
226
245
|
children: PaginationPrevious({
|
|
246
|
+
"aria-label": word("previousPage"),
|
|
247
|
+
children: word("previous"),
|
|
227
248
|
disabled: () => current() <= 1,
|
|
228
249
|
onSelect: go(current() - 1),
|
|
229
250
|
}),
|
|
230
251
|
}),
|
|
231
252
|
...pageWindow(current(), pageCount()).map((entry) => PaginationItem({
|
|
232
253
|
children: entry === null
|
|
233
|
-
? PaginationEllipsis({})
|
|
254
|
+
? PaginationEllipsis({ label: word("morePages") })
|
|
234
255
|
: PaginationLink({
|
|
235
256
|
children: String(entry),
|
|
236
257
|
isActive: () => current() === entry,
|
|
@@ -239,6 +260,8 @@ export function DataTable(props) {
|
|
|
239
260
|
})),
|
|
240
261
|
PaginationItem({
|
|
241
262
|
children: PaginationNext({
|
|
263
|
+
"aria-label": word("nextPage"),
|
|
264
|
+
children: word("next"),
|
|
242
265
|
disabled: () => current() >= pageCount(),
|
|
243
266
|
onSelect: go(current() + 1),
|
|
244
267
|
}),
|
|
@@ -247,21 +270,28 @@ export function DataTable(props) {
|
|
|
247
270
|
}),
|
|
248
271
|
});
|
|
249
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* One row, built once for its key. The cells read the row through its
|
|
275
|
+
* accessor, so a row whose data changed redraws its cells and nothing else.
|
|
276
|
+
*/
|
|
250
277
|
function renderRow(row) {
|
|
251
|
-
const key = props.rowKey(row);
|
|
278
|
+
const key = props.rowKey(row());
|
|
252
279
|
return TableRow({
|
|
253
280
|
selected: () => selected().includes(key),
|
|
254
281
|
children: [
|
|
255
282
|
props.selectable === true
|
|
256
283
|
? TableCell({
|
|
257
284
|
children: Checkbox({
|
|
258
|
-
label: `Select row ${key}`,
|
|
285
|
+
label: () => props.selectRowLabel?.(row()) ?? `Select row ${key}`,
|
|
259
286
|
checked: () => selected().includes(key),
|
|
260
287
|
onCheckedChange: () => toggleRow(key),
|
|
261
288
|
}),
|
|
262
289
|
})
|
|
263
290
|
: null,
|
|
264
|
-
...props.columns.map((column) => TableCell({
|
|
291
|
+
...props.columns.map((column) => TableCell({
|
|
292
|
+
class: column.class,
|
|
293
|
+
children: () => readCell(row(), column),
|
|
294
|
+
})),
|
|
265
295
|
],
|
|
266
296
|
});
|
|
267
297
|
}
|