@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
package/dist/flip.d.ts ADDED
@@ -0,0 +1,98 @@
1
+ import * as React from 'react';
2
+
3
+ interface FlipThemeSyncProps {
4
+ /**
5
+ * The Flip origins this app may be embedded in, such as
6
+ * `["https://acme.flip-app.com"]`. Outside them it does nothing. In Flip's
7
+ * mobile app the first one is used.
8
+ */
9
+ origins: readonly string[];
10
+ }
11
+ /**
12
+ * Follows the user's light or dark setting in Flip while the app is embedded
13
+ * there. Flip owns the theme while embedded: the app's own theme choice is
14
+ * overridden for as long as it runs inside one of `origins`, and left alone
15
+ * everywhere else.
16
+ *
17
+ * Inside a `ThemeProvider` it sets the provider's theme without saving it;
18
+ * without one it sets the `theme-light` / `theme-dark` class on `<html>`.
19
+ * Renders nothing.
20
+ *
21
+ * <body>
22
+ * <FlipThemeSync origins={["https://acme.flip-app.com"]} />
23
+ * {children}
24
+ * </body>
25
+ */
26
+ declare function FlipThemeSync({ origins }: FlipThemeSyncProps): null;
27
+
28
+ interface FlipAppHeaderProps extends Omit<React.ComponentProps<"header">, "title"> {
29
+ /** The Flip origins this app may be embedded in, as for `FlipThemeSync`. */
30
+ origins: readonly string[];
31
+ /** The page title, shown as the page's `<h1>`. */
32
+ title: React.ReactNode;
33
+ /**
34
+ * A link back, such as `<a href="/" />` or your router's `<Link href="/" />`.
35
+ * The header styles it as Flip's back arrow and fills it with the icon and
36
+ * `backLabel`, so its own children are replaced.
37
+ */
38
+ back?: React.ReactElement<{
39
+ children?: React.ReactNode;
40
+ }>;
41
+ /** Accessible name of the back link. */
42
+ backLabel?: string;
43
+ /** Accessible name of the button that closes the app, shown in Flip's web app on phones. */
44
+ closeLabel?: string;
45
+ /** Trailing content, such as an avatar or a button. */
46
+ actions?: React.ReactNode;
47
+ }
48
+ /**
49
+ * A header for an app embedded in Flip, drawn like Flip's own: a centred
50
+ * title between a back arrow and actions on phones, a left-aligned larger
51
+ * title on desktop.
52
+ *
53
+ * - **Flip's web app** can turn off its own header for an app (do so, to
54
+ * avoid two headers). On phones, with no `back` link, the header then shows
55
+ * an arrow that closes the app through the Flip bridge.
56
+ * - **Flip's mobile app** can't turn its header off, so this one hides there
57
+ * (`flip-app:hidden`; needs `<FlipAppScript>` in `<head>`). Flip's header
58
+ * shows the menu item's name, which the app can't change.
59
+ *
60
+ * <FlipAppHeader origins={FLIP_ORIGINS} title="Weekly Calls"
61
+ * back={<Link href="/" />} backLabel="Back to Weekly Calls" />
62
+ */
63
+ declare function FlipAppHeader({ origins, title, back, backLabel, closeLabel, actions, className, ...props }: FlipAppHeaderProps): React.JSX.Element;
64
+
65
+ /**
66
+ * Where an app embedded in Flip is running:
67
+ * - `"web"`: in an iframe in Flip's web app, at one of the given origins;
68
+ * - `"app"`: in Flip's mobile app, a Flutter webview. The bridge talks to it
69
+ * through `window.FlipFlutter.postMessage` rather than `postMessage` on a
70
+ * parent window, and its own header can't be turned off.
71
+ */
72
+ interface FlipHost {
73
+ origin: string;
74
+ kind: "web" | "app";
75
+ }
76
+ /**
77
+ * Detects Flip around this page, or `null` outside it. Browser only.
78
+ *
79
+ * In Flip's mobile app the host is `origins[0]`, since a webview has no parent
80
+ * origin to read. In an iframe, the parent's origin must be one of `origins`:
81
+ * `ancestorOrigins` is exact where supported (Chromium, Safari), and the
82
+ * referrer is the best signal elsewhere.
83
+ */
84
+ declare function flipHost(origins: readonly string[]): FlipHost | null;
85
+ /** Starts the Flip bridge for `host`, once: a second `initFlipBridge` only logs a warning. */
86
+ declare function ensureFlipBridge(host: FlipHost): void;
87
+ /**
88
+ * Asks Flip to close this app, as its own header's back arrow would. For an
89
+ * app that draws its own header; does nothing outside Flip.
90
+ */
91
+ declare function closeFlipApp(origins: readonly string[]): void;
92
+ /**
93
+ * `"web"`, `"app"` or `null` (outside Flip, and always on the server and
94
+ * during hydration, so the server's HTML and the first render agree).
95
+ */
96
+ declare function useFlipHost(origins: readonly string[]): FlipHost["kind"] | null;
97
+
98
+ export { FlipAppHeader, type FlipAppHeaderProps, type FlipHost, FlipThemeSync, type FlipThemeSyncProps, closeFlipApp, ensureFlipBridge, flipHost, useFlipHost };
package/dist/flip.js ADDED
@@ -0,0 +1,158 @@
1
+ "use client";
2
+ import { useOptionalTheme, Button, Glyph } from './chunk-7XUCETA6.js';
3
+ import { cn } from './chunk-KZESIYUN.js';
4
+ import * as React2 from 'react';
5
+ import { initFlipBridge, close, getTheme, subscribe as subscribe$1, BridgeEventType } from '@getflip/bridge';
6
+ import { jsxs, jsx } from 'react/jsx-runtime';
7
+
8
+ var normalize = (origin) => {
9
+ try {
10
+ return new URL(origin).origin;
11
+ } catch {
12
+ return origin;
13
+ }
14
+ };
15
+ function inFlipApp() {
16
+ return Boolean(window.FlipFlutter);
17
+ }
18
+ function flipHost(origins) {
19
+ if (typeof window === "undefined") return null;
20
+ const allowed = origins.map(normalize);
21
+ if (inFlipApp()) return allowed[0] ? { origin: allowed[0], kind: "app" } : null;
22
+ if (window.top === window) return null;
23
+ let parent = window.location.ancestorOrigins?.[0];
24
+ if (!parent && document.referrer) {
25
+ try {
26
+ parent = new URL(document.referrer).origin;
27
+ } catch {
28
+ parent = void 0;
29
+ }
30
+ }
31
+ return parent && allowed.includes(parent) ? { origin: parent, kind: "web" } : null;
32
+ }
33
+ function ensureFlipBridge(host) {
34
+ if (window.flipBridgeOptions) return;
35
+ initFlipBridge({ hostAppOrigin: host.origin });
36
+ }
37
+ function closeFlipApp(origins) {
38
+ const host = flipHost(origins);
39
+ if (!host) return;
40
+ ensureFlipBridge(host);
41
+ void close().catch(() => {
42
+ });
43
+ }
44
+ var subscribe = () => () => {
45
+ };
46
+ function useFlipHost(origins) {
47
+ const key = origins.join(" ");
48
+ const getSnapshot = React2.useCallback(() => flipHost(key.split(" "))?.kind ?? null, [key]);
49
+ return React2.useSyncExternalStore(subscribe, getSnapshot, () => null);
50
+ }
51
+
52
+ // src/components/flip-theme.tsx
53
+ var activeThemeOf = (result) => {
54
+ if (result && typeof result === "object" && "activeTheme" in result) {
55
+ const theme = result.activeTheme;
56
+ if (theme === "light" || theme === "dark") return theme;
57
+ }
58
+ return null;
59
+ };
60
+ function FlipThemeSync({ origins }) {
61
+ const provider = useOptionalTheme();
62
+ const setThemeRef = React2.useRef(provider?.setTheme);
63
+ React2.useEffect(() => {
64
+ setThemeRef.current = provider?.setTheme;
65
+ });
66
+ const originsKey = origins.join(" ");
67
+ React2.useEffect(() => {
68
+ const host = flipHost(originsKey.split(" "));
69
+ if (!host) return;
70
+ let cancelled = false;
71
+ let unsubscribe;
72
+ const apply = (theme) => {
73
+ if (cancelled || !theme) return;
74
+ const setTheme = setThemeRef.current;
75
+ if (setTheme) {
76
+ setTheme(theme, { persist: false });
77
+ } else {
78
+ const root = document.documentElement;
79
+ root.classList.remove("theme-light", "theme-dark");
80
+ root.classList.add(`theme-${theme}`);
81
+ }
82
+ };
83
+ ensureFlipBridge(host);
84
+ getTheme().then(
85
+ (result) => apply(activeThemeOf(result)),
86
+ () => {
87
+ }
88
+ );
89
+ subscribe$1(BridgeEventType.THEME_CHANGE, (event) => apply(activeThemeOf(event?.data))).then(
90
+ (stop) => {
91
+ if (cancelled) void stop();
92
+ else unsubscribe = stop;
93
+ },
94
+ () => {
95
+ }
96
+ );
97
+ return () => {
98
+ cancelled = true;
99
+ void unsubscribe?.();
100
+ };
101
+ }, [originsKey]);
102
+ return null;
103
+ }
104
+ function FlipAppHeader({
105
+ origins,
106
+ title,
107
+ back,
108
+ backLabel = "Back",
109
+ closeLabel = "Close",
110
+ actions,
111
+ className,
112
+ ...props
113
+ }) {
114
+ const host = useFlipHost(origins);
115
+ const arrow = /* @__PURE__ */ jsx(Glyph, { name: "arrowLeft" });
116
+ const arrowButton = "-ml-1.5 [&>svg]:size-5!";
117
+ return /* @__PURE__ */ jsxs(
118
+ "header",
119
+ {
120
+ className: cn(
121
+ "sticky top-0 z-10 min-h-14 bg-background px-4",
122
+ // Phones: back or close, a centred title, actions; ruled underneath.
123
+ "grid grid-cols-[1fr_minmax(0,auto)_1fr] items-center gap-2 border-b border-border",
124
+ // Desktop: one row with a left-aligned title, and no rule, as in Flip's web app.
125
+ "desktop:flex desktop:gap-0 desktop:border-b-0",
126
+ // Flip's mobile app keeps its own header, so this one steps aside.
127
+ "flip-app:hidden",
128
+ className
129
+ ),
130
+ ...props,
131
+ children: [
132
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center desktop:contents", children: [
133
+ back && /* @__PURE__ */ jsx(Button, { asChild: true, hideLabel: true, className: cn(arrowButton, "desktop:mr-2"), children: React2.cloneElement(
134
+ back,
135
+ void 0,
136
+ arrow,
137
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: backLabel })
138
+ ) }),
139
+ !back && host === "web" && // Flip's web app shows no arrow for a menu item on desktop.
140
+ /* @__PURE__ */ jsx(
141
+ Button,
142
+ {
143
+ hideLabel: true,
144
+ icon: arrow,
145
+ label: closeLabel,
146
+ onClick: () => closeFlipApp(origins),
147
+ className: cn(arrowButton, "desktop:hidden")
148
+ }
149
+ )
150
+ ] }),
151
+ /* @__PURE__ */ jsx("h1", { className: "m-0 min-w-0 truncate text-center text-base font-semibold desktop:flex-1 desktop:text-left desktop:text-lg", children: title }),
152
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-end desktop:ml-2", children: actions })
153
+ ]
154
+ }
155
+ );
156
+ }
157
+
158
+ export { FlipAppHeader, FlipThemeSync, closeFlipApp, ensureFlipBridge, flipHost, useFlipHost };
Binary file
@@ -0,0 +1,96 @@
1
+ Inter.var.woff2 and Inter-italic.var.woff2 are Inter 4.001 (https://github.com/rsms/inter),
2
+ redistributed unmodified from @getflip/swirl-components.
3
+
4
+ Copyright 2016 The Inter Project Authors (https://github.com/rsms/inter)
5
+
6
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
7
+ This license is copied below, and is also available with a FAQ at:
8
+ https://openfontlicense.org
9
+
10
+
11
+ -----------------------------------------------------------
12
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
13
+ -----------------------------------------------------------
14
+
15
+ PREAMBLE
16
+ The goals of the Open Font License (OFL) are to stimulate worldwide
17
+ development of collaborative font projects, to support the font creation
18
+ efforts of academic and linguistic communities, and to provide a free and
19
+ open framework in which fonts may be shared and improved in partnership
20
+ with others.
21
+
22
+ The OFL allows the licensed fonts to be used, studied, modified and
23
+ redistributed freely as long as they are not sold by themselves. The
24
+ fonts, including any derivative works, can be bundled, embedded,
25
+ redistributed and/or sold with any software provided that any reserved
26
+ names are not used by derivative works. The fonts and derivatives,
27
+ however, cannot be released under any other type of license. The
28
+ requirement for fonts to remain under this license does not apply
29
+ to any document created using the fonts or their derivatives.
30
+
31
+ DEFINITIONS
32
+ "Font Software" refers to the set of files released by the Copyright
33
+ Holder(s) under this license and clearly marked as such. This may
34
+ include source files, build scripts and documentation.
35
+
36
+ "Reserved Font Name" refers to any names specified as such after the
37
+ copyright statement(s).
38
+
39
+ "Original Version" refers to the collection of Font Software components as
40
+ distributed by the Copyright Holder(s).
41
+
42
+ "Modified Version" refers to any derivative made by adding to, deleting,
43
+ or substituting -- in part or in whole -- any of the components of the
44
+ Original Version, by changing formats or by porting the Font Software to a
45
+ new environment.
46
+
47
+ "Author" refers to any designer, engineer, programmer, technical
48
+ writer or other person who contributed to the Font Software.
49
+
50
+ PERMISSION & CONDITIONS
51
+ Permission is hereby granted, free of charge, to any person obtaining
52
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
53
+ redistribute, and sell modified and unmodified copies of the Font
54
+ Software, subject to the following conditions:
55
+
56
+ 1) Neither the Font Software nor any of its individual components,
57
+ in Original or Modified Versions, may be sold by itself.
58
+
59
+ 2) Original or Modified Versions of the Font Software may be bundled,
60
+ redistributed and/or sold with any software, provided that each copy
61
+ contains the above copyright notice and this license. These can be
62
+ included either as stand-alone text files, human-readable headers or
63
+ in the appropriate machine-readable metadata fields within text or
64
+ binary files as long as those fields can be easily viewed by the user.
65
+
66
+ 3) No Modified Version of the Font Software may use the Reserved Font
67
+ Name(s) unless explicit written permission is granted by the corresponding
68
+ Copyright Holder. This restriction only applies to the primary font name as
69
+ presented to the users.
70
+
71
+ 4) The name(s) of the Copyright Holder(s) and the Author(s) of the Font
72
+ Software shall not be used to promote, endorse or advertise any
73
+ Modified Version, except to acknowledge the contribution(s) of the
74
+ Copyright Holder(s) and the Author(s) or with their explicit written
75
+ permission.
76
+
77
+ 5) The Font Software, modified or unmodified, in part or in whole,
78
+ must be distributed entirely under this license, and must not be
79
+ distributed under any other license. The requirement for fonts to
80
+ remain under this license does not apply to any document created
81
+ using the Font Software.
82
+
83
+ TERMINATION
84
+ This license becomes null and void if any of the above conditions are
85
+ not met.
86
+
87
+ DISCLAIMER
88
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
89
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
90
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
91
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
92
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
93
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
94
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
95
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
96
+ OTHER DEALINGS IN THE FONT SOFTWARE.