@teamix-evo/ui 0.2.0 → 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 +15 -9
- package/src/components/accordion/accordion.meta.md +5 -9
- package/src/components/accordion/accordion.stories.tsx +3 -3
- package/src/components/accordion/accordion.tsx +104 -8
- package/src/components/affix/affix.meta.md +21 -12
- package/src/components/affix/affix.stories.tsx +101 -26
- package/src/components/affix/affix.tsx +79 -9
- package/src/components/alert/alert.meta.md +52 -26
- 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 +48 -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 +10 -14
- package/src/components/anchor/anchor.stories.tsx +3 -3
- package/src/components/anchor/anchor.tsx +2 -2
- package/src/components/app/app.meta.md +10 -14
- package/src/components/app/app.stories.tsx +6 -6
- package/src/components/aspect-ratio/aspect-ratio.meta.md +4 -8
- package/src/components/aspect-ratio/aspect-ratio.stories.tsx +3 -3
- package/src/components/auto-complete/auto-complete.meta.md +19 -20
- package/src/components/auto-complete/auto-complete.stories.tsx +44 -3
- package/src/components/auto-complete/auto-complete.tsx +119 -71
- package/src/components/avatar/avatar.meta.md +9 -22
- package/src/components/avatar/avatar.stories.tsx +21 -3
- package/src/components/avatar/avatar.tsx +24 -23
- package/src/components/badge/badge.meta.md +14 -18
- package/src/components/badge/badge.stories.tsx +2 -2
- package/src/components/badge/badge.tsx +2 -2
- package/src/components/breadcrumb/breadcrumb.meta.md +29 -20
- package/src/components/breadcrumb/breadcrumb.stories.tsx +120 -5
- package/src/components/breadcrumb/breadcrumb.tsx +22 -8
- package/src/components/button/button.meta.md +261 -29
- package/src/components/button/button.stories.tsx +549 -41
- package/src/components/button/button.tsx +335 -33
- package/src/components/calendar/calendar.meta.md +19 -14
- package/src/components/calendar/calendar.stories.tsx +5 -5
- package/src/components/calendar/calendar.tsx +73 -8
- package/src/components/card/card.meta.md +31 -34
- package/src/components/card/card.stories.tsx +34 -3
- package/src/components/card/card.tsx +146 -63
- package/src/components/carousel/carousel.meta.md +10 -14
- package/src/components/carousel/carousel.stories.tsx +1 -1
- package/src/components/cascader/cascader.meta.md +43 -22
- package/src/components/cascader/cascader.stories.tsx +13 -2
- package/src/components/cascader/cascader.tsx +427 -84
- package/src/components/checkbox/checkbox.meta.md +74 -24
- package/src/components/checkbox/checkbox.stories.tsx +160 -2
- package/src/components/checkbox/checkbox.tsx +77 -9
- package/src/components/collapsible/collapsible.meta.md +7 -6
- package/src/components/collapsible/collapsible.stories.tsx +2 -2
- package/src/components/collapsible/collapsible.tsx +93 -6
- package/src/components/color-picker/color-picker.meta.md +16 -20
- package/src/components/color-picker/color-picker.stories.tsx +86 -7
- package/src/components/color-picker/color-picker.tsx +19 -9
- package/src/components/command/command.meta.md +7 -11
- package/src/components/command/command.stories.tsx +4 -4
- package/src/components/command/command.tsx +18 -7
- package/src/components/context-menu/context-menu.meta.md +5 -25
- package/src/components/context-menu/context-menu.stories.tsx +4 -4
- package/src/components/context-menu/context-menu.tsx +21 -8
- package/src/components/data-table/data-table.meta.md +14 -18
- package/src/components/data-table/data-table.stories.tsx +1 -1
- package/src/components/data-table/data-table.tsx +2 -2
- package/src/components/date-picker/date-picker.meta.md +90 -41
- 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 +12 -16
- package/src/components/descriptions/descriptions.stories.tsx +2 -2
- package/src/components/descriptions/descriptions.tsx +22 -14
- package/src/components/dialog/dialog.meta.md +67 -17
- 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 +27 -39
- package/src/components/drawer/drawer.stories.tsx +29 -12
- package/src/components/drawer/drawer.tsx +22 -114
- package/src/components/dropdown-menu/dropdown-menu.meta.md +64 -24
- package/src/components/dropdown-menu/dropdown-menu.stories.tsx +81 -3
- 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 +10 -14
- package/src/components/empty/empty.stories.tsx +3 -3
- package/src/components/empty/empty.tsx +10 -3
- package/src/components/field/field.meta.md +46 -25
- package/src/components/field/field.stories.tsx +380 -3
- 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 +59 -20
- package/src/components/flex/flex.stories.tsx +65 -10
- package/src/components/flex/flex.tsx +27 -4
- package/src/components/float-button/float-button.meta.md +10 -29
- package/src/components/float-button/float-button.stories.tsx +6 -6
- package/src/components/form/form.meta.md +31 -52
- package/src/components/form/form.stories.tsx +350 -3
- package/src/components/form/form.tsx +101 -35
- package/src/components/grid/grid.meta.md +4 -24
- package/src/components/grid/grid.stories.tsx +2 -2
- package/src/components/hover-card/hover-card.meta.md +9 -10
- package/src/components/hover-card/hover-card.stories.tsx +29 -4
- 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 +14 -18
- package/src/components/image/image.stories.tsx +3 -3
- package/src/components/image/image.tsx +2 -0
- package/src/components/input/demo/sizes.tsx +2 -2
- package/src/components/input/input.meta.md +44 -43
- package/src/components/input/input.stories.tsx +62 -35
- package/src/components/input/input.tsx +96 -101
- package/src/components/input-group/input-group.meta.md +53 -39
- package/src/components/input-group/input-group.stories.tsx +49 -16
- package/src/components/input-group/input-group.tsx +43 -8
- package/src/components/input-number/input-number.meta.md +68 -20
- package/src/components/input-number/input-number.stories.tsx +33 -6
- package/src/components/input-number/input-number.tsx +79 -20
- package/src/components/input-otp/input-otp.meta.md +8 -20
- 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 -26
- package/src/components/item/item.stories.tsx +3 -3
- package/src/components/item/item.tsx +7 -6
- package/src/components/kbd/kbd.meta.md +7 -19
- package/src/components/kbd/kbd.stories.tsx +4 -4
- package/src/components/kbd/kbd.tsx +8 -4
- package/src/components/label/label.meta.md +21 -18
- 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 -12
- package/src/components/masonry/masonry.stories.tsx +4 -4
- package/src/components/mentions/mentions.meta.md +42 -21
- package/src/components/mentions/mentions.stories.tsx +120 -6
- package/src/components/mentions/mentions.tsx +10 -5
- package/src/components/menubar/menubar.meta.md +4 -8
- package/src/components/menubar/menubar.stories.tsx +55 -3
- package/src/components/menubar/menubar.tsx +9 -9
- package/src/components/native-select/native-select.meta.md +7 -11
- package/src/components/native-select/native-select.stories.tsx +4 -4
- package/src/components/native-select/native-select.tsx +1 -1
- package/src/components/navigation-menu/navigation-menu.meta.md +4 -8
- package/src/components/navigation-menu/navigation-menu.stories.tsx +106 -3
- package/src/components/navigation-menu/navigation-menu.tsx +6 -3
- package/src/components/notification/notification.meta.md +41 -8
- package/src/components/notification/notification.stories.tsx +9 -9
- package/src/components/notification/notification.tsx +34 -19
- 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 +122 -50
- package/src/components/pagination/pagination.stories.tsx +227 -11
- package/src/components/pagination/pagination.tsx +355 -63
- package/src/components/popconfirm/popconfirm.meta.md +19 -23
- package/src/components/popconfirm/popconfirm.stories.tsx +2 -2
- package/src/components/popconfirm/popconfirm.tsx +1 -1
- package/src/components/popover/popover.meta.md +64 -12
- package/src/components/popover/popover.stories.tsx +83 -7
- package/src/components/popover/popover.tsx +77 -28
- package/src/components/progress/progress.meta.md +43 -26
- package/src/components/progress/progress.stories.tsx +2 -2
- package/src/components/progress/progress.tsx +19 -11
- package/src/components/radio-group/radio-group.meta.md +78 -11
- package/src/components/radio-group/radio-group.stories.tsx +38 -2
- package/src/components/radio-group/radio-group.tsx +149 -18
- package/src/components/rate/rate.meta.md +41 -19
- package/src/components/rate/rate.stories.tsx +2 -2
- package/src/components/rate/rate.tsx +37 -10
- package/src/components/resizable/resizable.meta.md +4 -12
- package/src/components/resizable/resizable.stories.tsx +5 -5
- package/src/components/resizable/resizable.tsx +1 -1
- package/src/components/result/result.meta.md +10 -14
- package/src/components/result/result.stories.tsx +2 -2
- package/src/components/result/result.tsx +21 -12
- package/src/components/scroll-area/scroll-area.meta.md +4 -8
- package/src/components/scroll-area/scroll-area.stories.tsx +5 -5
- package/src/components/segmented/segmented.meta.md +15 -17
- package/src/components/segmented/segmented.stories.tsx +3 -3
- package/src/components/segmented/segmented.tsx +15 -7
- package/src/components/select/select.meta.md +199 -67
- package/src/components/select/select.stories.tsx +238 -63
- package/src/components/select/select.tsx +718 -171
- package/src/components/separator/separator.meta.md +10 -14
- package/src/components/separator/separator.stories.tsx +2 -2
- package/src/components/separator/separator.tsx +3 -7
- package/src/components/sheet/sheet.meta.md +26 -21
- package/src/components/sheet/sheet.stories.tsx +116 -10
- package/src/components/sheet/sheet.tsx +116 -29
- package/src/components/sidebar/sidebar.meta.md +28 -38
- package/src/components/sidebar/sidebar.stories.tsx +696 -29
- package/src/components/sidebar/sidebar.tsx +615 -142
- package/src/components/skeleton/skeleton.meta.md +7 -31
- package/src/components/skeleton/skeleton.stories.tsx +3 -3
- package/src/components/skeleton/skeleton.tsx +7 -7
- package/src/components/slider/slider.meta.md +60 -13
- package/src/components/slider/slider.stories.tsx +58 -6
- package/src/components/slider/slider.tsx +154 -13
- package/src/components/sonner/sonner.meta.md +54 -8
- package/src/components/sonner/sonner.stories.tsx +79 -11
- package/src/components/sonner/sonner.tsx +137 -8
- package/src/components/spinner/spinner.meta.md +57 -21
- package/src/components/spinner/spinner.stories.tsx +66 -14
- package/src/components/spinner/spinner.tsx +111 -9
- package/src/components/statistic/statistic.meta.md +14 -30
- package/src/components/statistic/statistic.stories.tsx +1 -1
- package/src/components/statistic/statistic.tsx +4 -5
- package/src/components/steps/steps.meta.md +20 -15
- package/src/components/steps/steps.stories.tsx +37 -2
- package/src/components/steps/steps.tsx +15 -12
- package/src/components/switch/switch.meta.md +56 -15
- package/src/components/switch/switch.stories.tsx +5 -5
- package/src/components/switch/switch.tsx +59 -13
- package/src/components/table/table.meta.md +3 -7
- package/src/components/table/table.stories.tsx +1 -1
- package/src/components/table/table.tsx +4 -4
- package/src/components/tabs/tabs.meta.md +40 -32
- package/src/components/tabs/tabs.stories.tsx +104 -26
- package/src/components/tabs/tabs.tsx +125 -54
- package/src/components/tag/tag.meta.md +104 -68
- package/src/components/tag/tag.stories.tsx +183 -15
- package/src/components/tag/tag.tsx +222 -21
- package/src/components/textarea/textarea.meta.md +42 -31
- package/src/components/textarea/textarea.stories.tsx +32 -6
- package/src/components/textarea/textarea.tsx +32 -8
- package/src/components/time-picker/time-picker.meta.md +119 -50
- package/src/components/time-picker/time-picker.stories.tsx +65 -33
- package/src/components/time-picker/time-picker.tsx +889 -101
- package/src/components/timeline/timeline.meta.md +16 -17
- package/src/components/timeline/timeline.stories.tsx +24 -4
- package/src/components/timeline/timeline.tsx +32 -12
- package/src/components/toggle/toggle.meta.md +8 -12
- 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 +10 -14
- 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 +63 -18
- package/src/components/tooltip/tooltip.stories.tsx +42 -5
- package/src/components/tooltip/tooltip.tsx +81 -21
- package/src/components/tour/tour.meta.md +16 -20
- package/src/components/tour/tour.stories.tsx +3 -3
- package/src/components/tour/tour.tsx +3 -3
- package/src/components/transfer/transfer.meta.md +18 -22
- package/src/components/transfer/transfer.stories.tsx +2 -2
- package/src/components/transfer/transfer.tsx +28 -21
- package/src/components/tree/tree.meta.md +67 -22
- package/src/components/tree/tree.stories.tsx +1 -1
- package/src/components/tree/tree.tsx +9 -8
- package/src/components/tree-select/tree-select.meta.md +59 -23
- package/src/components/tree-select/tree-select.stories.tsx +2 -2
- package/src/components/tree-select/tree-select.tsx +42 -7
- package/src/components/typography/typography.meta.md +61 -39
- package/src/components/typography/typography.stories.tsx +14 -9
- package/src/components/typography/typography.tsx +38 -25
- package/src/components/upload/upload.meta.md +61 -25
- package/src/components/upload/upload.stories.tsx +69 -3
- package/src/components/upload/upload.tsx +170 -37
- package/src/components/watermark/watermark.meta.md +15 -19
- package/src/components/watermark/watermark.stories.tsx +98 -8
- 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 -101
- package/src/components/button-group/button-group.stories.tsx +0 -93
- package/src/components/button-group/button-group.tsx +0 -75
- package/src/components/combobox/combobox.meta.md +0 -102
- package/src/components/combobox/combobox.stories.tsx +0 -55
- package/src/components/combobox/combobox.tsx +0 -130
- package/src/components/input/demo/addon.tsx +0 -15
- package/src/components/input/demo/with-prefix-suffix.tsx +0 -19
- package/src/components/space/space.meta.md +0 -103
- package/src/components/space/space.stories.tsx +0 -108
- package/src/components/space/space.tsx +0 -106
|
@@ -2,71 +2,72 @@
|
|
|
2
2
|
id: textarea
|
|
3
3
|
name: Textarea
|
|
4
4
|
type: component
|
|
5
|
-
category:
|
|
6
|
-
since: 0.
|
|
5
|
+
category: data-entry
|
|
6
|
+
since: 0.2.0
|
|
7
7
|
package: '@teamix-evo/ui'
|
|
8
8
|
displayName: 多行文本框
|
|
9
9
|
---
|
|
10
10
|
|
|
11
11
|
# Textarea 多行文本框
|
|
12
12
|
|
|
13
|
-
多行文本输入 — shadcn 简洁基底 + antd 的 `autoSize / showCount
|
|
13
|
+
多行文本输入 — shadcn 简洁基底 + antd `Input.TextArea` 的 `autoSize` / `showCount` 并集。从 v0.2 起作为**独立 entry**,与 [`Input`](../input/input.meta.md) 拆开(对齐 shadcn 2025-10 拆分粒度)。
|
|
14
|
+
|
|
15
|
+
`size` 三档字号与 Input 对齐(高度由 `rows` / `autoSize` 决定,**不受 size 影响**)。
|
|
14
16
|
|
|
15
17
|
## When to use
|
|
16
18
|
|
|
17
19
|
- 多行内容输入(评论 / 反馈 / 描述 / 备注)
|
|
18
|
-
- 配 `autoSize` 给"动态高度"输入
|
|
20
|
+
- 配 `autoSize={{ minRows, maxRows }}` 给"动态高度"输入
|
|
19
21
|
- 配 `showCount + maxLength` 控制长度
|
|
20
22
|
|
|
21
23
|
## When NOT to use
|
|
22
24
|
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
+
- 单行文本 → `Input`
|
|
26
|
+
- 输入 + 发送按钮(聊天框 / 评论框)→ `InputGroup` + `InputGroupTextarea` + `InputGroupAddon variant="button"`
|
|
27
|
+
- @提及输入 → `Mentions`
|
|
25
28
|
|
|
26
29
|
## Props
|
|
27
30
|
|
|
28
31
|
> 以下表格由 `pnpm --filter @teamix-evo/ui gen:meta` 自动生成。
|
|
29
32
|
|
|
30
33
|
<!-- auto:props:begin -->
|
|
31
|
-
|
|
32
|
-
|
|
|
33
|
-
|
|
|
34
|
-
| `
|
|
35
|
-
| `
|
|
36
|
-
| `
|
|
37
|
-
| `
|
|
38
|
-
| `
|
|
39
|
-
|
|
34
|
+
| 名称 | 类型 | 默认值 | 必填 | 说明 |
|
|
35
|
+
| --- | --- | --- | --- | --- |
|
|
36
|
+
| `autoSize` | `boolean \| { minRows?: number; maxRows?: number }` | `false` | – | 自动高度。`true` 时无上下限;传 `{ minRows, maxRows }` 时受限。 实现:监听 input 事件,把 textarea 设为 auto 后再读 scrollHeight。 |
|
|
37
|
+
| `showCount` | `boolean` | `false` | – | 显示字符计数(antd `showCount` 并集);需配合 `maxLength`。 |
|
|
38
|
+
| `size` | `'sm' \| 'md' \| 'lg'` | `"md"` | – | 字号档位,与 `Input` 三档对齐:`sm`(text-xs) / `md`(text-xs,默认) / `lg`(text-sm)。 高度由 `rows` / `autoSize` 决定,不受 size 影响。 |
|
|
39
|
+
| `error` | `boolean` | `false` | – | 错误态(快捷开关),会同时设置 `aria-invalid`,渲染 destructive 边框 / ring。 |
|
|
40
|
+
| `value` | `string` | – | – | 受控值。 |
|
|
41
|
+
| `defaultValue` | `string` | – | – | uncontrolled 初始值。 |
|
|
42
|
+
| `rows` | `number` | `3` | – | 行数(autoSize 关闭时生效)。 |
|
|
40
43
|
<!-- auto:props:end -->
|
|
41
44
|
|
|
42
45
|
## 依赖
|
|
43
46
|
|
|
44
|
-
> 以下表格由 `pnpm --filter @teamix-evo/ui gen:meta` 自动生成,数据源是 [`manifest.json`](../../../manifest.json)。**手工编辑 marker 之间的内容会在下次生成时被覆盖**。
|
|
45
|
-
|
|
46
47
|
<!-- auto:deps:begin -->
|
|
47
|
-
|
|
48
48
|
### 同库依赖
|
|
49
49
|
|
|
50
50
|
> `teamix-evo ui add textarea` 时,以下 entry 会被自动连带安装(无需手动 add)。
|
|
51
51
|
|
|
52
|
-
| Entry | 类型 | 描述
|
|
53
|
-
|
|
|
54
|
-
| `cn`
|
|
52
|
+
| Entry | 类型 | 描述 |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| `cn` | util | Tailwind className 合并工具(clsx + tailwind-merge) |
|
|
55
55
|
|
|
56
56
|
### npm 依赖
|
|
57
57
|
|
|
58
58
|
_无 — 本组件不依赖任何 npm 包。_
|
|
59
|
-
|
|
60
59
|
<!-- auto:deps:end -->
|
|
61
60
|
|
|
62
|
-
> 透传所有 `<textarea>` 原生属性(`name` / `
|
|
61
|
+
> 透传所有 `<textarea>` 原生属性(`name` / `id` / `placeholder` / `aria-*` / `onChange` / ...)。
|
|
63
62
|
|
|
64
63
|
## AI 生成纪律
|
|
65
64
|
|
|
66
|
-
- **`autoSize` 替代 `rows
|
|
67
|
-
- **autoSize 配 `maxRows`
|
|
68
|
-
- **`showCount` 必须配 `maxLength
|
|
69
|
-
- **粘贴长内容时
|
|
65
|
+
- **`autoSize` 替代 `rows`** —— autoSize 启用后 rows 被忽略,两者不要同时传
|
|
66
|
+
- **autoSize 配 `maxRows` 防止失控** —— 不限的 autoSize 在长内容下会撑爆容器,推荐 `{ minRows: 3, maxRows: 8 }`
|
|
67
|
+
- **`showCount` 必须配 `maxLength`** —— 无 maxLength 时 showCount 不显示
|
|
68
|
+
- **粘贴长内容时 effect 监听 value 自动 resize** —— 无需业务侧介入
|
|
69
|
+
- **错误态走 `error` prop** —— 自动反映 `aria-invalid="true"`,**不要**手动拼 `border-destructive`
|
|
70
|
+
- **不要硬编码颜色** —— `bg-background` / `border-input` / `placeholder:text-muted-foreground` 都是 design token
|
|
70
71
|
|
|
71
72
|
## Examples
|
|
72
73
|
|
|
@@ -76,13 +77,23 @@ import { Textarea } from '@/components/ui/textarea';
|
|
|
76
77
|
// 基础
|
|
77
78
|
<Textarea placeholder="留下你的反馈..." />
|
|
78
79
|
|
|
79
|
-
// 自动高度
|
|
80
|
+
// 自动高度(推荐配 maxRows)
|
|
80
81
|
<Textarea autoSize={{ minRows: 3, maxRows: 8 }} placeholder="..." />
|
|
81
82
|
|
|
82
83
|
// 字数统计
|
|
83
84
|
<Textarea showCount maxLength={500} placeholder="不超过 500 字" />
|
|
84
85
|
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
<Textarea value={v} onChange={(e) => setV(e.target.value)} />
|
|
86
|
+
// 错误态
|
|
87
|
+
<Textarea error defaultValue="非法内容" />
|
|
88
88
|
```
|
|
89
|
+
|
|
90
|
+
## Migration · 从旧 `@/components/input/input` 迁移
|
|
91
|
+
|
|
92
|
+
v0.2 起 Textarea 拆为独立 entry,import 路径变化:
|
|
93
|
+
|
|
94
|
+
```diff
|
|
95
|
+
- import { Textarea } from '@/components/input/input';
|
|
96
|
+
+ import { Textarea } from '@/components/textarea/textarea';
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
CLI 命令:`teamix-evo ui add textarea`(单独安装,不再需要先装 input)。组件 API 完全保持不变。
|
|
@@ -1,34 +1,39 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
|
|
2
3
|
import { Textarea } from './textarea';
|
|
3
4
|
|
|
4
5
|
const meta: Meta<typeof Textarea> = {
|
|
5
|
-
title: '
|
|
6
|
+
title: '数据录入 · Data Entry/Textarea',
|
|
6
7
|
component: Textarea,
|
|
7
8
|
tags: ['autodocs'],
|
|
8
9
|
parameters: {
|
|
9
10
|
docs: {
|
|
10
11
|
description: {
|
|
11
12
|
component:
|
|
12
|
-
'
|
|
13
|
+
'Textarea 多行文本框 —— shadcn 简洁基底 + antd `Input.TextArea` 的 `autoSize` / `showCount` 并集。`size` 三档字号与 Input 对齐(高度由 `rows` / `autoSize` 决定,**不受 size 影响**)。视觉走 OpenTrek semantic tokens,所有样式来自 `@teamix-evo/tokens`,无 mock。',
|
|
13
14
|
},
|
|
14
15
|
},
|
|
15
16
|
},
|
|
16
17
|
argTypes: {
|
|
18
|
+
size: { control: 'inline-radio', options: ['sm', 'md', 'lg'] },
|
|
17
19
|
rows: { control: 'number' },
|
|
18
|
-
maxLength: { control: 'number' },
|
|
19
20
|
showCount: { control: 'boolean' },
|
|
21
|
+
error: { control: 'boolean' },
|
|
20
22
|
disabled: { control: 'boolean' },
|
|
21
23
|
placeholder: { control: 'text' },
|
|
24
|
+
maxLength: { control: 'number' },
|
|
22
25
|
},
|
|
23
26
|
args: {
|
|
27
|
+
size: 'md',
|
|
24
28
|
rows: 3,
|
|
25
|
-
placeholder: '请输入...',
|
|
26
29
|
showCount: false,
|
|
30
|
+
error: false,
|
|
27
31
|
disabled: false,
|
|
32
|
+
placeholder: '请输入...',
|
|
28
33
|
},
|
|
29
34
|
decorators: [
|
|
30
35
|
(Story) => (
|
|
31
|
-
<div className="w-
|
|
36
|
+
<div className="w-96">
|
|
32
37
|
<Story />
|
|
33
38
|
</div>
|
|
34
39
|
),
|
|
@@ -40,6 +45,7 @@ type Story = StoryObj<typeof Textarea>;
|
|
|
40
45
|
|
|
41
46
|
export const Playground: Story = {};
|
|
42
47
|
|
|
48
|
+
/** 自动高度 —— `autoSize={{ minRows, maxRows }}` 让高度随内容生长,粘贴大段文本不撑爆容器。 */
|
|
43
49
|
export const AutoSize: Story = {
|
|
44
50
|
parameters: { controls: { disable: true } },
|
|
45
51
|
render: () => (
|
|
@@ -50,6 +56,7 @@ export const AutoSize: Story = {
|
|
|
50
56
|
),
|
|
51
57
|
};
|
|
52
58
|
|
|
59
|
+
/** 字数统计 —— `showCount` 必须配 `maxLength`,缺一不显示。 */
|
|
53
60
|
export const ShowCount: Story = {
|
|
54
61
|
parameters: { controls: { disable: true } },
|
|
55
62
|
render: () => (
|
|
@@ -57,6 +64,25 @@ export const ShowCount: Story = {
|
|
|
57
64
|
),
|
|
58
65
|
};
|
|
59
66
|
|
|
67
|
+
/** 三档字号 —— 高度仍由 rows 决定,只有字号变化(text-xs / text-xs / text-sm)。 */
|
|
68
|
+
export const Sizes: Story = {
|
|
69
|
+
parameters: { controls: { disable: true } },
|
|
70
|
+
render: () => (
|
|
71
|
+
<div className="flex flex-col gap-3">
|
|
72
|
+
<Textarea size="sm" placeholder="Small (text-xs)" />
|
|
73
|
+
<Textarea size="md" placeholder="Medium (text-xs)" />
|
|
74
|
+
<Textarea size="lg" placeholder="Large (text-sm)" />
|
|
75
|
+
</div>
|
|
76
|
+
),
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/** 错误态 —— `error` 自动设置 `aria-invalid="true"` + destructive 边框 / ring。 */
|
|
80
|
+
export const Error: Story = {
|
|
81
|
+
parameters: { controls: { disable: true } },
|
|
82
|
+
render: () => <Textarea error defaultValue="非法内容" />,
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/** 禁用态。 */
|
|
60
86
|
export const Disabled: Story = {
|
|
61
87
|
parameters: { controls: { disable: true } },
|
|
62
88
|
render: () => <Textarea disabled defaultValue="这是只读的内容,不可编辑。" />,
|
|
@@ -2,8 +2,16 @@ import * as React from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { cn } from '@/utils/cn';
|
|
4
4
|
|
|
5
|
+
// ─── Textarea ───────────────────────────────────────────────────────────────
|
|
6
|
+
//
|
|
7
|
+
// 多行文本输入。高度由 `rows` / `autoSize` 决定,`size` 仅控制字号档位与 Input 一致。
|
|
8
|
+
// 与 Input 拆分独立 entry(对齐 shadcn 2025-10 拆分粒度)。
|
|
9
|
+
|
|
5
10
|
export interface TextareaProps
|
|
6
|
-
extends Omit<
|
|
11
|
+
extends Omit<
|
|
12
|
+
React.TextareaHTMLAttributes<HTMLTextAreaElement>,
|
|
13
|
+
'rows' | 'size'
|
|
14
|
+
> {
|
|
7
15
|
/**
|
|
8
16
|
* 自动高度。`true` 时无上下限;传 `{ minRows, maxRows }` 时受限。
|
|
9
17
|
* 实现:监听 input 事件,把 textarea 设为 auto 后再读 scrollHeight。
|
|
@@ -15,6 +23,17 @@ export interface TextareaProps
|
|
|
15
23
|
* @default false
|
|
16
24
|
*/
|
|
17
25
|
showCount?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* 字号档位,与 `Input` 三档对齐:`sm`(text-xs) / `md`(text-xs,默认) / `lg`(text-sm)。
|
|
28
|
+
* 高度由 `rows` / `autoSize` 决定,不受 size 影响。
|
|
29
|
+
* @default "md"
|
|
30
|
+
*/
|
|
31
|
+
size?: 'sm' | 'md' | 'lg';
|
|
32
|
+
/**
|
|
33
|
+
* 错误态(快捷开关),会同时设置 `aria-invalid`,渲染 destructive 边框 / ring。
|
|
34
|
+
* @default false
|
|
35
|
+
*/
|
|
36
|
+
error?: boolean;
|
|
18
37
|
/** 受控值。 */
|
|
19
38
|
value?: string;
|
|
20
39
|
/** uncontrolled 初始值。 */
|
|
@@ -29,19 +48,23 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
|
|
|
29
48
|
className,
|
|
30
49
|
autoSize = false,
|
|
31
50
|
showCount = false,
|
|
51
|
+
size = 'md',
|
|
52
|
+
error = false,
|
|
32
53
|
value,
|
|
33
54
|
defaultValue,
|
|
34
55
|
rows = 3,
|
|
35
56
|
onChange,
|
|
36
57
|
maxLength,
|
|
58
|
+
'aria-invalid': ariaInvalidProp,
|
|
37
59
|
...props
|
|
38
60
|
},
|
|
39
61
|
ref,
|
|
40
62
|
) => {
|
|
63
|
+
const ariaInvalid = ariaInvalidProp ?? (error ? true : undefined);
|
|
64
|
+
const sizeClass =
|
|
65
|
+
size === 'sm' ? 'text-xs' : size === 'lg' ? 'text-sm' : 'text-xs';
|
|
41
66
|
const isControlled = value !== undefined;
|
|
42
|
-
const [internal, setInternal] = React.useState<string>(
|
|
43
|
-
defaultValue ?? '',
|
|
44
|
-
);
|
|
67
|
+
const [internal, setInternal] = React.useState<string>(defaultValue ?? '');
|
|
45
68
|
const current = isControlled ? value : internal;
|
|
46
69
|
|
|
47
70
|
const innerRef = React.useRef<HTMLTextAreaElement | null>(null);
|
|
@@ -62,8 +85,7 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
|
|
|
62
85
|
el.style.height = 'auto';
|
|
63
86
|
const next = el.scrollHeight;
|
|
64
87
|
const opts = typeof autoSize === 'object' ? autoSize : {};
|
|
65
|
-
const minH =
|
|
66
|
-
(opts.minRows ?? 0) * lineHeight + padTop + padBottom;
|
|
88
|
+
const minH = (opts.minRows ?? 0) * lineHeight + padTop + padBottom;
|
|
67
89
|
const maxH = opts.maxRows
|
|
68
90
|
? opts.maxRows * lineHeight + padTop + padBottom
|
|
69
91
|
: Number.POSITIVE_INFINITY;
|
|
@@ -85,9 +107,11 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
|
|
|
85
107
|
value={isControlled ? value : undefined}
|
|
86
108
|
defaultValue={!isControlled ? defaultValue : undefined}
|
|
87
109
|
maxLength={maxLength}
|
|
110
|
+
aria-invalid={ariaInvalid}
|
|
88
111
|
onChange={handleChange}
|
|
89
112
|
className={cn(
|
|
90
|
-
'flex w-full rounded-md border border-input bg-background px-3 py-2
|
|
113
|
+
'flex w-full rounded-md border border-input bg-background px-3 py-2 shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:focus-visible:ring-destructive',
|
|
114
|
+
sizeClass,
|
|
91
115
|
autoSize ? 'resize-none' : 'min-h-textarea',
|
|
92
116
|
className,
|
|
93
117
|
)}
|
|
@@ -97,7 +121,7 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
|
|
|
97
121
|
|
|
98
122
|
if (showCount && maxLength) {
|
|
99
123
|
return (
|
|
100
|
-
<div className="
|
|
124
|
+
<div className="flex flex-col gap-1">
|
|
101
125
|
{textarea}
|
|
102
126
|
<div className="text-right text-xs text-muted-foreground tabular-nums">
|
|
103
127
|
{current?.length ?? 0} / {maxLength}
|
|
@@ -3,57 +3,86 @@ id: time-picker
|
|
|
3
3
|
name: TimePicker
|
|
4
4
|
displayName: 时间选择
|
|
5
5
|
type: component
|
|
6
|
-
category:
|
|
6
|
+
category: data-entry
|
|
7
7
|
since: 0.1.0
|
|
8
8
|
package: '@teamix-evo/ui'
|
|
9
9
|
---
|
|
10
10
|
|
|
11
11
|
# TimePicker 时间选择
|
|
12
12
|
|
|
13
|
-
时间选择 —
|
|
13
|
+
时间选择 — 输入框 + 滚动列面板。提供两种形态:
|
|
14
|
+
|
|
15
|
+
- `<TimePicker />` — 单值(对应 antd `TimePicker`)
|
|
16
|
+
- `<TimeRangePicker />` — 范围(对应 antd `TimePicker.RangePicker`)
|
|
17
|
+
|
|
18
|
+
内核为 Radix Popover + 自研 `TimeColumn` 滚动列(每列单独滚动、点选高亮、自动 scroll into view),完全替换原 `<input type="time">` 实现以贴合 OpenTrek 设计语言。
|
|
14
19
|
|
|
15
20
|
## When to use
|
|
16
21
|
|
|
17
|
-
-
|
|
18
|
-
-
|
|
22
|
+
- 表单需要时分(可选秒)精确输入(会议预约、闹钟、营业时间)
|
|
23
|
+
- 需要时间区间(开始-结束)→ 用 `TimeRangePicker`
|
|
24
|
+
- 配 `DatePicker` 的 `showTime` 完成日期 + 时间填写
|
|
19
25
|
|
|
20
26
|
## When NOT to use
|
|
21
27
|
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
- 复杂禁用规则 / 自定义面板:当前实现走原生,**不支持** `disabledHours` / `disabledMinutes` 等 antd 高级 API — 需要时基于 Popover + ListBox 自实现
|
|
28
|
+
- 仅需日期 → `DatePicker`(纯日期模式)
|
|
29
|
+
- 不需要面板交互、SSR safe 优先、移动端原生体验 → 直接用原生 `<input type="time">`
|
|
25
30
|
|
|
26
31
|
## Props
|
|
27
32
|
|
|
33
|
+
> 以下表格由 `pnpm --filter @teamix-evo/ui gen:meta` 自动生成。
|
|
34
|
+
|
|
28
35
|
<!-- auto:props:begin -->
|
|
36
|
+
| 名称 | 类型 | 默认值 | 必填 | 说明 |
|
|
37
|
+
| --- | --- | --- | --- | --- |
|
|
38
|
+
| `value` | `string` | – | – | 受控值(由 `format` 决定字面)。空串表示未选。 |
|
|
39
|
+
| `defaultValue` | `string` | – | – | 非受控初值。 |
|
|
40
|
+
| `onChange` | `(value: string) => void` | – | – | 值变化回调(选中或清除时触发)。 |
|
|
41
|
+
| `format` | `string` | `"HH:mm:ss"` | – | 时间格式(date-fns / antd 风格 token):支持 `HH/H/mm/m/ss/s`。 不含 `s` token 时不渲染秒列。 |
|
|
42
|
+
| `hourStep` | `number` | `1` | – | 小时步长(antd 并集)。 |
|
|
43
|
+
| `minuteStep` | `number` | `1` | – | 分钟步长。 |
|
|
44
|
+
| `secondStep` | `number` | `1` | – | 秒步长。 |
|
|
45
|
+
| `disabledHours` | `() => number[]` | – | – | 禁用小时回调,返回禁用的小时数组。 |
|
|
46
|
+
| `disabledMinutes` | `(hour: number) => number[]` | – | – | 禁用分钟回调,接收当前选中小时。 |
|
|
47
|
+
| `disabledSeconds` | `(hour: number, minute: number) => number[]` | – | – | 禁用秒回调,接收当前选中小时/分钟。 |
|
|
48
|
+
| `placeholder` | `string` | `"请选择时间"` | – | 占位文本。 |
|
|
49
|
+
| `disabled` | `boolean` | – | – | 是否禁用。 |
|
|
50
|
+
| `size` | `'sm' \| 'md' \| 'lg'` | `"md"` | – | 触发器尺寸(对齐 Input)。 |
|
|
51
|
+
| `error` | `boolean` | `false` | – | 错误态(同时设置 `aria-invalid`)。 |
|
|
52
|
+
| `hasClear` | `boolean` | `true` | – | 显示清除按钮(antd `allowClear` 并集)。有值时显示 X,空值还原为时钟 icon。 |
|
|
53
|
+
| `className` | `string` | – | – | 触发器 className。 |
|
|
54
|
+
| `id` | `string` | – | – | 触发器 id(用于 label htmlFor)。 |
|
|
55
|
+
| `status` | `'default' \| 'error' \| 'warning'` | `"default"` | – | 校验状态(对齐 antd `status`)— `'error'` / `'warning'` / `'default'`。 与 `error` 并存时,`status='error'` 优先。 |
|
|
56
|
+
| `open` | `boolean` | – | – | 受控弹层显隐(对齐 antd `open`)。 业务侧需要"程序化打开 / 关闭"时使用;不传则组件内部自管。 |
|
|
57
|
+
| `onOpenChange` | `(open: boolean) => void` | – | – | 弹层显隐变化回调。 |
|
|
58
|
+
| `inputReadOnly` | `boolean` | `false` | – | 输入框只读 — 仅能通过点击弹层选择,不能直接键入(对齐 antd `inputReadOnly`)。 |
|
|
59
|
+
<!-- auto:props:end -->
|
|
29
60
|
|
|
30
|
-
|
|
31
|
-
| -------------- | --------------------------- | -------------- | ---- | -------------------------------------------------------------------- |
|
|
32
|
-
| `value` | `string` | – | – | 受控值(`HH:mm` 或 `HH:mm:ss`)— 空串表示未选。 |
|
|
33
|
-
| `defaultValue` | `string` | – | – | uncontrolled 初值。 |
|
|
34
|
-
| `onChange` | `(value: string) => void` | – | – | 值变化回调(实时,跟随原生 input)。 |
|
|
35
|
-
| `showSeconds` | `boolean` | `false` | – | 是否显示秒(antd `showSeconds` 并集)— 关闭时原生 input 仅显示 HH:mm。 |
|
|
36
|
-
| `step` | `number` | `60` | – | 步长(秒) — 影响原生 picker 的滚动粒度,e.g. 60 = 一分钟一档。 |
|
|
37
|
-
| `size` | `'sm' \| 'default' \| 'lg'` | `"default"` | – | 尺寸。 |
|
|
38
|
-
| `min` | `string` | – | – | 最小可选时间(antd `minDate` 并集),格式 `HH:mm` 或 `HH:mm:ss`。 |
|
|
39
|
-
| `max` | `string` | – | – | 最大可选时间(antd `maxDate` 并集),格式 `HH:mm` 或 `HH:mm:ss`。 |
|
|
40
|
-
| `allowClear` | `boolean` | `false` | – | 是否显示清除按钮(antd `allowClear` 并集)。 |
|
|
41
|
-
| `status` | `'error' \| 'warning'` | – | – | 校验状态,影响边框颜色(antd `status` 并集)。 |
|
|
42
|
-
| `placeholder` | `string` | `"请选择时间"` | – | 占位文本。 |
|
|
61
|
+
## TimeRangePicker Props
|
|
43
62
|
|
|
44
|
-
|
|
63
|
+
`TimeRangePicker` 共享 `TimePicker` 的所有 prop(format / hourStep / minuteStep / secondStep / disabledHours / disabledMinutes / disabledSeconds / size / disabled / error / clearable / className / id),并增加:
|
|
64
|
+
|
|
65
|
+
| 名称 | 类型 | 默认值 | 必填 | 说明 |
|
|
66
|
+
| -------------- | ----------------------------------- | ----------------------------- | ---- | -------------------------------------------- |
|
|
67
|
+
| `value` | `[string, string]` | – | – | 受控值(`[起始, 结束]`)。空串表示对应端未选。 |
|
|
68
|
+
| `defaultValue` | `[string, string]` | – | – | 非受控初值。 |
|
|
69
|
+
| `onChange` | `(value: [string, string]) => void` | – | – | 值变化回调(点击「确定」时触发)。 |
|
|
70
|
+
| `placeholders` | `[string, string]` | `["请选择时间","请选择时间"]` | – | 起始 / 结束占位文本。 |
|
|
45
71
|
|
|
46
72
|
## 依赖
|
|
47
73
|
|
|
48
|
-
|
|
74
|
+
> 以下表格由 `pnpm --filter @teamix-evo/ui gen:meta` 自动生成。
|
|
49
75
|
|
|
76
|
+
<!-- auto:deps:begin -->
|
|
50
77
|
### 同库依赖
|
|
51
78
|
|
|
52
79
|
> `teamix-evo ui add time-picker` 时,以下 entry 会被自动连带安装(无需手动 add)。
|
|
53
80
|
|
|
54
|
-
| Entry | 类型 | 描述
|
|
55
|
-
|
|
|
56
|
-
| `cn`
|
|
81
|
+
| Entry | 类型 | 描述 |
|
|
82
|
+
| --- | --- | --- |
|
|
83
|
+
| `cn` | util | Tailwind className 合并工具(clsx + tailwind-merge) |
|
|
84
|
+
| `popover` | component | 可交互浮层 — Radix Popover + antd arrow 并集,使用 showArrow 控制尖角(与 Tooltip / HoverCard 命名统一) |
|
|
85
|
+
| `button` | component | 通用按钮 — shadcn 实现 + cloud-design 能力并集(loading / icon / shape / block / dashed variant / color 语义双 prop / disabledTooltip)。同文件合一导出 ButtonGroup + ButtonGroupText(等价 antd Space.Compact + cd SplitButton)。 |
|
|
57
86
|
|
|
58
87
|
### npm 依赖
|
|
59
88
|
|
|
@@ -62,45 +91,85 @@ package: '@teamix-evo/ui'
|
|
|
62
91
|
```bash
|
|
63
92
|
pnpm add lucide-react@^0.460.0
|
|
64
93
|
```
|
|
65
|
-
|
|
66
94
|
<!-- auto:deps:end -->
|
|
67
95
|
|
|
68
96
|
## AI 生成纪律
|
|
69
97
|
|
|
70
|
-
-
|
|
71
|
-
-
|
|
72
|
-
- **`
|
|
73
|
-
-
|
|
74
|
-
-
|
|
75
|
-
-
|
|
76
|
-
- **`
|
|
77
|
-
- **`
|
|
98
|
+
- **`format` 决定列的显隐**:有 `s/ss` 才显示秒列,没有 `m/mm` 时不显示分钟列。**默认 "HH:mm:ss"** —— 单纯需要时分用 `format="HH:mm"`,**不要**为了"隐藏秒"而魔改样式
|
|
99
|
+
- **value 必须能被 `parseTime` 解析**:格式宽松,按非数字切分;但**强烈建议**与 `format` 保持一致,避免来回 round-trip 时丢失字段
|
|
100
|
+
- **`hourStep` / `minuteStep` / `secondStep` 是渲染步长**:仅决定可选项粒度,**不会**自动把已有值往档位上对齐(由消费方负责)
|
|
101
|
+
- **`disabledHours` / `disabledMinutes` / `disabledSeconds` 是高阶函数**:`disabledMinutes(hour)` 接收当前选中小时;切换小时后自动重新计算可选分钟。**不要**手动写 useState 维护可选集
|
|
102
|
+
- **空状态用空字符串** `""`,不要传 `null` / `undefined`(受控模式时类型即不允许)
|
|
103
|
+
- **Range 模式点「确定」才触发 `onChange`**:面板内的滚动调整只更新内部 draft;关闭面板等价于"取消"
|
|
104
|
+
- **`error` 是布尔开关**(对齐 Input);消费方可以直接 `aria-invalid` 也能达到同效果
|
|
105
|
+
- **`clearable` 仅在有值时显示**:点击清除会触发 `onChange('')` / `onChange(['', ''])`
|
|
78
106
|
|
|
79
107
|
## Examples
|
|
80
108
|
|
|
81
109
|
```tsx
|
|
82
|
-
import { TimePicker } from '@/components/ui/time-picker';
|
|
110
|
+
import { TimePicker, TimeRangePicker } from '@/components/ui/time-picker';
|
|
83
111
|
import * as React from 'react';
|
|
84
112
|
|
|
85
|
-
// 基础(HH:mm)
|
|
86
|
-
<TimePicker defaultValue="09:30" />
|
|
113
|
+
// 基础(默认 HH:mm:ss)
|
|
114
|
+
<TimePicker defaultValue="09:30:00" />
|
|
87
115
|
|
|
88
|
-
// 受控 +
|
|
116
|
+
// 受控 + 可清除
|
|
89
117
|
const [t, setT] = React.useState('09:30:00');
|
|
90
|
-
<TimePicker value={t} onChange={setT}
|
|
118
|
+
<TimePicker value={t} onChange={setT} clearable />
|
|
119
|
+
|
|
120
|
+
// 只显示时:分
|
|
121
|
+
<TimePicker format="HH:mm" defaultValue="09:30" />
|
|
91
122
|
|
|
92
|
-
//
|
|
93
|
-
<TimePicker
|
|
123
|
+
// 5 分钟一档,禁用工作时间外
|
|
124
|
+
<TimePicker
|
|
125
|
+
minuteStep={5}
|
|
126
|
+
disabledHours={() => [0, 1, 2, 3, 4, 5, 6, 7, 8, 19, 20, 21, 22, 23]}
|
|
127
|
+
/>
|
|
94
128
|
|
|
95
|
-
//
|
|
96
|
-
<TimePicker defaultValue="09:00
|
|
129
|
+
// 错误态
|
|
130
|
+
<TimePicker error defaultValue="09:00:00" />
|
|
97
131
|
|
|
98
|
-
//
|
|
99
|
-
<
|
|
132
|
+
// 范围
|
|
133
|
+
const [r, setR] = React.useState<[string, string]>(['09:00', '18:00']);
|
|
134
|
+
<TimeRangePicker value={r} onChange={setR} format="HH:mm" clearable />
|
|
100
135
|
|
|
101
|
-
// 与 DatePicker 配对
|
|
102
|
-
<
|
|
103
|
-
<DatePicker />
|
|
104
|
-
<TimePicker />
|
|
105
|
-
</div>
|
|
136
|
+
// 与 DatePicker.showTime 配对(走 DatePicker)
|
|
137
|
+
<DatePicker showTime />
|
|
106
138
|
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## TimePicker 形态 — 旧库 API → 新映射
|
|
143
|
+
|
|
144
|
+
> 旧库 `TimePicker2`(hybridcloud) → 新库 `TimePicker` + `TimeRangePicker`(独立导出)。
|
|
145
|
+
> 新库值类型为 `string`(如 `"09:30:00"`),不依赖 moment / dayjs。
|
|
146
|
+
|
|
147
|
+
### 命名 & 结构映射
|
|
148
|
+
|
|
149
|
+
| 旧库 | 新库 | 说明 |
|
|
150
|
+
| -------------------------------- | ------------------------------------------- | ------------------------------ |
|
|
151
|
+
| `TimePicker2` | `TimePicker` | 组件名简化 |
|
|
152
|
+
| `TimePicker2.RangePicker` | `TimeRangePicker` | 独立导出(非挂载) |
|
|
153
|
+
| `value` (Dayjs) | `value` (string) | 类型变更,无日期库依赖 |
|
|
154
|
+
| `onChange(Dayjs, string)` | `onChange(string)` | 签名简化,直接返回格式化字符串 |
|
|
155
|
+
| `size: large/medium/small` | `size: 'sm' \| 'md' \| 'lg'` | md = medium |
|
|
156
|
+
| `state="error"` | `error={true}` | 布尔开关(对齐 Input) |
|
|
157
|
+
| `format` (HH:mm:ss) | `format` (HH:mm:ss) | 相同语法 |
|
|
158
|
+
| `disabledHours(i) => bool` | `disabledHours() => number[]` | 返回禁用数组(对齐 antd v5) |
|
|
159
|
+
| `disabledMinutes(h,i) => bool` | `disabledMinutes(hour) => number[]` | 返回禁用数组 |
|
|
160
|
+
| `disabledSeconds(h,m,i) => bool` | `disabledSeconds(hour, minute) => number[]` | 返回禁用数组 |
|
|
161
|
+
| `hasClear` | `hasClear` | 命名保留 |
|
|
162
|
+
| `visible / onVisibleChange` | _(未来 P2)_ | MVP 内部管理 |
|
|
163
|
+
| `ranges` (快捷值) | _(未来 P2: presets)_ | MVP 不含预设 |
|
|
164
|
+
| `label` | 不复刻 | 用外部 FormItem label |
|
|
165
|
+
| `hasBorder` | 不复刻 | className 覆盖 |
|
|
166
|
+
| `isPreview / renderPreview` | 不复刻 | 新库无预览态 |
|
|
167
|
+
|
|
168
|
+
### 迁移 FAQ
|
|
169
|
+
|
|
170
|
+
| 问题 | 回答 |
|
|
171
|
+
| ----------------------- | ---------------------------------------------------------------------------------- |
|
|
172
|
+
| Dayjs → string 怎么转? | `dayjs.format('HH:mm:ss')` 即可;反向 `dayjs(str, 'HH:mm:ss')` |
|
|
173
|
+
| disabledHours 签名差异? | 旧: `(hour) => boolean` 返回单项是否禁用;新: `() => number[]` 返回所有禁用小时数组 |
|
|
174
|
+
| Range 值结构? | 旧: `[Dayjs, Dayjs]` → 新: `[string, string]`,如 `['09:00', '18:00']` |
|
|
175
|
+
| 只要时分怎么办? | `format="HH:mm"`,自动隐藏秒列 |
|