@enablo/swirlcn-ui 0.0.0-stage → 0.5.1

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.
Files changed (103) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +30 -2
  3. package/dist/chunk-3DJWDNQL.js +77 -0
  4. package/dist/chunk-7XUCETA6.js +447 -0
  5. package/dist/chunk-KZESIYUN.js +18 -0
  6. package/dist/flip.d.ts +98 -0
  7. package/dist/flip.js +158 -0
  8. package/dist/fonts/Inter-italic.var.woff2 +0 -0
  9. package/dist/fonts/Inter.var.woff2 +0 -0
  10. package/dist/fonts/OFL.txt +96 -0
  11. package/dist/index.d.ts +2459 -0
  12. package/dist/index.js +8439 -0
  13. package/dist/server.d.ts +144 -0
  14. package/dist/server.js +88 -0
  15. package/dist/spacing-BQaEPbUv.d.ts +59 -0
  16. package/dist/theme.css +146 -0
  17. package/package.json +84 -3
  18. package/src/components/accordion.tsx +102 -0
  19. package/src/components/action-list.tsx +294 -0
  20. package/src/components/alert-dialog.tsx +155 -0
  21. package/src/components/autocomplete.tsx +313 -0
  22. package/src/components/avatar.tsx +258 -0
  23. package/src/components/badge.tsx +100 -0
  24. package/src/components/banner.tsx +112 -0
  25. package/src/components/button-group.tsx +87 -0
  26. package/src/components/button.tsx +362 -0
  27. package/src/components/card.tsx +186 -0
  28. package/src/components/carousel.tsx +245 -0
  29. package/src/components/checkbox.tsx +125 -0
  30. package/src/components/chip.tsx +153 -0
  31. package/src/components/color-input.tsx +98 -0
  32. package/src/components/data-cell.tsx +230 -0
  33. package/src/components/date-input.tsx +223 -0
  34. package/src/components/date-picker.tsx +276 -0
  35. package/src/components/description-list.tsx +97 -0
  36. package/src/components/dialog.tsx +405 -0
  37. package/src/components/empty-state.tsx +63 -0
  38. package/src/components/file-chip.tsx +206 -0
  39. package/src/components/file-uploader.tsx +148 -0
  40. package/src/components/flip-app-header.tsx +104 -0
  41. package/src/components/flip-brand.tsx +77 -0
  42. package/src/components/flip-theme.tsx +95 -0
  43. package/src/components/form-control.tsx +397 -0
  44. package/src/components/form-group.tsx +26 -0
  45. package/src/components/heading.tsx +70 -0
  46. package/src/components/icon.tsx +119 -0
  47. package/src/components/image-grid.tsx +285 -0
  48. package/src/components/inline-notification.tsx +167 -0
  49. package/src/components/inline-status.tsx +100 -0
  50. package/src/components/input.tsx +390 -0
  51. package/src/components/label.tsx +28 -0
  52. package/src/components/lightbox.tsx +314 -0
  53. package/src/components/link.tsx +46 -0
  54. package/src/components/list.tsx +40 -0
  55. package/src/components/menu.tsx +530 -0
  56. package/src/components/option-list.tsx +582 -0
  57. package/src/components/pagination.tsx +336 -0
  58. package/src/components/popover.tsx +194 -0
  59. package/src/components/progress.tsx +158 -0
  60. package/src/components/radio-group.tsx +136 -0
  61. package/src/components/resource-list.tsx +686 -0
  62. package/src/components/search.tsx +127 -0
  63. package/src/components/select.tsx +456 -0
  64. package/src/components/separator.tsx +93 -0
  65. package/src/components/skeleton-box.tsx +63 -0
  66. package/src/components/skeleton-text.tsx +66 -0
  67. package/src/components/spinner.tsx +83 -0
  68. package/src/components/stack.tsx +86 -0
  69. package/src/components/status-indicator.tsx +31 -0
  70. package/src/components/switch.tsx +90 -0
  71. package/src/components/table.tsx +242 -0
  72. package/src/components/tabs.tsx +147 -0
  73. package/src/components/tag.tsx +169 -0
  74. package/src/components/text.tsx +126 -0
  75. package/src/components/textarea.tsx +130 -0
  76. package/src/components/theme-provider.tsx +115 -0
  77. package/src/components/thumbnail.tsx +250 -0
  78. package/src/components/time-input.tsx +123 -0
  79. package/src/components/toast.tsx +217 -0
  80. package/src/components/toggle-group.tsx +124 -0
  81. package/src/components/toolbar.tsx +105 -0
  82. package/src/components/tooltip.tsx +97 -0
  83. package/src/components/tree-navigation.tsx +194 -0
  84. package/src/components/tree-view.tsx +292 -0
  85. package/src/flip.ts +12 -0
  86. package/src/index.ts +317 -0
  87. package/src/lib/date-mask.ts +176 -0
  88. package/src/lib/field-context.ts +86 -0
  89. package/src/lib/flip-app-script.ts +38 -0
  90. package/src/lib/flip-host.ts +84 -0
  91. package/src/lib/flip-theme-css.ts +90 -0
  92. package/src/lib/focus.ts +18 -0
  93. package/src/lib/glyphs.ts +137 -0
  94. package/src/lib/spacing.ts +93 -0
  95. package/src/lib/theme-context.ts +27 -0
  96. package/src/lib/theme-script.ts +49 -0
  97. package/src/lib/use-mobile.ts +17 -0
  98. package/src/lib/utils.ts +28 -0
  99. package/src/server.ts +20 -0
  100. package/src/styles/fonts/Inter-italic.var.woff2 +0 -0
  101. package/src/styles/fonts/Inter.var.woff2 +0 -0
  102. package/src/styles/fonts/OFL.txt +96 -0
  103. package/src/styles/theme.css +146 -0
@@ -0,0 +1,314 @@
1
+ import * as React from "react";
2
+ import { Dialog as DialogPrimitive } from "radix-ui";
3
+ import { cn } from "../lib/utils";
4
+ import { Glyph } from "../lib/glyphs";
5
+ import { Button } from "./button";
6
+
7
+ interface SlideState {
8
+ /** Whether the slide is the current one or next to it, so worth rendering. */
9
+ near: boolean;
10
+ }
11
+
12
+ const SlideContext = React.createContext<SlideState>({ near: true });
13
+
14
+ /** Downloads `url` as `name`, without navigating away. */
15
+ async function saveFile(url: string, name: string) {
16
+ const blob = await (await fetch(url)).blob();
17
+ const href = URL.createObjectURL(blob);
18
+ const link = document.createElement("a");
19
+ link.href = href;
20
+ link.download = name;
21
+ link.click();
22
+ URL.revokeObjectURL(href);
23
+ }
24
+
25
+ export interface LightboxSlideProps {
26
+ /** The file's URL. */
27
+ file: string;
28
+ /** Its MIME type: images and videos are shown; anything else gets a download button. */
29
+ type: string;
30
+ /** Describes an image, as its alt text. */
31
+ description?: string;
32
+ /** Shown for files that can't be previewed, and used when downloading. */
33
+ fileName?: string;
34
+ /** A small image in the top corner of an image, such as a watermark. */
35
+ watermark?: React.ReactNode;
36
+ downloadButtonLabel?: string;
37
+ }
38
+
39
+ const IMAGE_TYPES = ["image/jpeg", "image/png", "image/avif", "image/gif", "image/webp"];
40
+
41
+ /** One file in a `Lightbox`: an image, a video, or a download for anything else. */
42
+ export function LightboxSlide({
43
+ file,
44
+ type,
45
+ description,
46
+ fileName,
47
+ watermark,
48
+ downloadButtonLabel = "Download",
49
+ }: LightboxSlideProps) {
50
+ const { near } = React.useContext(SlideContext);
51
+ if (!near) return null;
52
+
53
+ if (IMAGE_TYPES.includes(type)) {
54
+ return (
55
+ <figure className="pointer-events-none m-0 inline-flex max-h-full justify-center">
56
+ <span className="relative flex max-w-full">
57
+ <img
58
+ alt={description ?? ""}
59
+ src={file}
60
+ draggable={false}
61
+ className="pointer-events-auto max-h-[calc(100dvh-8rem)] max-w-full object-contain max-md:max-h-dvh"
62
+ />
63
+ {watermark !== undefined && (
64
+ <span className="pointer-events-none absolute top-3 right-3 z-1 inline-flex size-fit [&>img]:h-auto [&>img]:w-12">
65
+ {watermark}
66
+ </span>
67
+ )}
68
+ </span>
69
+ </figure>
70
+ );
71
+ }
72
+
73
+ if (type.startsWith("video/")) {
74
+ return (
75
+ <video
76
+ src={file}
77
+ controls
78
+ className="pointer-events-auto max-h-full min-h-32 w-full bg-black object-contain"
79
+ />
80
+ );
81
+ }
82
+
83
+ return (
84
+ <div className="pointer-events-auto flex size-full flex-col items-center justify-center gap-4 text-on-image">
85
+ <span className="inline-flex size-[2.875rem] [&>svg]:size-full">
86
+ <Glyph name="file" />
87
+ </span>
88
+ {fileName && <span className="text-lg font-medium">{fileName}</span>}
89
+ <Button
90
+ variant="on-image"
91
+ icon={<Glyph name="download" />}
92
+ label={downloadButtonLabel}
93
+ href={file}
94
+ download={fileName ?? ""}
95
+ />
96
+ </div>
97
+ );
98
+ }
99
+
100
+ export interface LightboxProps {
101
+ /** Accessible name of the lightbox. */
102
+ label: string;
103
+ open?: boolean;
104
+ defaultOpen?: boolean;
105
+ onOpenChange?: (open: boolean) => void;
106
+ /** `LightboxSlide`s. */
107
+ children: React.ReactNode;
108
+ /** The slide shown when it opens. */
109
+ defaultSlide?: number;
110
+ onActiveSlideChange?: (index: number) => void;
111
+ /** More buttons in the header, such as an `on-image` crop button. */
112
+ toolbar?: React.ReactNode;
113
+ /** Show a download button, and allow the browser's context menu. Defaults to true. */
114
+ downloadButtonEnabled?: boolean;
115
+ closeButtonLabel?: string;
116
+ downloadButtonLabel?: string;
117
+ nextSlideButtonLabel?: string;
118
+ previousSlideButtonLabel?: string;
119
+ }
120
+
121
+ /**
122
+ * Swirl's lightbox: files shown full screen, one at a time. Swipe, the
123
+ * arrow keys or the side buttons move between them; Escape, the close
124
+ * button or a click beside the file closes it.
125
+ *
126
+ * <Lightbox label="Photos" open={open} onOpenChange={setOpen}>
127
+ * <LightboxSlide file="/a.jpg" type="image/jpeg" description="A dog" />
128
+ * </Lightbox>
129
+ */
130
+ export function Lightbox({
131
+ label,
132
+ open,
133
+ defaultOpen,
134
+ onOpenChange,
135
+ children,
136
+ defaultSlide = 0,
137
+ onActiveSlideChange,
138
+ toolbar,
139
+ downloadButtonEnabled = true,
140
+ closeButtonLabel = "Close modal",
141
+ downloadButtonLabel = "Download",
142
+ nextSlideButtonLabel = "Next slide",
143
+ previousSlideButtonLabel = "Previous slide",
144
+ }: LightboxProps) {
145
+ const slides = React.Children.toArray(children).filter(React.isValidElement) as React.ReactElement<LightboxSlideProps>[];
146
+ const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen ?? false);
147
+ const isOpen = open ?? uncontrolledOpen;
148
+ const setOpen = (next: boolean) => {
149
+ if (open === undefined) setUncontrolledOpen(next);
150
+ onOpenChange?.(next);
151
+ };
152
+ // A swipe ends in a click; this keeps that click from closing the lightbox.
153
+ const swiped = React.useRef(false);
154
+ const [active, setActive] = React.useState(defaultSlide);
155
+ const [drag, setDrag] = React.useState<{ start: number; delta: number } | null>(null);
156
+ const [container, setContainer] = React.useState<HTMLElement | null>(null);
157
+ const count = slides.length;
158
+
159
+ const go = (index: number) => {
160
+ const next = Math.max(0, Math.min(count - 1, index));
161
+ if (next === active) return;
162
+ setActive(next);
163
+ onActiveSlideChange?.(next);
164
+ };
165
+
166
+ // A video stops when its slide is left, as in Swirl.
167
+ React.useEffect(() => {
168
+ container?.querySelectorAll("video").forEach((video) => video.pause());
169
+ }, [active, container]);
170
+
171
+ const download = () => {
172
+ const slide = slides[active]?.props;
173
+ if (slide) void saveFile(slide.file, slide.fileName ?? slide.file.split("/").pop() ?? "download");
174
+ };
175
+
176
+ const roundButton = cn(
177
+ "pointer-events-auto inline-flex size-10 cursor-pointer items-center justify-center rounded-full border-0 bg-black/60 p-0",
178
+ "text-[var(--s-icon-on-image)] transition-opacity duration-150 desktop:size-9 [&>svg]:size-6",
179
+ "outline-focus focus:not-focus-visible:outline-none focus-visible:outline-2 focus-visible:outline-solid",
180
+ "disabled:pointer-events-none disabled:opacity-0",
181
+ );
182
+
183
+ const endDrag = () => {
184
+ if (!drag || !container) return setDrag(null);
185
+ const ratio = drag.delta / container.getBoundingClientRect().width;
186
+ swiped.current = Math.abs(drag.delta) > 5;
187
+ setDrag(null);
188
+ if (ratio > 0.2) go(active - 1);
189
+ else if (ratio < -0.2) go(active + 1);
190
+ };
191
+
192
+ return (
193
+ <DialogPrimitive.Root open={isOpen} onOpenChange={setOpen}>
194
+ <DialogPrimitive.Portal>
195
+ <DialogPrimitive.Content
196
+ aria-label={label}
197
+ aria-describedby={undefined}
198
+ onKeyDown={(event) => {
199
+ if (event.key === "ArrowLeft") go(active - 1);
200
+ else if (event.key === "ArrowRight") go(active + 1);
201
+ }}
202
+ className={cn(
203
+ "fixed inset-0 z-40 h-dvh bg-black outline-none md:bg-black/80",
204
+ "duration-150 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=closed]:animate-out data-[state=closed]:fade-out-0",
205
+ "motion-reduce:animate-none",
206
+ )}
207
+ >
208
+ <DialogPrimitive.Title className="sr-only">{label}</DialogPrimitive.Title>
209
+ <div role="document" className="relative size-full">
210
+ <header
211
+ className={cn(
212
+ "pointer-events-none absolute inset-x-0 top-0 z-1 flex items-start justify-between gap-3",
213
+ "px-4 pt-[calc(0.75rem+env(safe-area-inset-top,0))] pb-3 md:justify-end",
214
+ )}
215
+ >
216
+ <div className="pointer-events-auto flex items-center gap-3">
217
+ {toolbar}
218
+ {downloadButtonEnabled && (
219
+ <button type="button" aria-label={downloadButtonLabel} className={roundButton} onClick={download}>
220
+ <Glyph name="download" />
221
+ </button>
222
+ )}
223
+ </div>
224
+ {/* First on phones, last from 768px, as in Swirl. */}
225
+ <DialogPrimitive.Close asChild>
226
+ <button type="button" aria-label={closeButtonLabel} className={cn(roundButton, "-order-1 md:order-none")}>
227
+ <Glyph name="close" />
228
+ </button>
229
+ </DialogPrimitive.Close>
230
+ </header>
231
+
232
+ <div role="group" aria-roledescription="carousel" className="size-full overflow-hidden select-none">
233
+ <div
234
+ ref={setContainer}
235
+ aria-live="polite"
236
+ aria-atomic={false}
237
+ className="flex size-full"
238
+ onContextMenu={(event) => {
239
+ if (!downloadButtonEnabled) event.preventDefault();
240
+ }}
241
+ onClick={(event) => {
242
+ if (swiped.current) {
243
+ swiped.current = false;
244
+ return;
245
+ }
246
+ // A click beside the file, on the backdrop, closes the lightbox.
247
+ if ((event.target as HTMLElement).dataset.lightboxSlide !== undefined) setOpen(false);
248
+ }}
249
+ onPointerDown={(event) => {
250
+ if (count <= 1 || event.button !== 0) return;
251
+ setDrag({ start: event.clientX, delta: 0 });
252
+ }}
253
+ onPointerMove={(event) => {
254
+ if (drag) setDrag({ ...drag, delta: event.clientX - drag.start });
255
+ }}
256
+ onPointerUp={endDrag}
257
+ onPointerLeave={endDrag}
258
+ >
259
+ {slides.map((slide, index) => (
260
+ <div
261
+ key={slide.key ?? index}
262
+ data-lightbox-slide=""
263
+ role="group"
264
+ aria-roledescription="slide"
265
+ aria-label={slide.props.fileName ?? slide.props.file}
266
+ aria-hidden={index !== active || undefined}
267
+ className={cn(
268
+ "flex shrink-0 basis-full items-center justify-center md:px-20 md:py-16",
269
+ !drag && "transition-transform duration-300 motion-reduce:transition-none",
270
+ )}
271
+ style={{
272
+ transform: drag
273
+ ? `translate3d(calc(${-100 * active}% + ${drag.delta}px), 0, 0)`
274
+ : `translate3d(${-100 * active}%, 0, 0)`,
275
+ }}
276
+ >
277
+ <SlideContext.Provider value={{ near: Math.abs(index - active) <= 1 }}>{slide}</SlideContext.Provider>
278
+ </div>
279
+ ))}
280
+ </div>
281
+ </div>
282
+
283
+ <div className="pointer-events-none absolute inset-x-0 top-1/2 z-1 hidden items-start justify-between px-4 md:flex">
284
+ <button
285
+ type="button"
286
+ aria-label={previousSlideButtonLabel}
287
+ className={roundButton}
288
+ disabled={active === 0}
289
+ onClick={() => go(active - 1)}
290
+ >
291
+ <Glyph name="arrowLeft" />
292
+ </button>
293
+ <button
294
+ type="button"
295
+ aria-label={nextSlideButtonLabel}
296
+ className={roundButton}
297
+ disabled={active === count - 1}
298
+ onClick={() => go(active + 1)}
299
+ >
300
+ <Glyph name="arrowRight" />
301
+ </button>
302
+ </div>
303
+
304
+ {count > 1 && (
305
+ <span className="pointer-events-none absolute bottom-8 left-1/2 -translate-x-1/2 rounded-base bg-black/60 px-3 py-1 leading-6 font-medium text-on-image md:hidden">
306
+ <span aria-current="page">{active + 1}</span> / {count}
307
+ </span>
308
+ )}
309
+ </div>
310
+ </DialogPrimitive.Content>
311
+ </DialogPrimitive.Portal>
312
+ </DialogPrimitive.Root>
313
+ );
314
+ }
@@ -0,0 +1,46 @@
1
+ import { Slot } from "radix-ui";
2
+ import { cn } from "../lib/utils";
3
+
4
+ export interface LinkProps extends Omit<React.ComponentProps<"a">, "color"> {
5
+ /** The link text. Interchangeable with `children`. */
6
+ label?: React.ReactNode;
7
+ /** `subdued` is a grey, medium-weight link with no underline. */
8
+ color?: "default" | "subdued";
9
+ /** Merge the styling onto the single child, such as a router's own link. */
10
+ asChild?: boolean;
11
+ }
12
+
13
+ /**
14
+ * Swirl's link: underlined, in the primary interactive colour.
15
+ *
16
+ * Pass `asChild` to style a framework link instead of rendering an `<a>`:
17
+ *
18
+ * <Link asChild><NextLink href="/settings">Settings</NextLink></Link>
19
+ */
20
+ export function Link({
21
+ className,
22
+ label,
23
+ children,
24
+ color = "default",
25
+ asChild = false,
26
+ ...props
27
+ }: LinkProps) {
28
+ const Component = asChild ? Slot.Root : "a";
29
+ return (
30
+ <Component
31
+ className={cn(
32
+ // Swirl renders the link inline-flex, so it never breaks across lines.
33
+ "inline-flex leading-6 underline-offset-4 desktop:text-sm desktop:leading-5",
34
+ "rounded-xs outline-none focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-focus",
35
+ color === "default" &&
36
+ "text-interactive-primary underline hover:text-interactive-primary-hovered active:text-interactive-primary-pressed",
37
+ color === "subdued" &&
38
+ "font-medium text-interactive-neutral no-underline hover:text-interactive-neutral-hovered active:text-interactive-neutral-pressed",
39
+ className,
40
+ )}
41
+ {...props}
42
+ >
43
+ {asChild ? children : (label ?? children)}
44
+ </Component>
45
+ );
46
+ }
@@ -0,0 +1,40 @@
1
+ import { cn } from "../lib/utils";
2
+
3
+ /*
4
+ * Swirl's list styles, applied to the plain <ul>/<ol> inside. Bullets and
5
+ * numbers sit in a 24px gutter; numbers are right-aligned with tabular digits,
6
+ * and a list nested in a numbered list counts with letters.
7
+ */
8
+ const listStyles = [
9
+ "leading-6 desktop:text-sm desktop:leading-5",
10
+ "[&_:is(ul,ol)]:m-0 [&_:is(ul,ol)]:list-none [&_:is(ul,ol)]:p-0",
11
+
12
+ "[&_ul>li]:pl-6",
13
+ "[&_ul>li]:before:-ml-6 [&_ul>li]:before:inline-block [&_ul>li]:before:w-6 [&_ul>li]:before:text-center",
14
+ "[&_ul>li]:before:content-['•']",
15
+
16
+ "[&_ol]:[counter-reset:item] [&_ol_ol]:[counter-reset:letter]",
17
+ "[&_ol>li]:pl-6",
18
+ "[&_ol>li]:before:-ml-6 [&_ol>li]:before:inline-block [&_ol>li]:before:min-w-6 [&_ol>li]:before:pr-2",
19
+ "[&_ol>li]:before:text-right [&_ol>li]:before:tabular-nums",
20
+ "[&_ol>li]:before:[counter-increment:item] [&_ol>li]:before:content-[counter(item)'.']",
21
+ "[&_ol_ol>li]:before:[counter-increment:letter] [&_ol_ol>li]:before:content-[counter(letter,lower-alpha)'.']",
22
+ ];
23
+
24
+ export interface ListProps extends React.ComponentProps<"div"> {}
25
+
26
+ /**
27
+ * Swirl's list: styles the `<ul>` and `<ol>` you put inside it, including
28
+ * nested ones. Use it for running text such as instructions or terms, not for
29
+ * interactive rows.
30
+ *
31
+ * <List>
32
+ * <ul>
33
+ * <li>First</li>
34
+ * <li>Second</li>
35
+ * </ul>
36
+ * </List>
37
+ */
38
+ export function List({ className, ...props }: ListProps) {
39
+ return <div className={cn(listStyles, className)} {...props} />;
40
+ }