@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,5 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
3
|
+
import { Search, Send, X } from 'lucide-react';
|
|
4
|
+
|
|
3
5
|
import {
|
|
4
6
|
InputGroup,
|
|
5
7
|
InputGroupAddon,
|
|
@@ -9,26 +11,34 @@ import {
|
|
|
9
11
|
import { Button } from '@/components/button/button';
|
|
10
12
|
|
|
11
13
|
const meta: Meta<typeof InputGroup> = {
|
|
12
|
-
title: '
|
|
14
|
+
title: '数据录入 · Data Entry/InputGroup',
|
|
13
15
|
component: InputGroup,
|
|
14
16
|
tags: ['autodocs'],
|
|
15
17
|
parameters: {
|
|
16
18
|
docs: {
|
|
17
19
|
description: {
|
|
18
20
|
component:
|
|
19
|
-
'
|
|
21
|
+
'InputGroup 输入框组 —— 等价 antd `Input` 的 `prefix` / `suffix` / `addonBefore` / `addonAfter` 集合,**完整覆盖前后缀图标 / 文本 / 按钮所有形态**。复合插槽:`<InputGroupAddon position variant>` + `<InputGroupInput>` / `<InputGroupTextarea>`,自由嵌套图标、文本、按钮(URL / 金额 / 搜索 / Send 等)。`shadcn 2025-10` 新增,与 Input / Button / Select 同档高度(32px)。视觉走 OpenTrek semantic tokens,所有样式来自 `@teamix-evo/tokens`,无 mock。',
|
|
20
22
|
},
|
|
21
23
|
},
|
|
22
24
|
},
|
|
25
|
+
decorators: [
|
|
26
|
+
(Story) => (
|
|
27
|
+
<div className="w-96">
|
|
28
|
+
<Story />
|
|
29
|
+
</div>
|
|
30
|
+
),
|
|
31
|
+
],
|
|
23
32
|
};
|
|
24
33
|
|
|
25
34
|
export default meta;
|
|
26
35
|
type Story = StoryObj<typeof InputGroup>;
|
|
27
36
|
|
|
28
|
-
|
|
37
|
+
/** 基础 —— 前置图标 + 单行输入(替代旧 `<Input prefix={<Search />} />`)。 */
|
|
38
|
+
export const Basic: Story = {
|
|
29
39
|
parameters: { controls: { disable: true } },
|
|
30
40
|
render: () => (
|
|
31
|
-
<InputGroup
|
|
41
|
+
<InputGroup>
|
|
32
42
|
<InputGroupAddon position="before" variant="icon">
|
|
33
43
|
<Search className="size-4" />
|
|
34
44
|
</InputGroupAddon>
|
|
@@ -37,10 +47,11 @@ export const Playground: Story = {
|
|
|
37
47
|
),
|
|
38
48
|
};
|
|
39
49
|
|
|
50
|
+
/** URL 输入 —— text 前后缀(替代旧 `<Input addonBefore="https://" addonAfter=".com" />`)。 */
|
|
40
51
|
export const Url: Story = {
|
|
41
52
|
parameters: { controls: { disable: true } },
|
|
42
53
|
render: () => (
|
|
43
|
-
<InputGroup
|
|
54
|
+
<InputGroup>
|
|
44
55
|
<InputGroupAddon position="before">https://</InputGroupAddon>
|
|
45
56
|
<InputGroupInput defaultValue="example" />
|
|
46
57
|
<InputGroupAddon position="after">.com</InputGroupAddon>
|
|
@@ -48,27 +59,48 @@ export const Url: Story = {
|
|
|
48
59
|
),
|
|
49
60
|
};
|
|
50
61
|
|
|
51
|
-
|
|
62
|
+
/** 金额输入 —— text 前后缀。 */
|
|
63
|
+
export const Currency: Story = {
|
|
64
|
+
parameters: { controls: { disable: true } },
|
|
65
|
+
render: () => (
|
|
66
|
+
<InputGroup>
|
|
67
|
+
<InputGroupAddon position="before">¥</InputGroupAddon>
|
|
68
|
+
<InputGroupInput type="number" defaultValue={199} />
|
|
69
|
+
<InputGroupAddon position="after">/ 月</InputGroupAddon>
|
|
70
|
+
</InputGroup>
|
|
71
|
+
),
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/** 可清空搜索 —— icon 前后缀,后缀槽放可点击的清空按钮。 */
|
|
75
|
+
export const SearchWithClear: Story = {
|
|
52
76
|
parameters: { controls: { disable: true } },
|
|
53
77
|
render: () => (
|
|
54
|
-
<InputGroup
|
|
78
|
+
<InputGroup>
|
|
55
79
|
<InputGroupAddon position="before" variant="icon">
|
|
56
80
|
<Search className="size-4" />
|
|
57
81
|
</InputGroupAddon>
|
|
58
|
-
<InputGroupInput
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
82
|
+
<InputGroupInput
|
|
83
|
+
defaultValue="OpenTrek 设计令牌"
|
|
84
|
+
placeholder="输入关键词..."
|
|
85
|
+
/>
|
|
86
|
+
<InputGroupAddon position="after" variant="icon">
|
|
87
|
+
<button
|
|
88
|
+
type="button"
|
|
89
|
+
aria-label="清空"
|
|
90
|
+
className="rounded-sm p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground"
|
|
91
|
+
>
|
|
92
|
+
<X className="size-4" />
|
|
93
|
+
</button>
|
|
63
94
|
</InputGroupAddon>
|
|
64
95
|
</InputGroup>
|
|
65
96
|
),
|
|
66
97
|
};
|
|
67
98
|
|
|
99
|
+
/** Textarea + Send 按钮 —— `variant="button"` 把 Button 的边框 / 圆角去掉,与外壳合一。 */
|
|
68
100
|
export const TextareaWithSend: Story = {
|
|
69
101
|
parameters: { controls: { disable: true } },
|
|
70
102
|
render: () => (
|
|
71
|
-
<InputGroup className="
|
|
103
|
+
<InputGroup className="items-end">
|
|
72
104
|
<InputGroupTextarea rows={3} placeholder="发表评论..." />
|
|
73
105
|
<InputGroupAddon position="after" variant="button">
|
|
74
106
|
<Button size="icon" icon={<Send />} aria-label="发送" />
|
|
@@ -77,10 +109,11 @@ export const TextareaWithSend: Story = {
|
|
|
77
109
|
),
|
|
78
110
|
};
|
|
79
111
|
|
|
112
|
+
/** 整组禁用 —— `disabled` 仅控制视觉 opacity,子项 disabled 仍需自行传。 */
|
|
80
113
|
export const Disabled: Story = {
|
|
81
114
|
parameters: { controls: { disable: true } },
|
|
82
115
|
render: () => (
|
|
83
|
-
<InputGroup
|
|
116
|
+
<InputGroup disabled>
|
|
84
117
|
<InputGroupAddon position="before">@</InputGroupAddon>
|
|
85
118
|
<InputGroupInput defaultValue="alice" disabled />
|
|
86
119
|
</InputGroup>
|
|
@@ -2,6 +2,18 @@ import * as React from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { cn } from '@/utils/cn';
|
|
4
4
|
|
|
5
|
+
// ─── InputGroup family ──────────────────────────────────────────────────────
|
|
6
|
+
//
|
|
7
|
+
// 复合输入框容器 — shadcn 2025-10 新增,等价 antd `Input` 的
|
|
8
|
+
// `prefix` / `suffix` / `addonBefore` / `addonAfter` 集合,但拆为更通用的
|
|
9
|
+
// **复合插槽**:`<InputGroupAddon position="before|after">`(addon)+
|
|
10
|
+
// `<InputGroupInput>` / `<InputGroupTextarea>`(主体)按需嵌套图标 / 按钮 / 文本。
|
|
11
|
+
//
|
|
12
|
+
// 设计纪律:
|
|
13
|
+
// - 主体高度对齐 Input md(h-8 / 32px),与 Button / Select / Input 同档同行混排
|
|
14
|
+
// - 圆角走 `rounded-md`(Tailwind v4 namespace),与 Input / Button 同档
|
|
15
|
+
// - 由 InputGroup 外壳承担 border + ring + focus-within,内部 input / addon 全去边框
|
|
16
|
+
|
|
5
17
|
export interface InputGroupProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
6
18
|
/**
|
|
7
19
|
* 整组禁用样式(子项请单独传 `disabled`,这里仅影响视觉上的 opacity)。
|
|
@@ -13,7 +25,7 @@ export interface InputGroupProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
13
25
|
* Input + addon 统一容器 — shadcn 2025-10 新增,等价 antd `Input` 的
|
|
14
26
|
* `prefix` / `suffix` / `addonBefore` / `addonAfter` 集合,但拆为更通用的
|
|
15
27
|
* **复合插槽**:`<InputGroupAddon position="before|after">`(addon)+
|
|
16
|
-
* `<InputGroupInput>` / `<InputGroupTextarea>`(主体)
|
|
28
|
+
* `<InputGroupInput>` / `<InputGroupTextarea>`(主体)按需嵌套图标 / 按钮 / 文本。
|
|
17
29
|
*/
|
|
18
30
|
const InputGroup = React.forwardRef<HTMLDivElement, InputGroupProps>(
|
|
19
31
|
({ className, disabled, children, ...props }, ref) => (
|
|
@@ -54,14 +66,27 @@ const InputGroupAddon = React.forwardRef<HTMLDivElement, InputGroupAddonProps>(
|
|
|
54
66
|
<div
|
|
55
67
|
ref={ref}
|
|
56
68
|
data-position={position}
|
|
69
|
+
data-variant={variant}
|
|
70
|
+
data-slot="input-group-addon"
|
|
57
71
|
className={cn(
|
|
58
72
|
'flex shrink-0 items-center',
|
|
59
73
|
variant === 'text' &&
|
|
60
|
-
'border-input bg-muted px-3 text-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
74
|
+
'border-input bg-muted px-3 text-xs text-muted-foreground',
|
|
75
|
+
// icon 形态:容器一侧 `pl-3 / pr-3` 与文本输入边距对齐;另一侧贴向 input,
|
|
76
|
+
// 让 input 自身的 `px-3` 提供 12px 图标-文字间距(总入边 12+16+12 = 40px,
|
|
77
|
+
// 与 shadcn / cd hybridcloud 模式接近)。
|
|
78
|
+
variant === 'icon' && 'text-muted-foreground',
|
|
79
|
+
variant === 'icon' && position === 'before' && 'pl-3 pr-0',
|
|
80
|
+
variant === 'icon' && position === 'after' && 'pl-0 pr-3',
|
|
81
|
+
// variant=button 下,直接子元素(Button / SelectTrigger / 自定义)的 border /
|
|
82
|
+
// 圆角 / 阴影 / hover/focus 反馈一律静默 — 视觉责任由 InputGroup 外壳承担。
|
|
83
|
+
// 用 `!` 锁优先级避免 uni-manager scoped CSS 的 hover-shadow 规则反复覆盖。
|
|
84
|
+
variant === 'button' &&
|
|
85
|
+
'[&>*]:!rounded-none [&>*]:!border-0 [&>*]:!shadow-none [&>*:hover]:!shadow-none [&>*:focus]:!shadow-none [&>*:focus-visible]:!shadow-none',
|
|
86
|
+
// 仅 variant=text 显示分隔线(与正文 input 区隔):button 自身有 primary 底色
|
|
87
|
+
// 作视觉分隔不需再叠灰条;icon 紧贴正文不分隔。
|
|
88
|
+
position === 'before' && variant === 'text' && 'border-r border-input',
|
|
89
|
+
position === 'after' && variant === 'text' && 'border-l border-input',
|
|
65
90
|
className,
|
|
66
91
|
)}
|
|
67
92
|
{...props}
|
|
@@ -78,8 +103,15 @@ const InputGroupInput = React.forwardRef<
|
|
|
78
103
|
ref={ref}
|
|
79
104
|
type={type}
|
|
80
105
|
className={cn(
|
|
81
|
-
|
|
106
|
+
// 高度与 Input md(h-8 / 32px)对齐 — 容器 InputGroup 不设高度,
|
|
107
|
+
// 由内部 input + addon 自身高度决定;Button 默认 h-8 也是 32px,自然对齐。
|
|
108
|
+
'flex h-8 w-full min-w-0 flex-1 bg-transparent px-3 text-xs placeholder:text-muted-foreground',
|
|
82
109
|
'focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50',
|
|
110
|
+
// 紧贴 icon-before addon 时左 padding 收到 8px(addon pl-3 + 0 + input pl-2 = 20px 总内边距,
|
|
111
|
+
// 等价于 antd `<Input prefix>` 的 px-3 + gap-2 模式)。
|
|
112
|
+
'[[data-slot=input-group-addon][data-variant=icon][data-position=before]+&]:pl-2',
|
|
113
|
+
// 同理:右侧紧贴 icon-after addon 时右 padding 收到 8px。
|
|
114
|
+
'[&:has(+[data-slot=input-group-addon][data-variant=icon][data-position=after])]:pr-2',
|
|
83
115
|
className,
|
|
84
116
|
)}
|
|
85
117
|
{...props}
|
|
@@ -95,8 +127,12 @@ const InputGroupTextarea = React.forwardRef<
|
|
|
95
127
|
ref={ref}
|
|
96
128
|
rows={rows}
|
|
97
129
|
className={cn(
|
|
98
|
-
'flex w-full min-w-0 flex-1 bg-transparent px-3 py-2 text-
|
|
130
|
+
'flex w-full min-w-0 flex-1 bg-transparent px-3 py-2 text-xs placeholder:text-muted-foreground',
|
|
99
131
|
'focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50',
|
|
132
|
+
// 默认关闭原生 resize 手柄 — 嵌在 InputGroup(常配 Send/工具栏按钮)里时,
|
|
133
|
+
// 右下角斜线 grip 会从相邻 addon 边缘 peek 出来视觉脏。
|
|
134
|
+
// 业务确需 resize:`className="resize-y"` 自行 override。
|
|
135
|
+
'resize-none',
|
|
100
136
|
className,
|
|
101
137
|
)}
|
|
102
138
|
{...props}
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
id: input-number
|
|
3
3
|
name: InputNumber
|
|
4
4
|
type: component
|
|
5
|
-
category:
|
|
5
|
+
category: data-entry
|
|
6
6
|
since: 0.1.0
|
|
7
|
-
package:
|
|
7
|
+
package: '@teamix-evo/ui'
|
|
8
|
+
displayName: 数字输入框
|
|
8
9
|
---
|
|
9
10
|
|
|
10
|
-
# InputNumber
|
|
11
|
+
# InputNumber 数字输入框
|
|
11
12
|
|
|
12
13
|
数字输入 — antd 独有补足。**等价 antd `InputNumber`**。区别于原生 `<input type="number">`:步进按钮显隐可配、范围裁剪与精度由组件保证、千分位展示、键盘 ↑↓ 步进、支持空状态(`value=null`)。
|
|
13
14
|
|
|
@@ -24,21 +25,27 @@ package: "@teamix-evo/ui"
|
|
|
24
25
|
- 多档枚举 → `Segmented` / `RadioGroup`
|
|
25
26
|
- 普通文本输入 → `Input`
|
|
26
27
|
|
|
28
|
+
## Props
|
|
29
|
+
|
|
27
30
|
<!-- auto:props:begin -->
|
|
28
31
|
| 名称 | 类型 | 默认值 | 必填 | 说明 |
|
|
29
32
|
| --- | --- | --- | --- | --- |
|
|
30
|
-
| `
|
|
31
|
-
| `
|
|
32
|
-
| `
|
|
33
|
+
| `stringMode` | `boolean` | `false` | – | 大数/高精度字符串模式(antd `stringMode` 并集)。开启后: - `value` / `defaultValue` / `onChange` 使用 `string` 类型(避免 IEEE 754 精度丢失) - 步进 / 夹紧仍用 `parseFloat` 执行算术,但最终返回 string |
|
|
34
|
+
| `value` | `number \| string \| null` | – | – | 受控值 — `null` 等价空输入。`stringMode` 时为 `string \| null`。 |
|
|
35
|
+
| `defaultValue` | `number \| string \| null` | – | – | uncontrolled 初值。`stringMode` 时为 `string \| null`。 |
|
|
36
|
+
| `onChange` | `(value: number \| string \| null) => void` | – | – | 值变化回调 — 输入清空时传 `null`。 `stringMode` 时回调 `(value: string \| null) => void`; 普通模式 `(value: number \| null) => void`。 |
|
|
33
37
|
| `min` | `number` | – | – | 最小值(antd `min` 并集)。 |
|
|
34
38
|
| `max` | `number` | – | – | 最大值(antd `max` 并集)。 |
|
|
35
39
|
| `step` | `number` | `1` | – | 步长(antd `step` 并集) — 增 / 减按钮以及键盘 ↑↓ 都按此步长。 |
|
|
36
40
|
| `precision` | `number` | – | – | 数值精度(antd `precision` 并集) — 保留小数位数(超出会四舍五入)。 |
|
|
37
41
|
| `groupSeparator` | `boolean` | `false` | – | 千分位分隔展示(仅展示用,实际 value 仍是 number)。 |
|
|
38
42
|
| `controls` | `boolean` | `true` | – | 是否显示右侧上下步进按钮(antd `controls` 并集) — `false` 时隐藏。 |
|
|
39
|
-
| `
|
|
43
|
+
| `type` | `'normal' \| 'inline'` | `"normal"` | – | 形态(cloud-design `type` 并集) — `"normal"` 右侧叠加 ChevronUp/Down 按钮(默认), `"inline"` 两侧各一个 Plus/Minus 按钮(【−】 value 【+】),适合紧凑表单。 |
|
|
44
|
+
| `size` | `'sm' \| 'md' \| 'default' \| 'lg'` | `"md"` | – | 尺寸。`md` 与 `default` 完全等价,后者作为向后兼容别名保留;新代码请优先使用 `md`, 与 Button / Input / Select 等表单原子的 size enum 一致。 |
|
|
40
45
|
<!-- auto:props:end -->
|
|
41
46
|
|
|
47
|
+
## 依赖
|
|
48
|
+
|
|
42
49
|
<!-- auto:deps:begin -->
|
|
43
50
|
### 同库依赖
|
|
44
51
|
|
|
@@ -66,6 +73,8 @@ pnpm add lucide-react@^0.460.0
|
|
|
66
73
|
- **`controls=false`** 仅在需要嵌入 InputGroup / 紧凑表格时关闭;默认带步进按钮更直观
|
|
67
74
|
- **键盘 ↑↓ 已实现** — 不要再监听 keydown 加自定义步进
|
|
68
75
|
- **不要传 `type="number"`** — 组件用 `type="text"` 才能支持千分位与精确控制
|
|
76
|
+
- **`type="inline"`(本组件自身的 prop,与原生 input.type 无关)**:两侧 Plus/Minus 按钮适合表格与紧凑表单;`type="normal"`(默认) 右侧叠加 ChevronUp/Down,有更多调试空间
|
|
77
|
+
- **步进 icon 走 lucide-react**:`ChevronUp` / `ChevronDown` (normal) 与 `Plus` / `Minus` (inline),**不要**换成 ▲/▼ 等 unicode 字符
|
|
69
78
|
|
|
70
79
|
## Examples
|
|
71
80
|
|
|
@@ -86,6 +95,54 @@ const [v, setV] = React.useState<number | null>(1);
|
|
|
86
95
|
// 隐藏步进按钮(配合 InputGroup 使用)
|
|
87
96
|
<InputNumber controls={false} defaultValue={1} className="rounded-none" />
|
|
88
97
|
|
|
98
|
+
// inline 模式(Plus/Minus 两侧按钮,对齐 cloud-design)
|
|
99
|
+
<InputNumber type="inline" defaultValue={1} min={0} max={10} className="w-32" />
|
|
100
|
+
|
|
89
101
|
// 小尺寸
|
|
90
102
|
<InputNumber size="sm" defaultValue={0} />
|
|
91
103
|
```
|
|
104
|
+
|
|
105
|
+
## InputNumber 形态 — 旧库 API → 新映射
|
|
106
|
+
|
|
107
|
+
> 决策:**不新增独立组件**,`InputNumber` 已承接 cloud-design `NumberPicker` 所有核心能力。本章节是迁移查表索引,与 [上面 Props 表](#props) 互补。
|
|
108
|
+
|
|
109
|
+
### 命名映射
|
|
110
|
+
|
|
111
|
+
| cloud-design 旧库 (`NumberPicker`) | `@teamix-evo/ui` (`InputNumber`) | 说明 |
|
|
112
|
+
| ---------------------------------- | --------------------------------- | ------------------------------- |
|
|
113
|
+
| 组件名 `NumberPicker` | `InputNumber` | 对齐 antd 命名 |
|
|
114
|
+
| `value: number \| string` | `value: number \| null` | 空态用 `null` 代替空字符串 |
|
|
115
|
+
| `onChange(value, e)` | `onChange(value: number \| null)` | 单参数简化(无 event) |
|
|
116
|
+
| `size="small\|medium\|large"` | `size="sm\|md\|lg"` | 三档 + `default` 兼容别名 |
|
|
117
|
+
| `hasTrigger` | `controls` | 显隐步进按钮 |
|
|
118
|
+
| `type="normal"` | `type="normal"`(默认) | 右侧 Chevron 上下按钮 |
|
|
119
|
+
| `type="inline"` | `type="inline"` | 两侧 Plus/Minus 按钮 |
|
|
120
|
+
| `format`(通用格式化) | `groupSeparator`(仅千分位) | 通用 formatter/parser 待后续 P2 |
|
|
121
|
+
| `editable` | 原生 `readOnly` | 直接用 HTML attr |
|
|
122
|
+
| `stringMode`(大数支持) | `stringMode` | ✅ 已实现 — 规避精度丢失 |
|
|
123
|
+
| `precision` | 同名 | 四舍五入保留小数位 |
|
|
124
|
+
| `min` / `max` / `step` | 同名 | 透传 |
|
|
125
|
+
|
|
126
|
+
### Breaking Changes(从旧库迁移时需改写)
|
|
127
|
+
|
|
128
|
+
1. 组件名 `NumberPicker` → `InputNumber`(import 路径变动)
|
|
129
|
+
2. `value` 类型 `string` → `null` 表示空态
|
|
130
|
+
3. `onChange(value, e)` → `onChange(value: number | null)` 单参数
|
|
131
|
+
4. `hasTrigger` → `controls`
|
|
132
|
+
5. `size` 命名缩写(small→sm / medium→md / large→lg)
|
|
133
|
+
6. `format` → `groupSeparator`(仅千分位;通用 formatter 待后续)
|
|
134
|
+
|
|
135
|
+
### 不修复 / 后续工序清单
|
|
136
|
+
|
|
137
|
+
- **~~stringMode 大数支持~~(P1)**:✅ 已落地 — `stringMode` prop 开启后 `value` 用 string 类型,规避 IEEE 754 精度丢失。报告 §3 标记为缺失为旧版本数据,本波次已纠正
|
|
138
|
+
- **通用 formatter / parser**(P2):当前仅 `groupSeparator`千分位;自定义格式化待后续 slot
|
|
139
|
+
- **size 档位对齐 Input/Button**(本波次):sm h-8 → h-7 / md h-9 → h-8 / lg h-10 → h-9(28/32/36),与表单原子家族同行视觉一致
|
|
140
|
+
- **device/isPreview/upBtnProps/downBtnProps/onCorrect/alwaysShowTrigger**:报告 §5 已列入"保留新库优势",**不修复**
|
|
141
|
+
|
|
142
|
+
### InputNumber 专项 AI 生成纪律
|
|
143
|
+
|
|
144
|
+
- 新代码用 `size="md"`,与 Button / Input / Select 一致;`"default"` 仅向后兼容
|
|
145
|
+
- 空态 = `null`(不要用 0 代表“空”)
|
|
146
|
+
- `min`/`max` 自动夹紧,**不要**在外层再做边界校验
|
|
147
|
+
- `controls=false` 仅在嵌入 InputGroup / 紧凑表格时关闭
|
|
148
|
+
- 不要传 `type="number"`(这里的 `type` 是 InputNumber 自己的 prop,与原生 input.type 无关)
|
|
@@ -1,26 +1,33 @@
|
|
|
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 { InputNumber } from './input-number';
|
|
4
4
|
|
|
5
5
|
const meta: Meta<typeof InputNumber> = {
|
|
6
|
-
title: '
|
|
6
|
+
title: '数据录入 · Data Entry/InputNumber',
|
|
7
7
|
component: InputNumber,
|
|
8
8
|
tags: ['autodocs'],
|
|
9
9
|
parameters: {
|
|
10
10
|
docs: {
|
|
11
11
|
description: {
|
|
12
12
|
component:
|
|
13
|
-
'数字输入框 — 区别于原生 type=number
|
|
13
|
+
'数字输入框 — 区别于原生 type=number:步进按钮显隐可配、范围裁剪与精度由组件保证、千分位展示、键盘 ↑↓ 步进、支持空状态。等价 antd `InputNumber`。',
|
|
14
14
|
},
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
argTypes: {
|
|
18
|
-
size: { control: 'inline-radio', options: ['sm', '
|
|
18
|
+
size: { control: 'inline-radio', options: ['sm', 'md', 'lg'] },
|
|
19
|
+
type: { control: 'inline-radio', options: ['normal', 'inline'] },
|
|
19
20
|
controls: { control: 'boolean' },
|
|
20
21
|
groupSeparator: { control: 'boolean' },
|
|
21
22
|
disabled: { control: 'boolean' },
|
|
22
23
|
},
|
|
23
|
-
args: {
|
|
24
|
+
args: {
|
|
25
|
+
size: 'md',
|
|
26
|
+
type: 'normal',
|
|
27
|
+
controls: true,
|
|
28
|
+
groupSeparator: false,
|
|
29
|
+
disabled: false,
|
|
30
|
+
},
|
|
24
31
|
};
|
|
25
32
|
|
|
26
33
|
export default meta;
|
|
@@ -28,7 +35,13 @@ type Story = StoryObj<typeof InputNumber>;
|
|
|
28
35
|
|
|
29
36
|
export const Playground: Story = {
|
|
30
37
|
render: (args) => (
|
|
31
|
-
<InputNumber
|
|
38
|
+
<InputNumber
|
|
39
|
+
{...args}
|
|
40
|
+
defaultValue={10}
|
|
41
|
+
min={0}
|
|
42
|
+
max={100}
|
|
43
|
+
className="w-40"
|
|
44
|
+
/>
|
|
32
45
|
),
|
|
33
46
|
};
|
|
34
47
|
|
|
@@ -53,7 +66,7 @@ export const Controlled: Story = {
|
|
|
53
66
|
<div className="flex items-center gap-3">
|
|
54
67
|
<InputNumber
|
|
55
68
|
value={v}
|
|
56
|
-
onChange={setV}
|
|
69
|
+
onChange={(val) => setV(val as number | null)}
|
|
57
70
|
step={0.5}
|
|
58
71
|
min={0}
|
|
59
72
|
max={5}
|
|
@@ -75,12 +88,37 @@ export const NoControls: Story = {
|
|
|
75
88
|
),
|
|
76
89
|
};
|
|
77
90
|
|
|
91
|
+
export const InlineType: Story = {
|
|
92
|
+
name: 'Inline (Plus/Minus)',
|
|
93
|
+
parameters: { controls: { disable: true } },
|
|
94
|
+
render: () => (
|
|
95
|
+
<div className="flex flex-col gap-3">
|
|
96
|
+
<InputNumber
|
|
97
|
+
type="inline"
|
|
98
|
+
defaultValue={1}
|
|
99
|
+
min={0}
|
|
100
|
+
max={10}
|
|
101
|
+
className="w-32"
|
|
102
|
+
/>
|
|
103
|
+
<InputNumber
|
|
104
|
+
type="inline"
|
|
105
|
+
size="sm"
|
|
106
|
+
defaultValue={3}
|
|
107
|
+
min={0}
|
|
108
|
+
max={10}
|
|
109
|
+
className="w-28"
|
|
110
|
+
/>
|
|
111
|
+
<InputNumber type="inline" disabled defaultValue={1} className="w-32" />
|
|
112
|
+
</div>
|
|
113
|
+
),
|
|
114
|
+
};
|
|
115
|
+
|
|
78
116
|
export const Sizes: Story = {
|
|
79
117
|
parameters: { controls: { disable: true } },
|
|
80
118
|
render: () => (
|
|
81
119
|
<div className="flex items-center gap-3">
|
|
82
120
|
<InputNumber size="sm" defaultValue={0} className="w-28" />
|
|
83
|
-
<InputNumber size="
|
|
121
|
+
<InputNumber size="md" defaultValue={0} className="w-32" />
|
|
84
122
|
<InputNumber size="lg" defaultValue={0} className="w-36" />
|
|
85
123
|
</div>
|
|
86
124
|
),
|
|
@@ -1,21 +1,37 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { ChevronDown, ChevronUp } from 'lucide-react';
|
|
2
|
+
import { ChevronDown, ChevronUp, Minus, Plus } from 'lucide-react';
|
|
3
3
|
|
|
4
4
|
import { cn } from '@/utils/cn';
|
|
5
5
|
|
|
6
6
|
export interface InputNumberProps
|
|
7
7
|
extends Omit<
|
|
8
8
|
React.InputHTMLAttributes<HTMLInputElement>,
|
|
9
|
-
|
|
9
|
+
| 'onChange'
|
|
10
|
+
| 'value'
|
|
11
|
+
| 'defaultValue'
|
|
12
|
+
| 'min'
|
|
13
|
+
| 'max'
|
|
14
|
+
| 'step'
|
|
15
|
+
| 'type'
|
|
16
|
+
| 'size'
|
|
10
17
|
> {
|
|
11
|
-
/** 受控值 — `null` 等价空输入。 */
|
|
12
|
-
value?: number | null;
|
|
13
|
-
/** uncontrolled 初值。 */
|
|
14
|
-
defaultValue?: number | null;
|
|
15
18
|
/**
|
|
16
|
-
*
|
|
19
|
+
* 大数/高精度字符串模式(antd `stringMode` 并集)。开启后:
|
|
20
|
+
* - `value` / `defaultValue` / `onChange` 使用 `string` 类型(避免 IEEE 754 精度丢失)
|
|
21
|
+
* - 步进 / 夹紧仍用 `parseFloat` 执行算术,但最终返回 string
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
stringMode?: boolean;
|
|
25
|
+
/** 受控值 — `null` 等价空输入。`stringMode` 时为 `string | null`。 */
|
|
26
|
+
value?: number | string | null;
|
|
27
|
+
/** uncontrolled 初值。`stringMode` 时为 `string | null`。 */
|
|
28
|
+
defaultValue?: number | string | null;
|
|
29
|
+
/**
|
|
30
|
+
* 值变化回调 — 输入清空时传 `null`。
|
|
31
|
+
* `stringMode` 时回调 `(value: string | null) => void`;
|
|
32
|
+
* 普通模式 `(value: number | null) => void`。
|
|
17
33
|
*/
|
|
18
|
-
onChange?: (value: number | null) => void;
|
|
34
|
+
onChange?: (value: number | string | null) => void;
|
|
19
35
|
/** 最小值(antd `min` 并集)。 */
|
|
20
36
|
min?: number;
|
|
21
37
|
/** 最大值(antd `max` 并集)。 */
|
|
@@ -40,10 +56,17 @@ export interface InputNumberProps
|
|
|
40
56
|
*/
|
|
41
57
|
controls?: boolean;
|
|
42
58
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
59
|
+
* 形态(cloud-design `type` 并集) — `"normal"` 右侧叠加 ChevronUp/Down 按钮(默认),
|
|
60
|
+
* `"inline"` 两侧各一个 Plus/Minus 按钮(【−】 value 【+】),适合紧凑表单。
|
|
61
|
+
* @default "normal"
|
|
62
|
+
*/
|
|
63
|
+
type?: 'normal' | 'inline';
|
|
64
|
+
/**
|
|
65
|
+
* 尺寸。`md` 与 `default` 完全等价,后者作为向后兼容别名保留;新代码请优先使用 `md`,
|
|
66
|
+
* 与 Button / Input / Select 等表单原子的 size enum 一致。
|
|
67
|
+
* @default "md"
|
|
45
68
|
*/
|
|
46
|
-
size?: 'sm' | 'default' | 'lg';
|
|
69
|
+
size?: 'sm' | 'md' | 'default' | 'lg';
|
|
47
70
|
}
|
|
48
71
|
|
|
49
72
|
function format(
|
|
@@ -60,9 +83,10 @@ function format(
|
|
|
60
83
|
}
|
|
61
84
|
|
|
62
85
|
const sizeMap = {
|
|
63
|
-
sm: 'h-
|
|
64
|
-
|
|
65
|
-
|
|
86
|
+
sm: 'h-6 text-xs',
|
|
87
|
+
md: 'h-8 text-xs',
|
|
88
|
+
default: 'h-8 text-xs',
|
|
89
|
+
lg: 'h-9 text-sm',
|
|
66
90
|
} as const;
|
|
67
91
|
|
|
68
92
|
/**
|
|
@@ -84,7 +108,9 @@ const InputNumber = React.forwardRef<HTMLInputElement, InputNumberProps>(
|
|
|
84
108
|
precision,
|
|
85
109
|
groupSeparator = false,
|
|
86
110
|
controls = true,
|
|
87
|
-
|
|
111
|
+
type = 'normal',
|
|
112
|
+
size = 'md',
|
|
113
|
+
stringMode = false,
|
|
88
114
|
disabled,
|
|
89
115
|
className,
|
|
90
116
|
onBlur,
|
|
@@ -94,13 +120,19 @@ const InputNumber = React.forwardRef<HTMLInputElement, InputNumberProps>(
|
|
|
94
120
|
ref,
|
|
95
121
|
) => {
|
|
96
122
|
const isControlled = value !== undefined;
|
|
123
|
+
const toNum = (v: number | string | null | undefined): number | null => {
|
|
124
|
+
if (v == null) return null;
|
|
125
|
+
const n = typeof v === 'string' ? parseFloat(v) : v;
|
|
126
|
+
return Number.isNaN(n) ? null : n;
|
|
127
|
+
};
|
|
97
128
|
const [internal, setInternal] = React.useState<number | null>(
|
|
98
|
-
defaultValue
|
|
129
|
+
toNum(defaultValue),
|
|
99
130
|
);
|
|
100
|
-
const current = isControlled ? value
|
|
131
|
+
const current = isControlled ? toNum(value) : internal;
|
|
101
132
|
const [editing, setEditing] = React.useState<string | null>(null);
|
|
102
133
|
|
|
103
|
-
const display =
|
|
134
|
+
const display =
|
|
135
|
+
editing !== null ? editing : format(current, precision, groupSeparator);
|
|
104
136
|
|
|
105
137
|
const clamp = (n: number): number => {
|
|
106
138
|
let v = n;
|
|
@@ -112,7 +144,11 @@ const InputNumber = React.forwardRef<HTMLInputElement, InputNumberProps>(
|
|
|
112
144
|
|
|
113
145
|
const commit = (next: number | null) => {
|
|
114
146
|
if (!isControlled) setInternal(next);
|
|
115
|
-
|
|
147
|
+
if (stringMode) {
|
|
148
|
+
onChange?.(next === null ? null : String(next));
|
|
149
|
+
} else {
|
|
150
|
+
onChange?.(next);
|
|
151
|
+
}
|
|
116
152
|
};
|
|
117
153
|
|
|
118
154
|
const handleInput = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
@@ -162,6 +198,21 @@ const InputNumber = React.forwardRef<HTMLInputElement, InputNumberProps>(
|
|
|
162
198
|
className,
|
|
163
199
|
)}
|
|
164
200
|
>
|
|
201
|
+
{controls && type === 'inline' ? (
|
|
202
|
+
<button
|
|
203
|
+
type="button"
|
|
204
|
+
tabIndex={-1}
|
|
205
|
+
disabled={
|
|
206
|
+
disabled ||
|
|
207
|
+
(typeof min === 'number' && (current ?? Infinity) <= min)
|
|
208
|
+
}
|
|
209
|
+
onClick={() => step1(-1)}
|
|
210
|
+
aria-label="减少"
|
|
211
|
+
className="flex items-center justify-center border-r border-input px-2 text-muted-foreground hover:bg-accent hover:text-foreground disabled:cursor-not-allowed disabled:opacity-30"
|
|
212
|
+
>
|
|
213
|
+
<Minus className="size-3.5" />
|
|
214
|
+
</button>
|
|
215
|
+
) : null}
|
|
165
216
|
<input
|
|
166
217
|
ref={ref}
|
|
167
218
|
type="text"
|
|
@@ -173,31 +224,53 @@ const InputNumber = React.forwardRef<HTMLInputElement, InputNumberProps>(
|
|
|
173
224
|
onKeyDown={handleKeyDown}
|
|
174
225
|
className={cn(
|
|
175
226
|
'w-full bg-transparent px-3 text-foreground placeholder:text-muted-foreground focus-visible:outline-none disabled:cursor-not-allowed',
|
|
227
|
+
type === 'inline' && 'text-center',
|
|
176
228
|
sizeMap[size],
|
|
177
229
|
)}
|
|
178
230
|
{...props}
|
|
179
231
|
/>
|
|
180
|
-
{controls ? (
|
|
181
|
-
<
|
|
232
|
+
{controls && type === 'inline' ? (
|
|
233
|
+
<button
|
|
234
|
+
type="button"
|
|
235
|
+
tabIndex={-1}
|
|
236
|
+
disabled={
|
|
237
|
+
disabled ||
|
|
238
|
+
(typeof max === 'number' && (current ?? -Infinity) >= max)
|
|
239
|
+
}
|
|
240
|
+
onClick={() => step1(1)}
|
|
241
|
+
aria-label="增加"
|
|
242
|
+
className="flex items-center justify-center border-l border-input px-2 text-muted-foreground hover:bg-accent hover:text-foreground disabled:cursor-not-allowed disabled:opacity-30"
|
|
243
|
+
>
|
|
244
|
+
<Plus className="size-3.5" />
|
|
245
|
+
</button>
|
|
246
|
+
) : null}
|
|
247
|
+
{controls && type === 'normal' ? (
|
|
248
|
+
<div className="flex flex-col border-l border-input">
|
|
182
249
|
<button
|
|
183
250
|
type="button"
|
|
184
251
|
tabIndex={-1}
|
|
185
|
-
disabled={
|
|
252
|
+
disabled={
|
|
253
|
+
disabled ||
|
|
254
|
+
(typeof max === 'number' && (current ?? -Infinity) >= max)
|
|
255
|
+
}
|
|
186
256
|
onClick={() => step1(1)}
|
|
187
257
|
aria-label="增加"
|
|
188
258
|
className="flex h-1/2 items-center justify-center px-1.5 text-muted-foreground hover:bg-accent hover:text-foreground disabled:cursor-not-allowed disabled:opacity-30"
|
|
189
259
|
>
|
|
190
|
-
<ChevronUp className="size-3" />
|
|
260
|
+
<ChevronUp className="size-3.5" />
|
|
191
261
|
</button>
|
|
192
262
|
<button
|
|
193
263
|
type="button"
|
|
194
264
|
tabIndex={-1}
|
|
195
|
-
disabled={
|
|
265
|
+
disabled={
|
|
266
|
+
disabled ||
|
|
267
|
+
(typeof min === 'number' && (current ?? Infinity) <= min)
|
|
268
|
+
}
|
|
196
269
|
onClick={() => step1(-1)}
|
|
197
270
|
aria-label="减少"
|
|
198
|
-
className="flex h-1/2 items-center justify-center border-t px-1.5 text-muted-foreground hover:bg-accent hover:text-foreground disabled:cursor-not-allowed disabled:opacity-30"
|
|
271
|
+
className="flex h-1/2 items-center justify-center border-t border-input px-1.5 text-muted-foreground hover:bg-accent hover:text-foreground disabled:cursor-not-allowed disabled:opacity-30"
|
|
199
272
|
>
|
|
200
|
-
<ChevronDown className="size-3" />
|
|
273
|
+
<ChevronDown className="size-3.5" />
|
|
201
274
|
</button>
|
|
202
275
|
</div>
|
|
203
276
|
) : null}
|