@finhay-pro/leaf-design-system 0.1.2 → 0.1.3

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 (102) hide show
  1. package/README.md +183 -53
  2. package/dist/border.css +44 -0
  3. package/dist/button.css +55 -25
  4. package/dist/cdn/leaf-0.1.3.min.css +2 -0
  5. package/dist/cdn/leaf-0.1.3.min.js +2 -0
  6. package/dist/classes.css +1240 -174
  7. package/dist/components/Button/Button.d.ts +20 -3
  8. package/dist/components/Button/Button.d.ts.map +1 -1
  9. package/dist/components/Button/Button.js +65 -2
  10. package/dist/components/Button/Button.js.map +1 -1
  11. package/dist/components/Dialog/Dialog.d.ts +36 -9
  12. package/dist/components/Dialog/Dialog.d.ts.map +1 -1
  13. package/dist/components/Dialog/Dialog.js +38 -16
  14. package/dist/components/Dialog/Dialog.js.map +1 -1
  15. package/dist/components/Dialog/index.d.ts +1 -1
  16. package/dist/components/Dialog/index.d.ts.map +1 -1
  17. package/dist/components/Dialog/index.js.map +1 -1
  18. package/dist/components/Logo/Logo.d.ts +2 -2
  19. package/dist/components/Logo/Logo.d.ts.map +1 -1
  20. package/dist/components/Logo/assets.d.ts.map +1 -1
  21. package/dist/components/Logo/assets.js +26 -26
  22. package/dist/components/Logo/assets.js.map +1 -1
  23. package/dist/components/Skeleton/Skeleton.d.ts +2 -2
  24. package/dist/components/Skeleton/Skeleton.d.ts.map +1 -1
  25. package/dist/components/Slider/Slider.d.ts +9 -5
  26. package/dist/components/Slider/Slider.d.ts.map +1 -1
  27. package/dist/components/Slider/Slider.js +21 -10
  28. package/dist/components/Slider/Slider.js.map +1 -1
  29. package/dist/components/Spinner/Spinner.d.ts +34 -0
  30. package/dist/components/Spinner/Spinner.d.ts.map +1 -0
  31. package/dist/components/Spinner/Spinner.js +37 -0
  32. package/dist/components/Spinner/Spinner.js.map +1 -0
  33. package/dist/components/Spinner/index.d.ts +2 -0
  34. package/dist/components/{Loading → Spinner}/index.d.ts.map +1 -1
  35. package/dist/components/Spinner/index.js +2 -0
  36. package/dist/components/Spinner/index.js.map +1 -0
  37. package/dist/components/Tabs/Tabs.d.ts +30 -24
  38. package/dist/components/Tabs/Tabs.d.ts.map +1 -1
  39. package/dist/components/Tabs/Tabs.js +22 -39
  40. package/dist/components/Tabs/Tabs.js.map +1 -1
  41. package/dist/components/Tabs/index.d.ts +1 -1
  42. package/dist/components/Tabs/index.d.ts.map +1 -1
  43. package/dist/components/Tabs/index.js +1 -1
  44. package/dist/components/Tabs/index.js.map +1 -1
  45. package/dist/components/Toggle/Toggle.d.ts +10 -3
  46. package/dist/components/Toggle/Toggle.d.ts.map +1 -1
  47. package/dist/components/Toggle/Toggle.js +3 -3
  48. package/dist/components/Toggle/Toggle.js.map +1 -1
  49. package/dist/components/Tooltip/Tooltip.d.ts +28 -12
  50. package/dist/components/Tooltip/Tooltip.d.ts.map +1 -1
  51. package/dist/components/Tooltip/Tooltip.js +83 -16
  52. package/dist/components/Tooltip/Tooltip.js.map +1 -1
  53. package/dist/components/Tooltip/index.d.ts +1 -1
  54. package/dist/components/Tooltip/index.d.ts.map +1 -1
  55. package/dist/components/Tooltip/index.js.map +1 -1
  56. package/dist/core/dialog.d.ts +7 -2
  57. package/dist/core/dialog.d.ts.map +1 -1
  58. package/dist/core/dialog.js +37 -2
  59. package/dist/core/dialog.js.map +1 -1
  60. package/dist/core/spinner.d.ts +10 -0
  61. package/dist/core/spinner.d.ts.map +1 -0
  62. package/dist/core/spinner.js +13 -0
  63. package/dist/core/spinner.js.map +1 -0
  64. package/dist/core/tooltip.d.ts +13 -1
  65. package/dist/core/tooltip.d.ts.map +1 -1
  66. package/dist/core/tooltip.js +75 -3
  67. package/dist/core/tooltip.js.map +1 -1
  68. package/dist/dialog.css +12 -8
  69. package/dist/index.d.ts +4 -4
  70. package/dist/index.d.ts.map +1 -1
  71. package/dist/index.js +2 -2
  72. package/dist/index.js.map +1 -1
  73. package/dist/slider.css +45 -8
  74. package/dist/spacing.css +838 -0
  75. package/dist/{loading.css → spinner.css} +31 -30
  76. package/dist/styles.css +1303 -193
  77. package/dist/tabs.css +69 -15
  78. package/dist/toggle.css +1 -1
  79. package/dist/tokens.css +52 -8
  80. package/dist/tooltip.css +64 -4
  81. package/dist/utils/mergeRefs.d.ts +4 -0
  82. package/dist/utils/mergeRefs.d.ts.map +1 -0
  83. package/dist/utils/mergeRefs.js +14 -0
  84. package/dist/utils/mergeRefs.js.map +1 -0
  85. package/dist/utils/useControllableState.d.ts +3 -0
  86. package/dist/utils/useControllableState.d.ts.map +1 -1
  87. package/dist/utils/useControllableState.js +16 -4
  88. package/dist/utils/useControllableState.js.map +1 -1
  89. package/dist/utils/useInheritedTheme.d.ts +10 -0
  90. package/dist/utils/useInheritedTheme.d.ts.map +1 -0
  91. package/dist/utils/useInheritedTheme.js +22 -0
  92. package/dist/utils/useInheritedTheme.js.map +1 -0
  93. package/package.json +13 -4
  94. package/dist/cdn/leaf-0.1.2.min.css +0 -2
  95. package/dist/cdn/leaf-0.1.2.min.js +0 -2
  96. package/dist/components/Loading/Loading.d.ts +0 -24
  97. package/dist/components/Loading/Loading.d.ts.map +0 -1
  98. package/dist/components/Loading/Loading.js +0 -28
  99. package/dist/components/Loading/Loading.js.map +0 -1
  100. package/dist/components/Loading/index.d.ts +0 -2
  101. package/dist/components/Loading/index.js +0 -2
  102. package/dist/components/Loading/index.js.map +0 -1
package/README.md CHANGED
@@ -23,16 +23,18 @@ chọn phần class cần dùng.
23
23
 
24
24
  | Import | Nội dung |
25
25
  | ------------------------------------------------ | ------------------------------------------------------------------------------- |
26
- | `@finhay-pro/leaf-design-system/tokens.css` | Chỉ token (primitive + semantic + typography), không class. |
26
+ | `@finhay-pro/leaf-design-system/tokens.css` | Chỉ token (primitive + semantic + typography + spacing + border), không class. |
27
27
  | `@finhay-pro/leaf-design-system/typography.css` | Chỉ class typography. |
28
28
  | `@finhay-pro/leaf-design-system/color.css` | Chỉ class color. |
29
+ | `@finhay-pro/leaf-design-system/spacing.css` | Chỉ class spacing (`p-*` / `m-*` / `gap-*`). |
30
+ | `@finhay-pro/leaf-design-system/border.css` | Chỉ class border radius (`radius-*`). |
29
31
  | `@finhay-pro/leaf-design-system/button.css` | Style của component `Button`. |
30
- | `@finhay-pro/leaf-design-system/tabs.css` | Style của component `Tabs` / `Tab`. |
32
+ | `@finhay-pro/leaf-design-system/tabs.css` | Style của component `Tabs`. |
31
33
  | `@finhay-pro/leaf-design-system/dialog.css` | Style của component `Dialog`. |
32
34
  | `@finhay-pro/leaf-design-system/logo.css` | Style của component `Logo`. |
33
35
  | `@finhay-pro/leaf-design-system/logo-assets.css` | SVG data-URI cho Logo HTML tĩnh — không nằm trong `classes.css` / `styles.css`. |
34
36
  | `@finhay-pro/leaf-design-system/skeleton.css` | Style của component `Skeleton`. |
35
- | `@finhay-pro/leaf-design-system/loading.css` | Style của component `Loading`. |
37
+ | `@finhay-pro/leaf-design-system/spinner.css` | Style của component `Spinner`. |
36
38
  | `@finhay-pro/leaf-design-system/toggle.css` | Style của component `Toggle`. |
37
39
  | `@finhay-pro/leaf-design-system/slider.css` | Style của component `Slider`. |
38
40
  | `@finhay-pro/leaf-design-system/tooltip.css` | Style của component `Tooltip`. |
@@ -50,6 +52,8 @@ Trong app dùng Tailwind v4, import bằng CSS, **sau** `@import "tailwindcss"`:
50
52
  /* 2. Bộ class nền tảng */
51
53
  @import "@finhay-pro/leaf-design-system/typography.css";
52
54
  @import "@finhay-pro/leaf-design-system/color.css";
55
+ @import "@finhay-pro/leaf-design-system/spacing.css";
56
+ @import "@finhay-pro/leaf-design-system/border.css";
53
57
 
54
58
  /* 3. Component nào dùng thì import cái đó */
55
59
  @import "@finhay-pro/leaf-design-system/button.css";
@@ -57,7 +61,7 @@ Trong app dùng Tailwind v4, import bằng CSS, **sau** `@import "tailwindcss"`:
57
61
  @import "@finhay-pro/leaf-design-system/dialog.css";
58
62
  @import "@finhay-pro/leaf-design-system/logo.css";
59
63
  @import "@finhay-pro/leaf-design-system/skeleton.css";
60
- @import "@finhay-pro/leaf-design-system/loading.css";
64
+ @import "@finhay-pro/leaf-design-system/spinner.css";
61
65
  @import "@finhay-pro/leaf-design-system/toggle.css";
62
66
  @import "@finhay-pro/leaf-design-system/slider.css";
63
67
  @import "@finhay-pro/leaf-design-system/tooltip.css";
@@ -114,8 +118,8 @@ Trong React / Next.js, class đi thẳng vào `className` của bất kỳ eleme
114
118
  ```tsx
115
119
  <h2 className="heading-2">Tài sản của bạn</h2>
116
120
 
117
- // Class typography lo cỡ chữ, class color lo màu, Tailwind lo spacing/layout
118
- <p className="body-3 text-secondary mt-2">Lợi nhuận kỳ vọng 8.5%/năm</p>
121
+ // Class typography lo cỡ chữ, color lo màu, spacing lo khoảng cách
122
+ <p className="body-3 text-secondary mt-s">Lợi nhuận kỳ vọng 8.5%/năm</p>
119
123
 
120
124
  // Gắn vào component của thư viện khác cũng chỉ là một chuỗi class
121
125
  <Link href="/tai-khoan" className="body-3-highlight">
@@ -140,7 +144,7 @@ viết thêm gì cho light mode.
140
144
  | System (đủ 3 bộ) | `text-*`, `base-*`, `border-*` với `red`, `green`, `yellow`, `orange`, `blue`, `purple` |
141
145
 
142
146
  ```html
143
- <div class="base-secondary border-quaternary border p-4">
147
+ <div class="base-secondary border-quaternary p-l radius-m border">
144
148
  <h3 class="heading-3 text-primary">Tích luỹ</h3>
145
149
  <p class="body-4 text-secondary">Lợi nhuận kỳ vọng 8.5%/năm</p>
146
150
  <p class="body-4 text-red">Số dư không đủ</p>
@@ -150,31 +154,85 @@ viết thêm gì cho light mode.
150
154
  <html data-theme="light"></html>
151
155
  ```
152
156
 
157
+ ## Spacing class
158
+
159
+ Token `--spacing-*` (Figma Application) áp dụng cho **margin · padding · gap**. Tiền tố = thuộc
160
+ tính, hậu tố = bậc: `0` · `xs` · `s` · `m` · `l` · `xl` · `2xl` … `7xl`.
161
+
162
+ | Prefix | Property |
163
+ | -------------------------------- | -------------------------------------------- |
164
+ | `p-*` `px-*` `py-*` `pt/r/b/l-*` | padding / padding-inline / block / từng cạnh |
165
+ | `m-*` `mx-*` `my-*` `mt/r/b/l-*` | margin tương tự |
166
+ | `gap-*` `gap-x-*` `gap-y-*` | gap / column-gap / row-gap |
167
+
168
+ | Hậu tố | Token | px |
169
+ | ------ | --------------- | --- |
170
+ | `0` | `--spacing-0` | 0 |
171
+ | `xs` | `--spacing-xs` | 4 |
172
+ | `s` | `--spacing-s` | 8 |
173
+ | `m` | `--spacing-m` | 12 |
174
+ | `l` | `--spacing-l` | 16 |
175
+ | `xl` | `--spacing-xl` | 24 |
176
+ | `2xl` | `--spacing-2xl` | 36 |
177
+ | `3xl` | `--spacing-3xl` | 48 |
178
+ | `4xl` | `--spacing-4xl` | 60 |
179
+ | `5xl` | `--spacing-5xl` | 84 |
180
+ | `6xl` | `--spacing-6xl` | 120 |
181
+ | `7xl` | `--spacing-7xl` | 240 |
182
+
183
+ ```html
184
+ <div class="gap-m p-l flex flex-col">
185
+ <h3 class="heading-3">Danh mục</h3>
186
+ <p class="body-4 mt-s text-secondary">Cập nhật 5 phút trước</p>
187
+ </div>
188
+ ```
189
+
190
+ ## Border radius class
191
+
192
+ Token `--radius-*` (Figma Border Application) — subset của spacing tới `2xl`. Class `radius-*`
193
+ chỉ set `border-radius` (không đụng `rounded-*` của Tailwind hay `border-*` màu viền).
194
+
195
+ | Class | Token | px |
196
+ | ------------ | -------------- | --- |
197
+ | `radius-0` | `--radius-0` | 0 |
198
+ | `radius-xs` | `--radius-xs` | 4 |
199
+ | `radius-s` | `--radius-s` | 8 |
200
+ | `radius-m` | `--radius-m` | 12 |
201
+ | `radius-l` | `--radius-l` | 16 |
202
+ | `radius-xl` | `--radius-xl` | 24 |
203
+ | `radius-2xl` | `--radius-2xl` | 36 |
204
+
205
+ ```html
206
+ <div class="base-secondary border-quaternary p-l radius-m border">Card</div>
207
+ ```
208
+
153
209
  ## Cần biết
154
210
 
155
- - **Class typography chỉ set đúng 3 thuộc tính** (`font-size`, `line-height`, `font-weight`) và
156
- **class color chỉ set đúng 1** (`color` / `background-color` / `border-color`). Font family,
157
- letter spacing, margin, border width… nằm ngoài phạm vi — app tự setup ở tầng global
211
+ - **Class typography chỉ set đúng 3 thuộc tính** (`font-size`, `line-height`, `font-weight`);
212
+ **class color chỉ set đúng 1** (`color` / `background-color` / `border-color`); **spacing /
213
+ radius chỉ set đúng 1** (margin/padding/gap hoặc `border-radius`). Font family, letter spacing,
214
+ border width… nằm ngoài phạm vi — app tự setup ở tầng global
158
215
  (`body { font-family: var(--font-sans) }`, CSS reset…) hoặc thêm bằng Tailwind.
159
216
  - **Typography nằm trong `@layer components`**, nên utility của Tailwind v4 (`@layer utilities`)
160
217
  luôn thắng: `class="heading-1 font-bold"` hay `class="body-3 text-2xl"` override được bình
161
218
  thường, không cần important modifier.
162
- - **Color nằm trong `@layer utilities`** — ngược lại: màu là token gốc nên trùng tên thì phải
163
- thắng. Class màu của Leaf đứng cùng layer với utility của Tailwind và được import sau, nên nếu
164
- app tự khai báo `--color-primary` / `--color-red` trong `@theme` thì `text-primary`, `text-red`
165
- vẫn ra màu của Leaf. Điều kiện: `@import "@finhay-pro/leaf-design-system/…"` phải nằm **sau**
166
- `@import "tailwindcss"`.
219
+ - **Color / spacing / border nằm trong `@layer utilities`** — token gốc nên trùng tên thì phải
220
+ thắng. Class đứng cùng layer với utility của Tailwind và được import sau, nên nếu app tự khai
221
+ báo cùng tên trong `@theme` thì class Leaf vẫn có hiệu lực. Điều kiện:
222
+ `@import "@finhay-pro/leaf-design-system/…"` phải nằm **sau** `@import "tailwindcss"`.
167
223
  - **Class không có biến thể `hover:` / `focus:` / opacity** — nó là CSS thuần, không phải utility do
168
224
  Tailwind sinh ra. Cần state thì dùng arbitrary value trỏ vào cùng token:
169
225
  `hover:text-[var(--text-highlight)]` (pseudo-class có specificity cao hơn nên thắng). Riêng biến
170
226
  thể responsive cùng specificity với class màu và được ghi ra trước, nên cần important modifier:
171
227
  `md:text-[var(--text-secondary)]!`.
172
- - **Chỉ semantic token mới có class.** Primitive (`--neutral-500`, `--brand-300`…) là nguồn nội bộ,
173
- dùng thẳng trong UI là mất khả năng đổi theme.
228
+ - **Chỉ semantic token mới có class màu.** Primitive (`--neutral-500`, `--brand-300`…) là nguồn nội
229
+ bộ, dùng thẳng trong UI là mất khả năng đổi theme. Spacing / radius là thang kích thước cố định,
230
+ không đổi theo theme.
174
231
  - **Tên class không có prefix.** Đây là những tên khá phổ thông, nên app dùng Leaf cần cân nhắc kỹ
175
232
  nếu load kèm CSS framework khác (Bootstrap cũng định nghĩa `.display-1`–`.display-6`). Với
176
- Tailwind thì màu của Leaf luôn thắng khi trùng tên — đó là chủ đích; muốn dùng màu riêng của app
177
- thì đặt tên khác `primary`/`secondary`/`red`… hoặc gọi qua arbitrary value.
233
+ Tailwind thì màu / spacing token-name của Leaf luôn thắng khi trùng tên — đó là chủ đích; muốn
234
+ dùng scale riêng của app thì đặt tên khác hoặc gọi qua arbitrary value. `radius-*` cố ý khác
235
+ `rounded-*` để không đụng bo góc mặc định của Tailwind.
178
236
  - Typography token hiện chỉ có **bộ Desktop**. Chưa có responsive type set, nên các style Display
179
237
  cần app tự xử lý ở breakpoint nhỏ.
180
238
 
@@ -212,17 +270,17 @@ vào bản CDN, không vào bản npm.
212
270
 
213
271
  ## Components
214
272
 
215
- | Export | Mô tả |
216
- | -------------- | -------------------------------------------------------------------------------------- |
217
- | `Button` | Khung icon · label · icon — bật/tắt từng phần (`showLeadingIcon` / `showTrailingIcon`) |
218
- | `Tabs` / `Tab` | Tabs Items — `addon` = slot động `[---]` (text / icon); phím ← → Home End |
219
- | `Dialog` | Panel + backdrop blur — `title` / `onBack` / `onClose`, `width` / `height` |
220
- | `Logo` | Wordmark FHSC · Finhay · FHC — `brand` / `mode` / `side` / `size` |
221
- | `Skeleton` | Placeholder shimmer — `width` / `height` / `border` (radius), nền `--base-tertiary` |
222
- | `Loading` | Indicator 8 nan — `animation` (`spin` · `fade` · `pulse` · `breathe`), `size` |
223
- | `Toggle` | Công tắc On/Off — `size` md/sm, `checked`, `disabled` (Figma Active Off) |
224
- | `Slider` | Kéo từng `step` trong `min`–`max` (mặc định 0–100, bước 1) · mốc `steps` · `labels` |
225
- | `Tooltip` | Hover/focus/Escape — `size`, `position`, `align`, `onOpenChange`; kèm `TooltipContent` |
273
+ | Export | Mô tả |
274
+ | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
275
+ | `Button` | Khung icon · label · icon — bật/tắt từng phần; `width` / `height`; `onClick` trả Promise → tự loading (spinner thay leading icon, khoá click), `loading` controlled |
276
+ | `Tabs` | Tabs Items — `items[]` (`value` · `label: ReactNode` · `disabled`); phím ← → Home End |
277
+ | `Dialog` | Panel + backdrop blur — `open` (controlled), `title` / `onBack` / `onClose(reason)`, `dismissible`, `closeLabel` / `backLabel`, `theme`, `maxWidth` / `maxHeight` |
278
+ | `Logo` | Wordmark FHSC · Finhay · FHC — `brand` / `mode` / `side` / `size` |
279
+ | `Skeleton` | Placeholder shimmer — `width` / `height` / `border` (radius), nền `--base-tertiary` |
280
+ | `Spinner` | Indicator 8 nan — `animation` (`spin` · `fade` · `pulse` · `breathe`), `size` |
281
+ | `Toggle` | Công tắc On/Off — `size` md/sm, `checked`, `disabled` (Figma Active Off); `name` / `value` → input ẩn cho form |
282
+ | `Slider` | Kéo từng `step` trong `min`–`max` (mặc định 0–100, bước 1) · mốc `steps` · `labels`; `name` → input ẩn |
283
+ | `Tooltip` | Hover/focus/Escape — `size`, `position`, `align`, `onOpenChange`; `trigger="click"`, `openDelay` / `closeDelay`, tự lật phía khi thiếu chỗ, `theme`; kèm `TooltipContent` |
226
284
 
227
285
  ```css
228
286
  /* Ngoài tokens.css + typography.css, mỗi component cần CSS riêng của nó */
@@ -231,7 +289,7 @@ vào bản CDN, không vào bản npm.
231
289
  @import "@finhay-pro/leaf-design-system/dialog.css";
232
290
  @import "@finhay-pro/leaf-design-system/logo.css";
233
291
  @import "@finhay-pro/leaf-design-system/skeleton.css";
234
- @import "@finhay-pro/leaf-design-system/loading.css";
292
+ @import "@finhay-pro/leaf-design-system/spinner.css";
235
293
  @import "@finhay-pro/leaf-design-system/toggle.css";
236
294
  @import "@finhay-pro/leaf-design-system/slider.css";
237
295
  @import "@finhay-pro/leaf-design-system/tooltip.css";
@@ -241,11 +299,10 @@ vào bản CDN, không vào bản npm.
241
299
  import {
242
300
  Button,
243
301
  Tabs,
244
- Tab,
245
302
  Dialog,
246
303
  Logo,
247
304
  Skeleton,
248
- Loading,
305
+ Spinner,
249
306
  Toggle,
250
307
  Slider,
251
308
  Tooltip,
@@ -256,17 +313,20 @@ import {
256
313
  </Button>
257
314
  {/* Chỉ icon → layout tròn */}
258
315
  <Button aria-label="Thêm" leadingIcon={<PlusIcon />} />
259
- <Button size="md" leadingIcon={<Loading size="md" />}>
316
+ <Button size="md" leadingIcon={<Spinner size="md" />}>
260
317
  Mua AAA
261
318
  </Button>
262
319
 
263
320
  <Skeleton height={48} border={12} />
264
321
 
265
- <Tabs variant="buy" defaultValue="buy">
266
- <Tab value="buy" addon="1.2%">
267
- Mua
268
- </Tab>
269
- </Tabs>
322
+ <Tabs
323
+ variant="buy"
324
+ defaultValue="buy"
325
+ items={[
326
+ { value: "buy", label: "Mua 1.2%" },
327
+ { value: "idle", label: "Mua" },
328
+ ]}
329
+ />
270
330
  ```
271
331
 
272
332
  ## HTML tĩnh (CDN)
@@ -276,8 +336,8 @@ dùng được toàn bộ class typography, color và mọi component (CSS). Scr
276
336
  Tabs · Toggle · Dialog · Slider · Tooltip (`data-leaf-*`).
277
337
 
278
338
  ```html
279
- <link rel="stylesheet" href="https://<cdn>/leaf-0.1.2.min.css" />
280
- <script src="https://<cdn>/leaf-0.1.2.min.js" defer></script>
339
+ <link rel="stylesheet" href="https://<cdn>/leaf-0.1.3.min.css" />
340
+ <script src="https://<cdn>/leaf-0.1.3.min.js" defer></script>
281
341
  ```
282
342
 
283
343
  | File | Nội dung |
@@ -299,12 +359,17 @@ Không cần JS. Thiếu attribute nào thì lấy mặc định giống prop Re
299
359
  | `data-status` | `normal` `destruction` | `normal` |
300
360
  | `data-icon-only` | `true` — chỉ có icon → tròn, cần `aria-label` | — |
301
361
  | `disabled` / `aria-disabled` | native / `"true"` | — |
362
+ | `data-loading` | `true` — `Leaf.button.setLoading` / `run` gắn | — |
302
363
 
303
364
  ```html
304
365
  <button class="leaf-button">Tiếp tục</button>
305
366
  <button class="leaf-button" data-priority="secondary" data-size="md">Secondary</button>
306
367
  ```
307
368
 
369
+ Loading (cần `leaf.js`): `Leaf.button.run(el, promise)` bật loading tới khi promise settle,
370
+ `Leaf.button.setLoading(el, true | false)` tự bật / tắt — spinner thay leading icon, `aria-busy`,
371
+ khoá `min-width`, nút đang loading không nhận click (kể cả handler của trang).
372
+
308
373
  ### Tabs
309
374
 
310
375
  Đánh dấu tablist bằng `data-leaf-tabs` (opt-in). `Leaf.tabs` · event `leaf:tabs-change`.
@@ -316,20 +381,29 @@ Không cần JS. Thiếu attribute nào thì lấy mặc định giống prop Re
316
381
  ### Dialog
317
382
 
318
383
  `data-leaf-dialog` trên `.leaf-dialog-backdrop`. Mở bằng `data-leaf-dialog-open="id"` hoặc
319
- `Leaf.dialog.open`. Đóng: Escape / backdrop / `data-leaf-dialog-close`. Back: `data-leaf-dialog-back`
320
- → `leaf:dialog-back` (không tự đóng).
384
+ `Leaf.dialog.open`. Đóng: Escape / backdrop / `data-leaf-dialog-close` /
385
+ `Leaf.dialog.close(el, reason?)` — `leaf:dialog-close` mang `detail.reason`
386
+ (`close` · `backdrop` · `escape` · `api`). `data-leaf-dialog-dismissible="false"` tắt đóng bằng
387
+ backdrop / Escape. Back: `data-leaf-dialog-back` → `leaf:dialog-back` (không tự đóng). Khi mở, các
388
+ con khác của `<body>` được đặt `inert` — đặt dialog tĩnh là con trực tiếp của `<body>`.
321
389
 
322
390
  ### Slider
323
391
 
324
392
  `data-leaf-slider` trên `.leaf-slider` + `data-min` / `data-max` / `data-step` / `data-value`
325
393
  (mặc định 0 / 100 / 1 / min). `Leaf.slider.set(el, value)` · `leaf:slider-input` (liên tục khi kéo)
326
394
  · `leaf:slider-change` (khi chốt). Sync `--leaf-slider-fill` (fill + thumb) / `data-state` mốc;
327
- thiếu `.leaf-slider__thumb` thì leaf.js tự tạo.
395
+ thiếu `.leaf-slider__thumb` thì leaf.js tự tạo. Có `input.leaf-slider__input[type=hidden]` trong
396
+ markup thì leaf.js ghi giá trị đã chốt vào đó (form). Toggle tương tự với
397
+ `input.leaf-toggle__input` — `disabled` khi Off, giống checkbox.
328
398
 
329
399
  ### Tooltip
330
400
 
331
401
  Bubble tĩnh: `.leaf-tooltip` + `data-size` / `data-position` / `data-align` — không cần JS.
332
- Hover/focus: `.leaf-tooltip-trigger` + `data-leaf-tooltip` + `data-content` (hoặc `data-tooltip`).
402
+ Hover/focus: `.leaf-tooltip-trigger` + `data-leaf-tooltip` + `data-content` (hoặc `data-tooltip`);
403
+ `data-leaf-tooltip-trigger="click"` để bấm mở/đóng, `data-focusable` khi trigger là icon thuần
404
+ (không có phần tử focus được — leaf.js gắn `tabindex` / `role="button"`), `data-open-delay` /
405
+ `data-close-delay` (ms), `data-flip="false"` tắt tự lật phía khi thiếu chỗ. Bubble kế thừa
406
+ `data-theme` của khối bọc trigger.
333
407
 
334
408
  ### Logo
335
409
 
@@ -337,10 +411,10 @@ Span rỗng `.leaf-logo` + `data-brand` / `data-mode` / `data-side` + `--leaf-lo
337
411
  SVG data-URI — không cần JS. Bản CDN đã gộp sẵn data-URI; dùng qua npm thì import thêm
338
412
  `logo-assets.css` (không nằm trong `classes.css` / `styles.css` vì component React không cần).
339
413
 
340
- ### Skeleton / Loading
414
+ ### Skeleton / Spinner
341
415
 
342
- Chỉ CSS. Skeleton: `--leaf-skeleton-width` / `height` / `radius`. Loading: `data-animation` /
343
- `data-size` + SVG path; overlay = `.leaf-loading-overlay` (app tự `hidden`/mount).
416
+ Chỉ CSS. Skeleton: `--leaf-skeleton-width` / `height` / `radius`. Spinner: `data-animation` /
417
+ `data-size` + SVG path; overlay = `.leaf-spinner-overlay` (app tự `hidden`/mount).
344
418
 
345
419
  ### Cần biết
346
420
 
@@ -351,6 +425,8 @@ Chỉ CSS. Skeleton: `--leaf-skeleton-width` / `height` / `radius`. Loading: `da
351
425
  `body { font-family: var(--font-sans) }`.
352
426
  - **Trình duyệt tối thiểu** (CSS dùng `@layer`): Chrome / Edge 99+, Safari 15.4+, Firefox 97+.
353
427
  - Dark là mặc định; `data-theme="light"` trên `<html>` để chuyển light.
428
+ - z-index của lớp phủ đọc `--leaf-z-dialog` (50) / `--leaf-z-spinner-overlay` (100) /
429
+ `--leaf-z-tooltip` (110) — override trên `:root` để chèn lớp của trang vào giữa.
354
430
  - Chi tiết attribute / markup từng component: tab **Code → HTML tĩnh** trên docs.
355
431
 
356
432
  ### Phát hành bản CDN
@@ -364,13 +440,64 @@ Chỉ CSS. Skeleton: `--leaf-skeleton-width` / `height` / `radius`. Loading: `da
364
440
 
365
441
  ## Changelog
366
442
 
367
- ### Chưa phát hành
368
-
443
+ ### 0.1.3
444
+
445
+ **Breaking**
446
+
447
+ - `Loading` → `Spinner`: component, type, class `leaf-spinner` / `leaf-spinner__icon` /
448
+ `leaf-spinner-overlay`, biến `--leaf-spinner-*`, file `spinner.css`, docs `/components/spinner`.
449
+ Không giữ alias (CDN gắn version nên landing page cũ không vỡ).
450
+ - `onValueChange` / `onCheckedChange` / `onOpenChange` không gọi lại khi giá trị không đổi (bấm
451
+ tab đang chọn, phím → khi Slider đã ở max) — khớp bản vanilla vốn chỉ phát `leaf:*-change` khi
452
+ thật sự đổi. App nào dựa vào việc bắn lại (vd. bấm tab đang mở để refetch) cần tự xử lý.
453
+ - Slider: label nằm ngoài thứ tự Tab (slider chỉ có một điểm dừng, nhảy mốc bằng PageUp /
454
+ PageDown); mốc là `<span>` thay vì `<button>` — snippet HTML tĩnh đã đổi theo (markup cũ vẫn chạy).
455
+ - Tabs: `size` chỉ nhận khi `variant="subcontent"` (TypeScript chặn tổ hợp không có trong Figma).
456
+ - Dialog: `width` / `height` → `maxWidth` / `maxHeight` (CSS `--leaf-dialog-max-width` /
457
+ `--leaf-dialog-max-height`). Panel luôn `width: 100%` / `height: auto` trong trần đó — mobile
458
+ không bị cố định kích thước.
459
+
460
+ **Sửa lỗi**
461
+
462
+ - Dialog: bôi đen text trong panel rồi thả chuột ra nền không còn đóng nhầm (chỉ đóng khi
463
+ pointerdown cũng bắt đầu trên backdrop) — cả React lẫn leaf.js.
464
+ - Slider: `touch-action: none` chỉ còn trên track; title / labels cuộn trang được trên mobile.
465
+ - Tabs: tab nhận `tabindex="0"` đúng ngay trong HTML server (SSR), không đợi effect.
466
+ - Tooltip: không gắn / gỡ listener lại mỗi lần cha render.
467
+
468
+ **Mới**
469
+
470
+ - Test: Vitest + jsdom (`pnpm test`). Test parity chạy cùng một bộ assertion trên component React và
471
+ markup HTML tĩnh (sinh từ `renderToStaticMarkup` + `data-leaf-*`) do leaf.js điều khiển.
472
+ - Mọi component nhận `ref` (React 19, không cần `forwardRef`).
473
+ - Button: `onClick` trả Promise → tự loading (spinner thay leading icon, giữ label và màu priority,
474
+ `aria-busy`, khoá click, `min-width` giữ nút không nhảy) tới khi settle; `loading` controlled.
475
+ leaf.js: `Leaf.button.setLoading` / `run` / `isLoading`; nút đang loading không nhận click.
476
+ Cảnh báo dev khi icon-only thiếu `aria-label`.
477
+ - Dialog: `open` (controlled — đóng thì giữ DOM + `hidden`), `onClose(reason)`, `dismissible`,
478
+ `closeLabel` / `backLabel`, `title: ReactNode`, `theme`. leaf.js: `data-leaf-dialog-dismissible`,
479
+ `leaf:dialog-close` có `detail.reason`, `Leaf.dialog.close(el, reason)`.
480
+ - Tooltip: `trigger="click"`, `openDelay` / `closeDelay`, `focusable`, tự lật phía khi thiếu chỗ
481
+ (`flip`), `theme`. leaf.js: `data-leaf-tooltip-trigger`, `data-focusable`, `data-open-delay` /
482
+ `data-close-delay`, `data-flip`.
483
+ - Slider: root gắn `data-min` / `data-max` / `data-step` / `data-value` — cùng surface HTML tĩnh.
484
+ - Tabs: `label: ReactNode` (badge, icon).
485
+ - Toggle / Slider: `name` (+ `value` cho Toggle) → `<input type="hidden">` đi vào `FormData`; leaf.js
486
+ sync `input.leaf-toggle__input` / `input.leaf-slider__input` nếu có trong markup.
487
+ - Portal (Dialog, Tooltip, Spinner overlay) kế thừa `data-theme` của khối bọc chỗ dùng; khi dialog
488
+ mở, phần còn lại của `<body>` được `inert`; z-index qua `--leaf-z-dialog` /
489
+ `--leaf-z-spinner-overlay` / `--leaf-z-tooltip` (giá trị mặc định không đổi).
490
+
491
+ - Button: width/height prop; size MD/SM khớp Figma gap/padding; token
492
+ `--button-disabled-base|content` (alias `--button-*-disable`).
493
+ - Spacing: token `--spacing-*` (0…7xl) + class `p-*` / `m-*` / `gap-*` (Figma 34:1034).
494
+ - Border: token `--radius-*` (0…2xl) + class `radius-*` (Figma 700:4390).
369
495
  - Dual-support HTML tĩnh: vanilla `Leaf.toggle` / `dialog` / `slider` / `tooltip` (`data-leaf-*`);
370
496
  Logo CSS data-URI theo `data-brand` / `data-mode` / `data-side`; docs `htmlSection` +
371
497
  `examples/static.html` cover đủ component.
372
498
  - Skeleton: placeholder shimmer (`width` / `height` / `border`), nền `--base-tertiary`.
373
- - Loading: indicator 8 nan (loader-line), animation `spin` · `fade` · `pulse` · `breathe`.
499
+ - Spinner: indicator 8 nan (loader-line), animation `spin` · `fade` · `pulse` · `breathe`; màu
500
+ mặc định trắng (dark) / đen (light) qua `--base-quinary`, overlay cũng vậy — không dùng highlight.
374
501
  - Toggle: công tắc On/Off (Figma 730:12438) — size md/sm, checked, disabled.
375
502
  - Slider: bước rời (Figma 730:12646) — title/unit, labels, activeColor.
376
503
  - Tooltip: hover/focus (Figma 891:4983) — size/position/align + TooltipContent.
@@ -378,6 +505,9 @@ Chỉ CSS. Skeleton: `--leaf-skeleton-width` / `height` / `radius`. Loading: `da
378
505
  - Thêm bản CDN cho HTML tĩnh: `leaf-<version>.min.css` + `leaf-<version>.min.js` (`window.Leaf`).
379
506
  - Button: typography của label chuyển vào `button.css`, component không còn gắn class
380
507
  `body-*-highlight`. Thiếu `data-priority` / `data-size` / `data-status` → primary / lg / normal.
381
- - Tabs: `data-variant` / `data-size` chỉ đọc từ tablist, `.leaf-tab` không còn mang hai attribute
382
- này; typography của label chuyển vào `tabs.css`; `<Tab>` thêm `data-value`.
508
+ - Tabs: API `items[]` (không export `Tab`); label là string đầy đủ, bỏ slot `addon`;
509
+ `data-variant` / `data-size` chỉ đọc từ tablist; typography của label trong `tabs.css`.
510
+ - Tooltip: caret khớp SVG Figma (tam giác nhỏ giữa khung hit-area), không còn full-width.
511
+ - Slider: thumb min = `--text-primary`, Active = `--text-highlight`; click label nhảy mốc.
512
+ - Token: `--icon-on-color` (Figma Icon/icon-on-color) cho Toggle thumb On.
383
513
  - Token: `--font-sans` có fallback khi không có `--font-inter` (trang ngoài Next.js).
@@ -0,0 +1,44 @@
1
+ /* @finhay-pro/leaf-design-system — generated by scripts/build-css.mjs. Do not edit. */
2
+
3
+ /* --- src/styles/border.css --- */
4
+
5
+ /*
6
+ * Border radius classes — map 1:1 sang --radius-* trong @finhay/leaf-tokens
7
+ * (Figma 700:4390).
8
+ *
9
+ * Tên class `radius-*` (không dùng `rounded-*`) để không đụng utility bo góc mặc
10
+ * định của Tailwind (`rounded-xl`…). `border-*` đã dành cho màu viền.
11
+ *
12
+ * Hậu tố = bậc token: 0 · xs · s · m · l · xl · 2xl.
13
+ * Chỉ set border-radius — width / style / color do app tự lo.
14
+ */
15
+
16
+ @layer utilities {
17
+ .radius-0 {
18
+ border-radius: var(--radius-0);
19
+ }
20
+
21
+ .radius-xs {
22
+ border-radius: var(--radius-xs);
23
+ }
24
+
25
+ .radius-s {
26
+ border-radius: var(--radius-s);
27
+ }
28
+
29
+ .radius-m {
30
+ border-radius: var(--radius-m);
31
+ }
32
+
33
+ .radius-l {
34
+ border-radius: var(--radius-l);
35
+ }
36
+
37
+ .radius-xl {
38
+ border-radius: var(--radius-xl);
39
+ }
40
+
41
+ .radius-2xl {
42
+ border-radius: var(--radius-2xl);
43
+ }
44
+ }
package/dist/button.css CHANGED
@@ -9,25 +9,27 @@
9
9
  * qua data-icon-only. Disabled dùng attribute native `:disabled` (và
10
10
  * `aria-disabled`) nên không cần class riêng.
11
11
  *
12
+ * Width / height override qua --leaf-button-width / --leaf-button-height
13
+ * (React gắn bằng prop; HTML tĩnh set style hoặc để mặc định theo size).
14
+ *
12
15
  * Toàn bộ hình thức (kể cả typography của label) nằm ở đây — React chỉ gắn
13
16
  * attribute, nên HTML tĩnh viết cùng markup là ra cùng kết quả. Thiếu attribute
14
17
  * nào thì lấy mặc định giống prop của React: lg · primary · normal.
15
- *
16
- * Variant chỉ đổi custom property `--leaf-button-*`; thuộc tính thật chỉ khai
17
- * báo một lần ở `.leaf-button`.
18
18
  */
19
19
 
20
20
  @layer components {
21
21
  .leaf-button {
22
- /* Mặc định: size lg */
22
+ /* Mặc định: size lg — Figma Large: h 56 · px XL · py S · gap L · icon 30 */
23
+ /* --leaf-button-width chỉ set khi prop width; không set → auto / icon-only = height */
23
24
  --leaf-button-height: 56px;
24
- --leaf-button-padding: 8px 24px;
25
- --leaf-button-icon-only-padding: 8px;
26
- --leaf-button-gap: 16px;
25
+ --leaf-button-padding: var(--spacing-s) var(--spacing-xl);
26
+ --leaf-button-icon-only-padding: var(--spacing-s);
27
+ --leaf-button-gap: var(--spacing-l);
27
28
  --leaf-button-icon-size: 30px;
28
29
  --leaf-button-font-size: var(--body-1-size);
29
30
  --leaf-button-line-height: var(--body-1-line-height);
30
31
  --leaf-button-font-weight: var(--body-1-highlight-weight);
32
+ --leaf-button-letter-spacing: 0.5px;
31
33
 
32
34
  /* Mặc định: priority primary, status normal */
33
35
  --leaf-button-bg: var(--button-base-primary);
@@ -36,6 +38,8 @@
36
38
  display: inline-flex;
37
39
  align-items: center;
38
40
  justify-content: center;
41
+ box-sizing: border-box;
42
+ width: var(--leaf-button-width, auto);
39
43
  height: var(--leaf-button-height);
40
44
  gap: var(--leaf-button-gap);
41
45
  border: none;
@@ -52,8 +56,8 @@
52
56
  font-size: var(--leaf-button-font-size);
53
57
  line-height: var(--leaf-button-line-height);
54
58
  font-weight: var(--leaf-button-font-weight);
59
+ letter-spacing: var(--leaf-button-letter-spacing);
55
60
  text-decoration: none;
56
- box-sizing: border-box;
57
61
  vertical-align: middle;
58
62
  }
59
63
 
@@ -74,49 +78,55 @@
74
78
  height: 1em;
75
79
  }
76
80
 
77
- /* ── Size ────────────────────────────────────────────────────────────── */
81
+ /* ── Size — Figma Medium/Small dùng padding (không ép height trong auto-layout);
82
+ * vẫn set height mặc định khớp frame để icon-only / căn hàng ổn định.
83
+ * Truyền height="auto" (prop) → chiều cao theo padding + nội dung. */
78
84
 
79
85
  .leaf-button[data-size="md"] {
86
+ /* Medium: px L · py S · gap M · icon 24 · frame 40 */
80
87
  --leaf-button-height: 40px;
81
- --leaf-button-padding: 8px 16px;
82
- --leaf-button-gap: 8px;
88
+ --leaf-button-padding: var(--spacing-s) var(--spacing-l);
89
+ --leaf-button-gap: var(--spacing-m);
83
90
  --leaf-button-icon-size: 24px;
84
91
  --leaf-button-font-size: var(--body-3-size);
85
92
  --leaf-button-line-height: var(--body-3-line-height);
86
93
  --leaf-button-font-weight: var(--body-3-highlight-weight);
94
+ --leaf-button-letter-spacing: 0;
87
95
  }
88
96
 
89
97
  .leaf-button[data-size="sm"] {
98
+ /* Small: px M · py XS · gap S · icon 20 · frame 28 */
90
99
  --leaf-button-height: 28px;
91
- --leaf-button-padding: 4px 8px;
92
- --leaf-button-icon-only-padding: 4px;
93
- --leaf-button-gap: 4px;
100
+ --leaf-button-padding: var(--spacing-xs) var(--spacing-m);
101
+ --leaf-button-icon-only-padding: var(--spacing-xs);
102
+ --leaf-button-gap: var(--spacing-s);
94
103
  --leaf-button-icon-size: 20px;
95
104
  --leaf-button-font-size: var(--body-4-size);
96
105
  --leaf-button-line-height: var(--body-4-line-height);
97
106
  --leaf-button-font-weight: var(--body-4-highlight-weight);
107
+ --leaf-button-letter-spacing: 0;
98
108
  }
99
109
 
100
- /* Icon-only: khung vuông (tròn nhờ border-radius) cạnh = height. */
110
+ /* Icon-only: khung vuông (tròn nhờ border-radius). Width custom vẫn được tôn trọng. */
101
111
  .leaf-button[data-icon-only="true"] {
102
- width: var(--leaf-button-height);
112
+ width: var(--leaf-button-width, var(--leaf-button-height));
103
113
  padding: var(--leaf-button-icon-only-padding);
104
114
  }
105
115
 
106
- /* Ghost không có khung — bỏ height/padding cố định. Đứng sau size để thắng. */
107
- .leaf-button[data-priority="ghost"] {
116
+ /* Ghost text — không khung; icon-only ghost vẫn giữ hit-area theo size. */
117
+ .leaf-button[data-priority="ghost"]:not([data-icon-only="true"]) {
108
118
  --leaf-button-height: auto;
109
119
  --leaf-button-padding: 0;
110
- --leaf-button-icon-only-padding: 0;
111
120
  }
112
121
 
113
122
  .leaf-button[data-priority="ghost"][data-icon-only="true"] {
114
- border-radius: 0;
123
+ --leaf-button-bg: transparent;
124
+ --leaf-button-padding: 0;
125
+ --leaf-button-icon-only-padding: 0;
115
126
  }
116
127
 
117
128
  /* ── Priority × status ───────────────────────────────────────────────── */
118
129
 
119
- /* Không có data-priority = primary. */
120
130
  .leaf-button[data-status="destruction"] {
121
131
  --leaf-button-bg: var(--button-base-destruction);
122
132
  --leaf-button-fg: var(--button-content-primary);
@@ -153,23 +163,43 @@
153
163
  }
154
164
 
155
165
  /*
156
- * Disabled — Primary / Ghost có trong Figma; Secondary/Tertiary dùng cùng token.
166
+ * Disabled — token --button-disabled-* (alias của --button-*-disable).
157
167
  * Specificity (0,3,0) và đứng cuối để thắng mọi tổ hợp priority × status.
158
168
  */
159
169
  .leaf-button:disabled:not([data-priority="ghost"]),
160
170
  .leaf-button[aria-disabled="true"]:not([data-priority="ghost"]) {
161
- --leaf-button-bg: var(--button-base-disable);
162
- --leaf-button-fg: var(--button-content-disable);
171
+ --leaf-button-bg: var(--button-disabled-base);
172
+ --leaf-button-fg: var(--button-disabled-content);
163
173
  }
164
174
 
165
175
  .leaf-button[data-priority="ghost"]:disabled,
166
176
  .leaf-button[data-priority="ghost"][aria-disabled="true"] {
167
177
  --leaf-button-bg: transparent;
168
- --leaf-button-fg: var(--button-content-disable);
178
+ --leaf-button-fg: var(--button-disabled-content);
169
179
  }
170
180
 
171
181
  .leaf-button:disabled,
172
182
  .leaf-button[aria-disabled="true"] {
173
183
  cursor: not-allowed;
174
184
  }
185
+
186
+ /*
187
+ * Loading — `data-loading="true"` (React: `loading` / onClick trả Promise; HTML tĩnh:
188
+ * `Leaf.button.setLoading`). Spinner thay leading icon, ăn --leaf-button-icon-size và
189
+ * màu chữ; màu nút giữ nguyên priority — không dùng `:disabled`.
190
+ */
191
+ .leaf-button[data-loading="true"] {
192
+ cursor: progress;
193
+ }
194
+
195
+ .leaf-button__spinner > svg {
196
+ animation: leaf-spinner-spin var(--leaf-spinner-duration, 1.2s) linear infinite;
197
+ }
198
+ }
199
+
200
+ /* Trùng tên với spinner.css để button.css tự đủ khi import riêng. */
201
+ @keyframes leaf-spinner-spin {
202
+ to {
203
+ transform: rotate(360deg);
204
+ }
175
205
  }