@teamix-evo/ui 0.1.1 → 0.3.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/README.md +184 -184
- package/manifest.json +680 -492
- package/package.json +20 -10
- package/src/components/accordion/accordion.meta.md +5 -4
- package/src/components/accordion/accordion.stories.tsx +14 -9
- package/src/components/accordion/accordion.tsx +104 -8
- package/src/components/affix/affix.meta.md +20 -2
- package/src/components/affix/affix.stories.tsx +102 -25
- package/src/components/affix/affix.tsx +79 -9
- package/src/components/alert/alert.meta.md +44 -13
- package/src/components/alert/alert.stories.tsx +66 -21
- package/src/components/alert/alert.tsx +81 -34
- package/src/components/alert-dialog/alert-dialog.meta.md +61 -16
- package/src/components/alert-dialog/alert-dialog.stories.tsx +145 -3
- package/src/components/alert-dialog/alert-dialog.tsx +60 -13
- package/src/components/anchor/anchor.meta.md +8 -3
- package/src/components/anchor/anchor.stories.tsx +3 -3
- package/src/components/anchor/anchor.tsx +2 -2
- package/src/components/app/app.meta.md +9 -4
- package/src/components/app/app.stories.tsx +9 -7
- package/src/components/aspect-ratio/aspect-ratio.meta.md +4 -3
- package/src/components/aspect-ratio/aspect-ratio.stories.tsx +3 -3
- package/src/components/auto-complete/auto-complete.meta.md +14 -6
- package/src/components/auto-complete/auto-complete.stories.tsx +47 -4
- package/src/components/auto-complete/auto-complete.tsx +119 -71
- package/src/components/avatar/avatar.meta.md +6 -7
- package/src/components/avatar/avatar.stories.tsx +21 -3
- package/src/components/avatar/avatar.tsx +24 -23
- package/src/components/badge/badge.meta.md +10 -9
- package/src/components/badge/badge.stories.tsx +2 -2
- package/src/components/badge/badge.tsx +9 -15
- package/src/components/breadcrumb/breadcrumb.meta.md +27 -7
- package/src/components/breadcrumb/breadcrumb.stories.tsx +127 -4
- package/src/components/breadcrumb/breadcrumb.tsx +22 -8
- package/src/components/button/button.meta.md +258 -21
- package/src/components/button/button.stories.tsx +549 -41
- package/src/components/button/button.tsx +335 -33
- package/src/components/button/demo/as-child.tsx +24 -0
- package/src/components/button/demo/basic.tsx +8 -0
- package/src/components/button/demo/block.tsx +16 -0
- package/src/components/button/demo/loading.tsx +19 -0
- package/src/components/button/demo/shapes.tsx +18 -0
- package/src/components/button/demo/sizes.tsx +19 -0
- package/src/components/button/demo/variants.tsx +19 -0
- package/src/components/button/demo/with-icon.tsx +20 -0
- package/src/components/calendar/calendar.meta.md +13 -3
- package/src/components/calendar/calendar.stories.tsx +6 -6
- package/src/components/calendar/calendar.tsx +73 -8
- package/src/components/card/card.meta.md +27 -5
- package/src/components/card/card.stories.tsx +42 -3
- package/src/components/card/card.tsx +146 -63
- package/src/components/carousel/carousel.meta.md +4 -3
- package/src/components/carousel/carousel.stories.tsx +11 -6
- package/src/components/cascader/cascader.meta.md +47 -17
- package/src/components/cascader/cascader.stories.tsx +22 -10
- package/src/components/cascader/cascader.tsx +428 -85
- package/src/components/checkbox/checkbox.meta.md +75 -7
- package/src/components/checkbox/checkbox.stories.tsx +161 -3
- package/src/components/checkbox/checkbox.tsx +77 -9
- package/src/components/collapsible/collapsible.meta.md +14 -6
- package/src/components/collapsible/collapsible.stories.tsx +10 -2
- package/src/components/collapsible/collapsible.tsx +93 -6
- package/src/components/color-picker/color-picker.meta.md +12 -7
- package/src/components/color-picker/color-picker.stories.tsx +86 -7
- package/src/components/color-picker/color-picker.tsx +20 -9
- package/src/components/command/command.meta.md +29 -13
- package/src/components/command/command.stories.tsx +4 -4
- package/src/components/command/command.tsx +19 -8
- package/src/components/context-menu/context-menu.meta.md +11 -8
- package/src/components/context-menu/context-menu.stories.tsx +11 -3
- package/src/components/context-menu/context-menu.tsx +21 -8
- package/src/components/data-table/data-table.meta.md +6 -5
- package/src/components/data-table/data-table.stories.tsx +13 -6
- package/src/components/data-table/data-table.tsx +2 -2
- package/src/components/date-picker/date-picker.meta.md +88 -19
- package/src/components/date-picker/date-picker.stories.tsx +55 -5
- package/src/components/date-picker/date-picker.tsx +1489 -91
- package/src/components/descriptions/descriptions.meta.md +10 -5
- package/src/components/descriptions/descriptions.stories.tsx +3 -3
- package/src/components/descriptions/descriptions.tsx +22 -14
- package/src/components/dialog/dialog.meta.md +76 -13
- package/src/components/dialog/dialog.stories.tsx +182 -20
- package/src/components/dialog/dialog.tsx +67 -15
- package/src/components/dialog/imperative.tsx +252 -0
- package/src/components/drawer/drawer.meta.md +33 -34
- package/src/components/drawer/drawer.stories.tsx +29 -12
- package/src/components/drawer/drawer.tsx +22 -113
- package/src/components/dropdown-menu/dropdown-menu.meta.md +78 -10
- package/src/components/dropdown-menu/dropdown-menu.stories.tsx +88 -2
- package/src/components/dropdown-menu/dropdown-menu.tsx +24 -10
- package/src/components/ellipsis/ellipsis.meta.md +87 -0
- package/src/components/ellipsis/ellipsis.stories.tsx +72 -0
- package/src/components/ellipsis/ellipsis.tsx +153 -0
- package/src/components/empty/empty.meta.md +9 -4
- package/src/components/empty/empty.stories.tsx +4 -4
- package/src/components/empty/empty.tsx +10 -3
- package/src/components/field/field.meta.md +47 -9
- package/src/components/field/field.stories.tsx +385 -5
- package/src/components/field/field.tsx +263 -35
- package/src/components/filter-bar/filter-bar.meta.md +92 -0
- package/src/components/filter-bar/filter-bar.stories.tsx +1083 -0
- package/src/components/filter-bar/filter-bar.tsx +568 -0
- package/src/components/flex/flex.meta.md +54 -6
- package/src/components/flex/flex.stories.tsx +107 -20
- package/src/components/flex/flex.tsx +27 -4
- package/src/components/float-button/float-button.meta.md +8 -3
- package/src/components/float-button/float-button.stories.tsx +9 -7
- package/src/components/float-button/float-button.tsx +1 -1
- package/src/components/form/form.meta.md +39 -17
- package/src/components/form/form.stories.tsx +350 -3
- package/src/components/form/form.tsx +101 -35
- package/src/components/grid/grid.meta.md +7 -2
- package/src/components/grid/grid.stories.tsx +6 -4
- package/src/components/hover-card/hover-card.meta.md +20 -9
- package/src/components/hover-card/hover-card.stories.tsx +34 -5
- package/src/components/hover-card/hover-card.tsx +51 -13
- package/src/components/icon/DEVELOPMENT.md +809 -0
- package/src/components/icon/icon.meta.md +170 -0
- package/src/components/icon/icon.stories.tsx +344 -0
- package/src/components/icon/icon.tsx +248 -0
- package/src/components/image/image.meta.md +9 -4
- package/src/components/image/image.stories.tsx +3 -3
- package/src/components/image/image.tsx +6 -4
- package/src/components/input/demo/basic.tsx +12 -0
- package/src/components/input/demo/clearable.tsx +21 -0
- package/src/components/input/demo/show-count.tsx +18 -0
- package/src/components/input/demo/sizes.tsx +15 -0
- package/src/components/input/input.meta.md +39 -33
- package/src/components/input/input.stories.tsx +62 -35
- package/src/components/input/input.tsx +97 -98
- package/src/components/input-group/input-group.meta.md +54 -22
- package/src/components/input-group/input-group.stories.tsx +49 -16
- package/src/components/input-group/input-group.tsx +44 -8
- package/src/components/input-number/input-number.meta.md +64 -7
- package/src/components/input-number/input-number.stories.tsx +46 -8
- package/src/components/input-number/input-number.tsx +99 -26
- package/src/components/input-otp/input-otp.meta.md +4 -3
- package/src/components/input-otp/input-otp.stories.tsx +3 -3
- package/src/components/input-otp/input-otp.tsx +1 -1
- package/src/components/item/item.meta.md +8 -3
- package/src/components/item/item.stories.tsx +8 -5
- package/src/components/item/item.tsx +7 -6
- package/src/components/kbd/kbd.meta.md +13 -4
- package/src/components/kbd/kbd.stories.tsx +4 -4
- package/src/components/kbd/kbd.tsx +10 -5
- package/src/components/label/label.meta.md +18 -10
- package/src/components/label/label.stories.tsx +64 -6
- package/src/components/label/label.tsx +91 -19
- package/src/components/masonry/masonry.meta.md +8 -3
- package/src/components/masonry/masonry.stories.tsx +7 -5
- package/src/components/masonry/masonry.tsx +1 -0
- package/src/components/mentions/mentions.meta.md +36 -6
- package/src/components/mentions/mentions.stories.tsx +120 -6
- package/src/components/mentions/mentions.tsx +11 -5
- package/src/components/menubar/menubar.meta.md +30 -12
- package/src/components/menubar/menubar.stories.tsx +62 -2
- package/src/components/menubar/menubar.tsx +9 -9
- package/src/components/native-select/native-select.meta.md +8 -3
- package/src/components/native-select/native-select.stories.tsx +8 -5
- package/src/components/native-select/native-select.tsx +1 -1
- package/src/components/navigation-menu/navigation-menu.meta.md +19 -9
- package/src/components/navigation-menu/navigation-menu.stories.tsx +112 -9
- package/src/components/navigation-menu/navigation-menu.tsx +8 -4
- package/src/components/notification/notification.meta.md +52 -10
- package/src/components/notification/notification.stories.tsx +11 -9
- package/src/components/notification/notification.tsx +36 -21
- package/src/components/page-header/DEVELOPMENT.md +842 -0
- package/src/components/page-header/page-header.meta.md +208 -0
- package/src/components/page-header/page-header.stories.tsx +421 -0
- package/src/components/page-header/page-header.tsx +281 -0
- package/src/components/pagination/pagination.meta.md +140 -37
- package/src/components/pagination/pagination.stories.tsx +232 -10
- package/src/components/pagination/pagination.tsx +355 -63
- package/src/components/popconfirm/popconfirm.meta.md +9 -4
- package/src/components/popconfirm/popconfirm.stories.tsx +3 -4
- package/src/components/popconfirm/popconfirm.tsx +2 -2
- package/src/components/popover/popover.meta.md +62 -5
- package/src/components/popover/popover.stories.tsx +83 -7
- package/src/components/popover/popover.tsx +77 -28
- package/src/components/progress/progress.meta.md +38 -6
- package/src/components/progress/progress.stories.tsx +3 -3
- package/src/components/progress/progress.tsx +24 -16
- package/src/components/radio-group/radio-group.meta.md +79 -7
- package/src/components/radio-group/radio-group.stories.tsx +39 -3
- package/src/components/radio-group/radio-group.tsx +149 -18
- package/src/components/rate/rate.meta.md +35 -4
- package/src/components/rate/rate.stories.tsx +13 -5
- package/src/components/rate/rate.tsx +37 -10
- package/src/components/resizable/resizable.meta.md +7 -4
- package/src/components/resizable/resizable.stories.tsx +6 -6
- package/src/components/resizable/resizable.tsx +1 -1
- package/src/components/result/result.meta.md +7 -2
- package/src/components/result/result.stories.tsx +4 -8
- package/src/components/result/result.tsx +24 -15
- package/src/components/scroll-area/scroll-area.meta.md +4 -3
- package/src/components/scroll-area/scroll-area.stories.tsx +12 -4
- package/src/components/scroll-area/scroll-area.tsx +3 -3
- package/src/components/segmented/segmented.meta.md +7 -4
- package/src/components/segmented/segmented.stories.tsx +37 -8
- package/src/components/segmented/segmented.tsx +15 -7
- package/src/components/select/select.meta.md +197 -52
- package/src/components/select/select.stories.tsx +238 -63
- package/src/components/select/select.tsx +718 -171
- package/src/components/separator/separator.meta.md +4 -3
- package/src/components/separator/separator.stories.tsx +3 -3
- package/src/components/separator/separator.tsx +3 -7
- package/src/components/sheet/sheet.meta.md +32 -16
- package/src/components/sheet/sheet.stories.tsx +116 -10
- package/src/components/sheet/sheet.tsx +116 -29
- package/src/components/sidebar/sidebar.meta.md +37 -18
- package/src/components/sidebar/sidebar.stories.tsx +701 -29
- package/src/components/sidebar/sidebar.tsx +615 -142
- package/src/components/skeleton/skeleton.meta.md +4 -5
- package/src/components/skeleton/skeleton.stories.tsx +4 -4
- package/src/components/skeleton/skeleton.tsx +7 -7
- package/src/components/slider/slider.meta.md +57 -5
- package/src/components/slider/slider.stories.tsx +58 -6
- package/src/components/slider/slider.tsx +154 -13
- package/src/components/sonner/sonner.meta.md +58 -7
- package/src/components/sonner/sonner.stories.tsx +78 -5
- package/src/components/sonner/sonner.tsx +137 -8
- package/src/components/spinner/spinner.meta.md +62 -13
- package/src/components/spinner/spinner.stories.tsx +66 -14
- package/src/components/spinner/spinner.tsx +111 -9
- package/src/components/statistic/statistic.meta.md +7 -2
- package/src/components/statistic/statistic.stories.tsx +3 -7
- package/src/components/statistic/statistic.tsx +5 -6
- package/src/components/steps/steps.meta.md +18 -4
- package/src/components/steps/steps.stories.tsx +43 -3
- package/src/components/steps/steps.tsx +15 -12
- package/src/components/switch/switch.meta.md +51 -5
- package/src/components/switch/switch.stories.tsx +6 -6
- package/src/components/switch/switch.tsx +109 -41
- package/src/components/table/table.meta.md +17 -6
- package/src/components/table/table.stories.tsx +10 -5
- package/src/components/table/table.tsx +4 -4
- package/src/components/tabs/tabs.meta.md +38 -25
- package/src/components/tabs/tabs.stories.tsx +111 -25
- package/src/components/tabs/tabs.tsx +125 -54
- package/src/components/tag/tag.meta.md +105 -40
- package/src/components/tag/tag.stories.tsx +189 -16
- package/src/components/tag/tag.tsx +222 -21
- package/src/components/textarea/textarea.meta.md +35 -19
- package/src/components/textarea/textarea.stories.tsx +32 -6
- package/src/components/textarea/textarea.tsx +33 -9
- package/src/components/time-picker/time-picker.meta.md +124 -32
- package/src/components/time-picker/time-picker.stories.tsx +85 -15
- package/src/components/time-picker/time-picker.tsx +913 -61
- package/src/components/timeline/timeline.meta.md +14 -6
- package/src/components/timeline/timeline.stories.tsx +37 -7
- package/src/components/timeline/timeline.tsx +35 -14
- package/src/components/toggle/toggle.meta.md +5 -4
- package/src/components/toggle/toggle.stories.tsx +4 -4
- package/src/components/toggle/toggle.tsx +4 -3
- package/src/components/toggle-group/toggle-group.meta.md +5 -4
- package/src/components/toggle-group/toggle-group.stories.tsx +3 -3
- package/src/components/toggle-group/toggle-group.tsx +2 -2
- package/src/components/tooltip/tooltip.meta.md +55 -5
- package/src/components/tooltip/tooltip.stories.tsx +42 -5
- package/src/components/tooltip/tooltip.tsx +81 -21
- package/src/components/tour/tour.meta.md +9 -4
- package/src/components/tour/tour.stories.tsx +3 -3
- package/src/components/tour/tour.tsx +4 -4
- package/src/components/transfer/transfer.meta.md +11 -6
- package/src/components/transfer/transfer.stories.tsx +4 -8
- package/src/components/transfer/transfer.tsx +28 -21
- package/src/components/tree/tree.meta.md +63 -5
- package/src/components/tree/tree.stories.tsx +31 -12
- package/src/components/tree/tree.tsx +9 -8
- package/src/components/tree-select/tree-select.meta.md +59 -8
- package/src/components/tree-select/tree-select.stories.tsx +3 -3
- package/src/components/tree-select/tree-select.tsx +42 -7
- package/src/components/typography/typography.meta.md +61 -14
- package/src/components/typography/typography.stories.tsx +12 -11
- package/src/components/typography/typography.tsx +43 -28
- package/src/components/upload/upload.meta.md +49 -4
- package/src/components/upload/upload.stories.tsx +72 -12
- package/src/components/upload/upload.tsx +170 -37
- package/src/components/watermark/watermark.meta.md +7 -2
- package/src/components/watermark/watermark.stories.tsx +101 -9
- package/src/components/watermark/watermark.tsx +1 -0
- package/src/hooks/use-breakpoint.ts +117 -0
- package/src/hooks/use-debounce-callback.ts +52 -0
- package/src/hooks/use-mobile.ts +23 -0
- package/src/stories/theme-tokens.stories.tsx +747 -0
- package/src/utils/trigger-input.ts +53 -0
- package/src/components/button-group/button-group.meta.md +0 -92
- package/src/components/button-group/button-group.stories.tsx +0 -90
- package/src/components/button-group/button-group.tsx +0 -75
- package/src/components/combobox/combobox.meta.md +0 -93
- package/src/components/combobox/combobox.stories.tsx +0 -55
- package/src/components/combobox/combobox.tsx +0 -130
- package/src/components/space/space.meta.md +0 -94
- package/src/components/space/space.stories.tsx +0 -94
- package/src/components/space/space.tsx +0 -106
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: radio-group
|
|
3
3
|
name: RadioGroup
|
|
4
|
+
displayName: 单选组
|
|
4
5
|
type: component
|
|
5
|
-
category:
|
|
6
|
+
category: data-entry
|
|
6
7
|
since: 0.1.0
|
|
7
|
-
package:
|
|
8
|
+
package: '@teamix-evo/ui'
|
|
8
9
|
---
|
|
9
10
|
|
|
10
|
-
# RadioGroup
|
|
11
|
+
# RadioGroup 单选组
|
|
11
12
|
|
|
12
13
|
单选组 — Radix RadioGroup,**两种渲染**:
|
|
13
14
|
|
|
14
|
-
| variant
|
|
15
|
-
|
|
|
16
|
-
| `default` | 圆点 + 文字(shadcn 风格)
|
|
17
|
-
| `button`
|
|
15
|
+
| variant | 形态 | 适用 |
|
|
16
|
+
| --------- | ------------------------------ | ------------------------------------ |
|
|
17
|
+
| `default` | 圆点 + 文字(shadcn 风格) | 表单 / 设置面板 |
|
|
18
|
+
| `button` | 按钮组(antd Radio.Button 并集) | 视图切换 / 时间区间切换 / 紧凑工具栏 |
|
|
18
19
|
|
|
19
20
|
## When to use
|
|
20
21
|
|
|
@@ -35,7 +36,15 @@ package: "@teamix-evo/ui"
|
|
|
35
36
|
<!-- auto:props:begin -->
|
|
36
37
|
| 名称 | 类型 | 默认值 | 必填 | 说明 |
|
|
37
38
|
| --- | --- | --- | --- | --- |
|
|
39
|
+
| `value` | `string` | – | – | 受控选中值(等价 antd `value`,Radix 命名一致)。 与 `defaultValue` 二选一,不同时传。 |
|
|
40
|
+
| `defaultValue` | `string` | – | – | 非受控初始选中值。 |
|
|
41
|
+
| `onValueChange` | `(value: string) => void` | – | – | 选中变化回调 — Radix 命名,等价 antd `onChange(value)`。 |
|
|
42
|
+
| `disabled` | `boolean` | `false` | – | 整组禁用(灰化所有 Item / Button + 不响应交互)。 |
|
|
43
|
+
| `required` | `boolean` | `false` | – | 表单必填 — 设置 HTML 原生 `required`,表单层校验依赖此值。 |
|
|
44
|
+
| `name` | `string` | – | – | 表单字段名(原生 `<input name>`,提交表单时使用;同组所有 Item 共用)。 |
|
|
45
|
+
| `orientation` | `'horizontal' \| 'vertical'` | `"vertical"` | – | 排列方向(键盘导航方向也跟随此值)。 |
|
|
38
46
|
| `variant` | `'default' \| 'button'` | `"default"` | – | 渲染样式 — `default` 经典圆点;`button` 渲染为按钮组(antd `Radio.Button` 并集)。 |
|
|
47
|
+
| `options` | `RadioGroupOption[]` | – | – | 选项数据源(数据驱动模式,与 CheckboxGroup `options` 对齐)。 传入后内部自动渲染 `RadioGroupItem` / `RadioGroupButton`,无需 `children`. 当同时存在 `children` 与 `options` 时,`children` 优先。 |
|
|
39
48
|
<!-- auto:props:end -->
|
|
40
49
|
|
|
41
50
|
## 依赖
|
|
@@ -68,6 +77,7 @@ pnpm add @radix-ui/react-radio-group@^1.2.0 lucide-react@^0.460.0
|
|
|
68
77
|
- **必须有 default 选中项**:用户进入页面看到全部未选会困惑;用 `defaultValue` 给一个合理初值
|
|
69
78
|
- **每项必关联 Label**:`<RadioGroupItem id="r1" value="a" /> + <Label htmlFor="r1">A</Label>` 或包裹模式
|
|
70
79
|
- **value 唯一稳定**:不要用 index,变化时 controlled diff 失败
|
|
80
|
+
- **横向排列固定 16px(组件内置 `gap-4`)**:对齐《Teamix UI 表单设计规范》§3.1 规则 3 "checkbox/radio 横向 16px";不要手动加 `gap-3` / `space-x-2` 等覆盖。纵向自动用 `gap-2`(8px,紧凑列表)。
|
|
71
81
|
|
|
72
82
|
## Examples
|
|
73
83
|
|
|
@@ -100,4 +110,66 @@ import { Label } from '@/components/ui/label';
|
|
|
100
110
|
<RadioGroupButton value="month">月</RadioGroupButton>
|
|
101
111
|
<RadioGroupButton value="year">年</RadioGroupButton>
|
|
102
112
|
</RadioGroup>
|
|
113
|
+
|
|
114
|
+
// 数据驱动模式(对齐 CheckboxGroup)
|
|
115
|
+
<RadioGroup
|
|
116
|
+
options={[
|
|
117
|
+
{ label: '苹果', value: 'apple' },
|
|
118
|
+
{ label: '香蕉', value: 'banana' },
|
|
119
|
+
{ label: '橘子', value: 'orange', disabled: true },
|
|
120
|
+
]}
|
|
121
|
+
defaultValue="apple"
|
|
122
|
+
/>
|
|
123
|
+
|
|
124
|
+
// 数据驱动 + 按钮模式
|
|
125
|
+
<RadioGroup
|
|
126
|
+
variant="button"
|
|
127
|
+
options={[
|
|
128
|
+
{ label: '日', value: 'day' },
|
|
129
|
+
{ label: '周', value: 'week' },
|
|
130
|
+
{ label: '月', value: 'month' },
|
|
131
|
+
]}
|
|
132
|
+
defaultValue="month"
|
|
133
|
+
/>
|
|
103
134
|
```
|
|
135
|
+
|
|
136
|
+
## Radio 形态 — 旧库 API → 新映射
|
|
137
|
+
|
|
138
|
+
> 决策:**不新增独立组件**,直接用 `RadioGroup` + `RadioGroupItem` / `RadioGroupButton` 承接 cloud-design `Radio` / `Radio.Group` 全部用法。本章节是从旧库平滑迁移的查表索引,与 [上面的 Props 表](#props) 互补。
|
|
139
|
+
|
|
140
|
+
### 命名映射
|
|
141
|
+
|
|
142
|
+
| cloud-design 旧库 | `@teamix-evo/ui` | 说明 |
|
|
143
|
+
| ----------------------------------------- | ------------------------------------------------------ | ------------------------------------------------------------------- |
|
|
144
|
+
| `Radio` + `Radio.Group` | `RadioGroup` + `RadioGroupItem` / `RadioGroupButton` | 父子拆分导出,shadcn 风格 |
|
|
145
|
+
| `Radio.Group shape="button"` | `<RadioGroup variant="button">` + `<RadioGroupButton>` | `shape` → `variant`(Radix 语义) |
|
|
146
|
+
| `Radio.Group direction="hor\|ver"` | `<RadioGroup orientation="horizontal\|vertical">` | 完整单词,Radix 原生 prop |
|
|
147
|
+
| `Radio.Group dataSource=[{label,value}]` | `<RadioGroup options={[{label,value}]}>` | `dataSource` → `options`(对齐 antd / CheckboxGroup) |
|
|
148
|
+
| `Radio.Group value / onChange` | `<RadioGroup value onValueChange>` | Radix 命名:`onValueChange(val: string)` |
|
|
149
|
+
| `Radio.Group defaultValue` | `<RadioGroup defaultValue>` | 同名 |
|
|
150
|
+
| `Radio.Group disabled` | `<RadioGroup disabled>` | 整组禁用 |
|
|
151
|
+
| `Radio.Group size="small\|medium\|large"` | Radix 无内置 size;可通过 className 调整 | 新库不内置 size — 按钮模式固定 h-9,圆点模式固定 size-4,满足多数场景 |
|
|
152
|
+
|
|
153
|
+
### Breaking Changes(从旧库迁移时需改写)
|
|
154
|
+
|
|
155
|
+
1. `Radio` → `RadioGroupItem`(import + 命名)
|
|
156
|
+
2. `Radio.Group` → `RadioGroup`(独立 named export)
|
|
157
|
+
3. `shape="button"` → `variant="button"`(子项同步换成 `RadioGroupButton`)
|
|
158
|
+
4. `direction` → `orientation`(取值从 `hor/ver` 改为 `horizontal/vertical`)
|
|
159
|
+
5. `dataSource` → `options`(签名一致)
|
|
160
|
+
6. `onChange(value)` → `onValueChange(value)` (Radix 命名)
|
|
161
|
+
|
|
162
|
+
### 不修复 / 后续工序清单
|
|
163
|
+
|
|
164
|
+
- **按钮模式圆角**(2px → 4px):报告 §2.2,归 `@teamix-evo/tokens` 后续工序
|
|
165
|
+
- **按钮模式选中视觉**(old: 品牌色边框+浅蓝底 vs new: 品牌色填充+白字):报告 §5 已标注 "新库更现代,设计确认后保留",**不修复**
|
|
166
|
+
- **disabled opacity vs 灰色**:全局策略,**不修复**
|
|
167
|
+
- **size prop**:新库不内置 size(Radix 无此 prop),圆点 `size-4` / 按钮 `h-9` 已覆盖多数场景;如业务确有 size 需求,属于二级 slot 后续添加
|
|
168
|
+
|
|
169
|
+
### Radio 专项 AI 生成纪律
|
|
170
|
+
|
|
171
|
+
- **形态由父级 `variant` + 子项组件共同决定**:default → `RadioGroupItem`,button → `RadioGroupButton`,**不要混用**
|
|
172
|
+
- **数据驱动 `options` 模式与 children 互斥**:同时传时 children 优先;统一用一种写法
|
|
173
|
+
- **必须有初始选中**:用 `defaultValue` 给一个合理初值(用户进入页面看到全未选会困惑)
|
|
174
|
+
- **`value` 稳定唯一**:options[].value 不要用 index / 动态 ID;类同 CheckboxGroup 约束
|
|
175
|
+
- **Radix `onValueChange(val: string)`**:单参数字符串,**不要按旧库习惯**期待事件对象
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
2
|
import { RadioGroup, RadioGroupItem, RadioGroupButton } from './radio-group';
|
|
3
|
+
import type { RadioGroupOption } from './radio-group';
|
|
3
4
|
|
|
4
5
|
const meta: Meta<typeof RadioGroup> = {
|
|
5
|
-
title: '
|
|
6
|
+
title: '数据录入 · Data Entry/RadioGroup',
|
|
6
7
|
component: RadioGroup,
|
|
7
8
|
tags: ['autodocs'],
|
|
8
9
|
parameters: {
|
|
9
10
|
docs: {
|
|
10
11
|
description: {
|
|
11
12
|
component:
|
|
12
|
-
'单选组 — 在一组互斥选项中选中唯一一个。Radix RadioGroup 实现 + antd Radio 的并集能力:同时提供默认的点选型 `RadioGroupItem` 与按钮型 `RadioGroupButton`(对齐 antd `Radio.Button`),通过 `variant` prop
|
|
13
|
+
'单选组 — 在一组互斥选项中选中唯一一个。Radix RadioGroup 实现 + antd Radio 的并集能力:同时提供默认的点选型 `RadioGroupItem` 与按钮型 `RadioGroupButton`(对齐 antd `Radio.Button`),通过 `variant` prop 切换。',
|
|
13
14
|
},
|
|
14
15
|
},
|
|
15
16
|
},
|
|
@@ -75,3 +76,38 @@ export const Disabled: Story = {
|
|
|
75
76
|
</div>
|
|
76
77
|
),
|
|
77
78
|
};
|
|
79
|
+
|
|
80
|
+
// ─── 数据驱动 options 模式(与 CheckboxGroup 对齐)──────────────────
|
|
81
|
+
|
|
82
|
+
const fruitOptions: RadioGroupOption[] = [
|
|
83
|
+
{ label: '苹果', value: 'apple' },
|
|
84
|
+
{ label: '香蕉', value: 'banana' },
|
|
85
|
+
{ label: '橘子', value: 'orange', disabled: true },
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 数据驱动 — 对齐 cloud-design `Radio.Group dataSource` / antd `Radio.Group options`。
|
|
90
|
+
* 传入 `options` prop 即可,内部自动渲染 `RadioGroupItem` + Label。
|
|
91
|
+
*/
|
|
92
|
+
export const OptionsGroup: Story = {
|
|
93
|
+
parameters: { controls: { disable: true } },
|
|
94
|
+
render: () => <RadioGroup options={fruitOptions} defaultValue="apple" />,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 数据驱动 + 按钮模式 — `variant="button"` + `options`。
|
|
99
|
+
*/
|
|
100
|
+
export const OptionsButtonGroup: Story = {
|
|
101
|
+
parameters: { controls: { disable: true } },
|
|
102
|
+
render: () => (
|
|
103
|
+
<RadioGroup
|
|
104
|
+
variant="button"
|
|
105
|
+
options={[
|
|
106
|
+
{ label: '日', value: 'day' },
|
|
107
|
+
{ label: '周', value: 'week' },
|
|
108
|
+
{ label: '月', value: 'month' },
|
|
109
|
+
]}
|
|
110
|
+
defaultValue="month"
|
|
111
|
+
/>
|
|
112
|
+
),
|
|
113
|
+
};
|
|
@@ -4,35 +4,149 @@ import { Circle } from 'lucide-react';
|
|
|
4
4
|
|
|
5
5
|
import { cn } from '@/utils/cn';
|
|
6
6
|
|
|
7
|
+
// ─── RadioGroupOption(数据驱动模式,对齐 CheckboxGroup)────────────────
|
|
8
|
+
|
|
9
|
+
export interface RadioGroupOption {
|
|
10
|
+
label: React.ReactNode;
|
|
11
|
+
value: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
7
15
|
export interface RadioGroupProps
|
|
8
|
-
extends
|
|
16
|
+
extends Omit<
|
|
17
|
+
React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root>,
|
|
18
|
+
| 'value'
|
|
19
|
+
| 'defaultValue'
|
|
20
|
+
| 'onValueChange'
|
|
21
|
+
| 'disabled'
|
|
22
|
+
| 'required'
|
|
23
|
+
| 'name'
|
|
24
|
+
| 'orientation'
|
|
25
|
+
| 'dir'
|
|
26
|
+
| 'loop'
|
|
27
|
+
> {
|
|
28
|
+
/**
|
|
29
|
+
* 受控选中值(等价 antd `value`,Radix 命名一致)。
|
|
30
|
+
* 与 `defaultValue` 二选一,不同时传。
|
|
31
|
+
*/
|
|
32
|
+
value?: string;
|
|
33
|
+
/** 非受控初始选中值。 */
|
|
34
|
+
defaultValue?: string;
|
|
35
|
+
/**
|
|
36
|
+
* 选中变化回调 — Radix 命名,等价 antd `onChange(value)`。
|
|
37
|
+
*/
|
|
38
|
+
onValueChange?: (value: string) => void;
|
|
39
|
+
/**
|
|
40
|
+
* 整组禁用(灰化所有 Item / Button + 不响应交互)。
|
|
41
|
+
* @default false
|
|
42
|
+
*/
|
|
43
|
+
disabled?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* 表单必填 — 设置 HTML 原生 `required`,表单层校验依赖此值。
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
required?: boolean;
|
|
49
|
+
/** 表单字段名(原生 `<input name>`,提交表单时使用;同组所有 Item 共用)。 */
|
|
50
|
+
name?: string;
|
|
51
|
+
/**
|
|
52
|
+
* 排列方向(键盘导航方向也跟随此值)。
|
|
53
|
+
* @default "vertical"
|
|
54
|
+
*/
|
|
55
|
+
orientation?: 'horizontal' | 'vertical';
|
|
9
56
|
/**
|
|
10
57
|
* 渲染样式 — `default` 经典圆点;`button` 渲染为按钮组(antd `Radio.Button` 并集)。
|
|
11
58
|
* @default "default"
|
|
12
59
|
*/
|
|
13
60
|
variant?: 'default' | 'button';
|
|
61
|
+
/**
|
|
62
|
+
* 选项数据源(数据驱动模式,与 CheckboxGroup `options` 对齐)。
|
|
63
|
+
* 传入后内部自动渲染 `RadioGroupItem` / `RadioGroupButton`,无需 `children`.
|
|
64
|
+
* 当同时存在 `children` 与 `options` 时,`children` 优先。
|
|
65
|
+
*/
|
|
66
|
+
options?: RadioGroupOption[];
|
|
14
67
|
}
|
|
15
68
|
|
|
16
69
|
const RadioGroup = React.forwardRef<
|
|
17
70
|
React.ElementRef<typeof RadioGroupPrimitive.Root>,
|
|
18
71
|
RadioGroupProps
|
|
19
|
-
>(({ className, variant = 'default', ...props }, ref) =>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
72
|
+
>(({ className, variant = 'default', orientation = 'vertical', options, children, ...props }, ref) => {
|
|
73
|
+
// children 优先;仅当无 children 且传入 options 时内部渲染
|
|
74
|
+
const content =
|
|
75
|
+
children ||
|
|
76
|
+
(options &&
|
|
77
|
+
options.map((opt) =>
|
|
78
|
+
variant === 'button' ? (
|
|
79
|
+
<RadioGroupButton
|
|
80
|
+
key={opt.value}
|
|
81
|
+
value={opt.value}
|
|
82
|
+
disabled={opt.disabled}
|
|
83
|
+
>
|
|
84
|
+
{opt.label}
|
|
85
|
+
</RadioGroupButton>
|
|
86
|
+
) : (
|
|
87
|
+
<div key={opt.value} className="flex items-center gap-2 text-xs">
|
|
88
|
+
<RadioGroupItem
|
|
89
|
+
value={opt.value}
|
|
90
|
+
id={`rg-opt-${opt.value}`}
|
|
91
|
+
disabled={opt.disabled}
|
|
92
|
+
/>
|
|
93
|
+
<label
|
|
94
|
+
htmlFor={`rg-opt-${opt.value}`}
|
|
95
|
+
className={cn(
|
|
96
|
+
(opt.disabled || props.disabled) &&
|
|
97
|
+
'cursor-not-allowed opacity-60',
|
|
98
|
+
)}
|
|
99
|
+
>
|
|
100
|
+
{opt.label}
|
|
101
|
+
</label>
|
|
102
|
+
</div>
|
|
103
|
+
),
|
|
104
|
+
));
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<RadioGroupPrimitive.Root
|
|
108
|
+
ref={ref}
|
|
109
|
+
data-variant={variant}
|
|
110
|
+
data-orientation={orientation}
|
|
111
|
+
orientation={orientation}
|
|
112
|
+
className={cn(
|
|
113
|
+
variant === 'button'
|
|
114
|
+
? 'inline-flex divide-x divide-input overflow-hidden rounded-md border border-input shadow-sm'
|
|
115
|
+
: // 默认形态:横向 16px (gap-4, 对齐规范 §3.1 规则 3 "checkbox/radio 横向 16px"),
|
|
116
|
+
// 纵向 8px (gap-2, 紧凑列表)
|
|
117
|
+
orientation === 'horizontal'
|
|
118
|
+
? 'flex flex-wrap gap-4'
|
|
119
|
+
: 'grid gap-2',
|
|
120
|
+
className,
|
|
121
|
+
)}
|
|
122
|
+
{...props}
|
|
123
|
+
>
|
|
124
|
+
{content}
|
|
125
|
+
</RadioGroupPrimitive.Root>
|
|
126
|
+
);
|
|
127
|
+
});
|
|
32
128
|
RadioGroup.displayName = RadioGroupPrimitive.Root.displayName;
|
|
33
129
|
|
|
34
130
|
export interface RadioGroupItemProps
|
|
35
|
-
extends
|
|
131
|
+
extends Omit<
|
|
132
|
+
React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>,
|
|
133
|
+
'value' | 'disabled' | 'required' | 'id'
|
|
134
|
+
> {
|
|
135
|
+
/**
|
|
136
|
+
* 选项 value — 选中时把此值赋给 RadioGroup 的 `value`。
|
|
137
|
+
* **必填** — 每个 Item 必须有稳定唯一的 value(string)。
|
|
138
|
+
*/
|
|
139
|
+
value: string;
|
|
140
|
+
/**
|
|
141
|
+
* 禁用此选项(整组 `disabled` 会覆盖单项的 `disabled={false}`)。
|
|
142
|
+
* @default false
|
|
143
|
+
*/
|
|
144
|
+
disabled?: boolean;
|
|
145
|
+
/** 必填(透传 HTML required)。 */
|
|
146
|
+
required?: boolean;
|
|
147
|
+
/** id 属性,配合 `<label htmlFor>` 关联选项文字。 */
|
|
148
|
+
id?: string;
|
|
149
|
+
}
|
|
36
150
|
|
|
37
151
|
const RadioGroupItem = React.forwardRef<
|
|
38
152
|
React.ElementRef<typeof RadioGroupPrimitive.Item>,
|
|
@@ -41,7 +155,7 @@ const RadioGroupItem = React.forwardRef<
|
|
|
41
155
|
<RadioGroupPrimitive.Item
|
|
42
156
|
ref={ref}
|
|
43
157
|
className={cn(
|
|
44
|
-
'aspect-square size-4 rounded-full border border-primary text-primary shadow focus:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50',
|
|
158
|
+
'aspect-square size-4 cursor-pointer rounded-full border border-primary text-primary shadow focus:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50',
|
|
45
159
|
className,
|
|
46
160
|
)}
|
|
47
161
|
{...props}
|
|
@@ -56,7 +170,24 @@ RadioGroupItem.displayName = RadioGroupPrimitive.Item.displayName;
|
|
|
56
170
|
// ─── RadioGroupButton(Button-style item, antd `Radio.Button` 并集)───────
|
|
57
171
|
|
|
58
172
|
export interface RadioGroupButtonProps
|
|
59
|
-
extends
|
|
173
|
+
extends Omit<
|
|
174
|
+
React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>,
|
|
175
|
+
'value' | 'disabled' | 'required' | 'id'
|
|
176
|
+
> {
|
|
177
|
+
/**
|
|
178
|
+
* 选项 value — 选中时把此值赋给 RadioGroup 的 `value`。**必填**,稳定唯一。
|
|
179
|
+
*/
|
|
180
|
+
value: string;
|
|
181
|
+
/**
|
|
182
|
+
* 禁用此选项(整组 `disabled` 会覆盖单项的 `disabled={false}`)。
|
|
183
|
+
* @default false
|
|
184
|
+
*/
|
|
185
|
+
disabled?: boolean;
|
|
186
|
+
/** 必填(透传 HTML required)。 */
|
|
187
|
+
required?: boolean;
|
|
188
|
+
/** id 属性,通常无需手传(按钮组形态自身已含可点击区域)。 */
|
|
189
|
+
id?: string;
|
|
190
|
+
}
|
|
60
191
|
|
|
61
192
|
const RadioGroupButton = React.forwardRef<
|
|
62
193
|
React.ElementRef<typeof RadioGroupPrimitive.Item>,
|
|
@@ -65,7 +196,7 @@ const RadioGroupButton = React.forwardRef<
|
|
|
65
196
|
<RadioGroupPrimitive.Item
|
|
66
197
|
ref={ref}
|
|
67
198
|
className={cn(
|
|
68
|
-
'inline-flex h-9 cursor-pointer items-center justify-center px-4 text-
|
|
199
|
+
'inline-flex h-9 cursor-pointer items-center justify-center px-4 text-xs font-medium transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground data-[state=checked]:hover:bg-primary/90',
|
|
69
200
|
className,
|
|
70
201
|
)}
|
|
71
202
|
{...props}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: rate
|
|
3
3
|
name: Rate
|
|
4
|
+
displayName: 评分
|
|
4
5
|
type: component
|
|
5
|
-
category:
|
|
6
|
+
category: data-entry
|
|
6
7
|
since: 0.1.0
|
|
7
|
-
package:
|
|
8
|
+
package: '@teamix-evo/ui'
|
|
8
9
|
---
|
|
9
10
|
|
|
10
|
-
# Rate
|
|
11
|
+
# Rate 评分
|
|
11
12
|
|
|
12
13
|
星级评分 — antd 独有补足。**等价 antd `Rate`**。支持半星(`allowHalf`)、再次点击清零(`allowClear`)、自定义图标(`character`)、只读展示(`disabled`)。
|
|
13
14
|
|
|
@@ -22,6 +23,8 @@ package: "@teamix-evo/ui"
|
|
|
22
23
|
- 二元选择(喜欢 / 不喜欢)→ `Toggle` / `Button` 配 icon
|
|
23
24
|
- 多档定量评分(0~100)→ `Slider`
|
|
24
25
|
|
|
26
|
+
## Props
|
|
27
|
+
|
|
25
28
|
<!-- auto:props:begin -->
|
|
26
29
|
| 名称 | 类型 | 默认值 | 必填 | 说明 |
|
|
27
30
|
| --- | --- | --- | --- | --- |
|
|
@@ -31,11 +34,13 @@ package: "@teamix-evo/ui"
|
|
|
31
34
|
| `allowHalf` | `boolean` | `false` | – | 允许半星(antd `allowHalf` 并集) — 启用后单星可点击左半 / 右半。 |
|
|
32
35
|
| `allowClear` | `boolean` | `true` | – | 允许再次点击同值清零(antd `allowClear` 并集)。 |
|
|
33
36
|
| `disabled` | `boolean` | – | – | 禁用(只展示)。 |
|
|
34
|
-
| `size` | `'sm' \| 'default' \| 'lg'` | `"default"` | – | 尺寸(影响星图大小)。 |
|
|
37
|
+
| `size` | `'sm' \| 'md' \| 'default' \| 'lg'` | `"default"` | – | 尺寸(影响星图大小)。 |
|
|
35
38
|
| `character` | `React.ReactNode` | – | – | 自定义图标(antd `character` 并集) — 默认 `lucide-react` 的 `Star`。 |
|
|
36
39
|
| `onChange` | `(value: number) => void` | – | – | value 变化回调。 |
|
|
37
40
|
<!-- auto:props:end -->
|
|
38
41
|
|
|
42
|
+
## 依赖
|
|
43
|
+
|
|
39
44
|
<!-- auto:deps:begin -->
|
|
40
45
|
### 同库依赖
|
|
41
46
|
|
|
@@ -61,6 +66,8 @@ pnpm add lucide-react@^0.460.0
|
|
|
61
66
|
- **`allowClear` 默认 true** — 与 antd 一致;关闭后用户无法清空评分,只能改值
|
|
62
67
|
- **`character` 自定义图标**:必须是 `React.isValidElement` 节点,组件会在选中态注入 `fill="currentColor"`;**不要**传字符串
|
|
63
68
|
- **大评分场景**(`count > 7`)视觉拥挤,建议改用 `Slider` + 数字展示
|
|
69
|
+
- **尺寸与 cloud-design 对齐**:`sm/default/lg` = 16/20/24px,与其他表单表一致的密度作业
|
|
70
|
+
- **半星渲染分两层**:底层 `text-muted-foreground/30` 描边空星 · 上层 `clipPath: inset(0 50% 0 0)` 裁切到左半边 + `text-warning` 填充;**不要**反过来(会丢失右半边描边)
|
|
64
71
|
|
|
65
72
|
## Examples
|
|
66
73
|
|
|
@@ -85,3 +92,27 @@ const [v, setV] = React.useState(0);
|
|
|
85
92
|
// 只读
|
|
86
93
|
<Rate disabled value={4.5} allowHalf />
|
|
87
94
|
```
|
|
95
|
+
|
|
96
|
+
## Rating 形态 — 旧库 API → 新库映射
|
|
97
|
+
|
|
98
|
+
> 旧库(Teamix 1.0 / `@alifd/next.Rating`)→ 新库 `Rate`(对齐 antd 命名)。能力**全部并集已实现**,只有少量低频 prop 不修复。
|
|
99
|
+
|
|
100
|
+
| 旧库 API | 新库 API | 备注 |
|
|
101
|
+
| --- | --- | --- |
|
|
102
|
+
| 组件名 `Rating` | `Rate` | 对齐 antd 命名 |
|
|
103
|
+
| `count` | `count` | 同名 |
|
|
104
|
+
| `value` / `defaultValue` | `value` / `defaultValue` | 同名 |
|
|
105
|
+
| `onChange` | `onChange` | 同名 |
|
|
106
|
+
| `allowHalf` | `allowHalf` | ✅ 已实现 — 半星裁切渲染(clipPath) |
|
|
107
|
+
| `readOnly` | `disabled` | 只展示场景用 `disabled` 实现(antd 当前版本也只有 disabled) |
|
|
108
|
+
| `size="small\|medium\|large"` | `size="sm\|md\|lg"` | 三档对应 16/20/24px |
|
|
109
|
+
| `character` 自定义图标 | `character` | ✅ 已实现 — 默认 `lucide.Star`,可传任意 ReactNode |
|
|
110
|
+
| `showGrade` 文案展示 | 不修复 | 外部组合 `<Text>` 更灵活,P2 |
|
|
111
|
+
| `onHoverChange` 悬浮值回调 | 不修复 | 低频,P2 |
|
|
112
|
+
| `isPreview` / `renderPreview` | `disabled` 替代 | 旧库低频 API,直接用 disabled |
|
|
113
|
+
|
|
114
|
+
### 不修复 / 后续工序清单
|
|
115
|
+
|
|
116
|
+
- **`showGrade` 文案展示**(P2):用 `<Rate value={4} disabled /> <Text>4.5 / 5</Text>` 外部组合更灵活
|
|
117
|
+
- **`onHoverChange` 悬浮回调**(P2):低频,业务侧用 `onMouseEnter` 事件捕获 thumb 位置自管
|
|
118
|
+
- **`isPreview` / `renderPreview`**:报告 §5 已列入"保留新库优势",`disabled` 已能替代,**不修复**
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
3
3
|
import { Heart } from 'lucide-react';
|
|
4
4
|
import { Rate } from './rate';
|
|
5
5
|
|
|
6
6
|
const meta: Meta<typeof Rate> = {
|
|
7
|
-
title: '
|
|
7
|
+
title: '数据录入 · Data Entry/Rate',
|
|
8
8
|
component: Rate,
|
|
9
9
|
tags: ['autodocs'],
|
|
10
10
|
parameters: {
|
|
11
11
|
docs: {
|
|
12
12
|
description: {
|
|
13
13
|
component:
|
|
14
|
-
'星级评分 — 评论 / 商品评分 / 偏好满意度。支持半星 + 再次点击清零 + 自定义图标 + 只读展示。等价 antd `Rate
|
|
14
|
+
'星级评分 — 评论 / 商品评分 / 偏好满意度。支持半星 + 再次点击清零 + 自定义图标 + 只读展示。等价 antd `Rate`。',
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
},
|
|
@@ -22,7 +22,13 @@ const meta: Meta<typeof Rate> = {
|
|
|
22
22
|
disabled: { control: 'boolean' },
|
|
23
23
|
size: { control: 'inline-radio', options: ['sm', 'default', 'lg'] },
|
|
24
24
|
},
|
|
25
|
-
args: {
|
|
25
|
+
args: {
|
|
26
|
+
count: 5,
|
|
27
|
+
allowHalf: false,
|
|
28
|
+
allowClear: true,
|
|
29
|
+
disabled: false,
|
|
30
|
+
size: 'default',
|
|
31
|
+
},
|
|
26
32
|
};
|
|
27
33
|
|
|
28
34
|
export default meta;
|
|
@@ -64,7 +70,9 @@ export const ReadOnly: Story = {
|
|
|
64
70
|
render: () => (
|
|
65
71
|
<div className="flex items-center gap-2">
|
|
66
72
|
<Rate disabled value={4.5} allowHalf size="sm" />
|
|
67
|
-
<span className="text-sm text-muted-foreground">
|
|
73
|
+
<span className="text-sm text-muted-foreground">
|
|
74
|
+
4.5 / 5 (1,287 评价)
|
|
75
|
+
</span>
|
|
68
76
|
</div>
|
|
69
77
|
),
|
|
70
78
|
};
|
|
@@ -4,7 +4,10 @@ import { Star } from 'lucide-react';
|
|
|
4
4
|
import { cn } from '@/utils/cn';
|
|
5
5
|
|
|
6
6
|
export interface RateProps
|
|
7
|
-
extends Omit<
|
|
7
|
+
extends Omit<
|
|
8
|
+
React.HTMLAttributes<HTMLDivElement>,
|
|
9
|
+
'onChange' | 'defaultValue'
|
|
10
|
+
> {
|
|
8
11
|
/**
|
|
9
12
|
* 总星数(antd `count` 并集)。
|
|
10
13
|
* @default 5
|
|
@@ -30,7 +33,7 @@ export interface RateProps
|
|
|
30
33
|
* 尺寸(影响星图大小)。
|
|
31
34
|
* @default "default"
|
|
32
35
|
*/
|
|
33
|
-
size?: 'sm' | 'default' | 'lg';
|
|
36
|
+
size?: 'sm' | 'md' | 'default' | 'lg';
|
|
34
37
|
/**
|
|
35
38
|
* 自定义图标(antd `character` 并集) — 默认 `lucide-react` 的 `Star`。
|
|
36
39
|
*/
|
|
@@ -39,10 +42,12 @@ export interface RateProps
|
|
|
39
42
|
onChange?: (value: number) => void;
|
|
40
43
|
}
|
|
41
44
|
|
|
45
|
+
// 与 cloud-design Rating small/medium/large = 16/20/24 对齐,使用三档以调与其他表单控件一致的视觉密度。
|
|
42
46
|
const sizeMap = {
|
|
43
47
|
sm: 'size-4',
|
|
48
|
+
md: 'size-5',
|
|
44
49
|
default: 'size-5',
|
|
45
|
-
lg: 'size-
|
|
50
|
+
lg: 'size-6',
|
|
46
51
|
} as const;
|
|
47
52
|
|
|
48
53
|
const Rate = React.forwardRef<HTMLDivElement, RateProps>(
|
|
@@ -54,7 +59,7 @@ const Rate = React.forwardRef<HTMLDivElement, RateProps>(
|
|
|
54
59
|
allowHalf = false,
|
|
55
60
|
allowClear = true,
|
|
56
61
|
disabled = false,
|
|
57
|
-
size = '
|
|
62
|
+
size = 'md',
|
|
58
63
|
character,
|
|
59
64
|
onChange,
|
|
60
65
|
className,
|
|
@@ -77,6 +82,10 @@ const Rate = React.forwardRef<HTMLDivElement, RateProps>(
|
|
|
77
82
|
|
|
78
83
|
const Icon = character ?? <Star className={cn(sizeMap[size])} />;
|
|
79
84
|
|
|
85
|
+
// 未选中的底色 — 使用 `text-muted-foreground/30` 与 cloud-design 空星描边一致
|
|
86
|
+
const inactiveClass = 'text-muted-foreground/30';
|
|
87
|
+
const activeClass = 'text-warning';
|
|
88
|
+
|
|
80
89
|
return (
|
|
81
90
|
<div
|
|
82
91
|
ref={ref}
|
|
@@ -128,18 +137,36 @@ const Rate = React.forwardRef<HTMLDivElement, RateProps>(
|
|
|
128
137
|
) : null}
|
|
129
138
|
|
|
130
139
|
{filledFull ? (
|
|
131
|
-
<span className=
|
|
140
|
+
<span className={activeClass}>
|
|
141
|
+
{React.isValidElement(Icon)
|
|
142
|
+
? React.cloneElement(
|
|
143
|
+
Icon as React.ReactElement<{ fill?: string }>,
|
|
144
|
+
{ fill: 'currentColor' },
|
|
145
|
+
)
|
|
146
|
+
: Icon}
|
|
147
|
+
</span>
|
|
132
148
|
) : filledHalf ? (
|
|
133
|
-
<span className="relative inline-block
|
|
134
|
-
|
|
149
|
+
<span className="relative inline-block">
|
|
150
|
+
{/* 底层:描边空星(完整轮廓,取代 muted-foreground/40 深度运动) */}
|
|
151
|
+
<span className={inactiveClass}>{Icon}</span>
|
|
152
|
+
{/* 上层:裁切到左半边 + 填充 currentColor */}
|
|
153
|
+
<span
|
|
154
|
+
className={cn(
|
|
155
|
+
'absolute inset-0 overflow-hidden',
|
|
156
|
+
activeClass,
|
|
157
|
+
)}
|
|
158
|
+
style={{ clipPath: 'inset(0 50% 0 0)' }}
|
|
159
|
+
>
|
|
135
160
|
{React.isValidElement(Icon)
|
|
136
|
-
? React.cloneElement(
|
|
161
|
+
? React.cloneElement(
|
|
162
|
+
Icon as React.ReactElement<{ fill?: string }>,
|
|
163
|
+
{ fill: 'currentColor' },
|
|
164
|
+
)
|
|
137
165
|
: Icon}
|
|
138
166
|
</span>
|
|
139
|
-
<span className="text-muted-foreground/40">{Icon}</span>
|
|
140
167
|
</span>
|
|
141
168
|
) : (
|
|
142
|
-
<span className=
|
|
169
|
+
<span className={inactiveClass}>{Icon}</span>
|
|
143
170
|
)}
|
|
144
171
|
</span>
|
|
145
172
|
);
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: resizable
|
|
3
3
|
name: Resizable
|
|
4
|
+
displayName: 可拖拽分栏
|
|
4
5
|
type: component
|
|
5
6
|
category: layout
|
|
6
7
|
since: 0.1.0
|
|
7
|
-
package:
|
|
8
|
+
package: '@teamix-evo/ui'
|
|
8
9
|
---
|
|
9
10
|
|
|
10
|
-
# Resizable
|
|
11
|
+
# Resizable 可拖拽分栏
|
|
11
12
|
|
|
12
13
|
可拖拽分栏 — 基于 [`react-resizable-panels`](https://react-resizable-panels.vercel.app/),桌面应用 / 编辑器风格(VS Code、Figma、Slack)。
|
|
13
14
|
对应 antd `Splitter`(v5.16+)的核心场景。
|
|
@@ -25,10 +26,14 @@ package: "@teamix-evo/ui"
|
|
|
25
26
|
- 临时分栏 → `Sheet` / `Drawer`
|
|
26
27
|
- 卡片网格 → CSS Grid
|
|
27
28
|
|
|
29
|
+
## Props
|
|
30
|
+
|
|
28
31
|
<!-- auto:props:begin -->
|
|
29
32
|
_(组件无 `<Name>Props` interface — props 详见 [`resizable.tsx`](./resizable.tsx))_
|
|
30
33
|
<!-- auto:props:end -->
|
|
31
34
|
|
|
35
|
+
## 依赖
|
|
36
|
+
|
|
32
37
|
<!-- auto:deps:begin -->
|
|
33
38
|
### 同库依赖
|
|
34
39
|
|
|
@@ -47,8 +52,6 @@ pnpm add react-resizable-panels@^2.0.0 lucide-react@^0.460.0
|
|
|
47
52
|
```
|
|
48
53
|
<!-- auto:deps:end -->
|
|
49
54
|
|
|
50
|
-
> 子组件:`ResizablePanelGroup`(`direction="horizontal" | "vertical"`)/ `ResizablePanel`(`defaultSize / minSize / maxSize` 百分比)/ `ResizableHandle`(分隔条,`withHandle` 显示握把)。
|
|
51
|
-
|
|
52
55
|
## AI 生成纪律
|
|
53
56
|
|
|
54
57
|
- **`PanelGroup` 必给容器固定尺寸**:height / width 不能 0(否则面板无可分配空间)
|