@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,285 @@
1
+ import * as React from "react";
2
+ import { cn } from "../lib/utils";
3
+ import { Glyph } from "../lib/glyphs";
4
+ import { Button } from "./button";
5
+ import { SkeletonBox } from "./skeleton-box";
6
+
7
+ interface ImageGridSlot {
8
+ index: number;
9
+ count: number;
10
+ overlay?: string;
11
+ }
12
+
13
+ const ImageGridContext = React.createContext<ImageGridSlot | null>(null);
14
+
15
+ const radii = { xs: "var(--radius-xs)", sm: "var(--radius-sm)", base: "var(--radius-base)", l: "var(--radius-l)", xl: "var(--radius-xl)" };
16
+
17
+ const layouts: Record<number, string> = {
18
+ 1: "grid-cols-[100%] grid-rows-[100%]",
19
+ 2: "grid-cols-[repeat(2,calc(50%-0.0625rem))]",
20
+ // One tall image on the left, two stacked on the right.
21
+ 3: "grid-cols-[calc(100%/3*2)_calc(100%/3-0.0625rem)] grid-rows-[calc(50%-0.0625rem)] [&>:nth-child(1)]:row-span-2 [&>:nth-child(3)]:col-start-2",
22
+ 4: "grid-cols-[repeat(2,calc(50%-0.0625rem))] grid-rows-[repeat(2,calc(50%-0.0625rem))]",
23
+ };
24
+
25
+ const defaultRatio: Record<number, string> = { 1: "1", 2: "2/1", 3: "3/2", 4: "1" };
26
+
27
+ export interface ImageGridProps extends React.ComponentProps<"div"> {
28
+ /** Accessible name of the grid. */
29
+ label?: string;
30
+ /** Defaults to one that suits the number of images. */
31
+ aspectRatio?: string;
32
+ borderRadius?: keyof typeof radii | (string & {});
33
+ }
34
+
35
+ /**
36
+ * Swirl's image grid: one to four `ImageGridItem`s laid out to fill a box.
37
+ * With more than four, the fourth shows "+N" for the rest.
38
+ */
39
+ export function ImageGrid({ label, aspectRatio, borderRadius = "sm", className, style, children, ...props }: ImageGridProps) {
40
+ const items = React.Children.toArray(children).filter(React.isValidElement);
41
+ const count = Math.min(4, items.length);
42
+ return (
43
+ <div
44
+ role="list"
45
+ aria-label={label}
46
+ className={cn("grid w-full min-h-0 gap-0.5 overflow-hidden", layouts[count], className)}
47
+ style={{
48
+ aspectRatio: aspectRatio ?? defaultRatio[count] ?? "1",
49
+ borderRadius: borderRadius in radii ? radii[borderRadius as keyof typeof radii] : borderRadius,
50
+ ...style,
51
+ }}
52
+ {...props}
53
+ >
54
+ {items.map((item, index) => (
55
+ <ImageGridContext.Provider
56
+ key={item.key ?? index}
57
+ value={{ index, count, overlay: items.length > 4 && index === 3 ? `+${items.length - 3}` : undefined }}
58
+ >
59
+ {item}
60
+ </ImageGridContext.Provider>
61
+ ))}
62
+ </div>
63
+ );
64
+ }
65
+
66
+ /** Draws the image's first frame, to stand in for a paused GIF. Needs CORS for other origins. */
67
+ function firstFrame(src: string): Promise<string> {
68
+ return new Promise((resolve, reject) => {
69
+ const image = new Image();
70
+ image.crossOrigin = "anonymous";
71
+ image.onload = () => {
72
+ const canvas = document.createElement("canvas");
73
+ canvas.width = image.width;
74
+ canvas.height = image.height;
75
+ canvas.getContext("2d")?.drawImage(image, 0, 0);
76
+ try {
77
+ resolve(canvas.toDataURL("image/jpeg"));
78
+ } catch (error) {
79
+ reject(error);
80
+ }
81
+ };
82
+ image.onerror = () => reject(new Error("Couldn't load the image"));
83
+ image.src = src;
84
+ });
85
+ }
86
+
87
+ // The corners each item's focus ring rounds, by its place in the grid.
88
+ const focusCorners: Record<number, string[]> = {
89
+ 1: ["before:rounded-sm after:rounded-sm"],
90
+ 2: ["before:rounded-l-sm after:rounded-l-sm", "before:rounded-r-sm after:rounded-r-sm"],
91
+ 3: [
92
+ "before:rounded-l-sm after:rounded-l-sm",
93
+ "before:rounded-tr-sm after:rounded-tr-sm",
94
+ "before:rounded-br-sm after:rounded-br-sm",
95
+ ],
96
+ 4: [
97
+ "before:rounded-tl-sm after:rounded-tl-sm",
98
+ "before:rounded-tr-sm after:rounded-tr-sm",
99
+ "before:rounded-bl-sm after:rounded-bl-sm",
100
+ "before:rounded-br-sm after:rounded-br-sm",
101
+ ],
102
+ };
103
+
104
+ export interface ImageGridItemProps extends Omit<React.ComponentProps<"div">, "onError" | "onLoad"> {
105
+ src: string;
106
+ alt: string;
107
+ /** `intersecting` loads the image only while it's on screen, as Swirl does. */
108
+ loading?: "lazy" | "eager" | "intersecting";
109
+ /** Makes the image a button. */
110
+ interactive?: boolean;
111
+ onClick?: React.MouseEventHandler<HTMLElement>;
112
+ /** An icon in a dark circle over the middle, such as a play button. */
113
+ icon?: React.ReactNode;
114
+ /** Text over the image, such as "+3". The grid sets it on the fourth image when there are more. */
115
+ overlay?: string;
116
+ /** A small image in the top corner, such as a watermark. */
117
+ watermark?: React.ReactNode;
118
+ /** Show a button that pauses and resumes a GIF. */
119
+ showGifControls?: boolean;
120
+ gifPauseLabel?: string;
121
+ gifPlayLabel?: string;
122
+ onImageLoad?: () => void;
123
+ onImageError?: () => void;
124
+ }
125
+
126
+ /** One image in an `ImageGrid`. Shown alone, it's letterboxed over a blurred copy of itself. */
127
+ export function ImageGridItem({
128
+ src,
129
+ alt,
130
+ loading = "lazy",
131
+ interactive = false,
132
+ onClick,
133
+ icon,
134
+ overlay: overlayProp,
135
+ watermark,
136
+ showGifControls = false,
137
+ gifPauseLabel = "Pause GIF playback",
138
+ gifPlayLabel = "Continue GIF playback",
139
+ onImageLoad,
140
+ onImageError,
141
+ className,
142
+ ...props
143
+ }: ImageGridItemProps) {
144
+ const slot = React.useContext(ImageGridContext);
145
+ const count = slot?.count ?? 1;
146
+ const index = slot?.index ?? 0;
147
+ const overlay = overlayProp ?? slot?.overlay;
148
+ const [element, setElement] = React.useState<HTMLElement | null>(null);
149
+ const [inView, setInView] = React.useState(false);
150
+ const [loaded, setLoaded] = React.useState(false);
151
+ const [error, setError] = React.useState(false);
152
+ const [paused, setPaused] = React.useState<string | null>(null);
153
+
154
+ // `intersecting` loads the image while it's on screen and drops it when it leaves.
155
+ React.useEffect(() => {
156
+ if (!element || loading !== "intersecting") return;
157
+ let timer: ReturnType<typeof setTimeout> | undefined;
158
+ const observer = new IntersectionObserver((entries) => {
159
+ clearTimeout(timer);
160
+ timer = setTimeout(() => {
161
+ const visible = entries[entries.length - 1]!.isIntersecting;
162
+ setInView(visible);
163
+ if (!visible) setLoaded(false);
164
+ }, 250);
165
+ });
166
+ observer.observe(element);
167
+ return () => {
168
+ clearTimeout(timer);
169
+ observer.disconnect();
170
+ };
171
+ }, [element, loading]);
172
+
173
+ const show = paused !== null || loading !== "intersecting" || inView;
174
+ const current = paused ?? src;
175
+ const only = count === 1;
176
+ const Tag = interactive ? "button" : "div";
177
+ if (index >= 4) return null;
178
+
179
+ return (
180
+ <div ref={setElement} role="listitem" className={cn("group/grid-cell relative block min-h-0 w-full", className)} {...props}>
181
+ <Tag
182
+ {...(interactive ? { type: "button" as const } : {})}
183
+ onClick={onClick}
184
+ className={cn(
185
+ "group/grid-item relative inline-flex size-full overflow-hidden",
186
+ interactive &&
187
+ cn(
188
+ "cursor-pointer border-0 bg-transparent p-0 outline-none",
189
+ // Swirl's ring: 2px focus colour inside a 3px gap of the background.
190
+ "focus-visible:before:absolute focus-visible:before:inset-0 focus-visible:before:z-3 focus-visible:before:border-2 focus-visible:before:border-focus focus-visible:before:content-['']",
191
+ "focus-visible:after:absolute focus-visible:after:inset-0 focus-visible:after:z-2 focus-visible:after:border-[3px] focus-visible:after:border-background focus-visible:after:content-['']",
192
+ focusCorners[count]?.[index],
193
+ ),
194
+ )}
195
+ >
196
+ {only && show && (
197
+ <div
198
+ aria-hidden
199
+ className="absolute -inset-10 bg-cover blur-[20px]"
200
+ style={{ backgroundImage: `url(${current})` }}
201
+ />
202
+ )}
203
+ {show ? (
204
+ <>
205
+ <img
206
+ alt={alt}
207
+ src={current}
208
+ loading={loading === "intersecting" ? undefined : loading}
209
+ onLoad={() => {
210
+ setError(false);
211
+ setLoaded(true);
212
+ onImageLoad?.();
213
+ }}
214
+ onError={() => {
215
+ setLoaded(true);
216
+ setError(true);
217
+ onImageError?.();
218
+ }}
219
+ className={cn(
220
+ "z-1 inline-flex size-full object-center opacity-0 transition-opacity duration-300 ease-in",
221
+ only ? "object-contain" : "object-cover",
222
+ loaded && "opacity-100",
223
+ error && "hidden",
224
+ overlay && "scale-110 blur-[5px]",
225
+ )}
226
+ />
227
+ {watermark !== undefined && (
228
+ <span className="pointer-events-none absolute top-2 right-2 z-1 inline-flex size-fit [&>img]:pointer-events-none [&>img]:h-auto [&>img]:w-12">
229
+ {watermark}
230
+ </span>
231
+ )}
232
+ </>
233
+ ) : (
234
+ <div className="inline-flex size-full">
235
+ <span className="sr-only">{alt}</span>
236
+ </div>
237
+ )}
238
+ {loaded && !error && icon !== undefined && !overlay && (
239
+ <div className="absolute top-1/2 left-1/2 z-1 flex size-12 -translate-1/2 items-center justify-center rounded-full bg-black/60 text-[var(--s-icon-on-image)] [&>svg]:size-8">
240
+ {icon}
241
+ </div>
242
+ )}
243
+ {overlay && (
244
+ <div className="absolute inset-0 z-2 flex items-center justify-center bg-black/40 text-2xl text-on-image">
245
+ {overlay}
246
+ </div>
247
+ )}
248
+ {!loaded && (
249
+ <span className="absolute inset-0 z-3">
250
+ <SkeletonBox width="100%" height="100%" borderRadius="none" />
251
+ </span>
252
+ )}
253
+ {loaded && error && (
254
+ <div className="absolute inset-0 z-3 flex items-center justify-center bg-black/10 text-critical [&>svg]:size-6">
255
+ <Glyph name="error" />
256
+ </div>
257
+ )}
258
+ </Tag>
259
+ {/* Beside the image, not in it: a button can't hold another button. */}
260
+ {showGifControls && (
261
+ <span
262
+ className={cn(
263
+ "absolute top-1/2 left-1/2 z-2 -translate-1/2 transition-opacity duration-200",
264
+ paused !== null
265
+ ? "opacity-100"
266
+ : "opacity-0 group-focus-within/grid-cell:opacity-100 group-hover/grid-cell:opacity-100",
267
+ )}
268
+ >
269
+ <Button
270
+ variant="on-image"
271
+ pill
272
+ hideLabel
273
+ label={paused !== null ? gifPlayLabel : gifPauseLabel}
274
+ icon={<Glyph name="gif" />}
275
+ onClick={(event) => {
276
+ event.stopPropagation();
277
+ if (paused !== null) setPaused(null);
278
+ else firstFrame(src).then(setPaused, () => {});
279
+ }}
280
+ />
281
+ </span>
282
+ )}
283
+ </div>
284
+ );
285
+ }
@@ -0,0 +1,167 @@
1
+ import { cva, type VariantProps } from "class-variance-authority";
2
+ import { cn } from "../lib/utils";
3
+ import { Button } from "./button";
4
+
5
+ // Swirl: 12px padding (16px from 768px), 8px between icon and text.
6
+ const notificationVariants = cva(
7
+ "flex w-full max-w-full items-start gap-2 p-3 text-sm leading-5 md:p-4",
8
+ {
9
+ variants: {
10
+ intent: {
11
+ info: "bg-surface-info-subdued text-foreground",
12
+ success: "bg-surface-success-subdued text-foreground",
13
+ warning: "bg-surface-warning-subdued text-foreground",
14
+ critical: "bg-surface-critical-subdued text-foreground",
15
+ default: "bg-surface-neutral-subdued text-foreground",
16
+ },
17
+ /** `outline` swaps the tint for a hairline, for use on tinted surfaces. */
18
+ variant: { default: "", outline: "bg-transparent outline-1 -outline-offset-1" },
19
+ borderRadius: { xs: "rounded-xs", sm: "rounded-sm" },
20
+ },
21
+ compoundVariants: [
22
+ { variant: "outline", intent: "info", class: "outline-border-info" },
23
+ { variant: "outline", intent: "success", class: "outline-border-success" },
24
+ { variant: "outline", intent: "warning", class: "outline-border-warning" },
25
+ { variant: "outline", intent: "critical", class: "outline-border-critical" },
26
+ { variant: "outline", intent: "default", class: "outline-border" },
27
+ ],
28
+ defaultVariants: { intent: "info", variant: "default", borderRadius: "sm" },
29
+ },
30
+ );
31
+
32
+ const iconColors = {
33
+ info: "text-info",
34
+ success: "text-success",
35
+ warning: "text-warning",
36
+ critical: "text-critical",
37
+ default: "text-subdued",
38
+ } as const;
39
+
40
+ /** Swirl's glyph per intent (info, error, check-circle, warning), at 20px. */
41
+ const defaultIcons = {
42
+ info: "M12 17C12.2833 17 12.521 16.904 12.713 16.712C12.9043 16.5207 13 16.2833 13 16V11.975C13 11.6917 12.9043 11.4583 12.713 11.275C12.521 11.0917 12.2833 11 12 11C11.7167 11 11.4793 11.0957 11.288 11.287C11.096 11.479 11 11.7167 11 12V16.025C11 16.3083 11.096 16.5417 11.288 16.725C11.4793 16.9083 11.7167 17 12 17ZM12 9C12.2833 9 12.521 8.904 12.713 8.712C12.9043 8.52067 13 8.28333 13 8C13 7.71667 12.9043 7.479 12.713 7.287C12.521 7.09567 12.2833 7 12 7C11.7167 7 11.4793 7.09567 11.288 7.287C11.096 7.479 11 7.71667 11 8C11 8.28333 11.096 8.52067 11.288 8.712C11.4793 8.904 11.7167 9 12 9ZM12 22C10.6167 22 9.31667 21.7373 8.1 21.212C6.88333 20.6873 5.825 19.975 4.925 19.075C4.025 18.175 3.31267 17.1167 2.788 15.9C2.26267 14.6833 2 13.3833 2 12C2 10.6167 2.26267 9.31667 2.788 8.1C3.31267 6.88333 4.025 5.825 4.925 4.925C5.825 4.025 6.88333 3.31233 8.1 2.787C9.31667 2.26233 10.6167 2 12 2C13.3833 2 14.6833 2.26233 15.9 2.787C17.1167 3.31233 18.175 4.025 19.075 4.925C19.975 5.825 20.6873 6.88333 21.212 8.1C21.7373 9.31667 22 10.6167 22 12C22 13.3833 21.7373 14.6833 21.212 15.9C20.6873 17.1167 19.975 18.175 19.075 19.075C18.175 19.975 17.1167 20.6873 15.9 21.212C14.6833 21.7373 13.3833 22 12 22ZM12 20C14.2167 20 16.1043 19.221 17.663 17.663C19.221 16.1043 20 14.2167 20 12C20 9.78333 19.221 7.89567 17.663 6.337C16.1043 4.779 14.2167 4 12 4C9.78333 4 7.896 4.779 6.338 6.337C4.77933 7.89567 4 9.78333 4 12C4 14.2167 4.77933 16.1043 6.338 17.663C7.896 19.221 9.78333 20 12 20Z",
43
+ success: "M10.6 13.8L8.425 11.625C8.24167 11.4417 8.01267 11.3543 7.738 11.363C7.46267 11.371 7.23333 11.4667 7.05 11.65C6.86667 11.8333 6.775 12.0667 6.775 12.35C6.775 12.6333 6.86667 12.8667 7.05 13.05L9.9 15.9C10.0833 16.0833 10.3167 16.175 10.6 16.175C10.8833 16.175 11.1167 16.0833 11.3 15.9L16.975 10.225C17.1583 10.0417 17.246 9.81233 17.238 9.537C17.2293 9.26233 17.1333 9.03333 16.95 8.85C16.7667 8.66667 16.5333 8.575 16.25 8.575C15.9667 8.575 15.7333 8.66667 15.55 8.85L10.6 13.8ZM12 22C10.6167 22 9.31667 21.7373 8.1 21.212C6.88333 20.6873 5.825 19.975 4.925 19.075C4.025 18.175 3.31267 17.1167 2.788 15.9C2.26267 14.6833 2 13.3833 2 12C2 10.6167 2.26267 9.31667 2.788 8.1C3.31267 6.88333 4.025 5.825 4.925 4.925C5.825 4.025 6.88333 3.31233 8.1 2.787C9.31667 2.26233 10.6167 2 12 2C13.3833 2 14.6833 2.26233 15.9 2.787C17.1167 3.31233 18.175 4.025 19.075 4.925C19.975 5.825 20.6873 6.88333 21.212 8.1C21.7373 9.31667 22 10.6167 22 12C22 13.3833 21.7373 14.6833 21.212 15.9C20.6873 17.1167 19.975 18.175 19.075 19.075C18.175 19.975 17.1167 20.6873 15.9 21.212C14.6833 21.7373 13.3833 22 12 22ZM12 20C14.2167 20 16.1043 19.221 17.663 17.663C19.221 16.1043 20 14.2167 20 12C20 9.78333 19.221 7.89567 17.663 6.337C16.1043 4.779 14.2167 4 12 4C9.78333 4 7.896 4.779 6.338 6.337C4.77933 7.89567 4 9.78333 4 12C4 14.2167 4.77933 16.1043 6.338 17.663C7.896 19.221 9.78333 20 12 20Z",
44
+ warning: "M2.72499 21C2.34165 21 2.05832 20.8333 1.87499 20.5C1.69165 20.1667 1.69165 19.8333 1.87499 19.5L11.125 3.5C11.3083 3.16667 11.6 3 12 3C12.4 3 12.6917 3.16667 12.875 3.5L22.125 19.5C22.3083 19.8333 22.3083 20.1667 22.125 20.5C21.9417 20.8333 21.6583 21 21.275 21H2.72499ZM12 10C11.7167 10 11.4793 10.0957 11.288 10.287C11.096 10.479 11 10.7167 11 11V14C11 14.2833 11.096 14.5207 11.288 14.712C11.4793 14.904 11.7167 15 12 15C12.2833 15 12.521 14.904 12.713 14.712C12.9043 14.5207 13 14.2833 13 14V11C13 10.7167 12.9043 10.479 12.713 10.287C12.521 10.0957 12.2833 10 12 10ZM12 18C12.2833 18 12.521 17.904 12.713 17.712C12.9043 17.5207 13 17.2833 13 17C13 16.7167 12.9043 16.4793 12.713 16.288C12.521 16.096 12.2833 16 12 16C11.7167 16 11.4793 16.096 11.288 16.288C11.096 16.4793 11 16.7167 11 17C11 17.2833 11.096 17.5207 11.288 17.712C11.4793 17.904 11.7167 18 12 18ZM4.44999 19H19.55L12 6L4.44999 19Z",
45
+ critical: "M9.075 21C8.80833 21 8.554 20.95 8.312 20.85C8.07067 20.75 7.85833 20.6083 7.675 20.425L3.575 16.325C3.39167 16.1417 3.25 15.9293 3.15 15.688C3.05 15.446 3 15.1917 3 14.925V9.075C3 8.80833 3.05 8.554 3.15 8.312C3.25 8.07067 3.39167 7.85833 3.575 7.675L7.675 3.575C7.85833 3.39167 8.07067 3.25 8.312 3.15C8.554 3.05 8.80833 3 9.075 3H14.925C15.1917 3 15.446 3.05 15.688 3.15C15.9293 3.25 16.1417 3.39167 16.325 3.575L20.425 7.675C20.6083 7.85833 20.75 8.07067 20.85 8.312C20.95 8.554 21 8.80833 21 9.075V14.925C21 15.1917 20.95 15.446 20.85 15.688C20.75 15.9293 20.6083 16.1417 20.425 16.325L16.325 20.425C16.1417 20.6083 15.9293 20.75 15.688 20.85C15.446 20.95 15.1917 21 14.925 21H9.075ZM12 17C12.2833 17 12.521 16.904 12.713 16.712C12.9043 16.5207 13 16.2833 13 16C13 15.7167 12.9043 15.479 12.713 15.287C12.521 15.0957 12.2833 15 12 15C11.7167 15 11.4793 15.0957 11.288 15.287C11.096 15.479 11 15.7167 11 16C11 16.2833 11.096 16.5207 11.288 16.712C11.4793 16.904 11.7167 17 12 17ZM12 13C12.2833 13 12.521 12.904 12.713 12.712C12.9043 12.5207 13 12.2833 13 12V8C13 7.71667 12.9043 7.479 12.713 7.287C12.521 7.09567 12.2833 7 12 7C11.7167 7 11.4793 7.09567 11.288 7.287C11.096 7.479 11 7.71667 11 8V12C11 12.2833 11.096 12.5207 11.288 12.712C11.4793 12.904 11.7167 13 12 13ZM9.1 19H14.9L19 14.9V9.1L14.9 5H9.1L5 9.1V14.9L9.1 19Z",
46
+ default: "M12 17C12.2833 17 12.521 16.904 12.713 16.712C12.9043 16.5207 13 16.2833 13 16V11.975C13 11.6917 12.9043 11.4583 12.713 11.275C12.521 11.0917 12.2833 11 12 11C11.7167 11 11.4793 11.0957 11.288 11.287C11.096 11.479 11 11.7167 11 12V16.025C11 16.3083 11.096 16.5417 11.288 16.725C11.4793 16.9083 11.7167 17 12 17ZM12 9C12.2833 9 12.521 8.904 12.713 8.712C12.9043 8.52067 13 8.28333 13 8C13 7.71667 12.9043 7.479 12.713 7.287C12.521 7.09567 12.2833 7 12 7C11.7167 7 11.4793 7.09567 11.288 7.287C11.096 7.479 11 7.71667 11 8C11 8.28333 11.096 8.52067 11.288 8.712C11.4793 8.904 11.7167 9 12 9ZM12 22C10.6167 22 9.31667 21.7373 8.1 21.212C6.88333 20.6873 5.825 19.975 4.925 19.075C4.025 18.175 3.31267 17.1167 2.788 15.9C2.26267 14.6833 2 13.3833 2 12C2 10.6167 2.26267 9.31667 2.788 8.1C3.31267 6.88333 4.025 5.825 4.925 4.925C5.825 4.025 6.88333 3.31233 8.1 2.787C9.31667 2.26233 10.6167 2 12 2C13.3833 2 14.6833 2.26233 15.9 2.787C17.1167 3.31233 18.175 4.025 19.075 4.925C19.975 5.825 20.6873 6.88333 21.212 8.1C21.7373 9.31667 22 10.6167 22 12C22 13.3833 21.7373 14.6833 21.212 15.9C20.6873 17.1167 19.975 18.175 19.075 19.075C18.175 19.975 17.1167 20.6873 15.9 21.212C14.6833 21.7373 13.3833 22 12 22ZM12 20C14.2167 20 16.1043 19.221 17.663 17.663C19.221 16.1043 20 14.2167 20 12C20 9.78333 19.221 7.89567 17.663 6.337C16.1043 4.779 14.2167 4 12 4C9.78333 4 7.896 4.779 6.338 6.337C4.77933 7.89567 4 9.78333 4 12C4 14.2167 4.77933 16.1043 6.338 17.663C7.896 19.221 9.78333 20 12 20Z",
47
+ } as const;
48
+
49
+ export type NotificationIntent = NonNullable<
50
+ VariantProps<typeof notificationVariants>["intent"]
51
+ >;
52
+
53
+ /** shadcn's Alert variants, mapped onto Swirl intents. */
54
+ const shadcnIntents = { default: "default", destructive: "critical" } as const;
55
+
56
+ export interface InlineNotificationProps
57
+ extends Omit<React.ComponentProps<"div">, "title">,
58
+ Omit<VariantProps<typeof notificationVariants>, "intent"> {
59
+ intent?: NotificationIntent | keyof typeof shadcnIntents;
60
+ /** Bold first line. `heading` is Swirl's name for the same thing. */
61
+ title?: React.ReactNode;
62
+ heading?: React.ReactNode;
63
+ /** Keep the heading for screen readers but don't show it. */
64
+ hideHeading?: boolean;
65
+ /** Pass `null` to drop the icon entirely. */
66
+ icon?: React.ReactNode | null;
67
+ /** Show a dismiss button and call this when pressed. */
68
+ onDismiss?: () => void;
69
+ dismissLabel?: string;
70
+ /** Trailing actions, e.g. a retry button. */
71
+ action?: React.ReactNode;
72
+ }
73
+
74
+ /**
75
+ * A persistent, in-flow message. shadcn calls this an Alert.
76
+ *
77
+ * Critical and warning messages render as `role="alert"` so they interrupt;
78
+ * informational ones use `role="status"` and wait their turn.
79
+ */
80
+ export function InlineNotification({
81
+ className,
82
+ intent,
83
+ variant,
84
+ borderRadius,
85
+ title,
86
+ heading,
87
+ hideHeading = false,
88
+ icon,
89
+ onDismiss,
90
+ dismissLabel = "Dismiss",
91
+ action,
92
+ children,
93
+ ...props
94
+ }: InlineNotificationProps) {
95
+ const resolved = (intent && intent in shadcnIntents
96
+ ? shadcnIntents[intent as keyof typeof shadcnIntents]
97
+ : (intent ?? "info")) as NotificationIntent;
98
+
99
+ const urgent = resolved === "critical" || resolved === "warning";
100
+ const headingText = title ?? heading;
101
+
102
+ return (
103
+ <div
104
+ role={urgent ? "alert" : "status"}
105
+ className={cn(notificationVariants({ intent: resolved, variant, borderRadius }), className)}
106
+ {...props}
107
+ >
108
+ {icon !== null && (
109
+ <span aria-hidden className={cn("inline-flex shrink-0 [&>svg]:size-5", iconColors[resolved])}>
110
+ {icon ?? (
111
+ <svg viewBox="0 0 24 24" focusable={false}>
112
+ <path d={defaultIcons[resolved]} fill="currentColor" />
113
+ </svg>
114
+ )}
115
+ </span>
116
+ )}
117
+
118
+ {/* Swirl nudges the text down 1px to sit on the icon's optical centre. */}
119
+ <div className="relative top-px min-w-0 flex-1 text-foreground">
120
+ {headingText &&
121
+ (hideHeading ? (
122
+ <span className="sr-only">{headingText}</span>
123
+ ) : (
124
+ <p className="font-semibold">{headingText}</p>
125
+ ))}
126
+ {children && <div>{children}</div>}
127
+ {action && <div className="mt-2 flex gap-2">{action}</div>}
128
+ </div>
129
+
130
+ {onDismiss && (
131
+ <Button
132
+ variant="ghost"
133
+ size="s"
134
+ hideLabel
135
+ label={dismissLabel}
136
+ onClick={onDismiss}
137
+ className="-my-1 -mr-1 shrink-0"
138
+ icon={
139
+ <svg viewBox="0 0 20 20" className="size-4" aria-hidden focusable={false}>
140
+ <path
141
+ d="M5 5l10 10M15 5L5 15"
142
+ stroke="currentColor"
143
+ strokeWidth="1.5"
144
+ strokeLinecap="round"
145
+ fill="none"
146
+ />
147
+ </svg>
148
+ }
149
+ />
150
+ )}
151
+ </div>
152
+ );
153
+ }
154
+
155
+ /** shadcn-compatible aliases. */
156
+ export const Alert = InlineNotification;
157
+ export type AlertProps = InlineNotificationProps;
158
+
159
+ export function AlertTitle({ className, ...props }: React.ComponentProps<"p">) {
160
+ return <p className={cn("font-semibold", className)} {...props} />;
161
+ }
162
+
163
+ export function AlertDescription({ className, ...props }: React.ComponentProps<"div">) {
164
+ return <div className={className} {...props} />;
165
+ }
166
+
167
+ export { notificationVariants };
@@ -0,0 +1,100 @@
1
+ import { cn } from "../lib/utils";
2
+
3
+ /*
4
+ * Swirl's inline status and inline error: a short message with a leading icon,
5
+ * set inline beside the thing it describes. The icon is 24px, 20px with the
6
+ * desktop layout, and 16px at size `s`; the text drops to 14px on desktop.
7
+ */
8
+ const root = "inline-flex leading-6 desktop:text-sm desktop:leading-5";
9
+ // Size s only shrinks the font: the line height stays 24px on touch screens.
10
+ const sizeS = "text-sm leading-6 desktop:leading-5";
11
+ const iconBox = (size: "m" | "s") =>
12
+ cn(
13
+ "inline-flex shrink-0 self-start [&>svg]:size-full",
14
+ size === "s" ? "mt-0.5 size-4" : "size-6 desktop:size-5",
15
+ );
16
+ const messageBox = (size: "m" | "s") =>
17
+ cn("w-fit", size === "s" ? "pt-0" : "pt-px desktop:pt-0");
18
+
19
+ // Swirl's status icon colours equal its text colours for every intent but
20
+ // neutral, so the icon inherits the text colour except there.
21
+ const statusColors = {
22
+ critical: "text-critical",
23
+ info: "text-info",
24
+ neutral: "text-subdued",
25
+ success: "text-success",
26
+ warning: "text-warning",
27
+ } as const;
28
+
29
+ export interface InlineStatusProps extends Omit<React.ComponentProps<"span">, "children"> {
30
+ /** The status text. Interchangeable with `children`. */
31
+ message?: React.ReactNode;
32
+ children?: React.ReactNode;
33
+ /** Leading icon, such as one from `@enablo/swirlcn-icons`. */
34
+ icon?: React.ReactNode;
35
+ /** Colours the text and icon. Without one, the text is the default colour. */
36
+ intent?: keyof typeof statusColors;
37
+ size?: "m" | "s";
38
+ }
39
+
40
+ /** A short status message with an optional icon, such as "Saved" or "Syncing". */
41
+ export function InlineStatus({
42
+ className,
43
+ message,
44
+ children,
45
+ icon,
46
+ intent,
47
+ size = "m",
48
+ ...props
49
+ }: InlineStatusProps) {
50
+ return (
51
+ <span
52
+ className={cn(root, intent ? statusColors[intent] : "text-foreground", size === "s" && sizeS, className)}
53
+ {...props}
54
+ >
55
+ {icon && (
56
+ <span
57
+ aria-hidden
58
+ className={cn(
59
+ iconBox(size),
60
+ "mr-1",
61
+ (!intent || intent === "neutral") && "text-icon-default",
62
+ )}
63
+ >
64
+ {icon}
65
+ </span>
66
+ )}
67
+ <span className={messageBox(size)}>{message ?? children}</span>
68
+ </span>
69
+ );
70
+ }
71
+
72
+ export interface InlineErrorProps extends Omit<React.ComponentProps<"span">, "children"> {
73
+ /** The error text. Line breaks in it are kept. Interchangeable with `children`. */
74
+ message?: React.ReactNode;
75
+ children?: React.ReactNode;
76
+ size?: "m" | "s";
77
+ }
78
+
79
+ /** An error message beside a control, with Swirl's error icon. */
80
+ export function InlineError({ className, message, children, size = "m", ...props }: InlineErrorProps) {
81
+ return (
82
+ <span className={cn(root, "text-critical", size === "s" && sizeS, className)} {...props}>
83
+ <span aria-hidden className={cn(iconBox(size), "text-critical")}>
84
+ {size === "s" ? (
85
+ <svg viewBox="0 0 16 16" focusable={false}>
86
+ <path d="M6.05 14C5.87222 14 5.70267 13.9667 5.54133 13.9C5.38044 13.8333 5.23889 13.7389 5.11667 13.6167L2.38333 10.8833C2.26111 10.7611 2.16667 10.6196 2.1 10.4587C2.03333 10.2973 2 10.1278 2 9.95V6.05C2 5.87222 2.03333 5.70267 2.1 5.54133C2.16667 5.38044 2.26111 5.23889 2.38333 5.11667L5.11667 2.38333C5.23889 2.26111 5.38044 2.16667 5.54133 2.1C5.70267 2.03333 5.87222 2 6.05 2H9.95C10.1278 2 10.2973 2.03333 10.4587 2.1C10.6196 2.16667 10.7611 2.26111 10.8833 2.38333L13.6167 5.11667C13.7389 5.23889 13.8333 5.38044 13.9 5.54133C13.9667 5.70267 14 5.87222 14 6.05V9.95C14 10.1278 13.9667 10.2973 13.9 10.4587C13.8333 10.6196 13.7389 10.7611 13.6167 10.8833L10.8833 13.6167C10.7611 13.7389 10.6196 13.8333 10.4587 13.9C10.2973 13.9667 10.1278 14 9.95 14H6.05ZM8 11.3333C8.18889 11.3333 8.34733 11.2693 8.47533 11.1413C8.60289 11.0138 8.66667 10.8556 8.66667 10.6667C8.66667 10.4778 8.60289 10.3193 8.47533 10.1913C8.34733 10.0638 8.18889 10 8 10C7.81111 10 7.65289 10.0638 7.52533 10.1913C7.39733 10.3193 7.33333 10.4778 7.33333 10.6667C7.33333 10.8556 7.39733 11.0138 7.52533 11.1413C7.65289 11.2693 7.81111 11.3333 8 11.3333ZM8 8.66667C8.18889 8.66667 8.34733 8.60267 8.47533 8.47467C8.60289 8.34711 8.66667 8.18889 8.66667 8V5.33333C8.66667 5.14444 8.60289 4.986 8.47533 4.858C8.34733 4.73044 8.18889 4.66667 8 4.66667C7.81111 4.66667 7.65289 4.73044 7.52533 4.858C7.39733 4.986 7.33333 5.14444 7.33333 5.33333V8C7.33333 8.18889 7.39733 8.34711 7.52533 8.47467C7.65289 8.60267 7.81111 8.66667 8 8.66667ZM6.06667 12.6667H9.93333L12.6667 9.93333V6.06667L9.93333 3.33333H6.06667L3.33333 6.06667V9.93333L6.06667 12.6667Z" fill="currentColor" />
87
+ </svg>
88
+ ) : (
89
+ <svg viewBox="0 0 24 24" focusable={false}>
90
+ <path d="M9.075 21C8.80833 21 8.554 20.95 8.312 20.85C8.07067 20.75 7.85833 20.6083 7.675 20.425L3.575 16.325C3.39167 16.1417 3.25 15.9293 3.15 15.688C3.05 15.446 3 15.1917 3 14.925V9.075C3 8.80833 3.05 8.554 3.15 8.312C3.25 8.07067 3.39167 7.85833 3.575 7.675L7.675 3.575C7.85833 3.39167 8.07067 3.25 8.312 3.15C8.554 3.05 8.80833 3 9.075 3H14.925C15.1917 3 15.446 3.05 15.688 3.15C15.9293 3.25 16.1417 3.39167 16.325 3.575L20.425 7.675C20.6083 7.85833 20.75 8.07067 20.85 8.312C20.95 8.554 21 8.80833 21 9.075V14.925C21 15.1917 20.95 15.446 20.85 15.688C20.75 15.9293 20.6083 16.1417 20.425 16.325L16.325 20.425C16.1417 20.6083 15.9293 20.75 15.688 20.85C15.446 20.95 15.1917 21 14.925 21H9.075ZM12 17C12.2833 17 12.521 16.904 12.713 16.712C12.9043 16.5207 13 16.2833 13 16C13 15.7167 12.9043 15.479 12.713 15.287C12.521 15.0957 12.2833 15 12 15C11.7167 15 11.4793 15.0957 11.288 15.287C11.096 15.479 11 15.7167 11 16C11 16.2833 11.096 16.5207 11.288 16.712C11.4793 16.904 11.7167 17 12 17ZM12 13C12.2833 13 12.521 12.904 12.713 12.712C12.9043 12.5207 13 12.2833 13 12V8C13 7.71667 12.9043 7.479 12.713 7.287C12.521 7.09567 12.2833 7 12 7C11.7167 7 11.4793 7.09567 11.288 7.287C11.096 7.479 11 7.71667 11 8V12C11 12.2833 11.096 12.5207 11.288 12.712C11.4793 12.904 11.7167 13 12 13ZM9.1 19H14.9L19 14.9V9.1L14.9 5H9.1L5 9.1V14.9L9.1 19Z" fill="currentColor" />
91
+ </svg>
92
+ )}
93
+ </span>
94
+ {/* Unlike the status, Swirl keeps the error's 1px nudge on desktop too. */}
95
+ <span className={cn("ml-1 w-fit whitespace-pre-line", size === "s" ? "pt-0" : "pt-px")}>
96
+ {message ?? children}
97
+ </span>
98
+ </span>
99
+ );
100
+ }