@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,112 @@
1
+ import { cva, type VariantProps } from "class-variance-authority";
2
+ import { cn } from "../lib/utils";
3
+
4
+ const bannerVariants = cva(
5
+ [
6
+ "flex min-h-14 w-full items-start gap-4 p-4 text-base leading-6",
7
+ "desktop:min-h-13 desktop:text-sm desktop:leading-5",
8
+ ],
9
+ {
10
+ variants: {
11
+ intent: {
12
+ info: "bg-surface-info text-on-status",
13
+ success: "bg-surface-success text-on-status",
14
+ warning: "bg-surface-warning text-foreground",
15
+ critical: "bg-surface-critical text-on-status",
16
+ neutral: "bg-surface-neutral text-on-status",
17
+ },
18
+ },
19
+ defaultVariants: { intent: "info" },
20
+ },
21
+ );
22
+
23
+ /* Swirl's banner controls are bare text, not buttons: semibold, no padding,
24
+ one line tall, truncating past 7rem (12rem from 768px). */
25
+ const control = [
26
+ "inline-flex h-6 max-w-28 shrink-0 cursor-pointer items-center overflow-hidden p-0 md:max-w-48",
27
+ "bg-transparent font-semibold text-ellipsis whitespace-nowrap text-current",
28
+ "rounded-xs focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus",
29
+ "desktop:h-5",
30
+ ];
31
+
32
+ export interface BannerProps
33
+ extends React.ComponentProps<"div">,
34
+ VariantProps<typeof bannerVariants> {
35
+ /** Leading icon. Hidden below 375px, as in Swirl. */
36
+ icon?: React.ReactNode;
37
+ /** Swirl's action: a text button with this label, calling `onAction`. */
38
+ actionLabel?: string;
39
+ onAction?: () => void;
40
+ /** A custom action element, in place of `actionLabel`. */
41
+ action?: React.ReactNode;
42
+ /** Shows a dismiss button that calls this. */
43
+ onDismiss?: () => void;
44
+ dismissLabel?: string;
45
+ }
46
+
47
+ /**
48
+ * A full-width, filled message pinned to the top of a region.
49
+ *
50
+ * Use this for system-wide state (maintenance, connectivity); use
51
+ * `InlineNotification` for a message about the content it sits beside.
52
+ */
53
+ export function Banner({
54
+ className,
55
+ intent,
56
+ icon,
57
+ actionLabel,
58
+ onAction,
59
+ action,
60
+ onDismiss,
61
+ dismissLabel = "Dismiss",
62
+ children,
63
+ ...props
64
+ }: BannerProps) {
65
+ const hasControls = Boolean(actionLabel || action || onDismiss);
66
+
67
+ return (
68
+ <div role="status" className={cn(bannerVariants({ intent }), className)} {...props}>
69
+ <div className="flex min-h-6 grow items-start desktop:min-h-5">
70
+ {icon && (
71
+ <span
72
+ aria-hidden
73
+ className={cn(
74
+ "mr-2 hidden size-6 shrink-0 min-[375px]:inline-flex desktop:size-5 [&>svg]:size-full",
75
+ intent === "warning" && "text-icon-strong",
76
+ )}
77
+ >
78
+ {icon}
79
+ </span>
80
+ )}
81
+ <span className="min-w-0">{children}</span>
82
+ </div>
83
+ {hasControls && (
84
+ <div className="inline-flex shrink-0 items-start gap-4 md:gap-6">
85
+ {action}
86
+ {actionLabel && !action && (
87
+ <button type="button" className={cn(control)} onClick={onAction}>
88
+ {actionLabel}
89
+ </button>
90
+ )}
91
+ {onDismiss && (
92
+ <button
93
+ type="button"
94
+ aria-label={dismissLabel}
95
+ className={cn(control)}
96
+ onClick={onDismiss}
97
+ >
98
+ <svg viewBox="0 0 24 24" className="size-6 desktop:size-5" aria-hidden focusable={false}>
99
+ <path
100
+ d="M12 13.6L7.19999 18.4C6.98333 18.6167 6.71666 18.725 6.39999 18.725C6.08333 18.725 5.81666 18.6167 5.59999 18.4C5.38333 18.1834 5.27499 17.9167 5.27499 17.6C5.27499 17.2834 5.38333 17.0167 5.59999 16.8L10.4 12L5.59999 7.20002C5.38333 6.98336 5.27499 6.71669 5.27499 6.40002C5.27499 6.08336 5.38333 5.81669 5.59999 5.60002C5.81666 5.38336 6.08333 5.27502 6.39999 5.27502C6.71666 5.27502 6.98333 5.38336 7.19999 5.60002L12 10.4L16.8 5.60002C17.0167 5.38336 17.2833 5.27502 17.6 5.27502C17.9167 5.27502 18.1833 5.38336 18.4 5.60002C18.6167 5.81669 18.725 6.08336 18.725 6.40002C18.725 6.71669 18.6167 6.98336 18.4 7.20002L13.6 12L18.4 16.8C18.6167 17.0167 18.725 17.2834 18.725 17.6C18.725 17.9167 18.6167 18.1834 18.4 18.4C18.1833 18.6167 17.9167 18.725 17.6 18.725C17.2833 18.725 17.0167 18.6167 16.8 18.4L12 13.6Z"
101
+ fill="currentColor"
102
+ />
103
+ </svg>
104
+ </button>
105
+ )}
106
+ </div>
107
+ )}
108
+ </div>
109
+ );
110
+ }
111
+
112
+ export { bannerVariants };
@@ -0,0 +1,87 @@
1
+ import { cn } from "../lib/utils";
2
+ import { gap, type SwirlSpacing } from "../lib/spacing";
3
+
4
+ /* Segmented: square off the inner corners and draw Swirl's divider - a
5
+ hairline inset 8px from each end - over the seam between buttons. The `!`
6
+ beats the buttons' own radius, which `desktop:` would otherwise restore. */
7
+ const segmentedHorizontal = cn(
8
+ "*:not-first:rounded-l-none! *:not-last:rounded-r-none!",
9
+ // Outlined buttons each draw their own edge; overlap them so the seam is
10
+ // one hairline, not two.
11
+ "*:data-[variant=outline]:not-first:-ml-px",
12
+ "*:not-last:relative *:not-last:after:pointer-events-none *:not-last:after:absolute *:not-last:after:z-1",
13
+ "*:not-last:after:top-1/2 *:not-last:after:left-full *:not-last:after:-translate-x-1/2 *:not-last:after:-translate-y-1/2",
14
+ "*:not-last:after:h-[calc(100%-1rem)] *:not-last:after:w-px",
15
+ );
16
+
17
+ const segmentedVertical = cn(
18
+ "*:not-first:rounded-t-none! *:not-last:rounded-b-none!",
19
+ "*:data-[variant=outline]:not-first:-mt-px",
20
+ "*:not-last:relative *:not-last:after:pointer-events-none *:not-last:after:absolute *:not-last:after:z-1",
21
+ "*:not-last:after:top-full *:not-last:after:left-1/2 *:not-last:after:-translate-x-1/2 *:not-last:after:-translate-y-1/2",
22
+ "*:not-last:after:h-px *:not-last:after:w-[calc(100%-1rem)]",
23
+ );
24
+
25
+ /* The divider sits on the button's own background, so on a filled primary
26
+ button it takes the button's text colour instead of the border colour. */
27
+ const dividerColour = cn(
28
+ "*:not-last:after:bg-border-strong",
29
+ // Outlined buttons already have an edge at the seam; a divider over it
30
+ // would double the translucent border colour.
31
+ "*:data-[variant=outline]:after:hidden",
32
+ "*:data-[variant=flat]:data-[intent=primary]:not-disabled:not-last:after:bg-on-primary",
33
+ );
34
+
35
+ export interface ButtonGroupProps extends React.ComponentProps<"div"> {
36
+ orientation?: "horizontal" | "vertical";
37
+ /** Join the buttons into one control, with a divider between each. */
38
+ segmented?: boolean;
39
+ /** Gap between buttons, in Swirl's px steps. Ignored when `segmented`. */
40
+ spacing?: SwirlSpacing;
41
+ /** Make the buttons share the full width (horizontal) or fill it (vertical). */
42
+ stretch?: boolean;
43
+ /** Let a horizontal group wrap onto further lines. */
44
+ wrap?: boolean;
45
+ }
46
+
47
+ /**
48
+ * Swirl's button group: lays out related `Button`s, optionally joined into one
49
+ * segmented control.
50
+ *
51
+ * Unlike shadcn's `ButtonGroup`, which is always joined, this follows Swirl
52
+ * and spaces the buttons apart unless `segmented` is set. For buttons that
53
+ * hold a selected state, use `ToggleGroup` instead.
54
+ */
55
+ export function ButtonGroup({
56
+ className,
57
+ orientation = "horizontal",
58
+ segmented = false,
59
+ spacing = "8",
60
+ stretch = false,
61
+ wrap = false,
62
+ ...props
63
+ }: ButtonGroupProps) {
64
+ const vertical = orientation === "vertical";
65
+
66
+ return (
67
+ <div
68
+ role="group"
69
+ data-orientation={orientation}
70
+ className={cn(
71
+ "flex",
72
+ vertical ? "flex-col" : "flex-row",
73
+ // A joined column has to be one width; without `stretch` it takes the
74
+ // width of its widest button rather than the container's.
75
+ vertical && (stretch || segmented) ? "items-stretch" : "items-start",
76
+ vertical && segmented && !stretch && "w-fit",
77
+ !vertical && stretch && "*:flex-1",
78
+ wrap && "flex-wrap",
79
+ segmented ? "gap-0" : gap(spacing),
80
+ segmented && (vertical ? segmentedVertical : segmentedHorizontal),
81
+ segmented && dividerColour,
82
+ className,
83
+ )}
84
+ {...props}
85
+ />
86
+ );
87
+ }
@@ -0,0 +1,362 @@
1
+ import { Slot } from "radix-ui";
2
+ import { cva, type VariantProps } from "class-variance-authority";
3
+ import { cn } from "../lib/utils";
4
+ import { focusRing } from "../lib/focus";
5
+ import { Spinner } from "./spinner";
6
+
7
+ /**
8
+ * Swirl models a button as `variant` (how it is drawn) x `intent` (what it
9
+ * means) x `size`, rather than shadcn's single flattened `variant`. Both APIs
10
+ * are accepted: see `shadcnVariants` below.
11
+ */
12
+ export type ButtonVariant =
13
+ | "ghost"
14
+ | "flat"
15
+ | "outline"
16
+ | "plain"
17
+ | "floating"
18
+ | "on-image"
19
+ | "translucent";
20
+
21
+ export type ButtonIntent = "default" | "primary" | "critical" | "strong";
22
+ export type ButtonSize = "s" | "m" | "l";
23
+
24
+ /** shadcn's `variant` values, mapped onto Swirl's variant + intent pair. */
25
+ const shadcnVariants = {
26
+ default: { variant: "flat", intent: "primary" },
27
+ destructive: { variant: "flat", intent: "critical" },
28
+ secondary: { variant: "flat", intent: "default" },
29
+ link: { variant: "plain", intent: "primary" },
30
+ // `ghost` and `outline` mean the same thing in both systems.
31
+ ghost: { variant: "ghost", intent: "default" },
32
+ outline: { variant: "outline", intent: "default" },
33
+ } as const satisfies Record<string, { variant: ButtonVariant; intent: ButtonIntent }>;
34
+
35
+ export type ShadcnButtonVariant = keyof typeof shadcnVariants;
36
+
37
+ /** shadcn's `size` values, mapped onto Swirl's scale. */
38
+ const shadcnSizes = { sm: "s", default: "m", lg: "l", icon: "m" } as const;
39
+
40
+ export type ShadcnButtonSize = keyof typeof shadcnSizes;
41
+
42
+ const buttonVariants = cva(
43
+ [
44
+ "inline-flex max-w-full shrink-0 items-center justify-center",
45
+ "font-medium no-underline transition-[box-shadow,background-color,color]",
46
+ // Swirl's buttons are touch-sized on small screens and denser from 992px up.
47
+ "gap-2 text-base leading-6 desktop:gap-1 desktop:text-sm desktop:leading-5",
48
+ "cursor-pointer disabled:cursor-default",
49
+ focusRing,
50
+ // Any icon inside inherits the button's colour.
51
+ "[&_svg]:pointer-events-none [&_svg]:shrink-0",
52
+ ],
53
+ {
54
+ variants: {
55
+ variant: {
56
+ ghost: "bg-transparent text-subdued hover:bg-state-hovered active:bg-state-pressed",
57
+ flat: "bg-neutral text-foreground hover:bg-neutral-hovered active:bg-neutral-pressed",
58
+ outline: [
59
+ "bg-transparent text-subdued outline-1 -outline-offset-1 outline-border-strong",
60
+ "hover:bg-state-hovered active:bg-state-pressed",
61
+ "disabled:outline-border",
62
+ ],
63
+ plain: [
64
+ "rounded-none bg-transparent p-0 text-subdued",
65
+ "hover:bg-transparent hover:underline hover:underline-offset-4",
66
+ "active:bg-transparent",
67
+ ],
68
+ floating: [
69
+ "bg-surface-overlay text-foreground shadow-level-1",
70
+ "hover:bg-surface-overlay-hovered active:bg-surface-overlay-pressed",
71
+ ],
72
+ "on-image": [
73
+ "bg-black/60 text-on-image hover:bg-black/50 active:bg-black/40",
74
+ "disabled:bg-black/30 disabled:text-on-image",
75
+ ],
76
+ translucent: [
77
+ "bg-translucent-medium text-foreground shadow-level-2 backdrop-blur-s",
78
+ "outline-1 -outline-offset-1 outline-border-translucent",
79
+ "hover:bg-translucent-medium-hovered active:bg-translucent-medium-pressed",
80
+ "disabled:bg-translucent-medium disabled:text-subdued",
81
+ ],
82
+ },
83
+ intent: {
84
+ default: "",
85
+ primary: "",
86
+ critical: "",
87
+ strong: "",
88
+ },
89
+ // Icons follow Swirl: 20px on small buttons, and 24px shrinking to 20px
90
+ // with the desktop layout, so an icon-only button stays as tall as a
91
+ // labelled one beside it.
92
+ size: {
93
+ s: "min-h-7 min-w-5 gap-1 rounded-sm px-2 py-1 text-sm leading-5 [&>svg]:size-5",
94
+ m: [
95
+ "min-w-6 rounded-base px-4 py-2 desktop:min-w-5 desktop:rounded-sm desktop:px-3",
96
+ "[&>svg]:size-6 desktop:[&>svg]:size-5",
97
+ ],
98
+ l: [
99
+ "min-w-6 rounded-base px-5 py-3 desktop:min-w-5 desktop:rounded-sm",
100
+ "[&>svg]:size-6 desktop:[&>svg]:size-5",
101
+ ],
102
+ },
103
+ iconOnly: { true: "w-auto", false: "" },
104
+ pill: { true: "", false: "" },
105
+ pressed: { true: "", false: "" },
106
+ elevated: { true: "shadow-level-2", false: "" },
107
+ block: { true: "w-full", false: "w-auto" },
108
+ },
109
+ compoundVariants: [
110
+ /* ---- intent colouring, per variant ---- */
111
+ { variant: "ghost", intent: "strong", class: "text-foreground" },
112
+ { variant: "ghost", intent: "primary", class: "text-highlight" },
113
+ { variant: "ghost", intent: "critical", class: "text-critical" },
114
+ { variant: "ghost", pressed: true, class: "text-highlight" },
115
+
116
+ { variant: "flat", intent: "strong", class: "text-foreground" },
117
+ {
118
+ variant: "flat",
119
+ intent: "primary",
120
+ class:
121
+ "bg-primary text-on-primary hover:bg-primary-hovered active:bg-primary-pressed disabled:bg-primary-disabled disabled:text-disabled",
122
+ },
123
+ {
124
+ variant: "flat",
125
+ intent: "critical",
126
+ class:
127
+ "bg-action-critical text-on-status hover:bg-action-critical-hovered active:bg-action-critical-pressed disabled:bg-action-critical-disabled disabled:text-disabled",
128
+ },
129
+
130
+ { variant: "outline", intent: "strong", class: "text-foreground" },
131
+ { variant: "outline", intent: "primary", class: "text-highlight outline-border-highlight" },
132
+ { variant: "outline", intent: "critical", class: "text-critical outline-border-critical" },
133
+
134
+ { variant: "plain", intent: "strong", class: "text-foreground" },
135
+ {
136
+ variant: "plain",
137
+ intent: "primary",
138
+ class:
139
+ "text-interactive-primary hover:text-interactive-primary-hovered active:text-interactive-primary-pressed disabled:text-interactive-primary-disabled",
140
+ },
141
+ {
142
+ variant: "plain",
143
+ intent: "critical",
144
+ class:
145
+ "text-interactive-critical hover:text-interactive-critical-hovered disabled:text-disabled",
146
+ },
147
+ // Swirl's plain button keeps its own padding at every size.
148
+ { variant: "plain", size: "s", class: "p-0" },
149
+ { variant: "plain", size: "m", class: "p-0 desktop:p-0" },
150
+ { variant: "plain", size: "l", class: "p-0" },
151
+
152
+ // The floating primary button is Swirl's FAB: fully rounded and filled.
153
+ {
154
+ variant: "floating",
155
+ intent: "primary",
156
+ class:
157
+ "rounded-3xl bg-primary px-5 py-3 text-on-primary hover:bg-primary-hovered active:bg-primary-pressed",
158
+ },
159
+
160
+ /* ---- icon-only padding, which Swirl squares off per size ---- */
161
+ { iconOnly: true, size: "s", class: "min-w-7 p-1" },
162
+ // Restate the padding under desktop: too, or the size's desktop:px-3
163
+ // wins and the button comes out 44px wide instead of square.
164
+ { iconOnly: true, size: "m", class: "min-w-10 p-2 desktop:p-2" },
165
+ { iconOnly: true, size: "l", class: "min-w-12 p-3" },
166
+ { iconOnly: true, variant: "plain", class: "min-w-0 p-0 desktop:p-0" },
167
+
168
+ /* ---- pill radii, which Swirl hard-codes per size ---- */
169
+ { pill: true, size: "s", class: "rounded-[0.875rem]" },
170
+ { pill: true, size: "m", class: "rounded-[1.25rem] desktop:rounded-[1.125rem]" },
171
+ { pill: true, size: "l", class: "rounded-[1.5rem] desktop:rounded-[1.375rem]" },
172
+
173
+ /* ---- disabled, for every variant that is not separately handled ---- */
174
+ {
175
+ variant: ["ghost", "outline", "floating", "translucent"],
176
+ class: "disabled:text-disabled",
177
+ },
178
+ {
179
+ variant: "flat",
180
+ intent: ["default", "strong"],
181
+ class: "disabled:bg-neutral-disabled disabled:text-disabled",
182
+ },
183
+ ],
184
+ defaultVariants: {
185
+ variant: "ghost",
186
+ intent: "default",
187
+ size: "m",
188
+ iconOnly: false,
189
+ pill: false,
190
+ pressed: false,
191
+ elevated: false,
192
+ block: false,
193
+ },
194
+ },
195
+ );
196
+
197
+ type ButtonVariantProps = Omit<
198
+ VariantProps<typeof buttonVariants>,
199
+ "variant" | "intent" | "size" | "iconOnly"
200
+ >;
201
+
202
+ export interface ButtonProps
203
+ extends Omit<React.ComponentProps<"button">, "children">,
204
+ ButtonVariantProps {
205
+ /**
206
+ * How the button is drawn. Accepts Swirl's variants (`ghost`, `flat`,
207
+ * `outline`, `plain`, `floating`, `on-image`, `translucent`) and shadcn's
208
+ * (`default`, `destructive`, `secondary`, `link`, `ghost`, `outline`).
209
+ */
210
+ variant?: ButtonVariant | ShadcnButtonVariant;
211
+ /** What the button means. Overrides any intent implied by a shadcn `variant`. */
212
+ intent?: ButtonIntent;
213
+ /** Swirl's `s`/`m`/`l`, or shadcn's `sm`/`default`/`lg`/`icon`. */
214
+ size?: ButtonSize | ShadcnButtonSize;
215
+ /** The button's text. Also used as the accessible name when `hideLabel` is set. */
216
+ label?: string;
217
+ /** Render icon-only while keeping `label` as the accessible name. */
218
+ hideLabel?: boolean;
219
+ /** Icon element, rendered at `iconPosition`. */
220
+ icon?: React.ReactNode;
221
+ iconPosition?: "start" | "end";
222
+ /** Swap the icon for a spinner and block interaction. */
223
+ loading?: boolean;
224
+ /** Render as an `<a>` instead of a `<button>`. */
225
+ href?: string;
226
+ target?: string;
227
+ download?: string;
228
+ /** Stretch to the width of the container. */
229
+ block?: boolean;
230
+ /** Merge props onto the single child instead of rendering an element. */
231
+ asChild?: boolean;
232
+ children?: React.ReactNode;
233
+ }
234
+
235
+ /**
236
+ * Swirl's button.
237
+ *
238
+ * `label` and `children` are interchangeable - `label` matches the Swirl API,
239
+ * `children` matches shadcn. Pass `hideLabel` for an icon button and the label
240
+ * becomes the accessible name.
241
+ */
242
+ export function Button({
243
+ className,
244
+ variant,
245
+ intent,
246
+ size,
247
+ label,
248
+ hideLabel = false,
249
+ icon,
250
+ iconPosition = "start",
251
+ loading = false,
252
+ pill,
253
+ pressed,
254
+ elevated,
255
+ block,
256
+ href,
257
+ target,
258
+ download,
259
+ asChild = false,
260
+ disabled,
261
+ children,
262
+ type = "button",
263
+ ...props
264
+ }: ButtonProps) {
265
+ // Resolve the dual API down to Swirl's variant + intent + size.
266
+ const alias = variant && variant in shadcnVariants
267
+ ? shadcnVariants[variant as ShadcnButtonVariant]
268
+ : undefined;
269
+
270
+ const resolvedVariant = (alias?.variant ?? variant ?? "ghost") as ButtonVariant;
271
+ const resolvedIntent = intent ?? alias?.intent ?? "default";
272
+ const resolvedSize = (size && size in shadcnSizes
273
+ ? shadcnSizes[size as ShadcnButtonSize]
274
+ : (size ?? "m")) as ButtonSize;
275
+
276
+ const content = children ?? label;
277
+ const iconOnly = hideLabel || size === "icon" || (!content && Boolean(icon));
278
+ const isDisabled = disabled || loading;
279
+
280
+ const classes = cn(
281
+ buttonVariants({
282
+ variant: resolvedVariant,
283
+ intent: resolvedIntent,
284
+ size: resolvedSize,
285
+ iconOnly,
286
+ pill,
287
+ pressed,
288
+ elevated,
289
+ block,
290
+ }),
291
+ className,
292
+ );
293
+
294
+ // `asChild` hands styling to the caller's element and renders nothing itself,
295
+ // so the icon/label scaffolding below is deliberately skipped.
296
+ if (asChild) {
297
+ return (
298
+ <Slot.Root
299
+ className={classes}
300
+ data-variant={resolvedVariant}
301
+ data-intent={resolvedIntent}
302
+ data-pressed={pressed || undefined}
303
+ {...props}
304
+ >
305
+ {children}
306
+ </Slot.Root>
307
+ );
308
+ }
309
+
310
+ // The spinner takes the icon's place, so it takes the icon's size and colour.
311
+ const spinnerSize = resolvedSize === "l" ? "s" : "xs";
312
+ const leading = loading ? <Spinner size={spinnerSize} label={null} inheritColor /> : icon;
313
+
314
+ const body = (
315
+ <>
316
+ {iconPosition === "start" && leading}
317
+ {!iconOnly &&
318
+ // A text label stays on one line and ends in an ellipsis when the
319
+ // button is squeezed, as Swirl's does.
320
+ (typeof content === "string" || typeof content === "number" ? (
321
+ <span className="min-w-0 truncate">{content}</span>
322
+ ) : (
323
+ content
324
+ ))}
325
+ {iconPosition === "end" && leading}
326
+ {iconOnly && label && <span className="sr-only">{label}</span>}
327
+ </>
328
+ );
329
+
330
+ const shared = {
331
+ className: classes,
332
+ "aria-busy": loading || undefined,
333
+ // Resolved values, so a parent such as ButtonGroup can style by them
334
+ // whichever API the caller used.
335
+ "data-variant": resolvedVariant,
336
+ "data-intent": resolvedIntent,
337
+ "data-pressed": pressed || undefined,
338
+ };
339
+
340
+ if (href !== undefined) {
341
+ return (
342
+ <a
343
+ href={isDisabled ? undefined : href}
344
+ target={target}
345
+ download={download}
346
+ aria-disabled={isDisabled || undefined}
347
+ {...shared}
348
+ {...(props as React.ComponentProps<"a">)}
349
+ >
350
+ {body}
351
+ </a>
352
+ );
353
+ }
354
+
355
+ return (
356
+ <button type={type} disabled={isDisabled} aria-pressed={pressed ?? undefined} {...shared} {...props}>
357
+ {body}
358
+ </button>
359
+ );
360
+ }
361
+
362
+ export { buttonVariants };