@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,22 +1,27 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
-
import {
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
3
|
+
import { Search } from 'lucide-react';
|
|
4
4
|
import { Input } from './input';
|
|
5
|
+
import {
|
|
6
|
+
InputGroup,
|
|
7
|
+
InputGroupAddon,
|
|
8
|
+
InputGroupInput,
|
|
9
|
+
} from '@/components/input-group/input-group';
|
|
5
10
|
|
|
6
11
|
const meta: Meta<typeof Input> = {
|
|
7
|
-
title: '
|
|
12
|
+
title: '数据录入 · Data Entry/Input',
|
|
8
13
|
component: Input,
|
|
9
14
|
tags: ['autodocs'],
|
|
10
15
|
parameters: {
|
|
11
16
|
docs: {
|
|
12
17
|
description: {
|
|
13
18
|
component:
|
|
14
|
-
'输入框 —
|
|
19
|
+
'输入框 — shadcn 简洁基底 + antd 并集中保留为内建逻辑能力的:`size` 三档(sm/md/lg,与 `Button` 同档)、`clearable` 一键清空、`showCount` + `maxLength` 字数统计、`error` / `aria-invalid` 错误态。**前后缀 / 单位 / 协议头 / 内嵌按钮**等"装饰类"形态请用同库 `InputGroup` 复合插槽(见下方 `WithInputGroup` 示例)— 单一职责更清晰,与 shadcn 2025-10 拆分对齐(ADR 0029)。',
|
|
15
20
|
},
|
|
16
21
|
},
|
|
17
22
|
},
|
|
18
23
|
argTypes: {
|
|
19
|
-
size: { control: 'inline-radio', options: ['sm', '
|
|
24
|
+
size: { control: 'inline-radio', options: ['sm', 'md', 'lg'] },
|
|
20
25
|
type: {
|
|
21
26
|
control: 'select',
|
|
22
27
|
options: ['text', 'email', 'password', 'search', 'tel', 'url'],
|
|
@@ -24,15 +29,17 @@ const meta: Meta<typeof Input> = {
|
|
|
24
29
|
clearable: { control: 'boolean' },
|
|
25
30
|
showCount: { control: 'boolean' },
|
|
26
31
|
disabled: { control: 'boolean' },
|
|
32
|
+
error: { control: 'boolean' },
|
|
27
33
|
placeholder: { control: 'text' },
|
|
28
34
|
maxLength: { control: 'number' },
|
|
29
35
|
},
|
|
30
36
|
args: {
|
|
31
|
-
size: '
|
|
37
|
+
size: 'md',
|
|
32
38
|
type: 'text',
|
|
33
39
|
clearable: false,
|
|
34
40
|
showCount: false,
|
|
35
41
|
disabled: false,
|
|
42
|
+
error: false,
|
|
36
43
|
placeholder: '请输入...',
|
|
37
44
|
},
|
|
38
45
|
decorators: [
|
|
@@ -53,35 +60,9 @@ export const Sizes: Story = {
|
|
|
53
60
|
parameters: { controls: { disable: true } },
|
|
54
61
|
render: () => (
|
|
55
62
|
<div className="flex flex-col gap-3">
|
|
56
|
-
<Input size="sm" placeholder="Small" />
|
|
57
|
-
<Input size="
|
|
58
|
-
<Input size="lg" placeholder="Large" />
|
|
59
|
-
</div>
|
|
60
|
-
),
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export const PrefixSuffix: Story = {
|
|
64
|
-
parameters: { controls: { disable: true } },
|
|
65
|
-
render: () => (
|
|
66
|
-
<div className="flex flex-col gap-3">
|
|
67
|
-
<Input prefix={<Search />} placeholder="搜索..." />
|
|
68
|
-
<Input type="email" suffix={<Mail />} placeholder="you@example.com" />
|
|
69
|
-
<Input prefix="¥" suffix="USD" placeholder="0.00" />
|
|
70
|
-
</div>
|
|
71
|
-
),
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export const Addon: Story = {
|
|
75
|
-
parameters: { controls: { disable: true } },
|
|
76
|
-
render: () => (
|
|
77
|
-
<div className="flex flex-col gap-3">
|
|
78
|
-
<Input
|
|
79
|
-
addonBefore="https://"
|
|
80
|
-
defaultValue="teamix-evo"
|
|
81
|
-
addonAfter=".com"
|
|
82
|
-
/>
|
|
83
|
-
<Input addonBefore="@" placeholder="username" />
|
|
84
|
-
<Input addonAfter="kg" defaultValue="42" />
|
|
63
|
+
<Input size="sm" placeholder="Small (h-6 / text-xs / 24px)" />
|
|
64
|
+
<Input size="md" placeholder="Medium (h-8 / text-xs / 32px)" />
|
|
65
|
+
<Input size="lg" placeholder="Large (h-9 / text-sm / 36px)" />
|
|
85
66
|
</div>
|
|
86
67
|
),
|
|
87
68
|
};
|
|
@@ -106,6 +87,16 @@ export const ShowCount: Story = {
|
|
|
106
87
|
render: () => <Input showCount maxLength={140} placeholder="发布动态" />,
|
|
107
88
|
};
|
|
108
89
|
|
|
90
|
+
export const Error: Story = {
|
|
91
|
+
parameters: { controls: { disable: true } },
|
|
92
|
+
render: () => (
|
|
93
|
+
<div className="flex flex-col gap-3">
|
|
94
|
+
<Input error placeholder="必填" />
|
|
95
|
+
<Input error defaultValue="非法值" />
|
|
96
|
+
</div>
|
|
97
|
+
),
|
|
98
|
+
};
|
|
99
|
+
|
|
109
100
|
export const Disabled: Story = {
|
|
110
101
|
parameters: { controls: { disable: true } },
|
|
111
102
|
render: () => (
|
|
@@ -115,3 +106,39 @@ export const Disabled: Story = {
|
|
|
115
106
|
</div>
|
|
116
107
|
),
|
|
117
108
|
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* 想加图标 / 单位 / 协议头?用 `InputGroup` 复合插槽 — 不再用已废弃的
|
|
112
|
+
* `prefix` / `suffix` / `addonBefore` / `addonAfter` 快捷 prop(ADR 0029)。
|
|
113
|
+
*
|
|
114
|
+
* 详细演示与 API 见 `数据录入 · Data Entry/InputGroup` 故事集。
|
|
115
|
+
*/
|
|
116
|
+
export const WithInputGroup: Story = {
|
|
117
|
+
name: '配合 InputGroup(替代旧 prefix/suffix/addon)',
|
|
118
|
+
parameters: { controls: { disable: true } },
|
|
119
|
+
render: () => (
|
|
120
|
+
<div className="flex w-80 flex-col gap-3">
|
|
121
|
+
{/* 图标前缀(替代旧 prefix={<Search />}) */}
|
|
122
|
+
<InputGroup>
|
|
123
|
+
<InputGroupAddon position="before" variant="icon">
|
|
124
|
+
<Search className="size-4" />
|
|
125
|
+
</InputGroupAddon>
|
|
126
|
+
<InputGroupInput placeholder="搜索..." />
|
|
127
|
+
</InputGroup>
|
|
128
|
+
|
|
129
|
+
{/* URL 协议头/后缀(替代旧 addonBefore="https://" addonAfter=".com") */}
|
|
130
|
+
<InputGroup>
|
|
131
|
+
<InputGroupAddon position="before">https://</InputGroupAddon>
|
|
132
|
+
<InputGroupInput defaultValue="example" />
|
|
133
|
+
<InputGroupAddon position="after">.com</InputGroupAddon>
|
|
134
|
+
</InputGroup>
|
|
135
|
+
|
|
136
|
+
{/* 金额/单位(替代旧 prefix="¥" suffix="USD") */}
|
|
137
|
+
<InputGroup>
|
|
138
|
+
<InputGroupAddon position="before">¥</InputGroupAddon>
|
|
139
|
+
<InputGroupInput type="number" defaultValue={199} />
|
|
140
|
+
<InputGroupAddon position="after">/ 月</InputGroupAddon>
|
|
141
|
+
</InputGroup>
|
|
142
|
+
</div>
|
|
143
|
+
),
|
|
144
|
+
};
|
|
@@ -1,19 +1,58 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { cva } from 'class-variance-authority';
|
|
2
3
|
import { X } from 'lucide-react';
|
|
3
4
|
|
|
4
5
|
import { cn } from '@/utils/cn';
|
|
5
6
|
|
|
7
|
+
// ─── shared sizing(对齐 Button 三档:24 / 32 / 36px) ────────────────────────
|
|
8
|
+
//
|
|
9
|
+
// 高度 24/32/36px 与 Button / Select 同档;
|
|
10
|
+
// 这里直接用对应的 Tailwind 高度刻度 `h-6 / h-8 / h-9`,字号档位与 Button 同步。
|
|
11
|
+
const SIZE_TO_HEIGHT = {
|
|
12
|
+
sm: 'h-6 text-xs',
|
|
13
|
+
// medium 字号对齐 cd hybridcloud --form-element-medium-font-size: 12px (ADR 0027)
|
|
14
|
+
md: 'h-8 text-xs',
|
|
15
|
+
lg: 'h-9 text-sm',
|
|
16
|
+
/** @deprecated 兼容旧调用,等价于 `md`。 */
|
|
17
|
+
default: 'h-8 text-xs',
|
|
18
|
+
} as const;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Input 主体(无 affix 时直接使用此变体)。
|
|
22
|
+
* 高度 `h-6 / h-8 / h-9`(24 / 32 / 36px,与 Button / Select 同档);
|
|
23
|
+
* 圆角走 Tailwind v4 标准 namespace `--radius-md`(uni-manager 2px / opentrek 6px),
|
|
24
|
+
* 与 Button 同档 — 同行混排时视觉自动对齐。
|
|
25
|
+
*
|
|
26
|
+
* **前后缀 / addon 不再内置** — 需要前后缀图标 / 文本 / 按钮请用同库 `InputGroup`
|
|
27
|
+
* + `InputGroupAddon` + `InputGroupInput` 复合 API(自由嵌套 icon / button / text)。
|
|
28
|
+
* 字符计数 `showCount` + 一键清空 `clearable` 仍保留为 Input 的内建逻辑能力。
|
|
29
|
+
*/
|
|
30
|
+
const inputVariants = cva(
|
|
31
|
+
'flex w-full rounded-md border border-input bg-background px-3 py-1 shadow-sm transition-colors 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',
|
|
32
|
+
{
|
|
33
|
+
variants: { size: SIZE_TO_HEIGHT },
|
|
34
|
+
defaultVariants: { size: 'md' },
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Input 包壳容器(`clearable` 启用时承载 border + ring,把内部 input 的边框转移到外层)。
|
|
40
|
+
*/
|
|
41
|
+
const inputWrapperVariants = cva(
|
|
42
|
+
'flex w-full items-center gap-2 rounded-md border border-input bg-background px-3 shadow-sm transition-colors focus-within:ring-1 focus-within:ring-ring aria-invalid:border-destructive aria-invalid:focus-within:ring-destructive',
|
|
43
|
+
{
|
|
44
|
+
variants: { size: SIZE_TO_HEIGHT },
|
|
45
|
+
defaultVariants: { size: 'md' },
|
|
46
|
+
},
|
|
47
|
+
);
|
|
48
|
+
|
|
6
49
|
export interface InputProps
|
|
7
|
-
extends Omit<
|
|
8
|
-
React.InputHTMLAttributes<HTMLInputElement>,
|
|
9
|
-
'size' | 'prefix' | 'suffix'
|
|
10
|
-
> {
|
|
11
|
-
/** 输入框前置图标 / 文本(antd `prefix` 并集)。 */
|
|
12
|
-
prefix?: React.ReactNode;
|
|
13
|
-
/** 输入框后置图标 / 文本(antd `suffix` 并集)。 */
|
|
14
|
-
suffix?: React.ReactNode;
|
|
50
|
+
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size' | 'prefix'> {
|
|
15
51
|
/**
|
|
16
52
|
* 显示清除按钮,有内容时点击清空(antd `allowClear` 并集)。
|
|
53
|
+
*
|
|
54
|
+
* 注:仅"快捷一键清空"逻辑保留为 Input 内建能力 — 复合的前后缀(图标 / 文本 / 按钮)
|
|
55
|
+
* 请用 `InputGroup` 系列。
|
|
17
56
|
* @default false
|
|
18
57
|
*/
|
|
19
58
|
clearable?: boolean;
|
|
@@ -22,38 +61,58 @@ export interface InputProps
|
|
|
22
61
|
* @default false
|
|
23
62
|
*/
|
|
24
63
|
showCount?: boolean;
|
|
25
|
-
/** 输入框前置标签(antd `addonBefore` 并集),与外层组合形成 input-group。 */
|
|
26
|
-
addonBefore?: React.ReactNode;
|
|
27
|
-
/** 输入框后置标签(antd `addonAfter` 并集)。 */
|
|
28
|
-
addonAfter?: React.ReactNode;
|
|
29
64
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
65
|
+
* 尺寸三档,与 `Button` 同档:`sm`(24px) / `md`(32px,默认) / `lg`(36px)。
|
|
66
|
+
* `"default"` 为兼容旧调用的别名,等价于 `"md"`,新代码请用 `"md"`。
|
|
67
|
+
* @default "md"
|
|
68
|
+
*/
|
|
69
|
+
size?: 'sm' | 'md' | 'lg' | 'default';
|
|
70
|
+
/**
|
|
71
|
+
* 错误态(快捷开关),会同时设置 `aria-invalid`,渲染 destructive 边框 / ring。
|
|
72
|
+
* 也可以直接传 `aria-invalid` 原生属性达到同效果。
|
|
73
|
+
* @default false
|
|
32
74
|
*/
|
|
33
|
-
|
|
75
|
+
error?: boolean;
|
|
34
76
|
/** 受控值,用于 clearable / showCount 的逻辑;未传时回退到 uncontrolled 行为。 */
|
|
35
77
|
value?: string;
|
|
36
78
|
/** uncontrolled 初始值。 */
|
|
37
79
|
defaultValue?: string;
|
|
38
80
|
}
|
|
39
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Input 单行文本输入 — shadcn 简洁基底 + antd `clearable` / `showCount` / `size` / `error` 并集。
|
|
84
|
+
*
|
|
85
|
+
* **想加图标 / 单位 / 按钮 / 协议头?用 InputGroup 复合插槽:**
|
|
86
|
+
* ```tsx
|
|
87
|
+
* import { InputGroup, InputGroupAddon, InputGroupInput } from '@/components/input-group/input-group';
|
|
88
|
+
* // 搜索图标 + 输入
|
|
89
|
+
* <InputGroup>
|
|
90
|
+
* <InputGroupAddon position="before" variant="icon"><Search /></InputGroupAddon>
|
|
91
|
+
* <InputGroupInput placeholder="搜索..." />
|
|
92
|
+
* </InputGroup>
|
|
93
|
+
* // URL(text 前后缀)
|
|
94
|
+
* <InputGroup>
|
|
95
|
+
* <InputGroupAddon position="before">https://</InputGroupAddon>
|
|
96
|
+
* <InputGroupInput defaultValue="example" />
|
|
97
|
+
* <InputGroupAddon position="after">.com</InputGroupAddon>
|
|
98
|
+
* </InputGroup>
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
40
101
|
const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
|
41
102
|
(
|
|
42
103
|
{
|
|
43
104
|
className,
|
|
44
105
|
type = 'text',
|
|
45
|
-
prefix,
|
|
46
|
-
suffix,
|
|
47
106
|
clearable = false,
|
|
48
107
|
showCount = false,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
size = 'default',
|
|
108
|
+
size = 'md',
|
|
109
|
+
error = false,
|
|
52
110
|
value,
|
|
53
111
|
defaultValue,
|
|
54
112
|
onChange,
|
|
55
113
|
maxLength,
|
|
56
114
|
disabled,
|
|
115
|
+
'aria-invalid': ariaInvalidProp,
|
|
57
116
|
...props
|
|
58
117
|
},
|
|
59
118
|
ref,
|
|
@@ -61,25 +120,13 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
|
|
61
120
|
// Track the current value for clearable / showCount; mirror uncontrolled
|
|
62
121
|
// input via internal state when `value` prop isn't provided.
|
|
63
122
|
const isControlled = value !== undefined;
|
|
64
|
-
const [internal, setInternal] = React.useState<string>(
|
|
65
|
-
defaultValue ?? '',
|
|
66
|
-
);
|
|
123
|
+
const [internal, setInternal] = React.useState<string>(defaultValue ?? '');
|
|
67
124
|
const current = isControlled ? value : internal;
|
|
68
125
|
|
|
69
126
|
const innerRef = React.useRef<HTMLInputElement | null>(null);
|
|
70
|
-
React.useImperativeHandle(
|
|
71
|
-
ref,
|
|
72
|
-
() => innerRef.current as HTMLInputElement,
|
|
73
|
-
);
|
|
127
|
+
React.useImperativeHandle(ref, () => innerRef.current as HTMLInputElement);
|
|
74
128
|
|
|
75
|
-
const
|
|
76
|
-
size === 'sm'
|
|
77
|
-
? 'h-8 text-xs'
|
|
78
|
-
: size === 'lg'
|
|
79
|
-
? 'h-10 text-base'
|
|
80
|
-
: 'h-9 text-sm';
|
|
81
|
-
|
|
82
|
-
const hasAffix = prefix != null || suffix != null || clearable;
|
|
129
|
+
const ariaInvalid = ariaInvalidProp ?? (error ? true : undefined);
|
|
83
130
|
|
|
84
131
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
85
132
|
if (!isControlled) setInternal(e.target.value);
|
|
@@ -88,7 +135,6 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
|
|
88
135
|
|
|
89
136
|
const handleClear = () => {
|
|
90
137
|
if (!isControlled) setInternal('');
|
|
91
|
-
// Synthetic event for callers wiring onChange to a setter
|
|
92
138
|
const target = innerRef.current;
|
|
93
139
|
if (target) {
|
|
94
140
|
const proto = Object.getPrototypeOf(target);
|
|
@@ -98,25 +144,18 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
|
|
98
144
|
}
|
|
99
145
|
};
|
|
100
146
|
|
|
101
|
-
|
|
102
|
-
|
|
147
|
+
const showClearBtn =
|
|
148
|
+
clearable && current && current.length > 0 && !disabled;
|
|
149
|
+
|
|
150
|
+
const innerInput = clearable ? (
|
|
103
151
|
<div
|
|
152
|
+
aria-invalid={ariaInvalid}
|
|
104
153
|
className={cn(
|
|
105
|
-
|
|
106
|
-
h,
|
|
154
|
+
inputWrapperVariants({ size }),
|
|
107
155
|
disabled && 'cursor-not-allowed opacity-50',
|
|
108
|
-
(addonBefore || addonAfter) && 'rounded-none border-x-0',
|
|
109
|
-
addonBefore && !addonAfter && 'rounded-l-none border-l-0',
|
|
110
|
-
addonAfter && !addonBefore && 'rounded-r-none border-r-0',
|
|
111
|
-
!addonBefore && !addonAfter && '',
|
|
112
156
|
className,
|
|
113
157
|
)}
|
|
114
158
|
>
|
|
115
|
-
{prefix ? (
|
|
116
|
-
<span className="flex shrink-0 items-center text-muted-foreground [&_svg]:size-4">
|
|
117
|
-
{prefix}
|
|
118
|
-
</span>
|
|
119
|
-
) : null}
|
|
120
159
|
<input
|
|
121
160
|
ref={innerRef}
|
|
122
161
|
type={type}
|
|
@@ -124,25 +163,21 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
|
|
124
163
|
defaultValue={!isControlled ? defaultValue : undefined}
|
|
125
164
|
maxLength={maxLength}
|
|
126
165
|
disabled={disabled}
|
|
166
|
+
aria-invalid={ariaInvalid}
|
|
127
167
|
onChange={handleChange}
|
|
128
168
|
className="grow bg-transparent outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed"
|
|
129
169
|
{...props}
|
|
130
170
|
/>
|
|
131
|
-
{
|
|
171
|
+
{showClearBtn ? (
|
|
132
172
|
<button
|
|
133
173
|
type="button"
|
|
134
174
|
onClick={handleClear}
|
|
135
175
|
aria-label="Clear"
|
|
136
|
-
className="shrink-0 rounded-sm text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
|
176
|
+
className="shrink-0 cursor-pointer rounded-sm text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
|
137
177
|
>
|
|
138
178
|
<X className="size-4" />
|
|
139
179
|
</button>
|
|
140
180
|
) : null}
|
|
141
|
-
{suffix ? (
|
|
142
|
-
<span className="flex shrink-0 items-center text-muted-foreground [&_svg]:size-4">
|
|
143
|
-
{suffix}
|
|
144
|
-
</span>
|
|
145
|
-
) : null}
|
|
146
181
|
</div>
|
|
147
182
|
) : (
|
|
148
183
|
<input
|
|
@@ -152,62 +187,26 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
|
|
152
187
|
defaultValue={!isControlled ? defaultValue : undefined}
|
|
153
188
|
maxLength={maxLength}
|
|
154
189
|
disabled={disabled}
|
|
190
|
+
aria-invalid={ariaInvalid}
|
|
155
191
|
onChange={handleChange}
|
|
156
|
-
className={cn(
|
|
157
|
-
'flex w-full rounded-md border border-input bg-background px-3 py-1 shadow-sm transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50',
|
|
158
|
-
h,
|
|
159
|
-
(addonBefore || addonAfter) && 'rounded-none',
|
|
160
|
-
addonBefore && !addonAfter && 'rounded-l-none',
|
|
161
|
-
addonAfter && !addonBefore && 'rounded-r-none',
|
|
162
|
-
className,
|
|
163
|
-
)}
|
|
192
|
+
className={cn(inputVariants({ size }), className)}
|
|
164
193
|
{...props}
|
|
165
194
|
/>
|
|
166
195
|
);
|
|
167
196
|
|
|
168
|
-
// Wrap with addons if any
|
|
169
|
-
const addonWrapper =
|
|
170
|
-
addonBefore || addonAfter ? (
|
|
171
|
-
<div className="flex">
|
|
172
|
-
{addonBefore ? (
|
|
173
|
-
<span
|
|
174
|
-
className={cn(
|
|
175
|
-
'inline-flex shrink-0 items-center rounded-l-md border border-r-0 border-input bg-muted px-3 text-muted-foreground',
|
|
176
|
-
h,
|
|
177
|
-
)}
|
|
178
|
-
>
|
|
179
|
-
{addonBefore}
|
|
180
|
-
</span>
|
|
181
|
-
) : null}
|
|
182
|
-
{innerInput}
|
|
183
|
-
{addonAfter ? (
|
|
184
|
-
<span
|
|
185
|
-
className={cn(
|
|
186
|
-
'inline-flex shrink-0 items-center rounded-r-md border border-l-0 border-input bg-muted px-3 text-muted-foreground',
|
|
187
|
-
h,
|
|
188
|
-
)}
|
|
189
|
-
>
|
|
190
|
-
{addonAfter}
|
|
191
|
-
</span>
|
|
192
|
-
) : null}
|
|
193
|
-
</div>
|
|
194
|
-
) : (
|
|
195
|
-
innerInput
|
|
196
|
-
);
|
|
197
|
-
|
|
198
197
|
if (showCount && maxLength) {
|
|
199
198
|
return (
|
|
200
|
-
<div className="
|
|
201
|
-
{
|
|
199
|
+
<div className="flex flex-col gap-1">
|
|
200
|
+
{innerInput}
|
|
202
201
|
<div className="text-right text-xs text-muted-foreground tabular-nums">
|
|
203
202
|
{current?.length ?? 0} / {maxLength}
|
|
204
203
|
</div>
|
|
205
204
|
</div>
|
|
206
205
|
);
|
|
207
206
|
}
|
|
208
|
-
return
|
|
207
|
+
return innerInput;
|
|
209
208
|
},
|
|
210
209
|
);
|
|
211
210
|
Input.displayName = 'Input';
|
|
212
211
|
|
|
213
|
-
export { Input };
|
|
212
|
+
export { Input, inputVariants };
|
|
@@ -2,27 +2,35 @@
|
|
|
2
2
|
id: input-group
|
|
3
3
|
name: InputGroup
|
|
4
4
|
type: component
|
|
5
|
-
category:
|
|
6
|
-
since: 0.
|
|
7
|
-
package:
|
|
5
|
+
category: data-entry
|
|
6
|
+
since: 0.2.0
|
|
7
|
+
package: '@teamix-evo/ui'
|
|
8
|
+
displayName: 输入框组
|
|
8
9
|
---
|
|
9
10
|
|
|
10
|
-
# InputGroup
|
|
11
|
+
# InputGroup 输入框组
|
|
11
12
|
|
|
12
|
-
输入框 + addon 统一容器 — shadcn 2025-10
|
|
13
|
+
输入框 + addon 统一容器 — **shadcn 2025-10 新增**。等价 antd `Input` 的 `prefix` / `suffix` / `addonBefore` / `addonAfter` 集合,**单独一个 entry**,与 [`Input`](../input/input.meta.md) 拆开管理(对齐 shadcn 2025-10 拆分粒度)。
|
|
14
|
+
|
|
15
|
+
复合插槽:`<InputGroupAddon position variant>` + `<InputGroupInput>` / `<InputGroupTextarea>`,自由嵌套图标 / 按钮 / 文本(URL / 金额 / 搜索 / Send 等形态)。容器外壳承担 border + ring + focus-within,内部全部去边框 — 与 Input / Button / Select 同档高度(32px)。
|
|
13
16
|
|
|
14
17
|
## When to use
|
|
15
18
|
|
|
16
|
-
-
|
|
17
|
-
- 输入框 + 操作按钮(
|
|
18
|
-
- 输入框 + 图标(
|
|
19
|
-
- Textarea + 上传 /
|
|
19
|
+
- 输入框需要**前 / 后缀**(`https://` `.com`、`¥`、`/ 月`)
|
|
20
|
+
- 输入框 + 操作按钮(搜索、清空、复制、Send)
|
|
21
|
+
- 输入框 + 图标(搜索、loading spinner、状态指示)
|
|
22
|
+
- Textarea + 上传 / 录音 / 发送类辅助按钮
|
|
20
23
|
|
|
21
24
|
## When NOT to use
|
|
22
25
|
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
+
- 仅"一键清空" → `Input` 自带 `clearable`,无需 InputGroup 包裹
|
|
27
|
+
- 字符计数 → `Input` 自带 `showCount` + `maxLength`
|
|
28
|
+
- @提及输入 → `Mentions`
|
|
29
|
+
- 多个**独立**输入框横排(姓 / 名 / 中间名)→ 用 `Flex` 直接 gap 排列,不要套 InputGroup(InputGroup 的"统一外壳"语义不适用)
|
|
30
|
+
|
|
31
|
+
## Props
|
|
32
|
+
|
|
33
|
+
> 以下表格由 `pnpm --filter @teamix-evo/ui gen:meta` 自动生成。
|
|
26
34
|
|
|
27
35
|
<!-- auto:props:begin -->
|
|
28
36
|
| 名称 | 类型 | 默认值 | 必填 | 说明 |
|
|
@@ -30,6 +38,10 @@ package: "@teamix-evo/ui"
|
|
|
30
38
|
| `disabled` | `boolean` | – | – | 整组禁用样式(子项请单独传 `disabled`,这里仅影响视觉上的 opacity)。 |
|
|
31
39
|
<!-- auto:props:end -->
|
|
32
40
|
|
|
41
|
+
## 依赖
|
|
42
|
+
|
|
43
|
+
> 以下表格由 `pnpm --filter @teamix-evo/ui gen:meta` 自动生成,数据源是 [`manifest.json`](../../../manifest.json)。**手工编辑 marker 之间的内容会在下次生成时被覆盖**。
|
|
44
|
+
|
|
33
45
|
<!-- auto:deps:begin -->
|
|
34
46
|
### 同库依赖
|
|
35
47
|
|
|
@@ -46,11 +58,13 @@ _无 — 本组件不依赖任何 npm 包。_
|
|
|
46
58
|
|
|
47
59
|
## AI 生成纪律
|
|
48
60
|
|
|
49
|
-
- **顺序按 JSX 写**:`<InputGroup>` 内的子节点顺序就是渲染顺序
|
|
50
|
-
- **不要在 InputGroupAddon 里再放 Input**
|
|
61
|
+
- **顺序按 JSX 写**:`<InputGroup>` 内的子节点顺序就是渲染顺序 —— `<InputGroupAddon position="before" />` 必须在主体前
|
|
62
|
+
- **不要在 `InputGroupAddon` 里再放 Input** —— addon 是辅助槽,主输入必须用 `InputGroupInput` / `InputGroupTextarea`
|
|
51
63
|
- **`variant="icon"`** 给图标用(无背景、紧凑);**`variant="text"`** 给纯文本前后缀(muted 背景);**`variant="button"`** 给嵌入 Button(去内边距 + 去圆角,避免双重边线)
|
|
52
|
-
-
|
|
53
|
-
-
|
|
64
|
+
- **嵌入 `Button`**:用 `<InputGroupAddon variant="button">` 包,Button 自身 `variant="ghost"` 或 `size="icon"` 效果最自然
|
|
65
|
+
- **不要套两层** —— `<InputGroup>` 内不要再嵌 `<Input>`(主输入用 `<InputGroupInput>`,因为 Input 自带 border 会与外壳冲突 1px 几何)
|
|
66
|
+
- **error 态走子项 `aria-invalid`** —— InputGroup 不直接支持 `error` prop,把 `aria-invalid` 写在 `InputGroupInput` 上即可触发外壳的 destructive 边框
|
|
67
|
+
- **不要硬编码颜色** —— `bg-background` / `border-input` / `bg-muted` 都是 design token
|
|
54
68
|
|
|
55
69
|
## Examples
|
|
56
70
|
|
|
@@ -64,29 +78,47 @@ import {
|
|
|
64
78
|
import { Button } from '@/components/ui/button';
|
|
65
79
|
import { Search, Send } from 'lucide-react';
|
|
66
80
|
|
|
67
|
-
//
|
|
81
|
+
// 搜索图标 + 输入(替代旧 <Input prefix={<Search />} />)
|
|
68
82
|
<InputGroup>
|
|
69
83
|
<InputGroupAddon position="before" variant="icon">
|
|
70
84
|
<Search className="size-4" />
|
|
71
85
|
</InputGroupAddon>
|
|
72
86
|
<InputGroupInput placeholder="搜索文档..." />
|
|
73
|
-
<InputGroupAddon position="after" variant="button">
|
|
74
|
-
<Button variant="ghost" size="sm">搜索</Button>
|
|
75
|
-
</InputGroupAddon>
|
|
76
87
|
</InputGroup>
|
|
77
88
|
|
|
78
|
-
//
|
|
89
|
+
// URL 输入(替代旧 <Input addonBefore="https://" addonAfter=".com" />)
|
|
79
90
|
<InputGroup>
|
|
80
91
|
<InputGroupAddon position="before">https://</InputGroupAddon>
|
|
81
92
|
<InputGroupInput defaultValue="example" />
|
|
82
93
|
<InputGroupAddon position="after">.com</InputGroupAddon>
|
|
83
94
|
</InputGroup>
|
|
84
95
|
|
|
85
|
-
//
|
|
96
|
+
// 金额输入
|
|
86
97
|
<InputGroup>
|
|
98
|
+
<InputGroupAddon position="before">¥</InputGroupAddon>
|
|
99
|
+
<InputGroupInput type="number" defaultValue={199} />
|
|
100
|
+
<InputGroupAddon position="after">/ 月</InputGroupAddon>
|
|
101
|
+
</InputGroup>
|
|
102
|
+
|
|
103
|
+
// Textarea + 发送按钮
|
|
104
|
+
<InputGroup className="items-end">
|
|
87
105
|
<InputGroupTextarea rows={3} placeholder="发表评论..." />
|
|
88
106
|
<InputGroupAddon position="after" variant="button">
|
|
89
107
|
<Button size="icon" icon={<Send />} aria-label="发送" />
|
|
90
108
|
</InputGroupAddon>
|
|
91
109
|
</InputGroup>
|
|
92
110
|
```
|
|
111
|
+
|
|
112
|
+
## Migration · 从旧 `Input` 快捷 prop 迁移
|
|
113
|
+
|
|
114
|
+
> v0.2 起 `<Input>` 的 `prefix` / `suffix` / `addonBefore` / `addonAfter` 已**移除**。请改用 InputGroup 复合 API(更灵活、可嵌任意子节点)。
|
|
115
|
+
|
|
116
|
+
| 旧用法(已移除) | 新用法 |
|
|
117
|
+
| ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
118
|
+
| `<Input prefix={<Search />} />` | `<InputGroup><InputGroupAddon position="before" variant="icon"><Search /></InputGroupAddon><InputGroupInput /></InputGroup>` |
|
|
119
|
+
| `<Input suffix={<Mail />} />` | `<InputGroup><InputGroupInput /><InputGroupAddon position="after" variant="icon"><Mail /></InputGroupAddon></InputGroup>` |
|
|
120
|
+
| `<Input addonBefore="https://" />` | `<InputGroup><InputGroupAddon position="before">https://</InputGroupAddon><InputGroupInput /></InputGroup>` |
|
|
121
|
+
| `<Input addonAfter=".com" />` | `<InputGroup><InputGroupInput /><InputGroupAddon position="after">.com</InputGroupAddon></InputGroup>` |
|
|
122
|
+
| `<Input prefix="¥" suffix="USD" />` | `<InputGroup><InputGroupAddon position="before">¥</InputGroupAddon><InputGroupInput /><InputGroupAddon position="after">USD</InputGroupAddon></InputGroup>` |
|
|
123
|
+
|
|
124
|
+
> 保留在 Input 的快捷能力:`clearable`(逻辑) / `showCount`(下方计数)/ `size` / `error` —— 这些与"前后缀"语义无关,继续作为 Input 的内建逻辑能力。
|