@enablo/swirlcn-ui 0.0.0-stage → 0.5.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/LICENSE +21 -0
- package/README.md +30 -2
- package/dist/chunk-3DJWDNQL.js +77 -0
- package/dist/chunk-7XUCETA6.js +447 -0
- package/dist/chunk-KZESIYUN.js +18 -0
- package/dist/flip.d.ts +98 -0
- package/dist/flip.js +158 -0
- package/dist/fonts/Inter-italic.var.woff2 +0 -0
- package/dist/fonts/Inter.var.woff2 +0 -0
- package/dist/fonts/OFL.txt +96 -0
- package/dist/index.d.ts +2459 -0
- package/dist/index.js +8439 -0
- package/dist/server.d.ts +144 -0
- package/dist/server.js +88 -0
- package/dist/spacing-BQaEPbUv.d.ts +59 -0
- package/dist/theme.css +146 -0
- package/package.json +84 -3
- package/src/components/accordion.tsx +102 -0
- package/src/components/action-list.tsx +294 -0
- package/src/components/alert-dialog.tsx +155 -0
- package/src/components/autocomplete.tsx +313 -0
- package/src/components/avatar.tsx +258 -0
- package/src/components/badge.tsx +100 -0
- package/src/components/banner.tsx +112 -0
- package/src/components/button-group.tsx +87 -0
- package/src/components/button.tsx +362 -0
- package/src/components/card.tsx +186 -0
- package/src/components/carousel.tsx +245 -0
- package/src/components/checkbox.tsx +125 -0
- package/src/components/chip.tsx +153 -0
- package/src/components/color-input.tsx +98 -0
- package/src/components/data-cell.tsx +230 -0
- package/src/components/date-input.tsx +223 -0
- package/src/components/date-picker.tsx +276 -0
- package/src/components/description-list.tsx +97 -0
- package/src/components/dialog.tsx +405 -0
- package/src/components/empty-state.tsx +63 -0
- package/src/components/file-chip.tsx +206 -0
- package/src/components/file-uploader.tsx +148 -0
- package/src/components/flip-app-header.tsx +104 -0
- package/src/components/flip-brand.tsx +77 -0
- package/src/components/flip-theme.tsx +95 -0
- package/src/components/form-control.tsx +397 -0
- package/src/components/form-group.tsx +26 -0
- package/src/components/heading.tsx +70 -0
- package/src/components/icon.tsx +119 -0
- package/src/components/image-grid.tsx +285 -0
- package/src/components/inline-notification.tsx +167 -0
- package/src/components/inline-status.tsx +100 -0
- package/src/components/input.tsx +390 -0
- package/src/components/label.tsx +28 -0
- package/src/components/lightbox.tsx +314 -0
- package/src/components/link.tsx +46 -0
- package/src/components/list.tsx +40 -0
- package/src/components/menu.tsx +530 -0
- package/src/components/option-list.tsx +582 -0
- package/src/components/pagination.tsx +336 -0
- package/src/components/popover.tsx +194 -0
- package/src/components/progress.tsx +158 -0
- package/src/components/radio-group.tsx +136 -0
- package/src/components/resource-list.tsx +686 -0
- package/src/components/search.tsx +127 -0
- package/src/components/select.tsx +456 -0
- package/src/components/separator.tsx +93 -0
- package/src/components/skeleton-box.tsx +63 -0
- package/src/components/skeleton-text.tsx +66 -0
- package/src/components/spinner.tsx +83 -0
- package/src/components/stack.tsx +86 -0
- package/src/components/status-indicator.tsx +31 -0
- package/src/components/switch.tsx +90 -0
- package/src/components/table.tsx +242 -0
- package/src/components/tabs.tsx +147 -0
- package/src/components/tag.tsx +169 -0
- package/src/components/text.tsx +126 -0
- package/src/components/textarea.tsx +130 -0
- package/src/components/theme-provider.tsx +115 -0
- package/src/components/thumbnail.tsx +250 -0
- package/src/components/time-input.tsx +123 -0
- package/src/components/toast.tsx +217 -0
- package/src/components/toggle-group.tsx +124 -0
- package/src/components/toolbar.tsx +105 -0
- package/src/components/tooltip.tsx +97 -0
- package/src/components/tree-navigation.tsx +194 -0
- package/src/components/tree-view.tsx +292 -0
- package/src/flip.ts +12 -0
- package/src/index.ts +317 -0
- package/src/lib/date-mask.ts +176 -0
- package/src/lib/field-context.ts +86 -0
- package/src/lib/flip-app-script.ts +38 -0
- package/src/lib/flip-host.ts +84 -0
- package/src/lib/flip-theme-css.ts +90 -0
- package/src/lib/focus.ts +18 -0
- package/src/lib/glyphs.ts +137 -0
- package/src/lib/spacing.ts +93 -0
- package/src/lib/theme-context.ts +27 -0
- package/src/lib/theme-script.ts +49 -0
- package/src/lib/use-mobile.ts +17 -0
- package/src/lib/utils.ts +28 -0
- package/src/server.ts +20 -0
- package/src/styles/fonts/Inter-italic.var.woff2 +0 -0
- package/src/styles/fonts/Inter.var.woff2 +0 -0
- package/src/styles/fonts/OFL.txt +96 -0
- package/src/styles/theme.css +146 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
2
|
+
import { cn } from "../lib/utils";
|
|
3
|
+
import { focusRing } from "../lib/focus";
|
|
4
|
+
import { padding as paddingClass, type SwirlSpacing } from "../lib/spacing";
|
|
5
|
+
|
|
6
|
+
// Swirl clips a card to its corners; `overflow` can lift that.
|
|
7
|
+
const cardVariants = cva("relative flex flex-col text-foreground transition-colors duration-200", {
|
|
8
|
+
variants: {
|
|
9
|
+
/** Swirl's card intents: a default surface plus tinted status surfaces. */
|
|
10
|
+
intent: {
|
|
11
|
+
default: "bg-surface",
|
|
12
|
+
"default-subdued": "bg-surface-raised",
|
|
13
|
+
highlight: "bg-surface-highlight text-on-highlight",
|
|
14
|
+
"info-subdued": "bg-surface-info-subdued",
|
|
15
|
+
"success-subdued": "bg-surface-success-subdued",
|
|
16
|
+
"warning-subdued": "bg-surface-warning-subdued",
|
|
17
|
+
"critical-subdued": "bg-surface-critical-subdued",
|
|
18
|
+
},
|
|
19
|
+
borderRadius: {
|
|
20
|
+
xs: "rounded-xs",
|
|
21
|
+
sm: "rounded-sm",
|
|
22
|
+
base: "rounded-base",
|
|
23
|
+
l: "rounded-(--radius-l)",
|
|
24
|
+
xl: "rounded-xl",
|
|
25
|
+
},
|
|
26
|
+
elevationLevel: {
|
|
27
|
+
1: "shadow-level-1",
|
|
28
|
+
2: "shadow-level-2",
|
|
29
|
+
3: "shadow-level-3",
|
|
30
|
+
},
|
|
31
|
+
borderless: { true: "border-0", false: "border border-border" },
|
|
32
|
+
interactive: {
|
|
33
|
+
true: cn("cursor-pointer text-left hover:bg-surface-hovered active:bg-surface-pressed", focusRing),
|
|
34
|
+
false: "",
|
|
35
|
+
},
|
|
36
|
+
highlighted: { true: "border-[0.1875rem] border-border-highlight", false: "" },
|
|
37
|
+
overflow: { auto: "overflow-auto", hidden: "overflow-hidden", visible: "overflow-visible" },
|
|
38
|
+
},
|
|
39
|
+
defaultVariants: {
|
|
40
|
+
intent: "default",
|
|
41
|
+
borderRadius: "base",
|
|
42
|
+
borderless: false,
|
|
43
|
+
interactive: false,
|
|
44
|
+
highlighted: false,
|
|
45
|
+
overflow: "hidden",
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export interface CardProps
|
|
50
|
+
extends Omit<React.ComponentProps<"div">, "children">,
|
|
51
|
+
Omit<VariantProps<typeof cardVariants>, "borderless" | "interactive"> {
|
|
52
|
+
as?: React.ElementType;
|
|
53
|
+
/** Uniform padding, in Swirl's px spacing steps. */
|
|
54
|
+
padding?: SwirlSpacing;
|
|
55
|
+
/** Drop the border. Swirl calls this `isBorderless`. */
|
|
56
|
+
borderless?: boolean;
|
|
57
|
+
/** Add a shadow. Pair with `elevationLevel` to choose which. */
|
|
58
|
+
elevated?: boolean;
|
|
59
|
+
/** Make the whole card a clickable control. */
|
|
60
|
+
interactive?: boolean;
|
|
61
|
+
/** Render as a link. Implies `interactive`. */
|
|
62
|
+
href?: string;
|
|
63
|
+
/** An image across the top, such as an `<img>`. The content then sits in a padded body under it. */
|
|
64
|
+
image?: React.ReactNode;
|
|
65
|
+
/** The image's aspect ratio, such as "16/9". */
|
|
66
|
+
imageAspectRatio?: string;
|
|
67
|
+
/** Controls in the top-right corner, shown while the card is hovered or has focus. */
|
|
68
|
+
floatingControls?: React.ReactNode;
|
|
69
|
+
/**
|
|
70
|
+
* Show the pressed background, to draw the eye to the card. Swirl's
|
|
71
|
+
* `flash()` shows it for five seconds; set this and clear it the same way.
|
|
72
|
+
*/
|
|
73
|
+
flashing?: boolean;
|
|
74
|
+
children?: React.ReactNode;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A surface container.
|
|
79
|
+
*
|
|
80
|
+
* Composes like shadcn's card (`CardHeader`, `CardTitle`, ...) while keeping
|
|
81
|
+
* Swirl's `intent`, `padding`, `elevationLevel` and `borderRadius` props.
|
|
82
|
+
*/
|
|
83
|
+
export function Card({
|
|
84
|
+
as,
|
|
85
|
+
className,
|
|
86
|
+
intent,
|
|
87
|
+
borderRadius,
|
|
88
|
+
elevated = false,
|
|
89
|
+
elevationLevel = 3,
|
|
90
|
+
padding,
|
|
91
|
+
borderless = false,
|
|
92
|
+
interactive = false,
|
|
93
|
+
highlighted,
|
|
94
|
+
overflow,
|
|
95
|
+
href,
|
|
96
|
+
image,
|
|
97
|
+
imageAspectRatio,
|
|
98
|
+
floatingControls,
|
|
99
|
+
flashing = false,
|
|
100
|
+
children,
|
|
101
|
+
...props
|
|
102
|
+
}: CardProps) {
|
|
103
|
+
const isLink = href !== undefined;
|
|
104
|
+
const Component = as ?? (isLink ? "a" : "div");
|
|
105
|
+
|
|
106
|
+
// With an image, the content sits in Swirl's padded body under it.
|
|
107
|
+
const body = image !== undefined;
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<Component
|
|
111
|
+
href={href}
|
|
112
|
+
className={cn(
|
|
113
|
+
cardVariants({
|
|
114
|
+
intent,
|
|
115
|
+
borderRadius,
|
|
116
|
+
elevationLevel: elevated ? elevationLevel : undefined,
|
|
117
|
+
borderless,
|
|
118
|
+
interactive: interactive || isLink,
|
|
119
|
+
highlighted,
|
|
120
|
+
overflow,
|
|
121
|
+
}),
|
|
122
|
+
flashing &&
|
|
123
|
+
(intent === "default-subdued"
|
|
124
|
+
? "bg-surface-raised-pressed"
|
|
125
|
+
: intent === "highlight"
|
|
126
|
+
? "bg-surface-highlight-pressed"
|
|
127
|
+
: "bg-surface-pressed"),
|
|
128
|
+
floatingControls !== undefined && "group/card",
|
|
129
|
+
!body && padding && paddingClass(padding),
|
|
130
|
+
className,
|
|
131
|
+
)}
|
|
132
|
+
{...props}
|
|
133
|
+
>
|
|
134
|
+
{body && (
|
|
135
|
+
<div
|
|
136
|
+
className="min-h-0 overflow-hidden [&>img]:inline-flex [&>img]:max-h-full [&>img]:w-full [&>img]:object-cover"
|
|
137
|
+
style={{ aspectRatio: imageAspectRatio }}
|
|
138
|
+
>
|
|
139
|
+
{image}
|
|
140
|
+
</div>
|
|
141
|
+
)}
|
|
142
|
+
{floatingControls !== undefined && (
|
|
143
|
+
<div
|
|
144
|
+
className={cn(
|
|
145
|
+
"pointer-events-none absolute top-0 right-0 z-1 p-3 opacity-0 transition-opacity duration-200",
|
|
146
|
+
"group-focus-within/card:pointer-events-auto group-focus-within/card:opacity-100",
|
|
147
|
+
"group-hover/card:pointer-events-auto group-hover/card:opacity-100",
|
|
148
|
+
)}
|
|
149
|
+
>
|
|
150
|
+
{floatingControls}
|
|
151
|
+
</div>
|
|
152
|
+
)}
|
|
153
|
+
{body ? (
|
|
154
|
+
<div className={cn("flex min-h-0 grow flex-col gap-4", padding ? paddingClass(padding) : "px-4 pt-3 pb-4")}>
|
|
155
|
+
{children}
|
|
156
|
+
</div>
|
|
157
|
+
) : (
|
|
158
|
+
children
|
|
159
|
+
)}
|
|
160
|
+
</Component>
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
|
165
|
+
return <div className={cn("flex flex-col gap-1 p-4", className)} {...props} />;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function CardTitle({ className, ...props }: React.ComponentProps<"h3">) {
|
|
169
|
+
return (
|
|
170
|
+
<h3 className={cn("text-lg font-semibold leading-6 text-foreground", className)} {...props} />
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function CardDescription({ className, ...props }: React.ComponentProps<"p">) {
|
|
175
|
+
return <p className={cn("text-sm leading-5 text-subdued", className)} {...props} />;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
179
|
+
return <div className={cn("p-4 pt-0", className)} {...props} />;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
|
183
|
+
return <div className={cn("flex items-center gap-2 p-4 pt-0", className)} {...props} />;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export { cardVariants };
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cn } from "../lib/utils";
|
|
3
|
+
import { Glyph } from "../lib/glyphs";
|
|
4
|
+
import type { SwirlSpacing } from "../lib/spacing";
|
|
5
|
+
import { Button } from "./button";
|
|
6
|
+
|
|
7
|
+
const SLIDE = "[data-carousel-slide]";
|
|
8
|
+
const space = (s: SwirlSpacing | undefined) => (s === undefined ? undefined : `var(--s-space-${s})`);
|
|
9
|
+
|
|
10
|
+
export interface CarouselHandle {
|
|
11
|
+
/** Scrolls the slide with this `id` into view. */
|
|
12
|
+
scrollToSlide: (id: string) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface CarouselProps extends Omit<React.ComponentProps<"div">, "ref"> {
|
|
16
|
+
/** Accessible name of the carousel. */
|
|
17
|
+
label?: string;
|
|
18
|
+
/** Fade the edges where more slides are hidden. */
|
|
19
|
+
fade?: boolean;
|
|
20
|
+
/** What the edges fade to: the page, or an overlay such as a dialog. */
|
|
21
|
+
fadeColor?: "default" | "on-surface-overlay";
|
|
22
|
+
/** Go from the last slide back to the first, and the other way. */
|
|
23
|
+
loopAround?: boolean;
|
|
24
|
+
/** Pixels between slides. Defaults to 16. */
|
|
25
|
+
spacing?: number | string;
|
|
26
|
+
/** Defaults to 16. */
|
|
27
|
+
padding?: SwirlSpacing;
|
|
28
|
+
paddingBlockStart?: SwirlSpacing;
|
|
29
|
+
paddingBlockEnd?: SwirlSpacing;
|
|
30
|
+
paddingInlineStart?: SwirlSpacing;
|
|
31
|
+
paddingInlineEnd?: SwirlSpacing;
|
|
32
|
+
/** Called with the ids of the slides fully in view. */
|
|
33
|
+
onActiveSlidesChange?: (ids: string[]) => void;
|
|
34
|
+
nextSlideButtonLabel?: string;
|
|
35
|
+
previousSlideButtonLabel?: string;
|
|
36
|
+
ref?: React.Ref<CarouselHandle>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Swirl's carousel: a row of `CarouselSlide`s that scrolls sideways and
|
|
41
|
+
* snaps to each slide, with buttons to page through on devices that can
|
|
42
|
+
* hover.
|
|
43
|
+
*/
|
|
44
|
+
export function Carousel({
|
|
45
|
+
label,
|
|
46
|
+
fade = false,
|
|
47
|
+
fadeColor = "default",
|
|
48
|
+
loopAround = false,
|
|
49
|
+
spacing = 16,
|
|
50
|
+
padding = "16",
|
|
51
|
+
paddingBlockStart,
|
|
52
|
+
paddingBlockEnd,
|
|
53
|
+
paddingInlineStart,
|
|
54
|
+
paddingInlineEnd,
|
|
55
|
+
onActiveSlidesChange,
|
|
56
|
+
nextSlideButtonLabel = "Next slide",
|
|
57
|
+
previousSlideButtonLabel = "Previous slide",
|
|
58
|
+
ref,
|
|
59
|
+
className,
|
|
60
|
+
style,
|
|
61
|
+
children,
|
|
62
|
+
...props
|
|
63
|
+
}: CarouselProps) {
|
|
64
|
+
const [scroller, setScroller] = React.useState<HTMLDivElement | null>(null);
|
|
65
|
+
const [state, setState] = React.useState({ scrollable: false, atStart: true, atEnd: true });
|
|
66
|
+
const activeKey = React.useRef("");
|
|
67
|
+
|
|
68
|
+
const slides = React.useCallback(
|
|
69
|
+
() => Array.from(scroller?.querySelectorAll<HTMLElement>(SLIDE) ?? []),
|
|
70
|
+
[scroller],
|
|
71
|
+
);
|
|
72
|
+
const inView = React.useCallback(
|
|
73
|
+
(el: HTMLElement) => {
|
|
74
|
+
if (!scroller) return false;
|
|
75
|
+
const left = scroller.scrollLeft;
|
|
76
|
+
const right = left + scroller.clientWidth;
|
|
77
|
+
return el.offsetLeft >= left && el.offsetLeft + el.clientWidth <= right;
|
|
78
|
+
},
|
|
79
|
+
[scroller],
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const measure = React.useCallback(() => {
|
|
83
|
+
if (!scroller) return;
|
|
84
|
+
const all = slides();
|
|
85
|
+
const active = all.filter(inView);
|
|
86
|
+
const next = {
|
|
87
|
+
scrollable: scroller.scrollWidth > scroller.offsetWidth,
|
|
88
|
+
atStart: active[0] === all[0],
|
|
89
|
+
atEnd: active[active.length - 1] === all[all.length - 1],
|
|
90
|
+
};
|
|
91
|
+
setState((prev) =>
|
|
92
|
+
prev.scrollable === next.scrollable && prev.atStart === next.atStart && prev.atEnd === next.atEnd ? prev : next,
|
|
93
|
+
);
|
|
94
|
+
const key = active.map((el) => el.id).join(" ");
|
|
95
|
+
if (key !== activeKey.current) {
|
|
96
|
+
activeKey.current = key;
|
|
97
|
+
onActiveSlidesChange?.(active.map((el) => el.id));
|
|
98
|
+
}
|
|
99
|
+
}, [scroller, slides, inView, onActiveSlidesChange]);
|
|
100
|
+
|
|
101
|
+
React.useEffect(() => {
|
|
102
|
+
if (!scroller) return;
|
|
103
|
+
const observer = new ResizeObserver(measure);
|
|
104
|
+
observer.observe(scroller);
|
|
105
|
+
const mutations = new MutationObserver(measure);
|
|
106
|
+
mutations.observe(scroller, { childList: true });
|
|
107
|
+
return () => {
|
|
108
|
+
observer.disconnect();
|
|
109
|
+
mutations.disconnect();
|
|
110
|
+
};
|
|
111
|
+
}, [scroller, measure]);
|
|
112
|
+
|
|
113
|
+
const scrollTo = (el: Element | null | undefined) => {
|
|
114
|
+
if (scroller && el instanceof HTMLElement) scroller.scroll({ left: el.offsetLeft, behavior: "smooth" });
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
React.useImperativeHandle(ref, () => ({
|
|
118
|
+
scrollToSlide: (id) => scrollTo(slides().find((el) => el.id === id)),
|
|
119
|
+
}));
|
|
120
|
+
|
|
121
|
+
const previous = () => {
|
|
122
|
+
const all = slides();
|
|
123
|
+
const active = all.filter(inView);
|
|
124
|
+
scrollTo(active[0]?.previousElementSibling ?? (loopAround ? all[all.length - 1] : active[0]));
|
|
125
|
+
};
|
|
126
|
+
const next = () => {
|
|
127
|
+
const all = slides();
|
|
128
|
+
const active = all.filter(inView);
|
|
129
|
+
const atEnd = !active[active.length - 1]?.nextElementSibling;
|
|
130
|
+
scrollTo(atEnd && loopAround ? all[0] : active[0]?.nextElementSibling);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const fadeTo = fadeColor === "default" ? "var(--s-background-default)" : "var(--s-surface-overlay-default)";
|
|
134
|
+
const arrow =
|
|
135
|
+
"absolute top-1/2 z-2 -translate-y-1/2 scale-[0.72] pointer-events-none [@media(hover:hover)]:group-hover/carousel:pointer-events-auto";
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<div
|
|
139
|
+
role="group"
|
|
140
|
+
aria-label={label}
|
|
141
|
+
aria-roledescription="carousel"
|
|
142
|
+
className={cn("group/carousel relative block w-full overflow-hidden", className)}
|
|
143
|
+
style={
|
|
144
|
+
{
|
|
145
|
+
"--carousel-spacing": typeof spacing === "number" ? `${spacing}px` : /^\d+$/.test(spacing) ? `${spacing}px` : spacing,
|
|
146
|
+
"--carousel-fade": fadeTo,
|
|
147
|
+
...style,
|
|
148
|
+
} as React.CSSProperties
|
|
149
|
+
}
|
|
150
|
+
{...props}
|
|
151
|
+
>
|
|
152
|
+
<div
|
|
153
|
+
className={cn(
|
|
154
|
+
"relative w-full overflow-hidden",
|
|
155
|
+
"before:pointer-events-none before:absolute before:top-0 before:left-0 before:z-1 before:h-full before:w-8 before:opacity-0 before:transition-opacity before:duration-200 before:content-['']",
|
|
156
|
+
"before:bg-[linear-gradient(90deg,var(--carousel-fade)_0%,transparent_100%)]",
|
|
157
|
+
"after:pointer-events-none after:absolute after:top-0 after:right-0 after:z-1 after:h-full after:w-8 after:opacity-0 after:transition-opacity after:duration-200 after:content-['']",
|
|
158
|
+
"after:bg-[linear-gradient(270deg,var(--carousel-fade)_0%,transparent_100%)]",
|
|
159
|
+
fade && !state.atStart && "before:opacity-100",
|
|
160
|
+
fade && !state.atEnd && "after:opacity-100",
|
|
161
|
+
)}
|
|
162
|
+
>
|
|
163
|
+
{state.scrollable && !state.atStart && (
|
|
164
|
+
<Button
|
|
165
|
+
variant="translucent"
|
|
166
|
+
pill
|
|
167
|
+
hideLabel
|
|
168
|
+
icon={<Glyph name="arrowBack" />}
|
|
169
|
+
label={previousSlideButtonLabel}
|
|
170
|
+
onClick={previous}
|
|
171
|
+
className={cn(arrow, "left-1")}
|
|
172
|
+
/>
|
|
173
|
+
)}
|
|
174
|
+
{state.scrollable && !state.atEnd && (
|
|
175
|
+
<Button
|
|
176
|
+
variant="translucent"
|
|
177
|
+
pill
|
|
178
|
+
hideLabel
|
|
179
|
+
icon={<Glyph name="arrowForward" />}
|
|
180
|
+
label={nextSlideButtonLabel}
|
|
181
|
+
onClick={next}
|
|
182
|
+
className={cn(arrow, "right-1")}
|
|
183
|
+
/>
|
|
184
|
+
)}
|
|
185
|
+
<div
|
|
186
|
+
ref={setScroller}
|
|
187
|
+
aria-live="polite"
|
|
188
|
+
onScroll={measure}
|
|
189
|
+
className={cn(
|
|
190
|
+
"relative flex w-full snap-x snap-mandatory overflow-x-auto overflow-y-hidden scroll-smooth",
|
|
191
|
+
"[scrollbar-width:none] [&::-webkit-scrollbar]:hidden",
|
|
192
|
+
"[&>*:not(:first-child)]:ml-(--carousel-spacing)",
|
|
193
|
+
)}
|
|
194
|
+
style={{
|
|
195
|
+
paddingBlockStart: space(paddingBlockStart ?? padding),
|
|
196
|
+
paddingBlockEnd: space(paddingBlockEnd ?? padding),
|
|
197
|
+
paddingInlineStart: space(paddingInlineStart ?? padding),
|
|
198
|
+
paddingInlineEnd: space(paddingInlineEnd ?? padding),
|
|
199
|
+
scrollPaddingInline: space(paddingInlineStart ?? padding),
|
|
200
|
+
}}
|
|
201
|
+
>
|
|
202
|
+
{children}
|
|
203
|
+
</div>
|
|
204
|
+
</div>
|
|
205
|
+
</div>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export interface CarouselSlideProps extends React.ComponentProps<"div"> {
|
|
210
|
+
/** Accessible name of the slide. */
|
|
211
|
+
label?: string;
|
|
212
|
+
/** Defaults to 15.5rem. */
|
|
213
|
+
width?: string;
|
|
214
|
+
minHeight?: string;
|
|
215
|
+
aspectRatio?: string;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** One slide in a `Carousel`. Its content fills it. */
|
|
219
|
+
export function CarouselSlide({
|
|
220
|
+
label,
|
|
221
|
+
width = "15.5rem",
|
|
222
|
+
minHeight,
|
|
223
|
+
aspectRatio,
|
|
224
|
+
className,
|
|
225
|
+
style,
|
|
226
|
+
...props
|
|
227
|
+
}: CarouselSlideProps) {
|
|
228
|
+
return (
|
|
229
|
+
<div
|
|
230
|
+
data-carousel-slide=""
|
|
231
|
+
role="group"
|
|
232
|
+
aria-roledescription="slide"
|
|
233
|
+
aria-label={label}
|
|
234
|
+
tabIndex={0}
|
|
235
|
+
className={cn(
|
|
236
|
+
"block min-w-0 shrink-0 grow-0 snap-start *:min-h-full *:w-full",
|
|
237
|
+
minHeight && "*:h-full",
|
|
238
|
+
"outline-focus focus:not-focus-visible:outline-none focus-visible:outline-2 focus-visible:outline-solid",
|
|
239
|
+
className,
|
|
240
|
+
)}
|
|
241
|
+
style={{ flexBasis: width, minHeight, aspectRatio, ...style }}
|
|
242
|
+
{...props}
|
|
243
|
+
/>
|
|
244
|
+
);
|
|
245
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Checkbox as CheckboxPrimitive } from "radix-ui";
|
|
2
|
+
import { cn } from "../lib/utils";
|
|
3
|
+
|
|
4
|
+
export interface CheckboxProps
|
|
5
|
+
extends React.ComponentProps<typeof CheckboxPrimitive.Root> {
|
|
6
|
+
/** Visible label rendered beside the box. */
|
|
7
|
+
label?: React.ReactNode;
|
|
8
|
+
/** Helper text below the label. */
|
|
9
|
+
description?: React.ReactNode;
|
|
10
|
+
/** `card` puts the checkbox and its text in a bordered, full-width box. */
|
|
11
|
+
variant?: "default" | "card";
|
|
12
|
+
/** `regular` sets the label in the normal weight instead of medium. */
|
|
13
|
+
labelWeight?: "medium" | "regular";
|
|
14
|
+
/** Draw the checkbox in the critical colour. */
|
|
15
|
+
invalid?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A checkbox, drawn as Swirl draws it: a 2px outlined box that fills with the
|
|
20
|
+
* highlight colour when checked.
|
|
21
|
+
*
|
|
22
|
+
* Pass `checked="indeterminate"` for the mixed state. When `label` is given the
|
|
23
|
+
* whole row is wrapped in a `<label>`, so clicking the text toggles the box.
|
|
24
|
+
*/
|
|
25
|
+
export function Checkbox({
|
|
26
|
+
className,
|
|
27
|
+
label,
|
|
28
|
+
description,
|
|
29
|
+
variant = "default",
|
|
30
|
+
labelWeight = "medium",
|
|
31
|
+
invalid = false,
|
|
32
|
+
id,
|
|
33
|
+
...props
|
|
34
|
+
}: CheckboxProps) {
|
|
35
|
+
const card = variant === "card";
|
|
36
|
+
const control = (
|
|
37
|
+
// Swirl's control: a 24px hit area (22px with the desktop layout) around
|
|
38
|
+
// the box, which hover tints.
|
|
39
|
+
<span className="group/control relative inline-flex size-6 shrink-0 p-0.5 desktop:size-5.5">
|
|
40
|
+
<CheckboxPrimitive.Root
|
|
41
|
+
id={id}
|
|
42
|
+
aria-invalid={props["aria-invalid"] ?? (invalid || undefined)}
|
|
43
|
+
className={cn(
|
|
44
|
+
"peer flex size-full cursor-pointer items-center justify-center rounded-(--radius-s)",
|
|
45
|
+
"border-2 border-icon-default bg-transparent text-on-status outline-none",
|
|
46
|
+
"group-hover/control:bg-neutral-hovered",
|
|
47
|
+
"data-[state=checked]:border-highlight data-[state=checked]:bg-highlight",
|
|
48
|
+
"data-[state=indeterminate]:border-highlight data-[state=indeterminate]:bg-highlight",
|
|
49
|
+
"group-hover/control:data-[state=checked]:border-interactive-primary-hovered group-hover/control:data-[state=checked]:bg-interactive-primary-hovered",
|
|
50
|
+
"group-hover/control:data-[state=indeterminate]:border-interactive-primary-hovered group-hover/control:data-[state=indeterminate]:bg-interactive-primary-hovered",
|
|
51
|
+
"aria-invalid:border-critical",
|
|
52
|
+
// Invalid wins over checked, for the border as well as the fill.
|
|
53
|
+
"aria-invalid:data-[state=checked]:border-critical aria-invalid:data-[state=checked]:bg-critical",
|
|
54
|
+
"aria-invalid:data-[state=indeterminate]:border-critical aria-invalid:data-[state=indeterminate]:bg-critical",
|
|
55
|
+
"disabled:cursor-default disabled:border-disabled disabled:group-hover/control:bg-transparent",
|
|
56
|
+
"disabled:data-[state=checked]:border-disabled disabled:data-[state=checked]:bg-disabled",
|
|
57
|
+
"disabled:data-[state=indeterminate]:border-disabled disabled:data-[state=indeterminate]:bg-disabled",
|
|
58
|
+
"disabled:group-hover/control:data-[state=checked]:border-disabled disabled:group-hover/control:data-[state=checked]:bg-disabled",
|
|
59
|
+
// Swirl's focus ring: a 1px gap in the page colour, then 2px of focus.
|
|
60
|
+
// A card draws the ring around the whole card instead.
|
|
61
|
+
!card && "focus-visible:shadow-[0_0_0_1px_var(--color-background),0_0_0_3px_var(--color-focus)]",
|
|
62
|
+
className,
|
|
63
|
+
)}
|
|
64
|
+
{...props}
|
|
65
|
+
>
|
|
66
|
+
<CheckboxPrimitive.Indicator className="flex size-[1.0625rem] items-center justify-center">
|
|
67
|
+
{props.checked === "indeterminate" ? (
|
|
68
|
+
<span className="h-0.5 w-2.5 rounded-[1px] bg-current" />
|
|
69
|
+
) : (
|
|
70
|
+
<svg viewBox="0 0 24 24" className="size-full" aria-hidden focusable={false}>
|
|
71
|
+
<path
|
|
72
|
+
fillRule="evenodd"
|
|
73
|
+
clipRule="evenodd"
|
|
74
|
+
d="M19.5607 6.43934C20.1464 7.02513 20.1464 7.97487 19.5607 8.56066L10.0607 18.0607C9.47487 18.6464 8.52513 18.6464 7.93934 18.0607L4.43934 14.5607C3.85355 13.9749 3.85355 13.0251 4.43934 12.4393C5.02513 11.8536 5.97487 11.8536 6.56066 12.4393L9 14.8787L17.4393 6.43934C18.0251 5.85355 18.9749 5.85355 19.5607 6.43934Z"
|
|
75
|
+
fill="currentColor"
|
|
76
|
+
/>
|
|
77
|
+
</svg>
|
|
78
|
+
)}
|
|
79
|
+
</CheckboxPrimitive.Indicator>
|
|
80
|
+
</CheckboxPrimitive.Root>
|
|
81
|
+
</span>
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
if (!label && !description) return control;
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<label
|
|
88
|
+
className={cn(
|
|
89
|
+
"group/checkbox inline-flex cursor-pointer leading-6 has-disabled:cursor-default",
|
|
90
|
+
card && [
|
|
91
|
+
"w-full rounded-sm border border-border bg-surface p-4",
|
|
92
|
+
"not-has-disabled:hover:bg-state-hovered not-has-disabled:active:bg-state-pressed",
|
|
93
|
+
"not-has-disabled:has-data-[state=checked]:border-highlight",
|
|
94
|
+
"not-has-disabled:has-aria-invalid:border-critical",
|
|
95
|
+
"has-focus-visible:shadow-[0_0_0_2px_var(--color-background),0_0_0_4px_var(--color-focus)]",
|
|
96
|
+
],
|
|
97
|
+
)}
|
|
98
|
+
>
|
|
99
|
+
{control}
|
|
100
|
+
<span className="ml-2 inline-flex flex-col items-start desktop:pt-0.5">
|
|
101
|
+
{label && (
|
|
102
|
+
<span
|
|
103
|
+
className={cn(
|
|
104
|
+
labelWeight === "regular" ? "font-normal" : "font-medium",
|
|
105
|
+
"text-foreground desktop:text-sm desktop:leading-5",
|
|
106
|
+
"group-has-disabled/checkbox:text-disabled",
|
|
107
|
+
)}
|
|
108
|
+
>
|
|
109
|
+
{label}
|
|
110
|
+
</span>
|
|
111
|
+
)}
|
|
112
|
+
{description && (
|
|
113
|
+
<span
|
|
114
|
+
className={cn(
|
|
115
|
+
"text-subdued desktop:text-sm desktop:leading-5",
|
|
116
|
+
"group-has-disabled/checkbox:text-disabled",
|
|
117
|
+
)}
|
|
118
|
+
>
|
|
119
|
+
{description}
|
|
120
|
+
</span>
|
|
121
|
+
)}
|
|
122
|
+
</span>
|
|
123
|
+
</label>
|
|
124
|
+
);
|
|
125
|
+
}
|