@lucasvu/scope-ui 0.0.3 → 0.0.5
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 +20 -4
- package/README.md +49 -61
- package/bin/scope-ui-init.mjs +308 -20
- package/dist/index.cjs +237 -15
- package/dist/index.d.cts +406 -5
- package/dist/index.d.ts +406 -5
- package/dist/index.js +236 -16
- package/package.json +2 -2
package/AI_SETUP.md
CHANGED
|
@@ -5,10 +5,13 @@ Mục tiêu của file này là để AI của project dùng `@lucasvu/scope-ui`
|
|
|
5
5
|
Nếu project consumer đã cài package, cách nhanh nhất là chạy:
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npx scope-ui-init
|
|
8
|
+
npx scope-ui-init --list-themes
|
|
9
|
+
npx scope-ui-init --theme forest
|
|
9
10
|
```
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
Nếu chưa cài `@lucasvu/scope-ui`, lệnh trên sẽ báo `E404` vì npm sẽ cố tải package tên `scope-ui-init`.
|
|
13
|
+
|
|
14
|
+
CLI này sẽ tạo `AGENTS.md` và `src/styles/ui-theme.css` theo đúng convention bên dưới. Nếu không truyền `--theme`, preset mặc định là `ocean`.
|
|
12
15
|
|
|
13
16
|
## 1. Import style đúng thứ tự
|
|
14
17
|
|
|
@@ -21,10 +24,19 @@ import './styles/ui-theme.css'
|
|
|
21
24
|
|
|
22
25
|
`ui-theme.css` nên là nơi duy nhất override màu, surface, border, shadow và gradient của thư viện.
|
|
23
26
|
|
|
24
|
-
## 2.
|
|
27
|
+
## 2. Chọn preset theme của project
|
|
25
28
|
|
|
26
29
|
Đặt file tại `src/styles/ui-theme.css`.
|
|
27
30
|
|
|
31
|
+
Dùng `--list-themes` để xem preset được duyệt, rồi generate preset đã chọn:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npx scope-ui-init --list-themes
|
|
35
|
+
npx scope-ui-init --theme graphite
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
File generate ra sẽ là source of truth cho palette, surface, radius và shadow của project. Agent phải bám vào file này thay vì tự nghĩ màu mới.
|
|
39
|
+
|
|
28
40
|
```css
|
|
29
41
|
:root {
|
|
30
42
|
--tw-primary: 12 88% 56%;
|
|
@@ -54,11 +66,13 @@ Always:
|
|
|
54
66
|
- import `@lucasvu/scope-ui/styles.css` once at the app entry
|
|
55
67
|
- import the project theme override file after the package stylesheet
|
|
56
68
|
- use root exports from `@lucasvu/scope-ui`
|
|
69
|
+
- stay inside the approved preset declared by `src/styles/ui-theme.css`
|
|
57
70
|
- read `uiAiManifest` to choose the right component by intent
|
|
58
71
|
- read `uiThemeContract` before changing colors, surfaces, borders, or shadows
|
|
59
72
|
|
|
60
73
|
Do not:
|
|
61
74
|
- import from `MainFe` unless the task explicitly targets a legacy screen
|
|
75
|
+
- invent a second palette outside the preset file
|
|
62
76
|
- hardcode brand colors inside page components when a theme token already exists
|
|
63
77
|
- create duplicate Button/Input/Select wrappers unless a project-specific behavior is required
|
|
64
78
|
|
|
@@ -79,11 +93,12 @@ Component choice:
|
|
|
79
93
|
Trong code, AI có thể đọc trực tiếp:
|
|
80
94
|
|
|
81
95
|
```ts
|
|
82
|
-
import { uiAiManifest, uiThemeContract, uiProjectAiRules } from '@lucasvu/scope-ui'
|
|
96
|
+
import { uiAiManifest, uiThemeContract, uiThemePresets, uiProjectAiRules } from '@lucasvu/scope-ui'
|
|
83
97
|
```
|
|
84
98
|
|
|
85
99
|
- `uiAiManifest`: chọn component theo intent
|
|
86
100
|
- `uiThemeContract`: biết override token nào và override ở đâu
|
|
101
|
+
- `uiThemePresets`: danh sách preset được duyệt để nhiều project dùng chung một visual language
|
|
87
102
|
- `uiProjectAiRules`: rule ngắn gọn để inject vào agent của project
|
|
88
103
|
|
|
89
104
|
## 5. Chỗ override theme
|
|
@@ -98,4 +113,5 @@ Nếu project có nhiều brand/theme:
|
|
|
98
113
|
|
|
99
114
|
- giữ `:root` là theme mặc định
|
|
100
115
|
- tạo selector như `[data-ui-theme='brand-a']`, `[data-ui-theme='brand-b']`
|
|
116
|
+
- vẫn nên xuất phát từ một preset duyệt sẵn rồi mới override token cần thiết
|
|
101
117
|
- chỉ override token trong file theme, không fork component
|
package/README.md
CHANGED
|
@@ -2,56 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
Bộ component phong cách **shadcn** dùng chung cho các app/micro-frontend trong workspace. Tất cả đều là React component thuần, kèm sẵn theme tối và hiệu ứng kính mờ.
|
|
4
4
|
|
|
5
|
-
## Publish lên npm
|
|
6
|
-
|
|
7
|
-
Nếu muốn publish public để người khác chỉ cần cài và import:
|
|
8
|
-
|
|
9
|
-
1. Đổi `name` trong `package.json` sang package name hoặc scope bạn thực sự sở hữu trên npm.
|
|
10
|
-
2. Chạy `npm install` để cài thêm tool build mới nếu máy chưa có lockfile/deps tương ứng.
|
|
11
|
-
3. Build package:
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
npm run build
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
4. Kiểm tra package trước khi publish:
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
npm pack --dry-run
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
5. Đăng nhập npm và publish:
|
|
24
|
-
|
|
25
|
-
```bash
|
|
26
|
-
npm login
|
|
27
|
-
npm publish
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
`publishConfig.access: public` đã được bật sẵn, nên với package dạng scope như `@lucasvu/scope-ui` không cần nhớ thêm `--access public`.
|
|
31
|
-
|
|
32
5
|
## Cách dùng nhanh
|
|
33
6
|
|
|
34
|
-
1
|
|
7
|
+
1. Cài package:
|
|
35
8
|
|
|
36
9
|
```bash
|
|
37
10
|
npm install @lucasvu/scope-ui
|
|
38
11
|
```
|
|
39
12
|
|
|
40
|
-
2
|
|
13
|
+
2. Import global style một lần ở entry (ví dụ `main.tsx`):
|
|
41
14
|
|
|
42
15
|
```ts
|
|
43
|
-
import '@lucasvu/scope-ui/styles.css'
|
|
16
|
+
import '@lucasvu/scope-ui/styles.css';
|
|
44
17
|
```
|
|
45
18
|
|
|
46
|
-
3
|
|
19
|
+
3. Nếu muốn bootstrap rule/theme cho AI trong project consumer:
|
|
47
20
|
|
|
48
21
|
```bash
|
|
49
|
-
npx scope-ui-init
|
|
22
|
+
npx scope-ui-init --list-themes
|
|
23
|
+
npx scope-ui-init --theme sunset
|
|
50
24
|
```
|
|
51
25
|
|
|
52
|
-
|
|
26
|
+
Lưu ý: lệnh này chỉ chạy được sau khi project đã cài `@lucasvu/scope-ui`. Nếu chưa cài package, `npx` sẽ đi tìm một package riêng tên `scope-ui-init` trên npm và báo `E404`.
|
|
53
27
|
|
|
54
|
-
|
|
28
|
+
Lệnh này sẽ tạo `AGENTS.md` và `src/styles/ui-theme.css` trong repo hiện tại theo preset đã chọn. 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.
|
|
29
|
+
|
|
30
|
+
4. Dùng component:
|
|
55
31
|
|
|
56
32
|
```tsx
|
|
57
33
|
import {
|
|
@@ -64,7 +40,7 @@ import {
|
|
|
64
40
|
Field,
|
|
65
41
|
Input,
|
|
66
42
|
Select,
|
|
67
|
-
} from '@lucasvu/scope-ui'
|
|
43
|
+
} from '@lucasvu/scope-ui';
|
|
68
44
|
|
|
69
45
|
export function Example() {
|
|
70
46
|
return (
|
|
@@ -97,7 +73,7 @@ export function Example() {
|
|
|
97
73
|
</CardContent>
|
|
98
74
|
<Button block>Tiếp tục</Button>
|
|
99
75
|
</Card>
|
|
100
|
-
)
|
|
76
|
+
);
|
|
101
77
|
}
|
|
102
78
|
```
|
|
103
79
|
|
|
@@ -128,18 +104,27 @@ Nếu muốn AI render UI đúng và ổn định theo thư viện này, đừng
|
|
|
128
104
|
|
|
129
105
|
- Import CSS global một lần: `@lucasvu/scope-ui/styles.css`
|
|
130
106
|
- Import file theme override của project ngay sau package CSS, ví dụ `./styles/ui-theme.css`
|
|
131
|
-
- Chạy `npx scope-ui-init`
|
|
107
|
+
- Chạy `npx scope-ui-init --list-themes` để xem preset được duyệt
|
|
108
|
+
- Chạy `npx scope-ui-init --theme <preset>` ở project consumer sau khi đã cài `@lucasvu/scope-ui` để tạo `AGENTS.md` và `src/styles/ui-theme.css`
|
|
109
|
+
- Khoá project vào một preset thay vì tự bịa palette mới cho từng page
|
|
132
110
|
- Chỉ dùng các component canonical ở root package; tránh `MainFe` nếu không phải legacy screen
|
|
133
111
|
- Cho agent đọc `uiAiManifest` để biết component nào dùng cho intent nào, props quan trọng là gì, và khi nào không nên dùng
|
|
134
|
-
- Cho agent đọc `uiThemeContract` để biết
|
|
112
|
+
- Cho agent đọc `uiThemeContract` và `uiThemePresets` để biết danh sách preset và token nào được phép override
|
|
135
113
|
|
|
136
114
|
```ts
|
|
137
|
-
import {
|
|
115
|
+
import {
|
|
116
|
+
uiAiManifest,
|
|
117
|
+
uiProjectAiRules,
|
|
118
|
+
uiThemeContract,
|
|
119
|
+
uiThemePresets,
|
|
120
|
+
} from '@lucasvu/scope-ui';
|
|
138
121
|
```
|
|
139
122
|
|
|
140
123
|
`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.
|
|
141
124
|
|
|
142
|
-
`uiThemeContract` mô tả token màu, surface, border, shadow, gradient và selector theme (`:root`, `.dark`, `[data-ui-theme='*']`) để AI không hardcode màu sai chỗ.
|
|
125
|
+
`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ỗ.
|
|
126
|
+
|
|
127
|
+
`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.
|
|
143
128
|
|
|
144
129
|
`AI_SETUP.md` và CLI `scope-ui-init` giúp bootstrap rule/theme cho repo consumer mà không cần copy tay.
|
|
145
130
|
|
|
@@ -147,9 +132,16 @@ import { uiAiManifest, uiProjectAiRules, uiThemeContract } from '@lucasvu/scope-
|
|
|
147
132
|
|
|
148
133
|
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`.
|
|
149
134
|
|
|
135
|
+
Cách nhanh nhất là generate file này từ preset:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
npx scope-ui-init --list-themes
|
|
139
|
+
npx scope-ui-init --theme ocean
|
|
140
|
+
```
|
|
141
|
+
|
|
150
142
|
```ts
|
|
151
|
-
import '@lucasvu/scope-ui/styles.css'
|
|
152
|
-
import './styles/ui-theme.css'
|
|
143
|
+
import '@lucasvu/scope-ui/styles.css';
|
|
144
|
+
import './styles/ui-theme.css';
|
|
153
145
|
```
|
|
154
146
|
|
|
155
147
|
Ví dụ:
|
|
@@ -213,12 +205,7 @@ type NumericInputProps = {
|
|
|
213
205
|
import { NumericInput } from '@lucasvu/scope-ui';
|
|
214
206
|
|
|
215
207
|
// 1) Integer qty
|
|
216
|
-
<NumericInput
|
|
217
|
-
mode="integer"
|
|
218
|
-
min={0}
|
|
219
|
-
value={qty}
|
|
220
|
-
onValueChange={setQty}
|
|
221
|
-
/>;
|
|
208
|
+
<NumericInput mode="integer" min={0} value={qty} onValueChange={setQty} />;
|
|
222
209
|
|
|
223
210
|
// 2) Money
|
|
224
211
|
<NumericInput
|
|
@@ -246,7 +233,7 @@ import { NumericInput } from '@lucasvu/scope-ui';
|
|
|
246
233
|
## DataTable
|
|
247
234
|
|
|
248
235
|
```tsx
|
|
249
|
-
import type { DataTableColumn, DataTableSortState } from '@lucasvu/scope-ui'
|
|
236
|
+
import type { DataTableColumn, DataTableSortState } from '@lucasvu/scope-ui';
|
|
250
237
|
```
|
|
251
238
|
|
|
252
239
|
### Tối thiểu
|
|
@@ -289,13 +276,13 @@ type DataTableProps<T> = {
|
|
|
289
276
|
|
|
290
277
|
```tsx
|
|
291
278
|
type DataTableColumn<T> = {
|
|
292
|
-
key: string;
|
|
293
|
-
title: ReactNode;
|
|
294
|
-
dataIndex?: keyof T;
|
|
295
|
-
width?: number | string;
|
|
279
|
+
key: string; // khóa duy nhất của cột
|
|
280
|
+
title: ReactNode; // tiêu đề hiển thị ở header
|
|
281
|
+
dataIndex?: keyof T; // map dữ liệu (mặc định lấy theo key)
|
|
282
|
+
width?: number | string; // độ rộng ưu tiên (vd: 180, '180px', '20%')
|
|
296
283
|
render?: (value, record, index) => ReactNode; // custom cell
|
|
297
|
-
sortable?: boolean;
|
|
298
|
-
sorter?: (a, b) => number;
|
|
284
|
+
sortable?: boolean; // bật/tắt sort cho cột (ưu tiên cao nhất)
|
|
285
|
+
sorter?: (a, b) => number; // so sánh asc/desc
|
|
299
286
|
sortValue?: (record) => string | number | Date | null;
|
|
300
287
|
};
|
|
301
288
|
```
|
|
@@ -371,7 +358,7 @@ Checkbox chỉ hiện khi truyền `rowSelection`. Không truyền thì sẽ ẩ
|
|
|
371
358
|
selectedRowKeys,
|
|
372
359
|
onChange: setSelectedRowKeys,
|
|
373
360
|
}}
|
|
374
|
-
|
|
361
|
+
/>
|
|
375
362
|
```
|
|
376
363
|
|
|
377
364
|
### Pagination + chọn page size
|
|
@@ -409,7 +396,7 @@ const [pageSize, setPageSize] = useState(20);
|
|
|
409
396
|
rowKey="id"
|
|
410
397
|
onRowClick={(row) => console.log(row)}
|
|
411
398
|
renderActions={(row) => <ActionMenu row={row} />}
|
|
412
|
-
|
|
399
|
+
/>
|
|
413
400
|
```
|
|
414
401
|
|
|
415
402
|
### Loading + empty
|
|
@@ -421,7 +408,7 @@ const [pageSize, setPageSize] = useState(20);
|
|
|
421
408
|
rowKey="id"
|
|
422
409
|
loading={isLoading}
|
|
423
410
|
emptyText="No data"
|
|
424
|
-
|
|
411
|
+
/>
|
|
425
412
|
```
|
|
426
413
|
|
|
427
414
|
### Sticky header khi scroll
|
|
@@ -449,7 +436,7 @@ DataTable tự hỗ trợ scroll ngang khi nội dung vượt chiều rộng (đ
|
|
|
449
436
|
Dùng khi cần hiển thị tối đa N dòng, nếu text bị cắt sẽ hiện tooltip đầy đủ khi hover.
|
|
450
437
|
|
|
451
438
|
```tsx
|
|
452
|
-
import { LineClampTooltip } from '@lucasvu/scope-ui'
|
|
439
|
+
import { LineClampTooltip } from '@lucasvu/scope-ui';
|
|
453
440
|
|
|
454
441
|
<LineClampTooltip
|
|
455
442
|
text={record.apiEndpoint}
|
|
@@ -458,12 +445,13 @@ import { LineClampTooltip } from '@lucasvu/scope-ui'
|
|
|
458
445
|
side="top"
|
|
459
446
|
wrap
|
|
460
447
|
portal
|
|
461
|
-
|
|
448
|
+
/>;
|
|
462
449
|
```
|
|
463
450
|
|
|
464
451
|
## Tuỳ chỉnh theme
|
|
465
452
|
|
|
466
|
-
-
|
|
453
|
+
- Ưu tiên chọn một preset duyệt sẵn qua `npx scope-ui-init --theme <preset>` để giữ UI đồng bộ giữa các project.
|
|
454
|
+
- Nếu cần tinh chỉnh thêm, chỉ sửa token trong `src/styles/ui-theme.css`, không restyle từng component riêng lẻ.
|
|
467
455
|
- Các lớp `ui-*` đã được namespaced để tránh va chạm với CSS hiện tại.
|
|
468
456
|
|
|
469
457
|
## Gợi ý tích hợp
|