@c9up/nebula 0.1.9 → 0.2.0
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/dist/atoms/Avatar.d.ts +36 -9
- package/dist/atoms/Avatar.js +66 -27
- package/dist/atoms/index.d.ts +1 -1
- package/dist/atoms/index.js +1 -1
- package/dist/lib/children.d.ts +30 -0
- package/dist/lib/motion.d.ts +10 -0
- package/dist/lib/motion.js +10 -0
- package/dist/molecules/Accordion.d.ts +36 -15
- package/dist/molecules/Accordion.js +68 -45
- package/dist/molecules/Breadcrumb.d.ts +29 -11
- package/dist/molecules/Breadcrumb.js +52 -52
- package/dist/molecules/Collapsible.d.ts +18 -17
- package/dist/molecules/Collapsible.js +42 -34
- package/dist/molecules/Field.d.ts +66 -30
- package/dist/molecules/Field.js +106 -55
- package/dist/molecules/InputGroup.d.ts +39 -21
- package/dist/molecules/InputGroup.js +43 -27
- package/dist/molecules/InputOTP.d.ts +26 -3
- package/dist/molecules/InputOTP.js +109 -76
- package/dist/molecules/Message.js +5 -4
- package/dist/molecules/Pagination.d.ts +36 -11
- package/dist/molecules/Pagination.js +58 -74
- package/dist/molecules/RadioGroup.d.ts +25 -17
- package/dist/molecules/RadioGroup.js +47 -43
- package/dist/molecules/Resizable.d.ts +32 -7
- package/dist/molecules/Resizable.js +76 -49
- package/dist/molecules/Tabs.d.ts +49 -11
- package/dist/molecules/Tabs.js +107 -51
- package/dist/molecules/ToggleGroup.d.ts +16 -10
- package/dist/molecules/ToggleGroup.js +37 -21
- package/dist/molecules/index.d.ts +11 -11
- package/dist/molecules/index.js +11 -11
- package/dist/organisms/AlertDialog.d.ts +80 -28
- package/dist/organisms/AlertDialog.js +192 -67
- package/dist/organisms/Carousel.d.ts +25 -3
- package/dist/organisms/Carousel.js +75 -43
- package/dist/organisms/Combobox.d.ts +2 -1
- package/dist/organisms/Combobox.js +46 -16
- package/dist/organisms/Command.d.ts +73 -32
- package/dist/organisms/Command.js +209 -131
- package/dist/organisms/CommandDialog.js +5 -5
- package/dist/organisms/ContextMenu.d.ts +41 -19
- package/dist/organisms/ContextMenu.js +112 -71
- package/dist/organisms/DataTable.js +42 -8
- package/dist/organisms/Dialog.d.ts +97 -31
- package/dist/organisms/Dialog.js +193 -68
- package/dist/organisms/Drawer.d.ts +33 -10
- package/dist/organisms/Drawer.js +130 -52
- package/dist/organisms/DropdownMenu.d.ts +58 -11
- package/dist/organisms/DropdownMenu.js +137 -50
- package/dist/organisms/Form.js +9 -11
- package/dist/organisms/HoverCard.d.ts +39 -19
- package/dist/organisms/HoverCard.js +116 -40
- package/dist/organisms/Menubar.d.ts +55 -19
- package/dist/organisms/Menubar.js +166 -82
- package/dist/organisms/NavigationMenu.d.ts +77 -31
- package/dist/organisms/NavigationMenu.js +169 -98
- package/dist/organisms/Popover.d.ts +72 -12
- package/dist/organisms/Popover.js +132 -25
- package/dist/organisms/Questionnaire.js +5 -5
- package/dist/organisms/Select.d.ts +99 -18
- package/dist/organisms/Select.js +253 -111
- package/dist/organisms/Sheet.d.ts +57 -13
- package/dist/organisms/Sheet.js +141 -54
- package/dist/organisms/Sidebar.d.ts +146 -56
- package/dist/organisms/Sidebar.js +236 -128
- package/dist/organisms/Tooltip.d.ts +88 -14
- package/dist/organisms/Tooltip.js +210 -47
- package/dist/organisms/index.d.ts +15 -15
- package/dist/organisms/index.js +15 -15
- package/dist/primitives/floating.js +25 -0
- package/dist/primitives/floatingSurface.d.ts +11 -0
- package/dist/primitives/floatingSurface.js +8 -0
- package/dist/primitives/menu.d.ts +45 -1
- package/dist/primitives/menu.js +45 -14
- package/dist/primitives/menuParts.d.ts +113 -0
- package/dist/primitives/menuParts.js +207 -0
- package/nebula.css +1 -1
- package/package.json +3 -3
- package/registry.json +18 -6
- package/src/atoms/Avatar.ts +141 -37
- package/src/atoms/index.ts +13 -1
- package/src/lib/children.ts +31 -0
- package/src/lib/motion.ts +12 -0
- package/src/molecules/Accordion.ts +120 -60
- package/src/molecules/Breadcrumb.ts +77 -76
- package/src/molecules/Collapsible.ts +77 -41
- package/src/molecules/Field.ts +187 -72
- package/src/molecules/InputGroup.ts +88 -35
- package/src/molecules/InputOTP.ts +150 -86
- package/src/molecules/Message.ts +6 -4
- package/src/molecules/Pagination.ts +96 -101
- package/src/molecules/RadioGroup.ts +70 -59
- package/src/molecules/Resizable.ts +138 -75
- package/src/molecules/Tabs.ts +187 -74
- package/src/molecules/ToggleGroup.ts +77 -38
- package/src/molecules/index.ts +85 -8
- package/src/organisms/AlertDialog.ts +319 -82
- package/src/organisms/Carousel.ts +129 -52
- package/src/organisms/Combobox.ts +64 -19
- package/src/organisms/Command.ts +342 -159
- package/src/organisms/CommandDialog.ts +6 -6
- package/src/organisms/ContextMenu.ts +185 -83
- package/src/organisms/DataTable.ts +56 -10
- package/src/organisms/Dialog.ts +312 -102
- package/src/organisms/Drawer.ts +219 -71
- package/src/organisms/DropdownMenu.ts +219 -61
- package/src/organisms/Form.ts +48 -34
- package/src/organisms/HoverCard.ts +187 -53
- package/src/organisms/Menubar.ts +247 -87
- package/src/organisms/NavigationMenu.ts +306 -128
- package/src/organisms/Popover.ts +215 -39
- package/src/organisms/Questionnaire.ts +9 -6
- package/src/organisms/Select.ts +397 -130
- package/src/organisms/Sheet.ts +252 -83
- package/src/organisms/Sidebar.ts +438 -185
- package/src/organisms/Tooltip.ts +315 -65
- package/src/organisms/index.ts +284 -14
- package/src/primitives/floating.ts +33 -0
- package/src/primitives/floatingSurface.ts +19 -0
- package/src/primitives/menu.ts +79 -18
- package/src/primitives/menuParts.ts +371 -0
package/dist/atoms/Avatar.d.ts
CHANGED
|
@@ -1,23 +1,50 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Avatar — a user's picture, with a fallback when there is none.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Avatar({ children: () => html`
|
|
5
|
+
* ${AvatarImage({ src: user.photo, alt: user.name })}
|
|
6
|
+
* ${AvatarFallback({ children: initials })}
|
|
7
|
+
* ` })
|
|
8
8
|
*
|
|
9
9
|
* Three states, not two. An image that has not loaded *yet* must not show the
|
|
10
10
|
* fallback — swapping initials in and a photo over them a moment later is the
|
|
11
11
|
* flicker this component exists to avoid. So the fallback appears only once
|
|
12
|
-
* the image has actually failed, or when there
|
|
12
|
+
* the image has actually failed, or when there is no `AvatarImage` at all.
|
|
13
|
+
*
|
|
14
|
+
* That is what the context carries: the image reports its own load state up,
|
|
15
|
+
* the fallback reads it, and neither knows the other exists. Radix needs the
|
|
16
|
+
* same three pieces for the same reason.
|
|
13
17
|
*/
|
|
14
|
-
import {
|
|
18
|
+
import type { Parts, Slot } from "../lib/children.js";
|
|
15
19
|
import { type Reactive } from "../lib/props.js";
|
|
16
20
|
export interface AvatarProps {
|
|
21
|
+
size?: "sm" | "default" | "lg";
|
|
22
|
+
class?: Reactive<string>;
|
|
23
|
+
children?: Parts;
|
|
24
|
+
}
|
|
25
|
+
export declare const Avatar: (props?: AvatarProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
26
|
+
export interface AvatarImageProps {
|
|
17
27
|
src?: Reactive<string | undefined>;
|
|
18
28
|
alt?: Reactive<string>;
|
|
19
|
-
/** Shown when there is no image, or it failed. Usually initials. */
|
|
20
|
-
fallback?: Slot;
|
|
21
29
|
class?: Reactive<string>;
|
|
22
30
|
}
|
|
23
|
-
export declare const
|
|
31
|
+
export declare const AvatarImage: (props?: AvatarImageProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
32
|
+
export interface AvatarFallbackProps {
|
|
33
|
+
children?: Slot;
|
|
34
|
+
class?: Reactive<string>;
|
|
35
|
+
}
|
|
36
|
+
export declare const AvatarFallback: (props?: AvatarFallbackProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
37
|
+
export interface AvatarBadgeProps {
|
|
38
|
+
children?: Slot;
|
|
39
|
+
class?: Reactive<string>;
|
|
40
|
+
}
|
|
41
|
+
/** A status dot in the corner — online, unread, verified. */
|
|
42
|
+
export declare const AvatarBadge: (props?: AvatarBadgeProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
43
|
+
export interface AvatarGroupProps {
|
|
44
|
+
children?: Slot;
|
|
45
|
+
class?: Reactive<string>;
|
|
46
|
+
}
|
|
47
|
+
/** Overlapping avatars, each ringed so the stack reads as separate faces. */
|
|
48
|
+
export declare const AvatarGroup: (props?: AvatarGroupProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
49
|
+
/** The "+3" that closes a group. */
|
|
50
|
+
export declare const AvatarGroupCount: (props?: AvatarGroupProps | undefined) => import("@c9up/aurora").TemplateResult;
|
package/dist/atoms/Avatar.js
CHANGED
|
@@ -1,46 +1,85 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Avatar — a user's picture, with a fallback when there is none.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Avatar({ children: () => html`
|
|
5
|
+
* ${AvatarImage({ src: user.photo, alt: user.name })}
|
|
6
|
+
* ${AvatarFallback({ children: initials })}
|
|
7
|
+
* ` })
|
|
8
8
|
*
|
|
9
9
|
* Three states, not two. An image that has not loaded *yet* must not show the
|
|
10
10
|
* fallback — swapping initials in and a photo over them a moment later is the
|
|
11
11
|
* flicker this component exists to avoid. So the fallback appears only once
|
|
12
|
-
* the image has actually failed, or when there
|
|
12
|
+
* the image has actually failed, or when there is no `AvatarImage` at all.
|
|
13
|
+
*
|
|
14
|
+
* That is what the context carries: the image reports its own load state up,
|
|
15
|
+
* the fallback reads it, and neither knows the other exists. Radix needs the
|
|
16
|
+
* same three pieces for the same reason.
|
|
13
17
|
*/
|
|
14
|
-
import { component, html, signal } from "@c9up/aurora";
|
|
18
|
+
import { component, createContext, html, inject, provide, signal, } from "@c9up/aurora";
|
|
15
19
|
import { slot } from "../lib/children.js";
|
|
16
20
|
import { cn } from "../lib/cn.js";
|
|
17
21
|
import { read, readOr } from "../lib/props.js";
|
|
22
|
+
const AvatarContext = createContext("Avatar");
|
|
18
23
|
export const Avatar = component((props) => {
|
|
19
|
-
|
|
24
|
+
// `absent` until an image says otherwise: an avatar with no `AvatarImage`
|
|
25
|
+
// is a fallback-only avatar, and it must not wait for a load that will
|
|
26
|
+
// never happen.
|
|
27
|
+
const state = signal("absent");
|
|
28
|
+
provide(AvatarContext, {
|
|
29
|
+
state: () => state(),
|
|
30
|
+
setState: (next) => state(next),
|
|
31
|
+
});
|
|
32
|
+
return html `<span
|
|
33
|
+
data-slot="avatar"
|
|
34
|
+
data-size="${props.size ?? "default"}"
|
|
35
|
+
class="${() => cn("group/avatar relative flex size-8 shrink-0 overflow-hidden rounded-full select-none data-[size=lg]:size-10 data-[size=sm]:size-6", read(props.class))}"
|
|
36
|
+
>${props.children?.()}</span>`;
|
|
37
|
+
});
|
|
38
|
+
export const AvatarImage = component((props) => {
|
|
39
|
+
const avatar = inject(AvatarContext);
|
|
20
40
|
const hasSrc = () => {
|
|
21
41
|
const src = read(props.src);
|
|
22
42
|
return src !== undefined && src !== "";
|
|
23
43
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
>
|
|
29
|
-
${() => hasSrc() && state() !== "failed"
|
|
44
|
+
// Reported during setup, so the fallback built after it already reads the
|
|
45
|
+
// right state rather than flashing through `absent`.
|
|
46
|
+
avatar.setState(hasSrc() ? "pending" : "absent");
|
|
47
|
+
return html `${() => hasSrc() && avatar.state() !== "failed"
|
|
30
48
|
? html `<img
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
: null}
|
|
39
|
-
|
|
49
|
+
data-slot="avatar-image"
|
|
50
|
+
src="${() => read(props.src)}"
|
|
51
|
+
alt="${() => readOr(props.alt, "")}"
|
|
52
|
+
class="${() => cn("aspect-square size-full object-cover", read(props.class))}"
|
|
53
|
+
@load="${() => avatar.setState("loaded")}"
|
|
54
|
+
@error="${() => avatar.setState("failed")}"
|
|
55
|
+
/>`
|
|
56
|
+
: null}`;
|
|
57
|
+
});
|
|
58
|
+
export const AvatarFallback = component((props) => {
|
|
59
|
+
const avatar = inject(AvatarContext);
|
|
60
|
+
const show = () => {
|
|
61
|
+
const state = avatar.state();
|
|
62
|
+
return state === "absent" || state === "failed";
|
|
63
|
+
};
|
|
64
|
+
return html `${() => show()
|
|
40
65
|
? html `<span
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
: null}
|
|
45
|
-
</span>`;
|
|
66
|
+
data-slot="avatar-fallback"
|
|
67
|
+
class="${() => cn("bg-muted text-muted-foreground flex size-full items-center justify-center rounded-full text-sm group-data-[size=sm]/avatar:text-xs", read(props.class))}"
|
|
68
|
+
>${slot(props.children)}</span>`
|
|
69
|
+
: null}`;
|
|
46
70
|
});
|
|
71
|
+
/** A status dot in the corner — online, unread, verified. */
|
|
72
|
+
export const AvatarBadge = component((props) => html `<span
|
|
73
|
+
data-slot="avatar-badge"
|
|
74
|
+
class="${() => cn("bg-primary text-primary-foreground ring-background absolute right-0 bottom-0 z-10 inline-flex items-center justify-center rounded-full ring-2 select-none", "group-data-[size=sm]/avatar:size-2 group-data-[size=sm]/avatar:[&>svg]:hidden", "group-data-[size=default]/avatar:size-2.5 group-data-[size=default]/avatar:[&>svg]:size-2", "group-data-[size=lg]/avatar:size-3 group-data-[size=lg]/avatar:[&>svg]:size-2", read(props.class))}"
|
|
75
|
+
>${slot(props.children)}</span>`);
|
|
76
|
+
/** Overlapping avatars, each ringed so the stack reads as separate faces. */
|
|
77
|
+
export const AvatarGroup = component((props) => html `<div
|
|
78
|
+
data-slot="avatar-group"
|
|
79
|
+
class="${() => cn("group/avatar-group flex -space-x-2 *:data-[slot=avatar]:ring-2 *:data-[slot=avatar]:ring-background", read(props.class))}"
|
|
80
|
+
>${slot(props.children)}</div>`);
|
|
81
|
+
/** The "+3" that closes a group. */
|
|
82
|
+
export const AvatarGroupCount = component((props) => html `<span
|
|
83
|
+
data-slot="avatar-group-count"
|
|
84
|
+
class="${() => cn("bg-muted text-muted-foreground ring-background relative flex size-8 shrink-0 items-center justify-center rounded-full text-sm ring-2 group-has-data-[size=lg]/avatar-group:size-10 group-has-data-[size=sm]/avatar-group:size-6 [&>svg]:size-4 group-has-data-[size=lg]/avatar-group:[&>svg]:size-5 group-has-data-[size=sm]/avatar-group:[&>svg]:size-3", read(props.class))}"
|
|
85
|
+
>${slot(props.children)}</span>`);
|
package/dist/atoms/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* Slider is an atom despite being interactive, because it is one input.
|
|
13
13
|
*/
|
|
14
14
|
export { AspectRatio, type AspectRatioProps } from "./AspectRatio.js";
|
|
15
|
-
export { Avatar, type AvatarProps } from "./Avatar.js";
|
|
15
|
+
export { Avatar, AvatarBadge, type AvatarBadgeProps, AvatarFallback, type AvatarFallbackProps, AvatarGroup, AvatarGroupCount, type AvatarGroupProps, AvatarImage, type AvatarImageProps, type AvatarProps, } from "./Avatar.js";
|
|
16
16
|
export { Badge, type BadgeProps, type BadgeVariants, badgeVariants, } from "./Badge.js";
|
|
17
17
|
export { Button, type ButtonProps, type ButtonVariants, buttonVariants, } from "./Button.js";
|
|
18
18
|
export { Checkbox, type CheckboxProps, checkboxClasses } from "./Checkbox.js";
|
package/dist/atoms/index.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* Slider is an atom despite being interactive, because it is one input.
|
|
13
13
|
*/
|
|
14
14
|
export { AspectRatio } from "./AspectRatio.js";
|
|
15
|
-
export { Avatar } from "./Avatar.js";
|
|
15
|
+
export { Avatar, AvatarBadge, AvatarFallback, AvatarGroup, AvatarGroupCount, AvatarImage, } from "./Avatar.js";
|
|
16
16
|
export { Badge, badgeVariants, } from "./Badge.js";
|
|
17
17
|
export { Button, buttonVariants, } from "./Button.js";
|
|
18
18
|
export { Checkbox, checkboxClasses } from "./Checkbox.js";
|
package/dist/lib/children.d.ts
CHANGED
|
@@ -17,6 +17,36 @@ import type { Reactive } from "./props.js";
|
|
|
17
17
|
export type Child = TemplateResult | Node | string | number | boolean | null | undefined | readonly Child[];
|
|
18
18
|
/** Content that may be constant or recomputed. */
|
|
19
19
|
export type Slot = Reactive<Child>;
|
|
20
|
+
/**
|
|
21
|
+
* The children of a component that PROVIDES context, as a function.
|
|
22
|
+
*
|
|
23
|
+
* A compound component — `Tooltip`, `Select`, `DropdownMenu` — shares its
|
|
24
|
+
* state with its parts through Aurora's context, and context reaches only what
|
|
25
|
+
* the provider creates inside its own setup. Aurora evaluates eagerly, so
|
|
26
|
+
* children handed over already built ran before the provider existed:
|
|
27
|
+
*
|
|
28
|
+
* Tooltip({ children: TooltipTrigger({ … }) }) // ✗ built too early
|
|
29
|
+
* Tooltip({ children: () => TooltipTrigger({ … }) }) // ✓ the setup calls it
|
|
30
|
+
*
|
|
31
|
+
* This is the aurora spelling of what JSX gets from deferring an element tree.
|
|
32
|
+
* `Parts` names it so the type makes the requirement, rather than a blank
|
|
33
|
+
* surface at runtime.
|
|
34
|
+
*
|
|
35
|
+
* Called ONCE, during setup — the structure of a compound component is fixed,
|
|
36
|
+
* and its moving pieces are signals inside the parts.
|
|
37
|
+
*
|
|
38
|
+
* The same rule read from the other end: a part that READS context must be
|
|
39
|
+
* built eagerly too, so it must not be hidden inside a `Slot`. `Slot` exists
|
|
40
|
+
* for content that CHANGES, and the renderer calls it later, by which time
|
|
41
|
+
* there is no context left to read:
|
|
42
|
+
*
|
|
43
|
+
* DialogHeader({ children: html`${DialogTitle(…)}` }) // ✓ a value
|
|
44
|
+
* DialogHeader({ children: () => html`${DialogTitle(…)}` }) // ✗ too late
|
|
45
|
+
*
|
|
46
|
+
* So: write `() =>` for a component that PROVIDES (its type says `Parts`), and
|
|
47
|
+
* a plain value everywhere else unless the content really does change.
|
|
48
|
+
*/
|
|
49
|
+
export type Parts = () => Child;
|
|
20
50
|
/**
|
|
21
51
|
* Bind content into a template so it stays live.
|
|
22
52
|
*
|
package/dist/lib/motion.d.ts
CHANGED
|
@@ -29,6 +29,16 @@ import type { Side } from "../primitives/floating.js";
|
|
|
29
29
|
* once, so reduced motion gets an instant close with no branch in the component.
|
|
30
30
|
*/
|
|
31
31
|
export declare const zoomInOut = "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=open]:fade-in-0 data-[state=closed]:fade-out-0 data-[state=open]:zoom-in-95 data-[state=closed]:zoom-out-95 motion-reduce:animate-none";
|
|
32
|
+
/**
|
|
33
|
+
* The entrance offset every anchored surface shares.
|
|
34
|
+
*
|
|
35
|
+
* shadcn puts these four on popover, dropdown, select, tooltip, hover card,
|
|
36
|
+
* menubar and context-menu content alike, so the surface slides in from the
|
|
37
|
+
* edge it is anchored against and the motion points back at whatever opened
|
|
38
|
+
* it. `data-side` is written by `autoPosition` after any flip, so a menu that
|
|
39
|
+
* flipped above its trigger slides the other way without a second class.
|
|
40
|
+
*/
|
|
41
|
+
export declare const slideInFromSide = "data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2";
|
|
32
42
|
/** Backdrops and tooltips — no movement, just opacity. */
|
|
33
43
|
export declare const fadeInOut = "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=open]:fade-in-0 data-[state=closed]:fade-out-0 motion-reduce:animate-none";
|
|
34
44
|
/**
|
package/dist/lib/motion.js
CHANGED
|
@@ -28,6 +28,16 @@
|
|
|
28
28
|
* once, so reduced motion gets an instant close with no branch in the component.
|
|
29
29
|
*/
|
|
30
30
|
export const zoomInOut = "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=open]:fade-in-0 data-[state=closed]:fade-out-0 data-[state=open]:zoom-in-95 data-[state=closed]:zoom-out-95 motion-reduce:animate-none";
|
|
31
|
+
/**
|
|
32
|
+
* The entrance offset every anchored surface shares.
|
|
33
|
+
*
|
|
34
|
+
* shadcn puts these four on popover, dropdown, select, tooltip, hover card,
|
|
35
|
+
* menubar and context-menu content alike, so the surface slides in from the
|
|
36
|
+
* edge it is anchored against and the motion points back at whatever opened
|
|
37
|
+
* it. `data-side` is written by `autoPosition` after any flip, so a menu that
|
|
38
|
+
* flipped above its trigger slides the other way without a second class.
|
|
39
|
+
*/
|
|
40
|
+
export const slideInFromSide = "data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2";
|
|
31
41
|
/** Backdrops and tooltips — no movement, just opacity. */
|
|
32
42
|
export const fadeInOut = "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=open]:fade-in-0 data-[state=closed]:fade-out-0 motion-reduce:animate-none";
|
|
33
43
|
/**
|
|
@@ -1,28 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Accordion — a stack of collapsible sections.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Accordion({ type: "single", children: () => html`
|
|
5
|
+
* ${AccordionItem({ value: "a", children: () => html`
|
|
6
|
+
* ${AccordionTrigger({ children: "Shipping" })}
|
|
7
|
+
* ${AccordionContent({ children: "Two to four days." })}
|
|
8
|
+
* ` })}
|
|
9
|
+
* ` })
|
|
10
|
+
*
|
|
11
|
+
* `type: "single"` needs to know about every section at once, which is what
|
|
12
|
+
* the context carries: the group owns the open SET and each item asks whether
|
|
13
|
+
* it is in it. Radix does the same, for the same reason.
|
|
8
14
|
*
|
|
9
15
|
* The keyboard behaviour is the WAI-ARIA accordion pattern, delegated to
|
|
10
16
|
* `rovingFocus` over the headers: arrows move between sections, Home and End
|
|
11
17
|
* jump to the ends, and the headers are one tab stop rather than one each.
|
|
12
18
|
*/
|
|
13
|
-
import type {
|
|
19
|
+
import type { Parts, Slot } from "../lib/children.js";
|
|
14
20
|
import { type Reactive } from "../lib/props.js";
|
|
15
|
-
export interface AccordionItem {
|
|
16
|
-
/** Stable key. Used for the open-state set and for the ARIA ids. */
|
|
17
|
-
value: string;
|
|
18
|
-
/** The header content. */
|
|
19
|
-
trigger: Child;
|
|
20
|
-
/** The panel content. */
|
|
21
|
-
content: Slot;
|
|
22
|
-
disabled?: boolean;
|
|
23
|
-
}
|
|
24
21
|
export interface AccordionProps {
|
|
25
|
-
|
|
22
|
+
children?: Parts;
|
|
26
23
|
/** `"single"` closes the open section when another opens. Default `"single"`. */
|
|
27
24
|
type?: "single" | "multiple";
|
|
28
25
|
/** Open at first render. A string, or several for `type: "multiple"`. */
|
|
@@ -33,3 +30,27 @@ export interface AccordionProps {
|
|
|
33
30
|
class?: Reactive<string>;
|
|
34
31
|
}
|
|
35
32
|
export declare const Accordion: (props?: AccordionProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
33
|
+
export interface AccordionItemProps {
|
|
34
|
+
/** Stable key. Used for the open-state set and for the ARIA ids. */
|
|
35
|
+
value: string;
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
class?: Reactive<string>;
|
|
38
|
+
children?: Parts;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* One section.
|
|
42
|
+
*
|
|
43
|
+
* Provides a second context of its own, so the trigger and the panel inside it
|
|
44
|
+
* share their ids without the caller repeating the value on each.
|
|
45
|
+
*/
|
|
46
|
+
export declare const AccordionItem: (props?: AccordionItemProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
47
|
+
export interface AccordionTriggerProps {
|
|
48
|
+
children?: Slot;
|
|
49
|
+
class?: Reactive<string>;
|
|
50
|
+
}
|
|
51
|
+
export declare const AccordionTrigger: (props?: AccordionTriggerProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
52
|
+
export interface AccordionContentProps {
|
|
53
|
+
children?: Slot;
|
|
54
|
+
class?: Reactive<string>;
|
|
55
|
+
}
|
|
56
|
+
export declare const AccordionContent: (props?: AccordionContentProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
@@ -1,22 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Accordion — a stack of collapsible sections.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Accordion({ type: "single", children: () => html`
|
|
5
|
+
* ${AccordionItem({ value: "a", children: () => html`
|
|
6
|
+
* ${AccordionTrigger({ children: "Shipping" })}
|
|
7
|
+
* ${AccordionContent({ children: "Two to four days." })}
|
|
8
|
+
* ` })}
|
|
9
|
+
* ` })
|
|
10
|
+
*
|
|
11
|
+
* `type: "single"` needs to know about every section at once, which is what
|
|
12
|
+
* the context carries: the group owns the open SET and each item asks whether
|
|
13
|
+
* it is in it. Radix does the same, for the same reason.
|
|
8
14
|
*
|
|
9
15
|
* The keyboard behaviour is the WAI-ARIA accordion pattern, delegated to
|
|
10
16
|
* `rovingFocus` over the headers: arrows move between sections, Home and End
|
|
11
17
|
* jump to the ends, and the headers are one tab stop rather than one each.
|
|
12
18
|
*/
|
|
13
|
-
import { component, html, onMount, onUnmount, signal } from "@c9up/aurora";
|
|
19
|
+
import { component, createContext, html, inject, onMount, onUnmount, provide, signal, } from "@c9up/aurora";
|
|
14
20
|
import { slot } from "../lib/children.js";
|
|
15
21
|
import { cn } from "../lib/cn.js";
|
|
16
22
|
import { ChevronDownIcon } from "../lib/icons.js";
|
|
17
23
|
import { uid } from "../lib/id.js";
|
|
18
24
|
import { read } from "../lib/props.js";
|
|
19
25
|
import { rovingFocus } from "../primitives/rovingFocus.js";
|
|
26
|
+
const AccordionContext = createContext("Accordion");
|
|
27
|
+
const AccordionItemContext = createContext("AccordionItem");
|
|
20
28
|
export const Accordion = component((props) => {
|
|
21
29
|
const type = props.type ?? "single";
|
|
22
30
|
const open = signal(normaliseInitial(props.defaultValue));
|
|
@@ -42,56 +50,71 @@ export const Accordion = component((props) => {
|
|
|
42
50
|
group.sync();
|
|
43
51
|
});
|
|
44
52
|
onUnmount(() => group?.destroy());
|
|
53
|
+
provide(AccordionContext, { isOpen, toggle });
|
|
45
54
|
return html `<div
|
|
46
55
|
data-slot="accordion"
|
|
47
56
|
id="${rootId}"
|
|
48
57
|
class="${() => cn("flex w-full flex-col", read(props.class))}"
|
|
49
|
-
|
|
50
|
-
${props.items.map((item) => renderItem(item, isOpen, toggle))}
|
|
51
|
-
</div>`;
|
|
58
|
+
>${props.children?.()}</div>`;
|
|
52
59
|
});
|
|
53
|
-
|
|
60
|
+
/**
|
|
61
|
+
* One section.
|
|
62
|
+
*
|
|
63
|
+
* Provides a second context of its own, so the trigger and the panel inside it
|
|
64
|
+
* share their ids without the caller repeating the value on each.
|
|
65
|
+
*/
|
|
66
|
+
export const AccordionItem = component((props) => {
|
|
67
|
+
const accordion = inject(AccordionContext);
|
|
54
68
|
const triggerId = uid("accordion-trigger");
|
|
55
69
|
const panelId = uid("accordion-panel");
|
|
56
|
-
const
|
|
70
|
+
const open = () => accordion.isOpen(props.value);
|
|
71
|
+
provide(AccordionItemContext, {
|
|
72
|
+
value: props.value,
|
|
73
|
+
triggerId,
|
|
74
|
+
panelId,
|
|
75
|
+
disabled: props.disabled === true,
|
|
76
|
+
open,
|
|
77
|
+
toggle: () => accordion.toggle(props.value),
|
|
78
|
+
});
|
|
57
79
|
return html `<div
|
|
58
80
|
data-slot="accordion-item"
|
|
59
|
-
data-state="${
|
|
60
|
-
class="border-b last:border-b-0"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
>
|
|
76
|
-
|
|
77
|
-
|
|
81
|
+
data-state="${() => (open() ? "open" : "closed")}"
|
|
82
|
+
class="${() => cn("border-b last:border-b-0", read(props.class))}"
|
|
83
|
+
>${props.children?.()}</div>`;
|
|
84
|
+
});
|
|
85
|
+
export const AccordionTrigger = component((props) => {
|
|
86
|
+
const item = inject(AccordionItemContext);
|
|
87
|
+
return html `<h3 class="flex"><button
|
|
88
|
+
type="button"
|
|
89
|
+
data-slot="accordion-trigger"
|
|
90
|
+
data-nebula-item
|
|
91
|
+
data-state="${() => (item.open() ? "open" : "closed")}"
|
|
92
|
+
data-disabled="${item.disabled ? "" : undefined}"
|
|
93
|
+
id="${item.triggerId}"
|
|
94
|
+
aria-expanded="${() => (item.open() ? "true" : "false")}"
|
|
95
|
+
aria-controls="${item.panelId}"
|
|
96
|
+
?disabled="${item.disabled}"
|
|
97
|
+
class="${() => cn("focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium outline-none transition-all hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180", read(props.class))}"
|
|
98
|
+
@click="${() => item.toggle()}"
|
|
99
|
+
>${slot(props.children)}${ChevronDownIcon({
|
|
78
100
|
class: "text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-200",
|
|
79
|
-
})}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
101
|
+
})}</button></h3>`;
|
|
102
|
+
});
|
|
103
|
+
export const AccordionContent = component((props) => {
|
|
104
|
+
const item = inject(AccordionItemContext);
|
|
105
|
+
return html `<div
|
|
106
|
+
data-slot="accordion-content"
|
|
107
|
+
id="${item.panelId}"
|
|
108
|
+
role="region"
|
|
109
|
+
data-state="${() => (item.open() ? "open" : "closed")}"
|
|
110
|
+
aria-labelledby="${item.triggerId}"
|
|
111
|
+
?inert="${() => !item.open()}"
|
|
112
|
+
class="grid text-sm transition-[grid-template-rows] duration-200 ease-out motion-reduce:transition-none"
|
|
113
|
+
style="${() => `grid-template-rows: ${item.open() ? "1fr" : "0fr"}`}"
|
|
114
|
+
><div class="overflow-hidden"><div
|
|
115
|
+
class="${() => cn("pt-0 pb-4", read(props.class))}"
|
|
116
|
+
>${slot(props.children)}</div></div></div>`;
|
|
117
|
+
});
|
|
95
118
|
function normaliseInitial(value) {
|
|
96
119
|
if (value === undefined)
|
|
97
120
|
return [];
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Breadcrumb — the trail back up the hierarchy.
|
|
3
3
|
*
|
|
4
|
+
* Breadcrumb({ children: BreadcrumbList({ children: html`
|
|
5
|
+
* ${BreadcrumbItem({ children: BreadcrumbLink({ href: "/", children: "Home" }) })}
|
|
6
|
+
* ${BreadcrumbSeparator({})}
|
|
7
|
+
* ${BreadcrumbItem({ children: BreadcrumbPage({ children: "Settings" }) })}
|
|
8
|
+
* ` }) })
|
|
9
|
+
*
|
|
10
|
+
* Every part is presentational, so none of them takes `Parts` — there is no
|
|
11
|
+
* context here to be inside of.
|
|
12
|
+
*
|
|
4
13
|
* `aria-label="breadcrumb"` on the `<nav>` and `aria-current="page"` on the
|
|
5
14
|
* last entry. Both matter: the label is how a screen reader distinguishes this
|
|
6
15
|
* navigation from the other landmarks on the page, and `aria-current` is what
|
|
@@ -11,19 +20,28 @@
|
|
|
11
20
|
* aloud, a chevron between every crumb is noise; the list structure already
|
|
12
21
|
* conveys the sequence.
|
|
13
22
|
*/
|
|
14
|
-
import type
|
|
23
|
+
import { type Slot } from "../lib/children.js";
|
|
15
24
|
import { type Reactive } from "../lib/props.js";
|
|
16
|
-
export interface Crumb {
|
|
17
|
-
label: Child;
|
|
18
|
-
/** Absent on the current page, and on a collapsed ellipsis. */
|
|
19
|
-
href?: string;
|
|
20
|
-
/** Renders an ellipsis standing in for hidden ancestors. */
|
|
21
|
-
ellipsis?: boolean;
|
|
22
|
-
}
|
|
23
25
|
export interface BreadcrumbProps {
|
|
24
|
-
|
|
25
|
-
/** Replaces the chevron between entries. */
|
|
26
|
-
separator?: Child;
|
|
26
|
+
children?: Slot;
|
|
27
27
|
class?: Reactive<string>;
|
|
28
28
|
}
|
|
29
29
|
export declare const Breadcrumb: (props?: BreadcrumbProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
30
|
+
export declare const BreadcrumbList: (props?: BreadcrumbProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
31
|
+
export declare const BreadcrumbItem: (props?: BreadcrumbProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
32
|
+
export interface BreadcrumbLinkProps extends BreadcrumbProps {
|
|
33
|
+
href?: string;
|
|
34
|
+
}
|
|
35
|
+
export declare const BreadcrumbLink: (props?: BreadcrumbLinkProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
36
|
+
/**
|
|
37
|
+
* The crumb for where you already are.
|
|
38
|
+
*
|
|
39
|
+
* `role="link"` with `aria-disabled` rather than an `<a>` without an `href`:
|
|
40
|
+
* upstream's shape, and it keeps the crumb in the same role as its siblings so
|
|
41
|
+
* a reader announces a consistent list.
|
|
42
|
+
*/
|
|
43
|
+
export declare const BreadcrumbPage: (props?: BreadcrumbProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
44
|
+
/** The chevron. Defaults to one; give children to replace it. */
|
|
45
|
+
export declare const BreadcrumbSeparator: (props?: BreadcrumbProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
46
|
+
/** Stands in for ancestors that did not fit. */
|
|
47
|
+
export declare const BreadcrumbEllipsis: (props?: BreadcrumbProps | undefined) => import("@c9up/aurora").TemplateResult;
|