@lucasvu/scope-ui 0.1.0 → 0.1.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.
- package/AI_SETUP.md +308 -45
- package/README.md +80 -7
- package/bin/copy-theme-assets.mjs +29 -0
- package/bin/scope-ui-init.mjs +74 -15
- package/dist/chunk-CL3F2TWE.js +1039 -0
- package/dist/core/index.cjs +1052 -0
- package/dist/core/index.d.cts +963 -0
- package/dist/core/index.d.ts +963 -0
- package/dist/core/index.js +1 -0
- package/dist/index.cjs +180 -3
- package/dist/index.d.cts +2 -855
- package/dist/index.d.ts +2 -855
- package/dist/index.js +4 -872
- package/dist/themes/theme-default.css +343 -0
- package/dist/themes/theme-ui-citrus-ink.css +364 -0
- package/dist/themes/theme-ui-custom-crisp.css +969 -0
- package/dist/themes/theme-ui-facebook-blue.css +381 -0
- package/dist/themes/theme-ui-neo-slate.css +962 -0
- package/dist/themes/theme-ui-new-main-fe-sunset.css +1316 -0
- package/dist/themes/theme-ui-new-main-fe.css +343 -0
- package/dist/themes/theme-ui-pure-white.css +377 -0
- package/dist/themes/theme-ui-siraya-vii-light.css +603 -0
- package/dist/themes/theme-ui-solstice-pop.css +1020 -0
- package/dist/themes/theme-ui-uat-aurora.css +962 -0
- package/package.json +20 -4
package/AI_SETUP.md
CHANGED
|
@@ -1,51 +1,271 @@
|
|
|
1
1
|
# AI Setup
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Muc tieu cua file nay la de AI cua project dung `@lucasvu/scope-ui` dung cach, khong import lung tung, khong hardcode mau sai cho, va giu dung base `Vite + micro frontend` khi repo duoc setup o may khac.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Tu phien ban nay, cac phan generic truoc day thuong nam o `packages/shared/theme` da duoc ship ngay trong package nay:
|
|
6
|
+
|
|
7
|
+
- base stylesheet
|
|
8
|
+
- color-mode runtime
|
|
9
|
+
- bundled theme layers
|
|
10
|
+
- preset theme token generator
|
|
11
|
+
- layout preset va AI playbook
|
|
12
|
+
|
|
13
|
+
Surface duoc chia thanh 2 lo:
|
|
14
|
+
|
|
15
|
+
- `@lucasvu/scope-ui`: React components + full UI surface
|
|
16
|
+
- `@lucasvu/scope-ui/core`: theme/runtime/contracts khong phu thuoc React
|
|
17
|
+
|
|
18
|
+
Vi vay consumer project o may khac chi can cai mot package la du.
|
|
19
|
+
|
|
20
|
+
Neu project consumer da cai package, cach nhanh nhat la chay:
|
|
6
21
|
|
|
7
22
|
```bash
|
|
8
23
|
npm install @lucasvu/scope-ui
|
|
9
24
|
npx scope-ui-init --theme forest
|
|
10
25
|
```
|
|
11
26
|
|
|
12
|
-
|
|
27
|
+
Neu chua biet chon preset nao thi chay them:
|
|
13
28
|
|
|
14
29
|
```bash
|
|
15
30
|
npx scope-ui-init --list-themes
|
|
16
31
|
```
|
|
17
32
|
|
|
18
|
-
|
|
33
|
+
Neu chua cai `@lucasvu/scope-ui`, cac lenh tren se bao `E404` vi npm se co tai package ten `scope-ui-init`.
|
|
34
|
+
|
|
35
|
+
CLI nay se tao:
|
|
36
|
+
|
|
37
|
+
- `AGENTS.md`
|
|
38
|
+
- `src/styles/ui-theme.css`
|
|
39
|
+
- `src/layout-presets/workspace-admin-v1.ts`
|
|
40
|
+
|
|
41
|
+
`AGENTS.md` khoa flow hoi input -> doc layout preset -> dung shell -> moi toi page body. `src/layout-presets/workspace-admin-v1.ts` giu shared shell contract. `src/styles/ui-theme.css` giu token theme cua project. Neu khong truyen `--theme`, preset mac dinh la `ocean`.
|
|
42
|
+
|
|
43
|
+
## 1. Chot dung ranh gioi trach nhiem
|
|
44
|
+
|
|
45
|
+
Voi base `Vite + micro frontend`, nen giu dung 3 lop nay:
|
|
46
|
+
|
|
47
|
+
- `@lucasvu/scope-ui`: React surface
|
|
48
|
+
- `@lucasvu/scope-ui/core`: design token, theme runtime, bundled theme layers, AI contract
|
|
49
|
+
- `apps/shell`: host app, so huu sidebar, topbar, remote mount, routing tong, va theme toan cuc.
|
|
50
|
+
- `apps/*-mfe`: remote app, chi so huu page business cua chinh no.
|
|
51
|
+
|
|
52
|
+
Neu repo van co `packages/shared`, hay giu no cho business util, constant, hoac remote loader noi bo. Khong nen de generic theme runtime nam ben ngoai package nua neu muc tieu la cai o may khac cung chay ngay.
|
|
53
|
+
|
|
54
|
+
Khong nen de moi MFE tu dung shell rieng, tu tao palette rieng, hoac tu viet lai `Button/Input/Card`.
|
|
55
|
+
|
|
56
|
+
## 2. Cau truc folder khuyen nghi
|
|
57
|
+
|
|
58
|
+
```text
|
|
59
|
+
.
|
|
60
|
+
├─ package.json
|
|
61
|
+
├─ pnpm-workspace.yaml
|
|
62
|
+
├─ tsconfig.base.json
|
|
63
|
+
└─ apps/
|
|
64
|
+
├─ shell/
|
|
65
|
+
│ ├─ src/app/
|
|
66
|
+
│ ├─ src/layouts/
|
|
67
|
+
│ ├─ src/routes/
|
|
68
|
+
│ ├─ src/remotes/
|
|
69
|
+
│ ├─ src/styles/
|
|
70
|
+
│ │ ├─ index.css
|
|
71
|
+
│ │ └─ ui-theme.css
|
|
72
|
+
│ ├─ src/main.tsx
|
|
73
|
+
│ └─ vite.config.ts
|
|
74
|
+
└─ users-mfe/
|
|
75
|
+
├─ src/features/
|
|
76
|
+
├─ src/pages/
|
|
77
|
+
├─ src/routes/
|
|
78
|
+
├─ src/services/
|
|
79
|
+
├─ src/styles/
|
|
80
|
+
│ └─ index.css
|
|
81
|
+
├─ src/bootstrap.tsx
|
|
82
|
+
└─ vite.config.ts
|
|
83
|
+
```
|
|
19
84
|
|
|
20
|
-
|
|
85
|
+
Neu base cua ban dang dung `mfes/` thay vi `apps/`, co the giu nguyen ten folder. Dieu can giu on dinh la trach nhiem cua `shell`, `remote`, va package UI chung.
|
|
21
86
|
|
|
22
|
-
##
|
|
87
|
+
## 3. Root config toi thieu
|
|
23
88
|
|
|
24
|
-
|
|
89
|
+
### `pnpm-workspace.yaml`
|
|
90
|
+
|
|
91
|
+
```yaml
|
|
92
|
+
packages:
|
|
93
|
+
- apps/*
|
|
94
|
+
- packages/*
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### `tsconfig.base.json`
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"compilerOptions": {
|
|
102
|
+
"baseUrl": "."
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`@lucasvu/scope-ui` nen duoc dung nhu workspace package that hoac npm package that. Neu project khong dung React, import tu `@lucasvu/scope-ui/core`.
|
|
108
|
+
|
|
109
|
+
## 4. Import style dung thu tu
|
|
110
|
+
|
|
111
|
+
Import package CSS truoc, roi moi toi bundled theme layer cua package neu can, roi moi toi file override rieng cua app.
|
|
25
112
|
|
|
26
113
|
```ts
|
|
27
114
|
import '@lucasvu/scope-ui/styles.css'
|
|
115
|
+
import '@lucasvu/scope-ui/themes/theme-ui-new-main-fe.css'
|
|
28
116
|
import './styles/ui-theme.css'
|
|
117
|
+
import './styles/index.css'
|
|
29
118
|
```
|
|
30
119
|
|
|
31
|
-
|
|
120
|
+
Thu tu nay co chu dich:
|
|
32
121
|
|
|
33
|
-
|
|
122
|
+
1. `@lucasvu/scope-ui/styles.css`: nap token va component style goc.
|
|
123
|
+
2. `@lucasvu/scope-ui/themes/*.css`: optional bundled shell/theme layer ship cung package.
|
|
124
|
+
3. `./styles/ui-theme.css`: app shell override nhe neu can.
|
|
125
|
+
4. `./styles/index.css`: reset va layout cuc bo cua shell.
|
|
34
126
|
|
|
35
|
-
|
|
127
|
+
Neu khong muon them bundled theme layer, co the bo qua buoc 2 va import `src/styles/ui-theme.css` ngay sau package stylesheet.
|
|
36
128
|
|
|
37
|
-
|
|
129
|
+
## 5. Color mode va packaged theme layer
|
|
38
130
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
131
|
+
Package da export san color-mode runtime:
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
import {
|
|
135
|
+
applyDocumentClientTheme,
|
|
136
|
+
initializeDocumentColorMode,
|
|
137
|
+
} from '@lucasvu/scope-ui/core'
|
|
138
|
+
|
|
139
|
+
initializeDocumentColorMode()
|
|
140
|
+
applyDocumentClientTheme('neo-slate')
|
|
42
141
|
```
|
|
43
142
|
|
|
44
|
-
|
|
143
|
+
Dung `applyDocumentClientTheme(...)` khi ban import theme layer dang attribute-scoped, vi du:
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
import '@lucasvu/scope-ui/themes/theme-ui-neo-slate.css'
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Theme layer co 2 nhom:
|
|
150
|
+
|
|
151
|
+
- global: import la apply ngay, vi du `theme-default.css`, `theme-ui-new-main-fe.css`
|
|
152
|
+
- data-client-theme: can them `data-client-theme` vao `document.documentElement`, vi du `theme-ui-neo-slate.css`
|
|
153
|
+
|
|
154
|
+
Danh sach nay co san trong `uiThemeLayerAssets`.
|
|
155
|
+
|
|
156
|
+
## 6. Step-by-step dung shell app
|
|
157
|
+
|
|
158
|
+
### Buoc 1: Tao folder shell
|
|
159
|
+
|
|
160
|
+
```text
|
|
161
|
+
apps/shell/src/
|
|
162
|
+
├─ app/
|
|
163
|
+
├─ layouts/
|
|
164
|
+
├─ routes/
|
|
165
|
+
├─ remotes/
|
|
166
|
+
├─ styles/
|
|
167
|
+
│ ├─ index.css
|
|
168
|
+
│ └─ ui-theme.css
|
|
169
|
+
└─ main.tsx
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Buoc 2: Khoi dong theme o entry
|
|
173
|
+
|
|
174
|
+
```tsx
|
|
175
|
+
import '@lucasvu/scope-ui/styles.css'
|
|
176
|
+
import '@lucasvu/scope-ui/themes/theme-ui-new-main-fe.css'
|
|
177
|
+
import './styles/ui-theme.css'
|
|
178
|
+
import './styles/index.css'
|
|
179
|
+
|
|
180
|
+
import { initializeDocumentColorMode } from '@lucasvu/scope-ui'
|
|
181
|
+
|
|
182
|
+
initializeDocumentColorMode()
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Neu dung mot client theme nhu `neo-slate`, `pure-white`, `solstice-pop`, them:
|
|
186
|
+
|
|
187
|
+
```tsx
|
|
188
|
+
import { applyDocumentClientTheme } from '@lucasvu/scope-ui'
|
|
189
|
+
|
|
190
|
+
applyDocumentClientTheme('neo-slate')
|
|
191
|
+
```
|
|
45
192
|
|
|
46
|
-
|
|
193
|
+
### Buoc 3: Shell so huu app frame
|
|
47
194
|
|
|
48
|
-
|
|
195
|
+
Shell nen so huu:
|
|
196
|
+
|
|
197
|
+
- sidebar
|
|
198
|
+
- topbar
|
|
199
|
+
- route container
|
|
200
|
+
- remote mount point
|
|
201
|
+
- theme selector
|
|
202
|
+
- toaster/modal root neu co
|
|
203
|
+
|
|
204
|
+
Remote khong nen tu render mot shell khac neu dang chay ben trong host shell.
|
|
205
|
+
|
|
206
|
+
### Buoc 4: Shell doc layout preset truoc khi dung page
|
|
207
|
+
|
|
208
|
+
`src/layout-presets/workspace-admin-v1.ts` la source of truth cho shared shell:
|
|
209
|
+
|
|
210
|
+
- dark sidebar
|
|
211
|
+
- gradient topbar
|
|
212
|
+
- intro card
|
|
213
|
+
- optional segmented tabs
|
|
214
|
+
- toolbar card
|
|
215
|
+
- body card/table/form
|
|
216
|
+
|
|
217
|
+
Khong nen bo qua preset nay roi ve mot page frame phang moi lan AI code.
|
|
218
|
+
|
|
219
|
+
## 7. Step-by-step dung remote app
|
|
220
|
+
|
|
221
|
+
### Folder toi thieu
|
|
222
|
+
|
|
223
|
+
```text
|
|
224
|
+
apps/users-mfe/src/
|
|
225
|
+
├─ features/users/
|
|
226
|
+
├─ pages/
|
|
227
|
+
├─ routes/
|
|
228
|
+
├─ services/
|
|
229
|
+
├─ styles/
|
|
230
|
+
│ └─ index.css
|
|
231
|
+
└─ bootstrap.tsx
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Rule cho remote
|
|
235
|
+
|
|
236
|
+
- Dung component tu `@lucasvu/scope-ui`.
|
|
237
|
+
- Khong tao them bo token/theme moi trong remote neu khong that can.
|
|
238
|
+
- Chi them CSS cho page hoac behavior dac thu cua remote.
|
|
239
|
+
- Neu remote chay standalone de local dev, van import style theo dung thu tu o tren.
|
|
240
|
+
- Remote so huu page business, khong so huu app shell chung.
|
|
241
|
+
|
|
242
|
+
## 8. Theme chung nen dat o dau
|
|
243
|
+
|
|
244
|
+
Nen chia thanh 3 lop:
|
|
245
|
+
|
|
246
|
+
### Lop 1: UI base
|
|
247
|
+
|
|
248
|
+
`@lucasvu/scope-ui/styles.css`
|
|
249
|
+
|
|
250
|
+
Lop nay dinh nghia token mac dinh va style component.
|
|
251
|
+
|
|
252
|
+
### Lop 2: Bundled theme layer cua package
|
|
253
|
+
|
|
254
|
+
`@lucasvu/scope-ui/themes/*.css`
|
|
255
|
+
|
|
256
|
+
Vi du:
|
|
257
|
+
|
|
258
|
+
- `@lucasvu/scope-ui/themes/theme-default.css`
|
|
259
|
+
- `@lucasvu/scope-ui/themes/theme-ui-new-main-fe.css`
|
|
260
|
+
- `@lucasvu/scope-ui/themes/theme-ui-neo-slate.css`
|
|
261
|
+
|
|
262
|
+
Day la noi package ship them shell token, typography, va visual language dung lai duoc tren may khac.
|
|
263
|
+
|
|
264
|
+
### Lop 3: App override rat mong
|
|
265
|
+
|
|
266
|
+
`apps/shell/src/styles/ui-theme.css`
|
|
267
|
+
|
|
268
|
+
File nay chi nen override mot vai token neu shell can branding rieng:
|
|
49
269
|
|
|
50
270
|
```css
|
|
51
271
|
:root {
|
|
@@ -53,37 +273,58 @@ File generate ra sẽ là source of truth cho palette, surface, radius và shado
|
|
|
53
273
|
--tw-accent: 24 95% 52%;
|
|
54
274
|
--primary-grad-from: 24 95% 52%;
|
|
55
275
|
--primary-grad-to: 12 88% 56%;
|
|
56
|
-
--surface: rgba(255, 248, 240, 0.92);
|
|
57
276
|
}
|
|
58
277
|
|
|
59
278
|
.dark {
|
|
60
279
|
--tw-primary: 18 100% 62%;
|
|
61
280
|
--tw-accent: 35 100% 58%;
|
|
62
|
-
--surface: rgba(24, 24, 27, 0.82);
|
|
63
281
|
}
|
|
64
282
|
```
|
|
65
283
|
|
|
66
|
-
|
|
284
|
+
Khong nen doi mau truc tiep trong tung component neu chi dang doi theme.
|
|
285
|
+
|
|
286
|
+
## 9. Chon preset theme cua project
|
|
287
|
+
|
|
288
|
+
Dat file tai `src/styles/ui-theme.css`.
|
|
289
|
+
|
|
290
|
+
Dung `--list-themes` de xem preset duoc duyet, roi generate preset da chon:
|
|
291
|
+
|
|
292
|
+
```bash
|
|
293
|
+
npx scope-ui-init --list-themes
|
|
294
|
+
npx scope-ui-init --theme graphite
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
File generate ra se la source of truth cho palette, surface, radius va shadow cua project. Agent phai bam vao file nay thay vi tu nghi mau moi.
|
|
298
|
+
|
|
299
|
+
Neu can them mot bundled package theme layer de co shell tone dung san, import no o app entry. Neu theme layer do la attribute-scoped, set them `data-client-theme` bang `applyDocumentClientTheme`.
|
|
67
300
|
|
|
68
|
-
`
|
|
301
|
+
`AGENTS.md` se co them shell brief + screen brief dang YAML de agent dien cac gia tri nhu `workspaceLabel`, `pageTabs`, `searchPlaceholder`, `routeUrl`, `sidebarItems`, `pageTitle`, `filters`, `fields`, `tableColumns` truoc khi bat dau viet JSX.
|
|
69
302
|
|
|
70
|
-
|
|
303
|
+
`src/layout-presets/workspace-admin-v1.ts` khong can import vao runtime. Day la layout contract cho agent/codegen doc de giu dark sidebar, gradient topbar, intro card, tab row, va toolbar card nhat quan giua cac man.
|
|
71
304
|
|
|
72
|
-
|
|
305
|
+
## 10. Rule cho AI cua project
|
|
306
|
+
|
|
307
|
+
Copy phan nay vao system prompt, repo instructions, `AGENTS.md`, Cursor rules, hoac bat ky cho nao project dang dung de ep AI theo convention:
|
|
73
308
|
|
|
74
309
|
```md
|
|
75
|
-
Use `@lucasvu/scope-ui`
|
|
310
|
+
Use `@lucasvu/scope-ui` for React projects and `@lucasvu/scope-ui/core` for framework-agnostic theme/runtime usage.
|
|
76
311
|
|
|
77
312
|
Always:
|
|
313
|
+
- use `@lucasvu/scope-ui` as the shared React UI package when the app is React
|
|
314
|
+
- use `@lucasvu/scope-ui/core` when the app only needs theme/runtime/contracts
|
|
78
315
|
- import `@lucasvu/scope-ui/styles.css` once at the app entry
|
|
79
|
-
-
|
|
316
|
+
- if the repo chooses a bundled theme layer, import it from `@lucasvu/scope-ui/themes/*` after the package stylesheet
|
|
317
|
+
- import the project theme override file after the bundled theme layer
|
|
318
|
+
- use `initializeDocumentColorMode` from `@lucasvu/scope-ui/core` when the app shell owns dark/light mode
|
|
319
|
+
- if a bundled theme layer is client-theme-scoped, set `data-client-theme` via `applyDocumentClientTheme` from `@lucasvu/scope-ui/core`
|
|
80
320
|
- use root exports from `@lucasvu/scope-ui`
|
|
81
321
|
- stay inside the approved preset declared by `src/styles/ui-theme.css`
|
|
82
322
|
- read `src/layout-presets/workspace-admin-v1.ts` before changing the app shell or page frame
|
|
83
323
|
- follow the step-by-step UI build workflow from `AGENTS.md` before writing JSX
|
|
324
|
+
- keep the shell in the host app and keep remotes focused on page business content
|
|
84
325
|
- fill the shell + screen brief first: `workspaceLabel`, `pageTabs`, `searchPlaceholder`, `routeUrl`, `sidebarItems`, `activeSidebarItemId`, `pageTitle`, `actions`, and the page-specific schema
|
|
85
326
|
- read `uiAiManifest` to choose the right component by intent
|
|
86
|
-
- read `uiScreenBlueprint` and `
|
|
327
|
+
- read `uiScreenBlueprint`, `uiThemeContract`, and `uiThemeLayerAssets` before changing layout, colors, surfaces, borders, or shadows
|
|
87
328
|
|
|
88
329
|
Do not:
|
|
89
330
|
- import from `MainFe` unless the task explicitly targets a legacy screen
|
|
@@ -91,6 +332,7 @@ Do not:
|
|
|
91
332
|
- replace the shared dark-sidebar + gradient-topbar shell unless the task explicitly asks for a new shell
|
|
92
333
|
- hardcode brand colors inside page components when a theme token already exists
|
|
93
334
|
- create duplicate Button/Input/Select wrappers unless a project-specific behavior is required
|
|
335
|
+
- let each remote define a different shell or a different palette
|
|
94
336
|
|
|
95
337
|
Component choice:
|
|
96
338
|
- `Input` for short text
|
|
@@ -104,32 +346,53 @@ Component choice:
|
|
|
104
346
|
- `DataTable` for tabular records
|
|
105
347
|
```
|
|
106
348
|
|
|
107
|
-
##
|
|
349
|
+
## 11. Runtime contract cho AI/codegen
|
|
108
350
|
|
|
109
|
-
Trong code, AI
|
|
351
|
+
Trong code, AI co the doc truc tiep:
|
|
110
352
|
|
|
111
353
|
```ts
|
|
112
|
-
import {
|
|
354
|
+
import {
|
|
355
|
+
applyDocumentClientTheme,
|
|
356
|
+
initializeDocumentColorMode,
|
|
357
|
+
uiAiManifest,
|
|
358
|
+
uiProjectAiRules,
|
|
359
|
+
uiScreenBlueprint,
|
|
360
|
+
uiThemeContract,
|
|
361
|
+
uiThemeLayerAssets,
|
|
362
|
+
uiThemePresets,
|
|
363
|
+
} from '@lucasvu/scope-ui/core'
|
|
113
364
|
```
|
|
114
365
|
|
|
115
|
-
- `
|
|
116
|
-
- `
|
|
117
|
-
- `
|
|
118
|
-
- `
|
|
119
|
-
- `
|
|
366
|
+
- `initializeDocumentColorMode`: dong bo dark/light mode o document root
|
|
367
|
+
- `applyDocumentClientTheme`: set `data-client-theme` cho bundled theme layer dang attribute-scoped
|
|
368
|
+
- `uiAiManifest`: chon component theo intent
|
|
369
|
+
- `uiScreenBlueprint`: brief input va khung layout chuan cho `list | form | detail | dashboard`, gom ca shell fields nhu `layoutPreset`, `workspaceLabel`, `pageTabs`, `searchPlaceholder`
|
|
370
|
+
- `uiThemeContract`: biet override token nao va override o dau
|
|
371
|
+
- `uiThemeLayerAssets`: danh sach bundled theme layer co san trong package, gom ca import path va activation mode
|
|
372
|
+
- `uiThemePresets`: danh sach preset duoc duyet de nhieu project dung chung mot visual language
|
|
373
|
+
- `uiProjectAiRules`: rule ngan gon de inject vao agent cua project
|
|
374
|
+
|
|
375
|
+
Neu project dung React components cua package, van import component tu root package:
|
|
376
|
+
|
|
377
|
+
```ts
|
|
378
|
+
import { Button, Card, Input, Select } from '@lucasvu/scope-ui'
|
|
379
|
+
```
|
|
120
380
|
|
|
121
|
-
##
|
|
381
|
+
## 12. Cho override theme
|
|
122
382
|
|
|
123
|
-
|
|
383
|
+
Neu project co app shell:
|
|
124
384
|
|
|
125
|
-
- import `@lucasvu/scope-ui/styles.css`
|
|
126
|
-
- import
|
|
127
|
-
-
|
|
128
|
-
-
|
|
385
|
+
- import `@lucasvu/scope-ui/styles.css` o app entry
|
|
386
|
+
- import mot bundled package theme layer neu muon
|
|
387
|
+
- import `src/styles/ui-theme.css` ngay sau do
|
|
388
|
+
- goi `initializeDocumentColorMode()` o host app
|
|
389
|
+
- neu dung client theme layer, goi `applyDocumentClientTheme('<theme-id>')`
|
|
390
|
+
- de agent doc `src/layout-presets/workspace-admin-v1.ts` truoc khi build page shell
|
|
391
|
+
- toggle dark mode bang class `.dark` tren `html` hoac `body`, hoac dung `[data-ui-theme='dark']`
|
|
129
392
|
|
|
130
|
-
|
|
393
|
+
Neu project co nhieu brand/theme:
|
|
131
394
|
|
|
132
|
-
-
|
|
133
|
-
-
|
|
134
|
-
-
|
|
135
|
-
-
|
|
395
|
+
- giu `:root` la theme mac dinh
|
|
396
|
+
- tao selector nhu `[data-ui-theme='brand-a']`, `[data-ui-theme='brand-b']` hoac dung `data-client-theme`
|
|
397
|
+
- van nen xuat phat tu mot preset duyet san roi moi override token can thiet
|
|
398
|
+
- chi override token trong file theme, khong fork component
|
package/README.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# @lucasvu/scope-ui
|
|
2
2
|
|
|
3
|
-
Bộ
|
|
3
|
+
Bộ UI dùng chung cho các app/micro-frontend trong workspace.
|
|
4
|
+
|
|
5
|
+
- Root package `@lucasvu/scope-ui`: React components + full UI surface
|
|
6
|
+
- Core subpath `@lucasvu/scope-ui/core`: theme/runtime/contracts không phụ thuộc React
|
|
4
7
|
|
|
5
8
|
## Cách dùng nhanh
|
|
6
9
|
|
|
@@ -10,13 +13,40 @@ Bộ component phong cách **shadcn** dùng chung cho các app/micro-frontend tr
|
|
|
10
13
|
npm install @lucasvu/scope-ui
|
|
11
14
|
```
|
|
12
15
|
|
|
13
|
-
2.
|
|
16
|
+
2. Nếu dùng React, import từ root package:
|
|
14
17
|
|
|
15
18
|
```ts
|
|
16
19
|
import '@lucasvu/scope-ui/styles.css';
|
|
20
|
+
import '@lucasvu/scope-ui/themes/theme-ui-new-main-fe.css';
|
|
21
|
+
import './styles/ui-theme.css';
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Nếu muốn dùng theme layer dạng client-theme, ví dụ `neo-slate`, set thêm ở app entry:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { applyDocumentClientTheme, initializeDocumentColorMode } from '@lucasvu/scope-ui';
|
|
28
|
+
|
|
29
|
+
initializeDocumentColorMode();
|
|
30
|
+
applyDocumentClientTheme('neo-slate');
|
|
17
31
|
```
|
|
18
32
|
|
|
19
|
-
3. Nếu
|
|
33
|
+
3. Nếu không dùng React, import phần generic từ `@lucasvu/scope-ui/core`:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import '@lucasvu/scope-ui/styles.css';
|
|
37
|
+
import '@lucasvu/scope-ui/themes/theme-ui-neo-slate.css';
|
|
38
|
+
|
|
39
|
+
import {
|
|
40
|
+
applyDocumentClientTheme,
|
|
41
|
+
initializeDocumentColorMode,
|
|
42
|
+
uiThemeLayerAssets,
|
|
43
|
+
} from '@lucasvu/scope-ui/core';
|
|
44
|
+
|
|
45
|
+
initializeDocumentColorMode();
|
|
46
|
+
applyDocumentClientTheme('neo-slate');
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
4. Nếu muốn bootstrap rule/theme/layout cho AI trong project consumer:
|
|
20
50
|
|
|
21
51
|
```bash
|
|
22
52
|
npm install @lucasvu/scope-ui
|
|
@@ -33,7 +63,7 @@ Lưu ý: các lệnh này chỉ chạy được sau khi project đã cài `@luca
|
|
|
33
63
|
|
|
34
64
|
Lệnh này sẽ tạo `AGENTS.md`, `src/styles/ui-theme.css`, và `src/layout-presets/workspace-admin-v1.ts` trong repo hiện tại theo preset đã chọn. `AGENTS.md` giờ có thêm playbook step-by-step để agent hỏi đủ input, đọc layout preset, rồi dựng màn hình đúng layout/component/theme chung. Nếu không truyền `--theme`, preset mặc định là `ocean`. Dùng `--force` nếu muốn overwrite file đã tồn tại.
|
|
35
65
|
|
|
36
|
-
|
|
66
|
+
5. Dùng component:
|
|
37
67
|
|
|
38
68
|
```tsx
|
|
39
69
|
import {
|
|
@@ -104,12 +134,49 @@ export function Example() {
|
|
|
104
134
|
- `Field` phù hợp khi bạn cần bọc một control custom hoặc gom nhiều control dưới cùng một nhãn.
|
|
105
135
|
- Nếu bạn đổi tên package trước khi publish, thay `@lucasvu/scope-ui` trong các ví dụ bằng package name mới.
|
|
106
136
|
|
|
137
|
+
## Bundled Theme Layers
|
|
138
|
+
|
|
139
|
+
Package ship sẵn các theme asset để máy khác cài vào là dùng được ngay:
|
|
140
|
+
|
|
141
|
+
- Global apply ngay khi import: `@lucasvu/scope-ui/themes/theme-default.css`, `@lucasvu/scope-ui/themes/theme-ui-new-main-fe.css`
|
|
142
|
+
- Client-theme scoped: `@lucasvu/scope-ui/themes/theme-ui-neo-slate.css`, `@lucasvu/scope-ui/themes/theme-ui-facebook-blue.css`, `@lucasvu/scope-ui/themes/theme-ui-solstice-pop.css`, ...
|
|
143
|
+
|
|
144
|
+
Bạn có thể đọc manifest ngay trong code:
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
import { uiThemeLayerAssets } from '@lucasvu/scope-ui/core';
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Nếu một theme có `activation: 'data-client-theme'`, hãy gọi `applyDocumentClientTheme('<theme-id>')` sau khi import CSS của theme đó.
|
|
151
|
+
|
|
152
|
+
## Core Surface
|
|
153
|
+
|
|
154
|
+
Nếu project không dùng React nhưng vẫn muốn dùng theme/runtime/contracts của package, dùng:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
import {
|
|
158
|
+
applyDocumentClientTheme,
|
|
159
|
+
initializeDocumentColorMode,
|
|
160
|
+
uiAiManifest,
|
|
161
|
+
uiProjectAiRules,
|
|
162
|
+
uiScreenBlueprint,
|
|
163
|
+
uiThemeContract,
|
|
164
|
+
uiThemeLayerAssets,
|
|
165
|
+
uiThemePresets,
|
|
166
|
+
} from '@lucasvu/scope-ui/core';
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
`@lucasvu/scope-ui/core` không export React component surface.
|
|
170
|
+
|
|
107
171
|
## Dùng cho AI/codegen
|
|
108
172
|
|
|
109
173
|
Nếu muốn AI render UI đúng và ổn định theo thư viện này, đừng chỉ đưa mỗi tên package. Hãy để agent bám vào một surface chuẩn:
|
|
110
174
|
|
|
111
175
|
- Import CSS global một lần: `@lucasvu/scope-ui/styles.css`
|
|
112
|
-
-
|
|
176
|
+
- Nếu project muốn dùng shell/theme layer dựng sẵn, import từ `@lucasvu/scope-ui/themes/*` ngay sau package CSS
|
|
177
|
+
- Import file theme override của project ngay sau bundled theme layer, ví dụ `./styles/ui-theme.css`
|
|
178
|
+
- Dùng `initializeDocumentColorMode()` từ `@lucasvu/scope-ui` khi shell sở hữu dark/light mode
|
|
179
|
+
- Nếu bundled theme layer là client-theme scoped, set `data-client-theme` bằng `applyDocumentClientTheme(...)`
|
|
113
180
|
- Cài package trước khi bootstrap: `npm install @lucasvu/scope-ui`
|
|
114
181
|
- Chạy `npx scope-ui-init --list-themes` để xem preset được duyệt
|
|
115
182
|
- Chạy `npx scope-ui-init --theme <preset>` ở project consumer sau khi đã cài `@lucasvu/scope-ui` để tạo `AGENTS.md`, `src/styles/ui-theme.css`, và `src/layout-presets/workspace-admin-v1.ts`
|
|
@@ -123,12 +190,15 @@ Nếu muốn AI render UI đúng và ổn định theo thư viện này, đừng
|
|
|
123
190
|
|
|
124
191
|
```ts
|
|
125
192
|
import {
|
|
193
|
+
applyDocumentClientTheme,
|
|
194
|
+
initializeDocumentColorMode,
|
|
126
195
|
uiAiManifest,
|
|
127
196
|
uiProjectAiRules,
|
|
128
197
|
uiScreenBlueprint,
|
|
129
198
|
uiThemeContract,
|
|
199
|
+
uiThemeLayerAssets,
|
|
130
200
|
uiThemePresets,
|
|
131
|
-
} from '@lucasvu/scope-ui';
|
|
201
|
+
} from '@lucasvu/scope-ui/core';
|
|
132
202
|
```
|
|
133
203
|
|
|
134
204
|
`uiAiManifest` mô tả luật chọn component theo intent như: text input, textarea, fixed select, searchable select, async combobox, multi select, data table, alert, card và field wrapper.
|
|
@@ -137,13 +207,15 @@ import {
|
|
|
137
207
|
|
|
138
208
|
`uiThemeContract` mô tả token màu, surface, border, shadow, radius, gradient và selector theme (`:root`, `.dark`, `[data-ui-theme='*']`) để AI không hardcode màu sai chỗ.
|
|
139
209
|
|
|
210
|
+
`uiThemeLayerAssets` mô tả các theme layer CSS được ship sẵn trong package, import path tương ứng, và theme nào cần `data-client-theme`.
|
|
211
|
+
|
|
140
212
|
`uiThemePresets` là danh sách preset được duyệt sẵn để nhiều project có thể chọn cùng một visual language mà không cần tự dựng theme từ đầu.
|
|
141
213
|
|
|
142
214
|
`AI_SETUP.md` và CLI `scope-ui-init` giúp bootstrap rule/theme/layout cho repo consumer mà không cần copy tay.
|
|
143
215
|
|
|
144
216
|
## Theme Override
|
|
145
217
|
|
|
146
|
-
Nên để toàn bộ override theme của project vào một file riêng, ví dụ `src/styles/ui-theme.css`, rồi import file này sau `@lucasvu/scope-ui/styles.css
|
|
218
|
+
Nên để toàn bộ override theme của project vào một file riêng, ví dụ `src/styles/ui-theme.css`, rồi import file này sau `@lucasvu/scope-ui/styles.css` và sau bundled theme layer nếu có.
|
|
147
219
|
|
|
148
220
|
Cách nhanh nhất là generate bộ file này từ preset:
|
|
149
221
|
|
|
@@ -155,6 +227,7 @@ npx scope-ui-init --theme ocean
|
|
|
155
227
|
|
|
156
228
|
```ts
|
|
157
229
|
import '@lucasvu/scope-ui/styles.css';
|
|
230
|
+
import '@lucasvu/scope-ui/themes/theme-ui-new-main-fe.css';
|
|
158
231
|
import './styles/ui-theme.css';
|
|
159
232
|
```
|
|
160
233
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, rmSync } from 'node:fs'
|
|
4
|
+
import { dirname, join, resolve } from 'node:path'
|
|
5
|
+
|
|
6
|
+
const sourceDir = resolve(process.cwd(), '../shared/theme')
|
|
7
|
+
const targetDir = resolve(process.cwd(), 'dist/themes')
|
|
8
|
+
|
|
9
|
+
if (!existsSync(sourceDir)) {
|
|
10
|
+
console.error(`Theme asset source not found: ${sourceDir}`)
|
|
11
|
+
process.exit(1)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
rmSync(targetDir, { force: true, recursive: true })
|
|
15
|
+
mkdirSync(targetDir, { recursive: true })
|
|
16
|
+
|
|
17
|
+
const themeFiles = readdirSync(sourceDir)
|
|
18
|
+
.filter((fileName) => fileName.endsWith('.css'))
|
|
19
|
+
.sort()
|
|
20
|
+
|
|
21
|
+
for (const fileName of themeFiles) {
|
|
22
|
+
const sourceFile = join(sourceDir, fileName)
|
|
23
|
+
const targetFile = join(targetDir, fileName)
|
|
24
|
+
|
|
25
|
+
mkdirSync(dirname(targetFile), { recursive: true })
|
|
26
|
+
copyFileSync(sourceFile, targetFile)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
console.log(`Copied ${themeFiles.length} theme assets to dist/themes`)
|