@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,144 @@
1
+ export { S as SwirlSpacing, c as cn, f as focusRing, a as focusRingInset, g as gap, b as gapX, d as gapY, p as padding, r as resolveAlias, s as spacingScale } from './spacing-BQaEPbUv.js';
2
+ import * as React from 'react';
3
+ import 'clsx';
4
+
5
+ /**
6
+ * Inline script that applies the stored theme class before first paint.
7
+ *
8
+ * This lives apart from `theme-provider.tsx` and is re-exported from
9
+ * `@enablo/swirlcn-ui/server` because it has to be callable from a *server* component
10
+ * - it belongs in the document `<head>`, and the component bundle is marked
11
+ * `"use client"`. It touches no React and no browser globals at call time; it
12
+ * only returns a string.
13
+ *
14
+ * Most apps want `<ThemeScript />` below instead. Use this directly only when
15
+ * the script has to go somewhere a React element cannot.
16
+ */
17
+ declare function themeScript(storageKey?: string): string;
18
+ interface ThemeScriptProps {
19
+ /** Must match the `storageKey` given to `ThemeProvider`. */
20
+ storageKey?: string;
21
+ /**
22
+ * CSP nonce for this request. Needed when the Content-Security-Policy does
23
+ * not allow inline scripts; omit it otherwise.
24
+ */
25
+ nonce?: string;
26
+ }
27
+ /**
28
+ * Renders `themeScript` as a `<script>` element. Place it in `<head>`.
29
+ *
30
+ * import { ThemeScript } from "@enablo/swirlcn-ui/server";
31
+ * <head><ThemeScript nonce={nonce} /></head>
32
+ *
33
+ * Written with `createElement` rather than JSX so it can stay a `.ts` file
34
+ * alongside the other server-safe helpers.
35
+ */
36
+ declare function ThemeScript({ storageKey, nonce }: ThemeScriptProps): React.DetailedReactHTMLElement<{
37
+ nonce: string | undefined;
38
+ suppressHydrationWarning: true;
39
+ dangerouslySetInnerHTML: {
40
+ __html: string;
41
+ };
42
+ }, HTMLElement>;
43
+
44
+ /**
45
+ * Inline script that marks `<html>` with `flip-app` inside Flip's mobile app,
46
+ * a Flutter webview that injects `window.FlipFlutter`, before first paint.
47
+ * `flip-app:` styles then apply from the start, so an app header hidden with
48
+ * `flip-app:hidden` never flashes; a React effect would run too late.
49
+ *
50
+ * Like `themeScript`, this is re-exported from `@enablo/swirlcn-ui/server` so
51
+ * it can render from a server component in the document `<head>`.
52
+ */
53
+ declare function flipAppScript(): string;
54
+ interface FlipAppScriptProps {
55
+ /** CSP nonce for this request, when inline scripts need one. */
56
+ nonce?: string;
57
+ }
58
+ /**
59
+ * Renders `flipAppScript` as a `<script>` element. Place it in `<head>`, and
60
+ * add `suppressHydrationWarning` to `<html>`: the class is there before React
61
+ * hydrates.
62
+ *
63
+ * import { FlipAppScript } from "@enablo/swirlcn-ui/server";
64
+ * <html lang="en" suppressHydrationWarning>
65
+ * <head><FlipAppScript /></head>
66
+ */
67
+ declare function FlipAppScript({ nonce }: FlipAppScriptProps): React.DetailedReactHTMLElement<{
68
+ nonce: string | undefined;
69
+ suppressHydrationWarning: true;
70
+ dangerouslySetInnerHTML: {
71
+ __html: string;
72
+ };
73
+ }, HTMLElement>;
74
+
75
+ /** One RGBA colour as Flip's branding API returns it. `a` runs 0-255. */
76
+ interface FlipColor {
77
+ r: number;
78
+ g: number;
79
+ b: number;
80
+ a: number;
81
+ }
82
+ interface FlipDesignToken {
83
+ /** A Swirl token name, such as `action-primary-default`. */
84
+ id: string;
85
+ color: FlipColor;
86
+ }
87
+ interface FlipTheme {
88
+ /** False when the tenant has not set up this theme. */
89
+ active?: boolean;
90
+ design_tokens?: FlipDesignToken[];
91
+ company_logo?: unknown;
92
+ company_icon?: unknown;
93
+ favicon?: unknown;
94
+ }
95
+ /**
96
+ * The response of `GET /api/branding/v4/bootstrap/web/themes`: the tenant's
97
+ * light and dark themes.
98
+ */
99
+ interface FlipThemes {
100
+ light?: FlipTheme;
101
+ dark?: FlipTheme;
102
+ }
103
+ /**
104
+ * CSS that applies a tenant's brand colours on top of swirlcn's theme.
105
+ *
106
+ * The selectors mirror the generated swirl-tokens stylesheet, so each block
107
+ * overrides its counterpart: light on `:root` and `.theme-light`, dark on
108
+ * `.theme-dark` and, when no class is set, under `prefers-color-scheme: dark`.
109
+ * A dark theme marked `active: false` is left out, so dark mode keeps Swirl's
110
+ * defaults.
111
+ *
112
+ * The output is meant to go into a `<style>` element as-is, so token ids are
113
+ * checked against `[a-z0-9-]` and every colour channel is coerced to a number.
114
+ * Returns an empty string when there is nothing to apply.
115
+ */
116
+ declare function flipThemeCss(themes: FlipThemes | null | undefined): string;
117
+
118
+ /**
119
+ * Fetches a tenant's themes and returns the CSS for them, or `null` when it
120
+ * cannot. Serves the cached copy for 5 minutes, and the last good copy when
121
+ * Flip is slow or down.
122
+ */
123
+ declare function fetchFlipBrandCss(origin: string): Promise<string | null>;
124
+ interface FlipBrandStyleProps {
125
+ /** The Flip tenant's origin, such as `https://acme.flip-app.com`. */
126
+ origin: string;
127
+ /** CSP nonce for the `<style>` element. */
128
+ nonce?: string;
129
+ }
130
+ /**
131
+ * A server component that renders a tenant's brand colours as
132
+ * `<style id="flip-brand">`, for the document `<head>`. Place it after the
133
+ * app's stylesheet so its values win.
134
+ *
135
+ * Renders nothing when the themes cannot be fetched and none are cached,
136
+ * which leaves Swirl's default colours.
137
+ *
138
+ * <head>
139
+ * <FlipBrandStyle origin="https://acme.flip-app.com" />
140
+ * </head>
141
+ */
142
+ declare function FlipBrandStyle({ origin, nonce }: FlipBrandStyleProps): Promise<React.JSX.Element | null>;
143
+
144
+ export { FlipAppScript, type FlipAppScriptProps, FlipBrandStyle, type FlipBrandStyleProps, type FlipColor, type FlipDesignToken, type FlipTheme, type FlipThemes, ThemeScript, type ThemeScriptProps, fetchFlipBrandCss, flipAppScript, flipThemeCss, themeScript };
package/dist/server.js ADDED
@@ -0,0 +1,88 @@
1
+ export { gap, gapX, gapY, padding, spacingScale } from './chunk-3DJWDNQL.js';
2
+ export { cn, focusRing, focusRingInset, resolveAlias } from './chunk-KZESIYUN.js';
3
+ import { createElement } from 'react';
4
+ import { jsx } from 'react/jsx-runtime';
5
+
6
+ function themeScript(storageKey = "swirlcn-theme") {
7
+ const key = JSON.stringify(storageKey).replace(/</g, "\\u003c");
8
+ return `(function(){try{var t=localStorage.getItem(${key});if(t==="light"||t==="dark"){document.documentElement.classList.add("theme-"+t)}}catch(e){}})()`;
9
+ }
10
+ function ThemeScript({ storageKey, nonce }) {
11
+ return createElement("script", {
12
+ nonce,
13
+ // Browsers hide a script's nonce from the DOM once it is parsed, so the
14
+ // attribute never matches during hydration.
15
+ suppressHydrationWarning: true,
16
+ dangerouslySetInnerHTML: { __html: themeScript(storageKey) }
17
+ });
18
+ }
19
+ function flipAppScript() {
20
+ return 'if(window.FlipFlutter)document.documentElement.classList.add("flip-app")';
21
+ }
22
+ function FlipAppScript({ nonce }) {
23
+ return createElement("script", {
24
+ nonce,
25
+ // Browsers hide a script's nonce from the DOM once it is parsed, so the
26
+ // attribute never matches during hydration.
27
+ suppressHydrationWarning: true,
28
+ dangerouslySetInnerHTML: { __html: flipAppScript() }
29
+ });
30
+ }
31
+
32
+ // src/lib/flip-theme-css.ts
33
+ var TOKEN_ID = /^[a-z0-9-]+$/;
34
+ var channel = (value) => {
35
+ const n = Math.round(Number(value));
36
+ return Number.isFinite(n) ? Math.min(255, Math.max(0, n)) : 0;
37
+ };
38
+ var rgba = ({ r, g, b, a }) => `rgba(${channel(r)},${channel(g)},${channel(b)},${Number((channel(a) / 255).toFixed(3))})`;
39
+ function declarations(theme) {
40
+ return (theme?.design_tokens ?? []).filter(
41
+ (token) => token != null && typeof token.id === "string" && TOKEN_ID.test(token.id) && token.color != null && typeof token.color === "object"
42
+ ).map((token) => `--s-${token.id}:${rgba(token.color)};`).join("");
43
+ }
44
+ function flipThemeCss(themes) {
45
+ if (!themes) return "";
46
+ const light = themes.light?.active === false ? "" : declarations(themes.light);
47
+ const dark = themes.dark?.active === false ? "" : declarations(themes.dark);
48
+ let css = "";
49
+ if (light) css += `:root,.theme-light{${light}}`;
50
+ if (dark) {
51
+ css += `.theme-dark{${dark}}`;
52
+ css += `@media (prefers-color-scheme:dark){:root:not(.theme-light){${dark}}}`;
53
+ }
54
+ return css;
55
+ }
56
+ var THEMES_PATH = "/api/branding/v4/bootstrap/web/themes";
57
+ var CACHE_MS = 5 * 60 * 1e3;
58
+ var TIMEOUT_MS = 2e3;
59
+ var cache = /* @__PURE__ */ new Map();
60
+ async function fetchFlipBrandCss(origin) {
61
+ let base;
62
+ try {
63
+ base = new URL(origin).origin;
64
+ } catch {
65
+ return null;
66
+ }
67
+ const cached = cache.get(base);
68
+ if (cached && Date.now() - cached.fetchedAt < CACHE_MS) return cached.css;
69
+ try {
70
+ const response = await fetch(`${base}${THEMES_PATH}`, {
71
+ headers: { accept: "application/json" },
72
+ signal: AbortSignal.timeout(TIMEOUT_MS)
73
+ });
74
+ if (!response.ok) throw new Error(`Flip themes: HTTP ${response.status}`);
75
+ const css = flipThemeCss(await response.json());
76
+ cache.set(base, { css, fetchedAt: Date.now() });
77
+ return css;
78
+ } catch {
79
+ return cached?.css ?? null;
80
+ }
81
+ }
82
+ async function FlipBrandStyle({ origin, nonce }) {
83
+ const css = await fetchFlipBrandCss(origin);
84
+ if (!css) return null;
85
+ return /* @__PURE__ */ jsx("style", { id: "flip-brand", nonce, dangerouslySetInnerHTML: { __html: css } });
86
+ }
87
+
88
+ export { FlipAppScript, FlipBrandStyle, ThemeScript, fetchFlipBrandCss, flipAppScript, flipThemeCss, themeScript };
@@ -0,0 +1,59 @@
1
+ import { ClassValue } from 'clsx';
2
+
3
+ /**
4
+ * Merges class names, letting a caller's utility win over the component's own.
5
+ * `twMerge` is what makes `<Button className="rounded-full">` actually override
6
+ * the variant's radius instead of producing two competing classes.
7
+ */
8
+ declare function cn(...inputs: ClassValue[]): string;
9
+ /**
10
+ * Resolves a Swirl prop and its shadcn-style alias down to one value.
11
+ *
12
+ * Every component accepts both spellings (`intent="critical"` and
13
+ * `variant="destructive"`); the Swirl prop wins when both are passed.
14
+ */
15
+ declare function resolveAlias<T extends string, A extends string>(swirl: T | undefined, alias: A | undefined, map: Record<A, T>, fallback: T): T;
16
+
17
+ /**
18
+ * Swirl's focus ring: a 2px outline in the focus token, offset by 2px, drawn
19
+ * only for keyboard focus. Shared by every interactive component so the ring is
20
+ * identical everywhere and can be changed in one place.
21
+ *
22
+ * Deliberately no `outline-none`: in Tailwind v4 that sets
23
+ * `--tw-outline-style: none` on the element, which also disables any resting
24
+ * `outline-*` the component uses as its border - that is what made unchecked
25
+ * radios and spaced toggle buttons render with no outline at all. Browsers
26
+ * only paint the UA ring on `:focus-visible` anyway, and these rules override
27
+ * it there.
28
+ */
29
+ declare const focusRing = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus";
30
+ /** For controls that sit flush against an edge, where an offset ring would clip. */
31
+ declare const focusRingInset = "focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus";
32
+
33
+ /**
34
+ * Swirl names spacing in pixels (`space-16`); Tailwind names it in 4px steps
35
+ * (`gap-4`). Every Swirl step exists in Tailwind's default scale, so this is a
36
+ * pure rename rather than a custom scale - see the note in the token generator.
37
+ */
38
+ declare const spacingScale: {
39
+ readonly "0": "0";
40
+ readonly "2": "0.5";
41
+ readonly "4": "1";
42
+ readonly "8": "2";
43
+ readonly "12": "3";
44
+ readonly "16": "4";
45
+ readonly "20": "5";
46
+ readonly "24": "6";
47
+ readonly "32": "8";
48
+ readonly "40": "10";
49
+ readonly "48": "12";
50
+ readonly "64": "16";
51
+ };
52
+ type SwirlSpacing = keyof typeof spacingScale;
53
+ /** `gap("16")` -> `"gap-4"` */
54
+ declare const gap: (s: SwirlSpacing) => "gap-0" | "gap-0.5" | "gap-1" | "gap-2" | "gap-3" | "gap-4" | "gap-5" | "gap-6" | "gap-8" | "gap-10" | "gap-12" | "gap-16";
55
+ declare const gapX: (s: SwirlSpacing) => "gap-x-0" | "gap-x-0.5" | "gap-x-1" | "gap-x-2" | "gap-x-3" | "gap-x-4" | "gap-x-5" | "gap-x-6" | "gap-x-8" | "gap-x-10" | "gap-x-12" | "gap-x-16";
56
+ declare const gapY: (s: SwirlSpacing) => "gap-y-0" | "gap-y-0.5" | "gap-y-1" | "gap-y-2" | "gap-y-3" | "gap-y-4" | "gap-y-5" | "gap-y-6" | "gap-y-8" | "gap-y-10" | "gap-y-12" | "gap-y-16";
57
+ declare const padding: (s: SwirlSpacing) => "p-0" | "p-0.5" | "p-1" | "p-2" | "p-3" | "p-4" | "p-5" | "p-6" | "p-8" | "p-10" | "p-12" | "p-16";
58
+
59
+ export { type SwirlSpacing as S, focusRingInset as a, gapX as b, cn as c, gapY as d, focusRing as f, gap as g, padding as p, resolveAlias as r, spacingScale as s };
package/dist/theme.css ADDED
@@ -0,0 +1,146 @@
1
+ /**
2
+ * The one stylesheet a consuming app needs.
3
+ *
4
+ * @import "tailwindcss";
5
+ * @import "@enablo/swirlcn-ui/theme.css";
6
+ *
7
+ * Brings in the generated Swirl token layer, a small base layer, and - when
8
+ * consuming the prebuilt npm package - a @source rule so Tailwind sees the
9
+ * class names baked into the shipped components. Apps that copied components in
10
+ * via the registry are scanned by Tailwind automatically and can ignore it.
11
+ */
12
+
13
+ @import "@enablo/swirlcn-tokens/theme.css";
14
+ @import "tw-animate-css";
15
+
16
+ /* Inter, as Swirl ships it. The family name is the first entry in
17
+ --s-font-family-text, so the token stack picks these up unchanged. The
18
+ paths are relative to this file; Tailwind rebases them when it inlines the
19
+ import, and the app's bundler emits the files. See fonts/OFL.txt. */
20
+ @font-face {
21
+ font-family: "Inter var experimental";
22
+ font-style: normal;
23
+ font-weight: 100 900;
24
+ font-display: swap;
25
+ src: url("./fonts/Inter.var.woff2") format("woff2");
26
+ }
27
+
28
+ @font-face {
29
+ font-family: "Inter var experimental";
30
+ font-style: italic;
31
+ font-weight: 100 900;
32
+ font-display: swap;
33
+ src: url("./fonts/Inter-italic.var.woff2") format("woff2");
34
+ }
35
+
36
+ /* Scan the bundle for class names - every file, not just index.js: helpers
37
+ shared with the /server entry (spacing, focus) land in a separate chunk.
38
+ Harmless when it resolves to nothing, as when imported straight from src. */
39
+ @source "./*.js";
40
+
41
+ /* Swirl switches buttons and inputs to a denser desktop layout - smaller
42
+ padding, type and radius - under this exact condition. It is not a plain
43
+ min-width breakpoint: between 992px and 1439px it also requires a real
44
+ pointer, so large touch tablets keep touch sizing. Components use
45
+ `desktop:`. */
46
+ @custom-variant desktop {
47
+ @media (min-width: 62rem) and (max-width: 89.9375rem) and (hover: hover),
48
+ (min-width: 90rem) {
49
+ @slot;
50
+ }
51
+ }
52
+
53
+ /* Inside Flip's mobile app, which can't hide its own header: `<FlipAppScript>`
54
+ marks <html> with `flip-app` before the first paint. Write `flip-app:hidden`
55
+ to drop the app's own header there, or `hidden flip-app:inline-flex` to
56
+ show something only there. */
57
+ @custom-variant flip-app (&:where(.flip-app, .flip-app *));
58
+
59
+ @layer base {
60
+ *,
61
+ ::after,
62
+ ::before {
63
+ border-color: var(--color-border);
64
+ }
65
+
66
+ html {
67
+ -webkit-text-size-adjust: 100%;
68
+ }
69
+
70
+ body {
71
+ background-color: var(--color-background);
72
+ color: var(--color-foreground);
73
+ font-family: var(--font-sans);
74
+ font-size: var(--text-base);
75
+ line-height: var(--s-line-height-base);
76
+ -webkit-font-smoothing: antialiased;
77
+ }
78
+
79
+ /* Swirl relies on a variable Inter; fall back cleanly when it is absent. */
80
+ @supports (font-variation-settings: normal) {
81
+ body {
82
+ font-optical-sizing: auto;
83
+ }
84
+ }
85
+
86
+ ::selection {
87
+ background-color: var(--color-highlight-surface);
88
+ color: var(--color-on-highlight);
89
+ }
90
+ }
91
+
92
+ @utility scrollbar-swirl {
93
+ scrollbar-width: thin;
94
+ scrollbar-color: var(--color-border-strong) transparent;
95
+ }
96
+
97
+ /* The indeterminate Progress sweep and Swirl's skeleton and spinner motion. tw-animate-css covers the rest. */
98
+ @theme {
99
+ --animate-spinner-rotate: spinner-rotate 2s linear infinite;
100
+ --animate-spinner-dash: spinner-dash 1.5s ease-in-out infinite;
101
+
102
+ @keyframes spinner-rotate {
103
+ 100% {
104
+ transform: rotate(360deg);
105
+ }
106
+ }
107
+
108
+ @keyframes spinner-dash {
109
+ 0% {
110
+ stroke-dasharray: 1, 200;
111
+ stroke-dashoffset: 0;
112
+ }
113
+ 50% {
114
+ stroke-dasharray: 89, 200;
115
+ stroke-dashoffset: -35;
116
+ }
117
+ 100% {
118
+ stroke-dasharray: 89, 200;
119
+ stroke-dashoffset: -124;
120
+ }
121
+ }
122
+
123
+ --animate-progress-indeterminate: progress-indeterminate 1.4s ease-in-out infinite;
124
+ --animate-skeleton-shimmer: skeleton-shimmer 3s infinite;
125
+
126
+ @keyframes skeleton-shimmer {
127
+ 0% {
128
+ transform: translateX(-100%);
129
+ }
130
+ 100% {
131
+ transform: translateX(100%);
132
+ }
133
+ }
134
+
135
+ @keyframes progress-indeterminate {
136
+ 0% {
137
+ transform: translateX(-100%) scaleX(0.4);
138
+ }
139
+ 50% {
140
+ transform: translateX(10%) scaleX(0.6);
141
+ }
142
+ 100% {
143
+ transform: translateX(100%) scaleX(0.4);
144
+ }
145
+ }
146
+ }
package/package.json CHANGED
@@ -1,6 +1,87 @@
1
1
  {
2
2
  "name": "@enablo/swirlcn-ui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.5.1",
4
+ "description": "A shadcn/ui-style React component library themed with the Flip Swirl design system.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/Enablo/swirlcn.git",
9
+ "directory": "packages/ui"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "type": "module",
15
+ "sideEffects": [
16
+ "*.css"
17
+ ],
18
+ "files": [
19
+ "dist",
20
+ "src",
21
+ "README.md"
22
+ ],
23
+ "main": "./dist/index.js",
24
+ "module": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "default": "./dist/index.js"
30
+ },
31
+ "./theme.css": "./dist/theme.css",
32
+ "./src/*": "./src/*",
33
+ "./server": {
34
+ "types": "./dist/server.d.ts",
35
+ "default": "./dist/server.js"
36
+ },
37
+ "./flip": {
38
+ "types": "./dist/flip.d.ts",
39
+ "default": "./dist/flip.js"
40
+ }
41
+ },
42
+ "dependencies": {
43
+ "class-variance-authority": "^0.7.1",
44
+ "clsx": "^2.1.1",
45
+ "date-fns": "^4.4.0",
46
+ "radix-ui": "^1.8.1",
47
+ "react-colorful": "^5.8.1",
48
+ "react-day-picker": "^10.0.2",
49
+ "tailwind-merge": "^3.7.0",
50
+ "tw-animate-css": "^1.4.0"
51
+ },
52
+ "peerDependencies": {
53
+ "@getflip/bridge": "^0.11.86",
54
+ "react": "^18.0.0 || ^19.0.0",
55
+ "react-dom": "^18.0.0 || ^19.0.0",
56
+ "tailwindcss": "^4.0.0",
57
+ "@enablo/swirlcn-tokens": "^0.5.1",
58
+ "@enablo/swirlcn-icons": "^0.5.1"
59
+ },
60
+ "peerDependenciesMeta": {
61
+ "@getflip/bridge": {
62
+ "optional": true
63
+ }
64
+ },
65
+ "devDependencies": {
66
+ "@getflip/bridge": "0.11.86",
67
+ "@types/react": "^19.3.0",
68
+ "@types/react-dom": "^19.3.0",
69
+ "eslint": "9.39.5",
70
+ "eslint-plugin-react-hooks": "7.1.1",
71
+ "react": "^19.3.0",
72
+ "react-dom": "^19.3.0",
73
+ "tailwindcss": "^4.3.3",
74
+ "tsup": "^8.5.1",
75
+ "typescript": "5.9.3",
76
+ "typescript-eslint": "8.71.0",
77
+ "@enablo/swirlcn-icons": "0.5.1",
78
+ "@enablo/swirlcn-tokens": "0.5.1"
79
+ },
80
+ "scripts": {
81
+ "build": "tsup && node scripts/postbuild.mjs",
82
+ "dev": "tsup --watch",
83
+ "typecheck": "tsc -p . --noEmit",
84
+ "test": "node --test \"test/**/*.test.ts\"",
85
+ "lint": "eslint ."
86
+ }
6
87
  }
@@ -0,0 +1,102 @@
1
+ import * as React from "react";
2
+ import { Accordion as AccordionPrimitive } from "radix-ui";
3
+ import { cn } from "../lib/utils";
4
+ import { Glyph } from "../lib/glyphs";
5
+
6
+ /**
7
+ * Swirl's accordion: a stack of sections, each opened by its heading.
8
+ * `type="single" collapsible` keeps one open at a time, as Swirl does by
9
+ * default; `type="multiple"` is Swirl's `multiExpand`.
10
+ */
11
+ export const Accordion = AccordionPrimitive.Root;
12
+
13
+ /** One section. Items are ruled off above, and the last one below too. */
14
+ export function AccordionItem({
15
+ className,
16
+ ...props
17
+ }: React.ComponentProps<typeof AccordionPrimitive.Item>) {
18
+ return (
19
+ <AccordionPrimitive.Item
20
+ className={cn("border-t border-border last:border-b", className)}
21
+ {...props}
22
+ />
23
+ );
24
+ }
25
+
26
+ export interface AccordionTriggerProps extends React.ComponentProps<typeof AccordionPrimitive.Trigger> {
27
+ /** A quieter line under the heading. */
28
+ description?: React.ReactNode;
29
+ /** Shown before the heading, such as an avatar. */
30
+ media?: React.ReactNode;
31
+ /** Shown after the heading, before the expand icon. */
32
+ trailing?: React.ReactNode;
33
+ /** The heading element's level. Defaults to 2, as in Swirl. */
34
+ headingLevel?: 1 | 2 | 3 | 4 | 5 | 6;
35
+ }
36
+
37
+ /** The section's heading: a button that opens and closes it. */
38
+ export function AccordionTrigger({
39
+ className,
40
+ children,
41
+ description,
42
+ media,
43
+ trailing,
44
+ headingLevel = 2,
45
+ ...props
46
+ }: AccordionTriggerProps) {
47
+ const Heading = `h${headingLevel}` as const;
48
+ return (
49
+ <AccordionPrimitive.Header asChild>
50
+ <Heading className="m-0 p-0 text-base font-semibold desktop:text-sm">
51
+ <AccordionPrimitive.Trigger
52
+ className={cn(
53
+ "group flex w-full cursor-pointer items-center gap-4 border-0 bg-transparent py-4 pr-0 pl-2 text-start",
54
+ "leading-6 text-foreground desktop:leading-5",
55
+ "hover:bg-state-hovered active:bg-state-pressed",
56
+ "disabled:cursor-default disabled:bg-transparent disabled:text-disabled",
57
+ "outline-focus focus:not-focus-visible:outline-none focus-visible:outline-2 focus-visible:outline-solid",
58
+ className,
59
+ )}
60
+ {...props}
61
+ >
62
+ {media}
63
+ <span className="flex grow flex-col">
64
+ {children}
65
+ {description && (
66
+ // Swirl's description takes the heading's line height: 24px on phones, 20px on desktop.
67
+ <span className="text-sm leading-6 font-normal text-subdued group-disabled:text-disabled desktop:leading-5">
68
+ {description}
69
+ </span>
70
+ )}
71
+ </span>
72
+ {trailing}
73
+ {/* Swirl swaps a chevron for an expand icon rather than turning one. */}
74
+ <span aria-hidden className="inline-flex shrink-0 pr-2 [&>svg]:size-5">
75
+ <Glyph name="chevronRight" className="group-data-[state=open]:hidden" />
76
+ <Glyph name="expandMore" className="hidden group-data-[state=open]:block" />
77
+ </span>
78
+ </AccordionPrimitive.Trigger>
79
+ </Heading>
80
+ </AccordionPrimitive.Header>
81
+ );
82
+ }
83
+
84
+ /** The section's content, which slides open under its heading. */
85
+ export function AccordionContent({
86
+ className,
87
+ children,
88
+ ...props
89
+ }: React.ComponentProps<typeof AccordionPrimitive.Content>) {
90
+ return (
91
+ <AccordionPrimitive.Content
92
+ // Radix publishes the measured height, which is what makes the slide work.
93
+ className={cn(
94
+ "overflow-hidden duration-150 motion-reduce:animate-none",
95
+ "data-[state=open]:animate-accordion-down data-[state=closed]:animate-accordion-up",
96
+ )}
97
+ {...props}
98
+ >
99
+ <div className={cn("py-4 desktop:pt-2", className)}>{children}</div>
100
+ </AccordionPrimitive.Content>
101
+ );
102
+ }