@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.
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,294 @@
1
+ import * as React from "react";
2
+ import { cn } from "../lib/utils";
3
+ import { gap, type SwirlSpacing } from "../lib/spacing";
4
+
5
+ const ITEM = '[role="menuitem"]';
6
+
7
+ function enabledItems(list: HTMLElement) {
8
+ return Array.from(list.querySelectorAll<HTMLElement>(ITEM)).filter(
9
+ (item) => !(item as HTMLButtonElement).disabled,
10
+ );
11
+ }
12
+
13
+ export interface ActionListProps extends React.ComponentProps<"div"> {}
14
+
15
+ /**
16
+ * Swirl's action list: a vertical menu of actions, standalone or inside a
17
+ * popover. For a menu that opens from a trigger, use `Menu`.
18
+ *
19
+ * It is one tab stop. Arrow keys move between items and wrap at the ends;
20
+ * Home and End jump to the first and last. Tabbing back in returns to the
21
+ * item that last had focus.
22
+ */
23
+ export function ActionList({ className, onKeyDown, onFocus, onBlur, ...props }: ActionListProps) {
24
+ const ref = React.useRef<HTMLDivElement>(null);
25
+ const lastFocused = React.useRef<HTMLElement | null>(null);
26
+ // The list itself is the tab stop until focus is inside. Once it is, the
27
+ // list drops out of the tab order, or Shift+Tab from an item would land on
28
+ // the list and bounce straight back in.
29
+ const [focusWithin, setFocusWithin] = React.useState(false);
30
+
31
+ const move = (to: (index: number, count: number) => number) => {
32
+ const list = ref.current;
33
+ if (!list) return;
34
+ const items = enabledItems(list);
35
+ if (items.length === 0) return;
36
+ const current = items.indexOf(document.activeElement as HTMLElement);
37
+ items[to(current, items.length)]?.focus();
38
+ };
39
+
40
+ return (
41
+ <div
42
+ ref={ref}
43
+ role="menu"
44
+ aria-orientation="vertical"
45
+ tabIndex={focusWithin ? -1 : 0}
46
+ className={cn("flex w-full flex-col outline-none", className)}
47
+ onFocus={(event) => {
48
+ onFocus?.(event);
49
+ setFocusWithin(true);
50
+ const list = ref.current;
51
+ if (!list) return;
52
+ if (event.target === list) {
53
+ // Arriving via Tab: hand focus to the remembered item, else the first.
54
+ const items = enabledItems(list);
55
+ const target =
56
+ lastFocused.current && items.includes(lastFocused.current)
57
+ ? lastFocused.current
58
+ : items[0];
59
+ target?.focus();
60
+ } else if ((event.target as HTMLElement).matches(ITEM)) {
61
+ lastFocused.current = event.target as HTMLElement;
62
+ }
63
+ }}
64
+ onBlur={(event) => {
65
+ onBlur?.(event);
66
+ if (!ref.current?.contains(event.relatedTarget as Node | null)) setFocusWithin(false);
67
+ }}
68
+ onKeyDown={(event) => {
69
+ onKeyDown?.(event);
70
+ if (event.defaultPrevented) return;
71
+ const step: Record<string, (index: number, count: number) => number> = {
72
+ ArrowDown: (i, n) => (i + 1) % n,
73
+ ArrowRight: (i, n) => (i + 1) % n,
74
+ ArrowUp: (i, n) => (i <= 0 ? n - 1 : i - 1),
75
+ ArrowLeft: (i, n) => (i <= 0 ? n - 1 : i - 1),
76
+ Home: () => 0,
77
+ End: (_, n) => n - 1,
78
+ };
79
+ const to = step[event.key];
80
+ if (!to) return;
81
+ event.preventDefault();
82
+ event.stopPropagation();
83
+ move(to);
84
+ }}
85
+ {...props}
86
+ />
87
+ );
88
+ }
89
+
90
+ export interface ActionListItemProps extends Omit<React.ComponentProps<"button">, "children"> {
91
+ /** The action's name. Interchangeable with `children`. */
92
+ label?: React.ReactNode;
93
+ children?: React.ReactNode;
94
+ /** Secondary text under the label. */
95
+ description?: React.ReactNode;
96
+ /** Leading icon. Sized 24px, or 20px with the desktop layout. */
97
+ icon?: React.ReactNode;
98
+ /** Small marker over the icon's corner, such as a dot `Badge`. */
99
+ iconBadge?: React.ReactNode;
100
+ /** Leading avatar, in place of or as well as an icon. */
101
+ avatar?: React.ReactNode;
102
+ /** Right-aligned meta text: a shortcut, a count. */
103
+ badge?: React.ReactNode;
104
+ /** Trailing icon or `Tag`. Hidden while the item is disabled, as in Swirl. */
105
+ suffix?: React.ReactNode;
106
+ intent?: "default" | "critical";
107
+ /** `l` pads the item evenly by 16px. */
108
+ size?: "m" | "l";
109
+ /** Let a long label wrap instead of truncating. */
110
+ truncateLabel?: boolean;
111
+ /**
112
+ * Mark the item as the chosen option: label, icon and suffix take the
113
+ * highlight colour, as Swirl's option items do.
114
+ */
115
+ selected?: boolean;
116
+ }
117
+
118
+ /**
119
+ * One action. Renders a button with `role="menuitem"`; disable it with
120
+ * `disabled`, or with `aria-disabled` to keep it focusable for screen readers.
121
+ */
122
+ export function ActionListItem({
123
+ className,
124
+ label,
125
+ children,
126
+ description,
127
+ icon,
128
+ iconBadge,
129
+ avatar,
130
+ badge,
131
+ suffix,
132
+ intent = "default",
133
+ size = "m",
134
+ truncateLabel = true,
135
+ selected = false,
136
+ disabled,
137
+ onClick,
138
+ type = "button",
139
+ ...props
140
+ }: ActionListItemProps) {
141
+ const ariaDisabled = props["aria-disabled"] === true || props["aria-disabled"] === "true";
142
+ const inactive = disabled || ariaDisabled;
143
+
144
+ return (
145
+ <button
146
+ type={type}
147
+ role="menuitem"
148
+ tabIndex={-1}
149
+ disabled={disabled}
150
+ data-intent={intent}
151
+ className={cn(
152
+ "group/item relative inline-flex w-full min-w-60 cursor-pointer items-center justify-start gap-3",
153
+ "rounded-sm bg-transparent px-4 py-3 text-left text-base leading-6 text-foreground",
154
+ "desktop:gap-2 desktop:px-3 desktop:py-2 desktop:text-sm desktop:leading-5",
155
+ size === "l" && "p-4 desktop:p-4",
156
+ "not-disabled:not-aria-disabled:hover:bg-state-hovered",
157
+ "not-disabled:not-aria-disabled:active:bg-translucent-low-pressed",
158
+ "outline-none focus-visible:z-1 focus-visible:bg-state-hovered focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-focus",
159
+ "disabled:cursor-default aria-disabled:cursor-default",
160
+ className,
161
+ )}
162
+ onClick={(event) => {
163
+ // aria-disabled keeps the item focusable, so the click is blocked here.
164
+ if (ariaDisabled) {
165
+ event.preventDefault();
166
+ event.stopPropagation();
167
+ return;
168
+ }
169
+ onClick?.(event);
170
+ }}
171
+ {...props}
172
+ >
173
+ {avatar}
174
+ {icon && (
175
+ <span
176
+ className={cn(
177
+ "relative inline-flex size-6 shrink-0 desktop:size-5 [&>svg]:size-full",
178
+ inactive
179
+ ? "text-disabled"
180
+ : selected
181
+ ? "text-highlight"
182
+ : intent === "critical"
183
+ ? "text-critical"
184
+ : "text-icon-default",
185
+ )}
186
+ >
187
+ {icon}
188
+ {iconBadge && <span className="absolute right-0 bottom-0 grid">{iconBadge}</span>}
189
+ </span>
190
+ )}
191
+ <span className="inline-flex min-w-0 shrink grow flex-col items-start">
192
+ <span
193
+ className={cn(
194
+ "max-w-full font-medium",
195
+ truncateLabel ? "truncate" : "whitespace-normal",
196
+ inactive
197
+ ? "text-disabled"
198
+ : selected
199
+ ? "text-highlight"
200
+ : intent === "critical" && "text-critical",
201
+ )}
202
+ >
203
+ {label ?? children}
204
+ </span>
205
+ {description && (
206
+ <span className={inactive ? "text-disabled" : "text-subdued"}>{description}</span>
207
+ )}
208
+ </span>
209
+ {badge && (
210
+ <span className="min-w-16 shrink-[3] truncate pl-2 text-right font-medium text-subdued">
211
+ {badge}
212
+ </span>
213
+ )}
214
+ {suffix && !inactive && (
215
+ <span
216
+ className={cn(
217
+ "inline-flex shrink-0 [&>svg]:size-6 desktop:[&>svg]:size-5",
218
+ selected ? "text-highlight" : "text-icon-default",
219
+ )}
220
+ >
221
+ {suffix}
222
+ </span>
223
+ )}
224
+ </button>
225
+ );
226
+ }
227
+
228
+ /* Vertical margin around the separator line, per Swirl spacing step. */
229
+ const separatorSpacings = {
230
+ "0": "my-0",
231
+ "2": "my-0.5",
232
+ "4": "my-1",
233
+ "8": "my-2",
234
+ "12": "my-3",
235
+ "16": "my-4",
236
+ "20": "my-5",
237
+ "24": "my-6",
238
+ "32": "my-8",
239
+ "40": "my-10",
240
+ "48": "my-12",
241
+ "64": "my-16",
242
+ } as const satisfies Record<SwirlSpacing, string>;
243
+
244
+ export interface ActionListSectionProps extends React.ComponentProps<"div"> {
245
+ /** Heading for the group of items. Required, as in Swirl: it names the group. */
246
+ label: React.ReactNode;
247
+ /** Gap between the section's items, in Swirl's px steps. */
248
+ spacing?: SwirlSpacing;
249
+ /**
250
+ * Draw a separator above the section. Ignored on a section that opens the
251
+ * list, where there is nothing above to separate it from.
252
+ */
253
+ hasSeparator?: boolean;
254
+ /** Space above and below the separator line, in Swirl's px steps. */
255
+ separatorSpacing?: SwirlSpacing;
256
+ }
257
+
258
+ /** A labelled group of items. */
259
+ export function ActionListSection({
260
+ className,
261
+ label,
262
+ spacing = "0",
263
+ hasSeparator = false,
264
+ separatorSpacing = "4",
265
+ children,
266
+ ...props
267
+ }: ActionListSectionProps) {
268
+ const id = React.useId();
269
+ return (
270
+ <div className={cn("group/section w-full", className)} {...props}>
271
+ {hasSeparator && (
272
+ <div
273
+ role="separator"
274
+ className={cn(
275
+ "h-px w-full bg-border group-first/section:hidden",
276
+ separatorSpacings[separatorSpacing],
277
+ )}
278
+ />
279
+ )}
280
+ <div role="group" aria-labelledby={id}>
281
+ <span
282
+ id={id}
283
+ className={cn(
284
+ "block w-full px-4 py-2 text-left leading-6 font-medium text-subdued",
285
+ "desktop:px-3 desktop:text-sm desktop:leading-5",
286
+ )}
287
+ >
288
+ {label}
289
+ </span>
290
+ <div className={cn("flex flex-col items-stretch", gap(spacing))}>{children}</div>
291
+ </div>
292
+ </div>
293
+ );
294
+ }
@@ -0,0 +1,155 @@
1
+ import { AlertDialog as AlertDialogPrimitive } from "radix-ui";
2
+ import { cn } from "../lib/utils";
3
+ import { Button, type ButtonProps } from "./button";
4
+
5
+ /**
6
+ * Swirl's dialog (`swirl-dialog`): a small, focused confirmation such as "Leave
7
+ * this chat?". It uses the `alertdialog` role, so it has no close button and
8
+ * an outside click does not dismiss it; the user answers with an action, or
9
+ * Escape. For forms and other content, use `Dialog` (Swirl's modal).
10
+ */
11
+ export const AlertDialog = AlertDialogPrimitive.Root;
12
+ export const AlertDialogTrigger = AlertDialogPrimitive.Trigger;
13
+ export const AlertDialogPortal = AlertDialogPrimitive.Portal;
14
+
15
+ export function AlertDialogOverlay({
16
+ className,
17
+ ...props
18
+ }: React.ComponentProps<typeof AlertDialogPrimitive.Overlay>) {
19
+ return (
20
+ <AlertDialogPrimitive.Overlay
21
+ className={cn(
22
+ "fixed inset-0 z-50 bg-black/20 duration-150",
23
+ "data-[state=open]:animate-in data-[state=open]:fade-in-0",
24
+ "data-[state=closed]:animate-out data-[state=closed]:fade-out-0",
25
+ className,
26
+ )}
27
+ {...props}
28
+ />
29
+ );
30
+ }
31
+
32
+ export interface AlertDialogContentProps
33
+ extends React.ComponentProps<typeof AlertDialogPrimitive.Content> {
34
+ /** `large` widens the dialog to 35rem with the desktop layout. */
35
+ size?: "default" | "large";
36
+ /** A frosted, see-through surface instead of the solid overlay colour. */
37
+ translucent?: boolean;
38
+ }
39
+
40
+ export function AlertDialogContent({
41
+ className,
42
+ children,
43
+ size = "default",
44
+ translucent = false,
45
+ ...props
46
+ }: AlertDialogContentProps) {
47
+ return (
48
+ <AlertDialogPortal>
49
+ <AlertDialogOverlay />
50
+ <AlertDialogPrimitive.Content
51
+ className={cn(
52
+ "fixed top-1/2 left-1/2 z-50 -translate-x-1/2 -translate-y-1/2 overflow-hidden",
53
+ "w-[18.5rem] rounded-(--radius-l) text-center text-foreground shadow-level-3",
54
+ "desktop:w-[25rem] desktop:rounded-base min-[992px]:text-start",
55
+ size === "large" && "desktop:w-[35rem]",
56
+ translucent
57
+ ? [
58
+ "bg-transparent outline-1 outline-border-translucent",
59
+ "before:absolute before:inset-0 before:-z-10 before:rounded-[inherit] before:bg-translucent-low before:backdrop-blur-l",
60
+ ]
61
+ : "bg-surface-overlay",
62
+ "duration-150 data-[state=open]:animate-in data-[state=open]:zoom-in-0",
63
+ "data-[state=closed]:animate-out data-[state=closed]:fade-out-0",
64
+ "outline-none",
65
+ className,
66
+ )}
67
+ {...props}
68
+ >
69
+ <div className="max-h-[90vh] overflow-x-hidden overflow-y-auto px-4 pt-6 pb-4">{children}</div>
70
+ </AlertDialogPrimitive.Content>
71
+ </AlertDialogPortal>
72
+ );
73
+ }
74
+
75
+ /** Groups the title and description. Present for shadcn parity; adds no styling. */
76
+ export function AlertDialogHeader({ className, ...props }: React.ComponentProps<"div">) {
77
+ return <div className={className} {...props} />;
78
+ }
79
+
80
+ export function AlertDialogTitle({
81
+ className,
82
+ ...props
83
+ }: React.ComponentProps<typeof AlertDialogPrimitive.Title>) {
84
+ return (
85
+ <AlertDialogPrimitive.Title
86
+ className={cn(
87
+ "m-0 mb-2 max-w-full min-w-0 px-2 text-lg font-semibold wrap-break-word desktop:leading-6",
88
+ className,
89
+ )}
90
+ {...props}
91
+ />
92
+ );
93
+ }
94
+
95
+ /** The dialog's message. Swirl gives it the body text colour, not a subdued one. */
96
+ export function AlertDialogDescription({
97
+ className,
98
+ ...props
99
+ }: React.ComponentProps<typeof AlertDialogPrimitive.Description>) {
100
+ return (
101
+ <AlertDialogPrimitive.Description
102
+ className={cn(
103
+ "mb-5 px-2 leading-6 wrap-break-word min-[992px]:mb-6 desktop:text-sm desktop:leading-5",
104
+ className,
105
+ )}
106
+ {...props}
107
+ />
108
+ );
109
+ }
110
+
111
+ export interface AlertDialogFooterProps extends React.ComponentProps<"div"> {
112
+ /** `vertical` stacks the actions full width, as Swirl's `actionsOrientation`. */
113
+ orientation?: "horizontal" | "vertical";
114
+ }
115
+
116
+ /**
117
+ * The actions. On touch screens they share the full width; from 992px they
118
+ * sit at their natural width on the right.
119
+ */
120
+ export function AlertDialogFooter({
121
+ className,
122
+ orientation = "horizontal",
123
+ ...props
124
+ }: AlertDialogFooterProps) {
125
+ return (
126
+ <div
127
+ className={cn(
128
+ "flex w-full min-w-0 gap-2",
129
+ orientation === "vertical"
130
+ ? "flex-col items-stretch"
131
+ : "items-stretch *:min-w-0 *:flex-1 min-[992px]:justify-end min-[992px]:*:flex-initial",
132
+ className,
133
+ )}
134
+ {...props}
135
+ />
136
+ );
137
+ }
138
+
139
+ /** The confirming action: a flat button, primary unless `intent` says otherwise. */
140
+ export function AlertDialogAction({ variant = "flat", intent = "primary", ...props }: ButtonProps) {
141
+ return (
142
+ <AlertDialogPrimitive.Action asChild>
143
+ <Button variant={variant} intent={intent} {...props} />
144
+ </AlertDialogPrimitive.Action>
145
+ );
146
+ }
147
+
148
+ /** The dismissing action: a ghost button, as Swirl's secondary action. */
149
+ export function AlertDialogCancel({ variant = "ghost", ...props }: ButtonProps) {
150
+ return (
151
+ <AlertDialogPrimitive.Cancel asChild>
152
+ <Button variant={variant} {...props} />
153
+ </AlertDialogPrimitive.Cancel>
154
+ );
155
+ }