@snap-rail/ui 0.1.0 → 0.2.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.
- package/lib/charts.js +6 -29
- package/lib/contract.js +119 -78
- package/lib/fallback.js +11 -1
- package/lib/index.js +2466 -735
- package/lib/runtime.js +1552 -490
- package/lib/settings.js +1162 -244
- package/lib/skins.js +163 -189
- package/lib/types/charts.d.ts +1 -1
- package/lib/types/charts.js +5 -5
- package/lib/types/components/alert.d.ts +57 -0
- package/lib/types/components/alert.js +46 -0
- package/lib/types/components/controls.d.ts +74 -11
- package/lib/types/components/controls.js +60 -17
- package/lib/types/components/dialog.d.ts +5 -5
- package/lib/types/components/dialog.js +2 -2
- package/lib/types/components/form-rhf.d.ts +56 -0
- package/lib/types/components/form-rhf.js +74 -0
- package/lib/types/components/form.d.ts +33 -5
- package/lib/types/components/form.js +22 -6
- package/lib/types/components/index.d.ts +7 -0
- package/lib/types/components/index.js +7 -0
- package/lib/types/components/input.d.ts +16 -7
- package/lib/types/components/input.js +39 -9
- package/lib/types/components/layout.d.ts +32 -7
- package/lib/types/components/layout.js +88 -15
- package/lib/types/components/overlay.d.ts +95 -0
- package/lib/types/components/overlay.js +138 -0
- package/lib/types/components/schema-form.d.ts +16 -4
- package/lib/types/components/schema-form.js +69 -40
- package/lib/types/components/slider.d.ts +18 -0
- package/lib/types/components/slider.js +15 -0
- package/lib/types/contract.d.ts +49 -37
- package/lib/types/contract.js +49 -33
- package/lib/types/fallback.js +1 -1
- package/lib/types/runtime.d.ts +23 -1
- package/lib/types/runtime.js +77 -20
- package/lib/types/settings-pages/appearance.d.ts +6 -4
- package/lib/types/settings-pages/appearance.js +33 -36
- package/lib/types/settings-pages/plugin-feed.d.ts +17 -0
- package/lib/types/settings-pages/plugin-feed.js +66 -0
- package/lib/types/settings-pages/plugins.d.ts +10 -5
- package/lib/types/settings-pages/plugins.js +284 -21
- package/lib/types/settings.d.ts +1 -0
- package/lib/types/settings.js +14 -8
- package/lib/types/skins.d.ts +38 -44
- package/lib/types/skins.js +172 -169
- package/package.json +16 -9
- package/src/styles/base.css +251 -5
- package/src/styles/default.css +315 -136
package/lib/skins.js
CHANGED
|
@@ -1,190 +1,160 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, useContext, useSyncExternalStore } from "react";
|
|
3
|
-
//#region lib/types/contract.js
|
|
4
|
-
/** The stable region slots every layout may provide. */
|
|
5
|
-
const UI_SLOT_IDS = {
|
|
6
|
-
/** The one active layout of the operator window. */
|
|
7
|
-
layout: "shell.layout",
|
|
8
|
-
/** The operator titlebar. */
|
|
9
|
-
titlebar: "shell.titlebar",
|
|
10
|
-
/** Contributed titlebar actions. */
|
|
11
|
-
titlebarActions: "shell.titlebar.actions",
|
|
12
|
-
/** Sidebar extension area. */
|
|
13
|
-
sidebar: "shell.sidebar",
|
|
14
|
-
/** Statusbar extension area. */
|
|
15
|
-
statusbar: "shell.statusbar",
|
|
16
|
-
/** The global overlay stack (dialogs, confirms). */
|
|
17
|
-
overlay: "shell.overlay",
|
|
18
|
-
/** The floating ball surface face. */
|
|
19
|
-
ball: "shell.ball",
|
|
20
|
-
/** The settings trigger. */
|
|
21
|
-
settingsEntry: "settings.entry",
|
|
22
|
-
/** The settings surface itself. */
|
|
23
|
-
settingsSurface: "settings.surface"
|
|
24
|
-
};
|
|
25
|
-
UI_SLOT_IDS.layout, UI_SLOT_IDS.titlebar, UI_SLOT_IDS.titlebarActions, UI_SLOT_IDS.sidebar, UI_SLOT_IDS.statusbar, UI_SLOT_IDS.overlay, UI_SLOT_IDS.ball, UI_SLOT_IDS.settingsEntry, UI_SLOT_IDS.settingsSurface;
|
|
26
|
-
/** The presentation targets a skin may tune. */
|
|
27
|
-
const PRESENTATION_TARGETS = [
|
|
28
|
-
"dialog",
|
|
29
|
-
"select",
|
|
30
|
-
"tabs",
|
|
31
|
-
"toast"
|
|
32
|
-
];
|
|
33
|
-
//#endregion
|
|
34
3
|
//#region lib/types/skins.js
|
|
35
|
-
/** The
|
|
36
|
-
const
|
|
37
|
-
/** The
|
|
38
|
-
const
|
|
39
|
-
/** The
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
4
|
+
/** The factory day theme id (cobalt palette, light surfaces). */
|
|
5
|
+
const DEFAULT_LIGHT_ID = "default-light";
|
|
6
|
+
/** The factory night theme id (cobalt palette, dark surfaces). */
|
|
7
|
+
const DEFAULT_DARK_ID = "default-dark";
|
|
8
|
+
/** The contributor label for the factory themes. */
|
|
9
|
+
const FACTORY_CALLER = "@snap-rail/ui";
|
|
10
|
+
const COBALT_DARK_TOKENS = {
|
|
11
|
+
colorBg: "#0b0f14",
|
|
12
|
+
colorSurface: "#11161d",
|
|
13
|
+
colorSurfaceRaised: "#161b22",
|
|
14
|
+
colorText: "#ced8e3",
|
|
15
|
+
colorMuted: "#8b949e",
|
|
16
|
+
colorPrimary: "#4a6cff",
|
|
17
|
+
colorOnPrimary: "#ffffff",
|
|
18
|
+
colorDanger: "#f85149",
|
|
19
|
+
colorSuccess: "#3fb950",
|
|
20
|
+
colorWarning: "#d29922",
|
|
21
|
+
colorBorder: "#1f2933",
|
|
22
|
+
colorFocus: "#4a6cff",
|
|
23
|
+
chart1: "#4a6cff",
|
|
24
|
+
chart2: "#3147a1",
|
|
25
|
+
chart3: "#667fcd",
|
|
26
|
+
chart4: "#7d8fa5",
|
|
27
|
+
chart5: "#55677c",
|
|
28
|
+
chart6: "#33414f",
|
|
29
|
+
fontSans: "system-ui, \"Segoe UI\", \"Microsoft YaHei\", sans-serif",
|
|
30
|
+
fontMono: "\"Cascadia Code\", \"Cascadia Mono\", Consolas, ui-monospace, monospace",
|
|
31
|
+
textXs: "13px",
|
|
32
|
+
textSm: "15px",
|
|
33
|
+
textMd: "17px",
|
|
34
|
+
textLg: "20px",
|
|
35
|
+
textXl: "24px",
|
|
36
|
+
weightNormal: "400",
|
|
37
|
+
weightMedium: "500",
|
|
38
|
+
weightStrong: "600",
|
|
39
|
+
leadingTight: "1.2",
|
|
40
|
+
leadingNormal: "1.55",
|
|
41
|
+
spaceXs: "4px",
|
|
42
|
+
spaceSm: "8px",
|
|
43
|
+
spaceMd: "12px",
|
|
44
|
+
spaceLg: "20px",
|
|
45
|
+
spaceXl: "32px",
|
|
46
|
+
radiusSm: "6px",
|
|
47
|
+
radiusMd: "8px",
|
|
48
|
+
radiusLg: "12px",
|
|
49
|
+
radiusFull: "999px",
|
|
50
|
+
borderWidth: "1px",
|
|
51
|
+
shadowSm: "0 1px 2px rgb(0 0 0 / 0.25)",
|
|
52
|
+
shadowMd: "0 8px 24px rgb(0 0 0 / 0.28)",
|
|
53
|
+
shadowLg: "0 24px 64px rgb(0 0 0 / 0.36)",
|
|
54
|
+
durationFast: "120ms",
|
|
55
|
+
durationNormal: "180ms",
|
|
56
|
+
durationSlow: "280ms",
|
|
57
|
+
easeStandard: "cubic-bezier(0.2, 0, 0, 1)",
|
|
58
|
+
zOverlay: "50",
|
|
59
|
+
zModal: "60",
|
|
60
|
+
zToast: "70",
|
|
61
|
+
controlHeightSm: "40px",
|
|
62
|
+
controlHeightMd: "48px",
|
|
63
|
+
controlHeightLg: "56px",
|
|
64
|
+
density: "comfortable"
|
|
65
|
+
};
|
|
66
|
+
/** The factory day theme. Always registered; never the first paint though — the night theme is. */
|
|
67
|
+
const DEFAULT_LIGHT = {
|
|
68
|
+
id: DEFAULT_LIGHT_ID,
|
|
69
|
+
title: "钴蓝·白天",
|
|
49
70
|
tokens: {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
density: "comfortable"
|
|
105
|
-
},
|
|
106
|
-
light: {
|
|
107
|
-
colorBg: "#e4e9ef",
|
|
108
|
-
colorSurface: "#f3f6f9",
|
|
109
|
-
colorSurfaceRaised: "#ffffff",
|
|
110
|
-
colorText: "#26323e",
|
|
111
|
-
colorMuted: "#5d6d7e",
|
|
112
|
-
colorPrimary: "#3857e8",
|
|
113
|
-
colorOnPrimary: "#ffffff",
|
|
114
|
-
colorDanger: "#dc2626",
|
|
115
|
-
colorSuccess: "#15803d",
|
|
116
|
-
colorWarning: "#b45309",
|
|
117
|
-
colorBorder: "#c7d0da",
|
|
118
|
-
colorFocus: "#3857e8",
|
|
119
|
-
chart1: "#3857e8",
|
|
120
|
-
chart2: "#7088ee",
|
|
121
|
-
chart3: "#667dd0",
|
|
122
|
-
chart4: "#94a3b8",
|
|
123
|
-
chart5: "#b3c0cd",
|
|
124
|
-
chart6: "#ccd6e0",
|
|
125
|
-
fontSans: "system-ui, \"Segoe UI\", \"Microsoft YaHei\", sans-serif",
|
|
126
|
-
fontMono: "\"Cascadia Code\", \"Cascadia Mono\", Consolas, ui-monospace, monospace",
|
|
127
|
-
textXs: "13px",
|
|
128
|
-
textSm: "15px",
|
|
129
|
-
textMd: "17px",
|
|
130
|
-
textLg: "20px",
|
|
131
|
-
textXl: "24px",
|
|
132
|
-
weightNormal: "400",
|
|
133
|
-
weightMedium: "500",
|
|
134
|
-
weightStrong: "600",
|
|
135
|
-
leadingTight: "1.2",
|
|
136
|
-
leadingNormal: "1.55",
|
|
137
|
-
spaceXs: "4px",
|
|
138
|
-
spaceSm: "8px",
|
|
139
|
-
spaceMd: "12px",
|
|
140
|
-
spaceLg: "20px",
|
|
141
|
-
spaceXl: "32px",
|
|
142
|
-
radiusSm: "6px",
|
|
143
|
-
radiusMd: "8px",
|
|
144
|
-
radiusLg: "12px",
|
|
145
|
-
radiusFull: "999px",
|
|
146
|
-
borderWidth: "1px",
|
|
147
|
-
shadowSm: "0 1px 2px rgb(0 0 0 / 0.08)",
|
|
148
|
-
shadowMd: "0 8px 24px rgb(0 0 0 / 0.12)",
|
|
149
|
-
shadowLg: "0 24px 64px rgb(0 0 0 / 0.18)",
|
|
150
|
-
durationFast: "120ms",
|
|
151
|
-
durationNormal: "180ms",
|
|
152
|
-
durationSlow: "280ms",
|
|
153
|
-
easeStandard: "cubic-bezier(0.2, 0, 0, 1)",
|
|
154
|
-
zOverlay: "50",
|
|
155
|
-
zModal: "60",
|
|
156
|
-
zToast: "70",
|
|
157
|
-
controlHeightSm: "40px",
|
|
158
|
-
controlHeightMd: "48px",
|
|
159
|
-
controlHeightLg: "56px",
|
|
160
|
-
density: "comfortable"
|
|
161
|
-
}
|
|
71
|
+
colorBg: "#e4e9ef",
|
|
72
|
+
colorSurface: "#f3f6f9",
|
|
73
|
+
colorSurfaceRaised: "#ffffff",
|
|
74
|
+
colorText: "#26323e",
|
|
75
|
+
colorMuted: "#5d6d7e",
|
|
76
|
+
colorPrimary: "#3857e8",
|
|
77
|
+
colorOnPrimary: "#ffffff",
|
|
78
|
+
colorDanger: "#dc2626",
|
|
79
|
+
colorSuccess: "#15803d",
|
|
80
|
+
colorWarning: "#b45309",
|
|
81
|
+
colorBorder: "#c7d0da",
|
|
82
|
+
colorFocus: "#3857e8",
|
|
83
|
+
chart1: "#3857e8",
|
|
84
|
+
chart2: "#7088ee",
|
|
85
|
+
chart3: "#667dd0",
|
|
86
|
+
chart4: "#94a3b8",
|
|
87
|
+
chart5: "#b3c0cd",
|
|
88
|
+
chart6: "#ccd6e0",
|
|
89
|
+
fontSans: "system-ui, \"Segoe UI\", \"Microsoft YaHei\", sans-serif",
|
|
90
|
+
fontMono: "\"Cascadia Code\", \"Cascadia Mono\", Consolas, ui-monospace, monospace",
|
|
91
|
+
textXs: "13px",
|
|
92
|
+
textSm: "15px",
|
|
93
|
+
textMd: "17px",
|
|
94
|
+
textLg: "20px",
|
|
95
|
+
textXl: "24px",
|
|
96
|
+
weightNormal: "400",
|
|
97
|
+
weightMedium: "500",
|
|
98
|
+
weightStrong: "600",
|
|
99
|
+
leadingTight: "1.2",
|
|
100
|
+
leadingNormal: "1.55",
|
|
101
|
+
spaceXs: "4px",
|
|
102
|
+
spaceSm: "8px",
|
|
103
|
+
spaceMd: "12px",
|
|
104
|
+
spaceLg: "20px",
|
|
105
|
+
spaceXl: "32px",
|
|
106
|
+
radiusSm: "6px",
|
|
107
|
+
radiusMd: "8px",
|
|
108
|
+
radiusLg: "12px",
|
|
109
|
+
radiusFull: "999px",
|
|
110
|
+
borderWidth: "1px",
|
|
111
|
+
shadowSm: "0 1px 2px rgb(0 0 0 / 0.08)",
|
|
112
|
+
shadowMd: "0 8px 24px rgb(0 0 0 / 0.12)",
|
|
113
|
+
shadowLg: "0 24px 64px rgb(0 0 0 / 0.18)",
|
|
114
|
+
durationFast: "120ms",
|
|
115
|
+
durationNormal: "180ms",
|
|
116
|
+
durationSlow: "280ms",
|
|
117
|
+
easeStandard: "cubic-bezier(0.2, 0, 0, 1)",
|
|
118
|
+
zOverlay: "50",
|
|
119
|
+
zModal: "60",
|
|
120
|
+
zToast: "70",
|
|
121
|
+
controlHeightSm: "40px",
|
|
122
|
+
controlHeightMd: "48px",
|
|
123
|
+
controlHeightLg: "56px",
|
|
124
|
+
density: "comfortable"
|
|
162
125
|
}
|
|
163
126
|
};
|
|
127
|
+
/** The factory night theme and the registry's fallback. */
|
|
128
|
+
const DEFAULT_DARK = {
|
|
129
|
+
id: DEFAULT_DARK_ID,
|
|
130
|
+
title: "钴蓝·黑夜",
|
|
131
|
+
tokens: COBALT_DARK_TOKENS
|
|
132
|
+
};
|
|
164
133
|
/** Turn a token key into its CSS custom property (`chart1` → `--snap-chart-1`). */
|
|
165
134
|
function skinTokenVar(key) {
|
|
166
135
|
return `--snap-${key.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`).replace(/(\d+)$/, "-$1")}`;
|
|
167
136
|
}
|
|
168
|
-
/** Apply the active
|
|
169
|
-
function applySkin(skin
|
|
137
|
+
/** Apply the active theme to the document root. */
|
|
138
|
+
function applySkin(skin) {
|
|
170
139
|
if (typeof document === "undefined") return;
|
|
171
140
|
const root = document.documentElement;
|
|
172
141
|
root.dataset["snapSkin"] = skin.id;
|
|
173
|
-
|
|
174
|
-
const tokens = skin.tokens[mode];
|
|
175
|
-
for (const [key, value] of Object.entries(tokens)) root.style.setProperty(skinTokenVar(key), value);
|
|
142
|
+
for (const [key, value] of Object.entries(skin.tokens)) root.style.setProperty(skinTokenVar(key), value);
|
|
176
143
|
}
|
|
177
144
|
/** Mount the `ctx.skins` registry. */
|
|
178
145
|
const skinsPlugin = {
|
|
179
146
|
name: "snap-rail ui skins",
|
|
180
147
|
apply(ctx) {
|
|
181
148
|
const skins = /* @__PURE__ */ new Map();
|
|
149
|
+
const callers = /* @__PURE__ */ new Map();
|
|
182
150
|
const listeners = /* @__PURE__ */ new Set();
|
|
183
151
|
const styleTags = /* @__PURE__ */ new Map();
|
|
184
|
-
let activeId =
|
|
185
|
-
let mode = "dark";
|
|
152
|
+
let activeId = DEFAULT_DARK_ID;
|
|
186
153
|
let revision = 0;
|
|
187
|
-
skins.set(
|
|
154
|
+
skins.set(DEFAULT_LIGHT_ID, DEFAULT_LIGHT);
|
|
155
|
+
callers.set(DEFAULT_LIGHT_ID, FACTORY_CALLER);
|
|
156
|
+
skins.set(DEFAULT_DARK_ID, DEFAULT_DARK);
|
|
157
|
+
callers.set(DEFAULT_DARK_ID, FACTORY_CALLER);
|
|
188
158
|
const notify = () => {
|
|
189
159
|
revision += 1;
|
|
190
160
|
for (const listener of listeners) listener();
|
|
@@ -200,48 +170,52 @@ const skinsPlugin = {
|
|
|
200
170
|
styleTags.set(skin.id, tag);
|
|
201
171
|
};
|
|
202
172
|
const refresh = () => {
|
|
203
|
-
const skin = skins.get(activeId) ??
|
|
173
|
+
const skin = skins.get(activeId) ?? DEFAULT_DARK;
|
|
204
174
|
activeId = skin.id;
|
|
205
175
|
ensureStyleTag(skin);
|
|
206
|
-
applySkin(skin
|
|
176
|
+
applySkin(skin);
|
|
207
177
|
notify();
|
|
208
178
|
};
|
|
209
179
|
ctx.provide("skins", {
|
|
210
180
|
register(caller, skin) {
|
|
211
181
|
skins.set(skin.id, skin);
|
|
212
|
-
|
|
182
|
+
callers.set(skin.id, caller.fiber.name);
|
|
213
183
|
refresh();
|
|
214
184
|
const remove = () => {
|
|
215
185
|
if (!skins.delete(skin.id)) return;
|
|
186
|
+
callers.delete(skin.id);
|
|
216
187
|
const tag = styleTags.get(skin.id);
|
|
217
188
|
if (tag !== void 0) {
|
|
218
189
|
tag.remove();
|
|
219
190
|
styleTags.delete(skin.id);
|
|
220
191
|
}
|
|
221
|
-
if (activeId === skin.id) activeId =
|
|
192
|
+
if (activeId === skin.id) activeId = DEFAULT_DARK_ID;
|
|
222
193
|
refresh();
|
|
223
194
|
};
|
|
224
195
|
caller.effect(() => remove);
|
|
225
196
|
return remove;
|
|
226
197
|
},
|
|
227
|
-
activate(
|
|
228
|
-
|
|
229
|
-
|
|
198
|
+
activate(selection) {
|
|
199
|
+
let next = skins.has(selection) ? selection : void 0;
|
|
200
|
+
if (next === void 0) {
|
|
201
|
+
for (const [id, owner] of callers) if (id !== selection && owner === selection && skins.has(id)) {
|
|
202
|
+
next = id;
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (next === void 0) return false;
|
|
207
|
+
if (next === activeId) return true;
|
|
208
|
+
activeId = next;
|
|
230
209
|
refresh();
|
|
231
210
|
return true;
|
|
232
211
|
},
|
|
233
|
-
list: () => [
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
mode: () => mode,
|
|
241
|
-
presentation(target) {
|
|
242
|
-
return (skins.get(activeId) ?? DEFAULT_SKIN).presentations?.[target];
|
|
243
|
-
},
|
|
244
|
-
tokens: () => (skins.get(activeId) ?? DEFAULT_SKIN).tokens[mode],
|
|
212
|
+
list: () => [...skins.values()].map((skin) => ({
|
|
213
|
+
id: skin.id,
|
|
214
|
+
title: skin.title,
|
|
215
|
+
caller: callers.get(skin.id) ?? FACTORY_CALLER
|
|
216
|
+
})),
|
|
217
|
+
active: () => skins.get(activeId) ?? DEFAULT_DARK,
|
|
218
|
+
tokens: () => (skins.get(activeId) ?? DEFAULT_DARK).tokens,
|
|
245
219
|
subscribe(listener) {
|
|
246
220
|
listeners.add(listener);
|
|
247
221
|
return () => {
|
|
@@ -268,17 +242,17 @@ function useSkins() {
|
|
|
268
242
|
if (service === null) throw new Error("useSkins: no SkinsProvider in the tree");
|
|
269
243
|
return service;
|
|
270
244
|
}
|
|
271
|
-
/** Re-render on
|
|
245
|
+
/** Re-render on theme changes and return the active token set. */
|
|
272
246
|
function useSkinTokens() {
|
|
273
247
|
const service = useSkins();
|
|
274
248
|
useSyncExternalStore(service.subscribe, service.version, service.version);
|
|
275
249
|
return service.tokens();
|
|
276
250
|
}
|
|
277
|
-
/** Re-render on
|
|
278
|
-
function
|
|
251
|
+
/** Re-render on theme changes and return the active theme id. */
|
|
252
|
+
function useSkinId() {
|
|
279
253
|
const service = useSkins();
|
|
280
254
|
useSyncExternalStore(service.subscribe, service.version, service.version);
|
|
281
|
-
return service.
|
|
255
|
+
return service.active().id;
|
|
282
256
|
}
|
|
283
257
|
//#endregion
|
|
284
|
-
export {
|
|
258
|
+
export { DEFAULT_DARK, DEFAULT_DARK_ID, DEFAULT_LIGHT, DEFAULT_LIGHT_ID, SkinsProvider, skinsPlugin as default, skinTokenVar, useSkinId, useSkinTokens, useSkins };
|
package/lib/types/charts.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export interface ChartFrameProps {
|
|
|
24
24
|
}
|
|
25
25
|
/** A semantic frame for a chart, gauge, map, or custom visualization. */
|
|
26
26
|
export declare function ChartFrame({ title, description, actions, state, empty, error, loading, children, className, style, }: ChartFrameProps): ReactNode;
|
|
27
|
-
/**
|
|
27
|
+
/** An alias of {@link ChartFrame} for pages that prefer the generic name. */
|
|
28
28
|
export declare function Visualization(props: ChartFrameProps): ReactNode;
|
|
29
29
|
/** The theme object ECharts/D3 adapters can consume. */
|
|
30
30
|
export interface ChartTheme {
|
package/lib/types/charts.js
CHANGED
|
@@ -3,15 +3,15 @@ import { cn, part } from "./utils.js";
|
|
|
3
3
|
import { useSkinTokens } from "./skins.js";
|
|
4
4
|
/** A semantic frame for a chart, gauge, map, or custom visualization. */
|
|
5
5
|
export function ChartFrame({ title, description, actions, state = 'ready', empty, error, loading, children, className, style, }) {
|
|
6
|
-
return (_jsxs("section", { ...part('chart-frame', 'root'), className: cn('snap-chart-frame', className), "data-state": state, style: style, children: [(title !== undefined || description !== undefined || actions !== undefined) && (_jsxs("header", { ...part('chart-frame', 'header'), className: "snap-chart-frame-header", children: [_jsxs("div", { children: [title !== undefined && _jsx("div", { ...part('chart-frame', 'title'), children: title }), description !== undefined && _jsx("div", { className: "snap-chart-frame-description", children: description })] }), actions !== undefined && _jsx("div", { ...part('chart-frame', 'actions'), children: actions })] })), _jsx("div", { ...part('chart-frame', 'body'), className: "snap-chart-frame-body", "data-state": state, children: state === 'loading'
|
|
7
|
-
? loading ?? _jsx("div", { ...part('
|
|
6
|
+
return (_jsxs("section", { ...part('chart-frame', 'root'), className: cn('snap-chart-frame', className), "data-state": state, style: style, children: [(title !== undefined || description !== undefined || actions !== undefined) && (_jsxs("header", { ...part('chart-frame', 'header'), className: "snap-chart-frame-header", children: [_jsxs("div", { children: [title !== undefined && _jsx("div", { ...part('chart-frame', 'title'), children: title }), description !== undefined && _jsx("div", { ...part('chart-frame', 'description'), className: "snap-chart-frame-description", children: description })] }), actions !== undefined && _jsx("div", { ...part('chart-frame', 'actions'), children: actions })] })), _jsx("div", { ...part('chart-frame', 'body'), className: "snap-chart-frame-body", "data-state": state, children: state === 'loading'
|
|
7
|
+
? loading ?? _jsx("div", { ...part('chart-frame', 'loading'), children: "\u52A0\u8F7D\u4E2D\u2026" })
|
|
8
8
|
: state === 'empty'
|
|
9
|
-
? empty ?? _jsx("div", { ...part('
|
|
9
|
+
? empty ?? _jsx("div", { ...part('chart-frame', 'empty'), children: "\u6682\u65E0\u6570\u636E" })
|
|
10
10
|
: state === 'error'
|
|
11
|
-
? error ?? _jsx("div", { ...part('
|
|
11
|
+
? error ?? _jsx("div", { ...part('chart-frame', 'error'), role: "alert", children: "\u56FE\u8868\u52A0\u8F7D\u5931\u8D25" })
|
|
12
12
|
: children })] }));
|
|
13
13
|
}
|
|
14
|
-
/**
|
|
14
|
+
/** An alias of {@link ChartFrame} for pages that prefer the generic name. */
|
|
15
15
|
export function Visualization(props) {
|
|
16
16
|
return _jsx(ChartFrame, { ...props });
|
|
17
17
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attention surfaces: alerts (inline banners), separators, skeletons, and
|
|
3
|
+
* lists. Read-only primitives; the skin owns their visuals through the
|
|
4
|
+
* `alert.*`, `separator.*`, `skeleton.*`, and `list.*` parts.
|
|
5
|
+
*
|
|
6
|
+
* @module @snap-rail/ui/components/alert
|
|
7
|
+
*/
|
|
8
|
+
import * as SeparatorPrimitive from '@radix-ui/react-separator';
|
|
9
|
+
import type { ComponentPropsWithoutRef, ReactNode } from 'react';
|
|
10
|
+
import type { ButtonIntent } from './button.tsx';
|
|
11
|
+
/** Props of {@link Alert}. */
|
|
12
|
+
export interface AlertProps extends ComponentPropsWithoutRef<'div'> {
|
|
13
|
+
/** The semantic tone; the skin maps it to colour like a button intent. */
|
|
14
|
+
intent?: ButtonIntent;
|
|
15
|
+
}
|
|
16
|
+
/** An inline status banner for results and failures. */
|
|
17
|
+
export declare function Alert({ intent, className, children, ...props }: AlertProps): ReactNode;
|
|
18
|
+
/** The alert heading line. */
|
|
19
|
+
export declare function AlertTitle({ className, children, ...props }: ComponentPropsWithoutRef<'h5'>): ReactNode;
|
|
20
|
+
/** The alert body text. */
|
|
21
|
+
export declare function AlertDescription({ className, children, ...props }: ComponentPropsWithoutRef<'div'>): ReactNode;
|
|
22
|
+
/** Props of {@link Separator}. */
|
|
23
|
+
export interface SeparatorProps extends ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root> {
|
|
24
|
+
orientation?: 'horizontal' | 'vertical';
|
|
25
|
+
}
|
|
26
|
+
/** A themed rule between sections. */
|
|
27
|
+
export declare function Separator({ orientation, className, ...props }: SeparatorProps): ReactNode;
|
|
28
|
+
/** Props of {@link Skeleton}. */
|
|
29
|
+
export interface SkeletonProps extends ComponentPropsWithoutRef<'div'> {
|
|
30
|
+
/** The shape variant; `text` matches the line height of body text. */
|
|
31
|
+
variant?: 'block' | 'text' | 'circle';
|
|
32
|
+
}
|
|
33
|
+
/** A neutral loading placeholder shaped by the skin. */
|
|
34
|
+
export declare function Skeleton({ variant, className, ...props }: SkeletonProps): ReactNode;
|
|
35
|
+
/** Props of {@link List}. */
|
|
36
|
+
export interface ListProps extends ComponentPropsWithoutRef<'ul'> {
|
|
37
|
+
/** Draw hairlines between items (default false). */
|
|
38
|
+
divided?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/** A vertical collection of {@link ListItem} rows. */
|
|
41
|
+
export declare function List({ divided, className, children, ...props }: ListProps): ReactNode;
|
|
42
|
+
/** Props of {@link ListItem}. */
|
|
43
|
+
export interface ListItemProps extends Omit<ComponentPropsWithoutRef<'li'>, 'onClick' | 'disabled'> {
|
|
44
|
+
/** Leading glyph/figure slot (status LED, icon, thumbnail). */
|
|
45
|
+
leading?: ReactNode;
|
|
46
|
+
/** Trailing slot (badge, timestamp, action). */
|
|
47
|
+
trailing?: ReactNode;
|
|
48
|
+
/** Marks the row as the current selection. */
|
|
49
|
+
selected?: boolean;
|
|
50
|
+
/** Dim the row and ignore activation. */
|
|
51
|
+
disabled?: boolean;
|
|
52
|
+
/** Makes the row interactive (role=button, keyboard activation). */
|
|
53
|
+
onClick?: () => void;
|
|
54
|
+
}
|
|
55
|
+
/** One list row with leading/trailing slots. */
|
|
56
|
+
export declare function ListItem({ leading, trailing, selected, disabled, onClick, className, children, ...props }: ListItemProps): ReactNode;
|
|
57
|
+
//# sourceMappingURL=alert.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Attention surfaces: alerts (inline banners), separators, skeletons, and
|
|
4
|
+
* lists. Read-only primitives; the skin owns their visuals through the
|
|
5
|
+
* `alert.*`, `separator.*`, `skeleton.*`, and `list.*` parts.
|
|
6
|
+
*
|
|
7
|
+
* @module @snap-rail/ui/components/alert
|
|
8
|
+
*/
|
|
9
|
+
import * as SeparatorPrimitive from '@radix-ui/react-separator';
|
|
10
|
+
import { cn, part } from "../utils.js";
|
|
11
|
+
/** An inline status banner for results and failures. */
|
|
12
|
+
export function Alert({ intent = 'neutral', className, children, ...props }) {
|
|
13
|
+
return (_jsx("div", { ...part('alert', 'root'), role: "alert", className: cn('snap-alert', className), "data-intent": intent, ...props, children: children }));
|
|
14
|
+
}
|
|
15
|
+
/** The alert heading line. */
|
|
16
|
+
export function AlertTitle({ className, children, ...props }) {
|
|
17
|
+
return _jsx("h5", { ...part('alert', 'title'), className: cn('snap-alert-title', className), ...props, children: children });
|
|
18
|
+
}
|
|
19
|
+
/** The alert body text. */
|
|
20
|
+
export function AlertDescription({ className, children, ...props }) {
|
|
21
|
+
return _jsx("div", { ...part('alert', 'description'), className: cn('snap-alert-description', className), ...props, children: children });
|
|
22
|
+
}
|
|
23
|
+
/** A themed rule between sections. */
|
|
24
|
+
export function Separator({ orientation = 'horizontal', className, ...props }) {
|
|
25
|
+
return (_jsx(SeparatorPrimitive.Root, { ...part('separator', 'root'), orientation: orientation, className: cn('snap-separator', className), ...props }));
|
|
26
|
+
}
|
|
27
|
+
/** A neutral loading placeholder shaped by the skin. */
|
|
28
|
+
export function Skeleton({ variant = 'block', className, ...props }) {
|
|
29
|
+
return _jsx("div", { ...part('skeleton', 'root'), className: cn('snap-skeleton', className), "data-variant": variant, "aria-hidden": "true", ...props });
|
|
30
|
+
}
|
|
31
|
+
/** A vertical collection of {@link ListItem} rows. */
|
|
32
|
+
export function List({ divided = false, className, children, ...props }) {
|
|
33
|
+
return (_jsx("ul", { ...part('list', 'root'), className: cn('snap-list', className), "data-divided": divided || undefined, ...props, children: children }));
|
|
34
|
+
}
|
|
35
|
+
/** One list row with leading/trailing slots. */
|
|
36
|
+
export function ListItem({ leading, trailing, selected = false, disabled = false, onClick, className, children, ...props }) {
|
|
37
|
+
const interactive = onClick !== undefined && !disabled;
|
|
38
|
+
const activate = (event) => {
|
|
39
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
40
|
+
event.preventDefault();
|
|
41
|
+
onClick?.();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
return (_jsxs("li", { ...part('list', 'item'), className: cn('snap-list-item', className), "data-selected": selected || undefined, "data-interactive": interactive || undefined, "data-disabled": disabled || undefined, "aria-disabled": disabled || undefined, ...interactive ? { role: 'button', tabIndex: 0, onClick, onKeyDown: activate } : {}, ...props, children: [leading !== undefined && _jsx("span", { ...part('list', 'leading'), children: leading }), _jsx("span", { ...part('list', 'content'), style: { flex: 1, minWidth: 0 }, children: children }), trailing !== undefined && _jsx("span", { ...part('list', 'trailing'), children: trailing })] }));
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=alert.js.map
|