@teamix-evo/ui 0.1.1
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/LICENSE +21 -0
- package/README.md +336 -0
- package/_data.json +12 -0
- package/manifest.json +1688 -0
- package/package.json +90 -0
- package/src/components/accordion/accordion.meta.md +87 -0
- package/src/components/accordion/accordion.stories.tsx +67 -0
- package/src/components/accordion/accordion.tsx +58 -0
- package/src/components/affix/affix.meta.md +80 -0
- package/src/components/affix/affix.stories.tsx +57 -0
- package/src/components/affix/affix.tsx +97 -0
- package/src/components/alert/alert.meta.md +101 -0
- package/src/components/alert/alert.stories.tsx +93 -0
- package/src/components/alert/alert.tsx +132 -0
- package/src/components/alert-dialog/alert-dialog.meta.md +107 -0
- package/src/components/alert-dialog/alert-dialog.stories.tsx +81 -0
- package/src/components/alert-dialog/alert-dialog.tsx +136 -0
- package/src/components/anchor/anchor.meta.md +87 -0
- package/src/components/anchor/anchor.stories.tsx +74 -0
- package/src/components/anchor/anchor.tsx +130 -0
- package/src/components/app/app.meta.md +86 -0
- package/src/components/app/app.stories.tsx +62 -0
- package/src/components/app/app.tsx +58 -0
- package/src/components/aspect-ratio/aspect-ratio.meta.md +81 -0
- package/src/components/aspect-ratio/aspect-ratio.stories.tsx +59 -0
- package/src/components/aspect-ratio/aspect-ratio.tsx +22 -0
- package/src/components/auto-complete/auto-complete.meta.md +102 -0
- package/src/components/auto-complete/auto-complete.stories.tsx +93 -0
- package/src/components/auto-complete/auto-complete.tsx +205 -0
- package/src/components/avatar/avatar.meta.md +94 -0
- package/src/components/avatar/avatar.stories.tsx +80 -0
- package/src/components/avatar/avatar.tsx +126 -0
- package/src/components/badge/badge.meta.md +119 -0
- package/src/components/badge/badge.stories.tsx +153 -0
- package/src/components/badge/badge.tsx +210 -0
- package/src/components/breadcrumb/breadcrumb.meta.md +107 -0
- package/src/components/breadcrumb/breadcrumb.stories.tsx +84 -0
- package/src/components/breadcrumb/breadcrumb.tsx +122 -0
- package/src/components/button/button.meta.md +98 -0
- package/src/components/button/button.stories.tsx +235 -0
- package/src/components/button/button.tsx +160 -0
- package/src/components/button-group/button-group.meta.md +92 -0
- package/src/components/button-group/button-group.stories.tsx +90 -0
- package/src/components/button-group/button-group.tsx +75 -0
- package/src/components/calendar/calendar.meta.md +118 -0
- package/src/components/calendar/calendar.stories.tsx +68 -0
- package/src/components/calendar/calendar.tsx +107 -0
- package/src/components/card/card.meta.md +117 -0
- package/src/components/card/card.stories.tsx +112 -0
- package/src/components/card/card.tsx +222 -0
- package/src/components/carousel/carousel.meta.md +117 -0
- package/src/components/carousel/carousel.stories.tsx +84 -0
- package/src/components/carousel/carousel.tsx +224 -0
- package/src/components/cascader/cascader.meta.md +110 -0
- package/src/components/cascader/cascader.stories.tsx +108 -0
- package/src/components/cascader/cascader.tsx +198 -0
- package/src/components/checkbox/checkbox.meta.md +99 -0
- package/src/components/checkbox/checkbox.stories.tsx +130 -0
- package/src/components/checkbox/checkbox.tsx +125 -0
- package/src/components/collapsible/collapsible.meta.md +80 -0
- package/src/components/collapsible/collapsible.stories.tsx +35 -0
- package/src/components/collapsible/collapsible.tsx +18 -0
- package/src/components/color-picker/color-picker.meta.md +84 -0
- package/src/components/color-picker/color-picker.stories.tsx +80 -0
- package/src/components/color-picker/color-picker.tsx +160 -0
- package/src/components/combobox/combobox.meta.md +93 -0
- package/src/components/combobox/combobox.stories.tsx +55 -0
- package/src/components/combobox/combobox.tsx +130 -0
- package/src/components/command/command.meta.md +104 -0
- package/src/components/command/command.stories.tsx +59 -0
- package/src/components/command/command.tsx +147 -0
- package/src/components/context-menu/context-menu.meta.md +90 -0
- package/src/components/context-menu/context-menu.stories.tsx +46 -0
- package/src/components/context-menu/context-menu.tsx +191 -0
- package/src/components/data-table/data-table.meta.md +149 -0
- package/src/components/data-table/data-table.stories.tsx +125 -0
- package/src/components/data-table/data-table.tsx +185 -0
- package/src/components/date-picker/date-picker.meta.md +106 -0
- package/src/components/date-picker/date-picker.stories.tsx +58 -0
- package/src/components/date-picker/date-picker.tsx +156 -0
- package/src/components/descriptions/descriptions.meta.md +78 -0
- package/src/components/descriptions/descriptions.stories.tsx +60 -0
- package/src/components/descriptions/descriptions.tsx +129 -0
- package/src/components/dialog/dialog.meta.md +105 -0
- package/src/components/dialog/dialog.stories.tsx +93 -0
- package/src/components/dialog/dialog.tsx +128 -0
- package/src/components/drawer/drawer.meta.md +96 -0
- package/src/components/drawer/drawer.stories.tsx +54 -0
- package/src/components/drawer/drawer.tsx +114 -0
- package/src/components/dropdown-menu/dropdown-menu.meta.md +103 -0
- package/src/components/dropdown-menu/dropdown-menu.stories.tsx +112 -0
- package/src/components/dropdown-menu/dropdown-menu.tsx +195 -0
- package/src/components/empty/empty.meta.md +81 -0
- package/src/components/empty/empty.stories.tsx +46 -0
- package/src/components/empty/empty.tsx +47 -0
- package/src/components/field/field.meta.md +116 -0
- package/src/components/field/field.stories.tsx +117 -0
- package/src/components/field/field.tsx +164 -0
- package/src/components/flex/flex.meta.md +94 -0
- package/src/components/flex/flex.stories.tsx +112 -0
- package/src/components/flex/flex.tsx +122 -0
- package/src/components/float-button/float-button.meta.md +87 -0
- package/src/components/float-button/float-button.stories.tsx +78 -0
- package/src/components/float-button/float-button.tsx +143 -0
- package/src/components/form/form.meta.md +131 -0
- package/src/components/form/form.stories.tsx +122 -0
- package/src/components/form/form.tsx +194 -0
- package/src/components/grid/grid.meta.md +87 -0
- package/src/components/grid/grid.stories.tsx +99 -0
- package/src/components/grid/grid.tsx +130 -0
- package/src/components/hover-card/hover-card.meta.md +92 -0
- package/src/components/hover-card/hover-card.stories.tsx +68 -0
- package/src/components/hover-card/hover-card.tsx +29 -0
- package/src/components/image/image.meta.md +94 -0
- package/src/components/image/image.stories.tsx +55 -0
- package/src/components/image/image.tsx +138 -0
- package/src/components/input/input.meta.md +109 -0
- package/src/components/input/input.stories.tsx +117 -0
- package/src/components/input/input.tsx +213 -0
- package/src/components/input-group/input-group.meta.md +92 -0
- package/src/components/input-group/input-group.stories.tsx +88 -0
- package/src/components/input-group/input-group.tsx +107 -0
- package/src/components/input-number/input-number.meta.md +91 -0
- package/src/components/input-number/input-number.stories.tsx +87 -0
- package/src/components/input-number/input-number.tsx +210 -0
- package/src/components/input-otp/input-otp.meta.md +105 -0
- package/src/components/input-otp/input-otp.stories.tsx +65 -0
- package/src/components/input-otp/input-otp.tsx +97 -0
- package/src/components/item/item.meta.md +116 -0
- package/src/components/item/item.stories.tsx +113 -0
- package/src/components/item/item.tsx +171 -0
- package/src/components/kbd/kbd.meta.md +85 -0
- package/src/components/kbd/kbd.stories.tsx +70 -0
- package/src/components/kbd/kbd.tsx +81 -0
- package/src/components/label/label.meta.md +91 -0
- package/src/components/label/label.stories.tsx +87 -0
- package/src/components/label/label.tsx +66 -0
- package/src/components/masonry/masonry.meta.md +85 -0
- package/src/components/masonry/masonry.stories.tsx +66 -0
- package/src/components/masonry/masonry.tsx +59 -0
- package/src/components/mentions/mentions.meta.md +89 -0
- package/src/components/mentions/mentions.stories.tsx +75 -0
- package/src/components/mentions/mentions.tsx +237 -0
- package/src/components/menubar/menubar.meta.md +100 -0
- package/src/components/menubar/menubar.stories.tsx +81 -0
- package/src/components/menubar/menubar.tsx +232 -0
- package/src/components/native-select/native-select.meta.md +88 -0
- package/src/components/native-select/native-select.stories.tsx +80 -0
- package/src/components/native-select/native-select.tsx +54 -0
- package/src/components/navigation-menu/navigation-menu.meta.md +108 -0
- package/src/components/navigation-menu/navigation-menu.stories.tsx +112 -0
- package/src/components/navigation-menu/navigation-menu.tsx +125 -0
- package/src/components/notification/notification.meta.md +91 -0
- package/src/components/notification/notification.stories.tsx +96 -0
- package/src/components/notification/notification.tsx +84 -0
- package/src/components/pagination/pagination.meta.md +127 -0
- package/src/components/pagination/pagination.stories.tsx +62 -0
- package/src/components/pagination/pagination.tsx +285 -0
- package/src/components/popconfirm/popconfirm.meta.md +109 -0
- package/src/components/popconfirm/popconfirm.stories.tsx +76 -0
- package/src/components/popconfirm/popconfirm.tsx +134 -0
- package/src/components/popover/popover.meta.md +97 -0
- package/src/components/popover/popover.stories.tsx +82 -0
- package/src/components/popover/popover.tsx +55 -0
- package/src/components/progress/progress.meta.md +86 -0
- package/src/components/progress/progress.stories.tsx +75 -0
- package/src/components/progress/progress.tsx +195 -0
- package/src/components/radio-group/radio-group.meta.md +103 -0
- package/src/components/radio-group/radio-group.stories.tsx +77 -0
- package/src/components/radio-group/radio-group.tsx +78 -0
- package/src/components/rate/rate.meta.md +87 -0
- package/src/components/rate/rate.stories.tsx +81 -0
- package/src/components/rate/rate.tsx +153 -0
- package/src/components/resizable/resizable.meta.md +92 -0
- package/src/components/resizable/resizable.stories.tsx +104 -0
- package/src/components/resizable/resizable.tsx +56 -0
- package/src/components/result/result.meta.md +90 -0
- package/src/components/result/result.stories.tsx +71 -0
- package/src/components/result/result.tsx +91 -0
- package/src/components/scroll-area/scroll-area.meta.md +84 -0
- package/src/components/scroll-area/scroll-area.stories.tsx +41 -0
- package/src/components/scroll-area/scroll-area.tsx +51 -0
- package/src/components/segmented/segmented.meta.md +103 -0
- package/src/components/segmented/segmented.stories.tsx +101 -0
- package/src/components/segmented/segmented.tsx +138 -0
- package/src/components/select/select.meta.md +110 -0
- package/src/components/select/select.stories.tsx +100 -0
- package/src/components/select/select.tsx +188 -0
- package/src/components/separator/separator.meta.md +74 -0
- package/src/components/separator/separator.stories.tsx +71 -0
- package/src/components/separator/separator.tsx +104 -0
- package/src/components/sheet/sheet.meta.md +97 -0
- package/src/components/sheet/sheet.stories.tsx +82 -0
- package/src/components/sheet/sheet.tsx +139 -0
- package/src/components/sidebar/sidebar.meta.md +131 -0
- package/src/components/sidebar/sidebar.stories.tsx +82 -0
- package/src/components/sidebar/sidebar.tsx +351 -0
- package/src/components/skeleton/skeleton.meta.md +95 -0
- package/src/components/skeleton/skeleton.stories.tsx +79 -0
- package/src/components/skeleton/skeleton.tsx +144 -0
- package/src/components/slider/slider.meta.md +94 -0
- package/src/components/slider/slider.stories.tsx +69 -0
- package/src/components/slider/slider.tsx +86 -0
- package/src/components/sonner/sonner.meta.md +96 -0
- package/src/components/sonner/sonner.stories.tsx +91 -0
- package/src/components/sonner/sonner.tsx +40 -0
- package/src/components/space/space.meta.md +94 -0
- package/src/components/space/space.stories.tsx +94 -0
- package/src/components/space/space.tsx +106 -0
- package/src/components/spinner/spinner.meta.md +76 -0
- package/src/components/spinner/spinner.stories.tsx +71 -0
- package/src/components/spinner/spinner.tsx +64 -0
- package/src/components/statistic/statistic.meta.md +99 -0
- package/src/components/statistic/statistic.stories.tsx +71 -0
- package/src/components/statistic/statistic.tsx +197 -0
- package/src/components/steps/steps.meta.md +102 -0
- package/src/components/steps/steps.stories.tsx +75 -0
- package/src/components/steps/steps.tsx +170 -0
- package/src/components/switch/switch.meta.md +92 -0
- package/src/components/switch/switch.stories.tsx +75 -0
- package/src/components/switch/switch.tsx +101 -0
- package/src/components/table/table.meta.md +95 -0
- package/src/components/table/table.stories.tsx +75 -0
- package/src/components/table/table.tsx +122 -0
- package/src/components/tabs/tabs.meta.md +98 -0
- package/src/components/tabs/tabs.stories.tsx +70 -0
- package/src/components/tabs/tabs.tsx +119 -0
- package/src/components/tag/tag.meta.md +94 -0
- package/src/components/tag/tag.stories.tsx +77 -0
- package/src/components/tag/tag.tsx +185 -0
- package/src/components/textarea/textarea.meta.md +83 -0
- package/src/components/textarea/textarea.stories.tsx +63 -0
- package/src/components/textarea/textarea.tsx +113 -0
- package/src/components/time-picker/time-picker.meta.md +83 -0
- package/src/components/time-picker/time-picker.stories.tsx +59 -0
- package/src/components/time-picker/time-picker.tsx +94 -0
- package/src/components/timeline/timeline.meta.md +102 -0
- package/src/components/timeline/timeline.stories.tsx +104 -0
- package/src/components/timeline/timeline.tsx +147 -0
- package/src/components/toggle/toggle.meta.md +88 -0
- package/src/components/toggle/toggle.stories.tsx +66 -0
- package/src/components/toggle/toggle.tsx +53 -0
- package/src/components/toggle-group/toggle-group.meta.md +90 -0
- package/src/components/toggle-group/toggle-group.stories.tsx +83 -0
- package/src/components/toggle-group/toggle-group.tsx +78 -0
- package/src/components/tooltip/tooltip.meta.md +99 -0
- package/src/components/tooltip/tooltip.stories.tsx +71 -0
- package/src/components/tooltip/tooltip.tsx +93 -0
- package/src/components/tour/tour.meta.md +116 -0
- package/src/components/tour/tour.stories.tsx +66 -0
- package/src/components/tour/tour.tsx +242 -0
- package/src/components/transfer/transfer.meta.md +90 -0
- package/src/components/transfer/transfer.stories.tsx +68 -0
- package/src/components/transfer/transfer.tsx +251 -0
- package/src/components/tree/tree.meta.md +111 -0
- package/src/components/tree/tree.stories.tsx +109 -0
- package/src/components/tree/tree.tsx +367 -0
- package/src/components/tree-select/tree-select.meta.md +100 -0
- package/src/components/tree-select/tree-select.stories.tsx +80 -0
- package/src/components/tree-select/tree-select.tsx +171 -0
- package/src/components/typography/typography.meta.md +102 -0
- package/src/components/typography/typography.stories.tsx +115 -0
- package/src/components/typography/typography.tsx +245 -0
- package/src/components/upload/upload.meta.md +111 -0
- package/src/components/upload/upload.stories.tsx +75 -0
- package/src/components/upload/upload.tsx +265 -0
- package/src/components/watermark/watermark.meta.md +95 -0
- package/src/components/watermark/watermark.stories.tsx +78 -0
- package/src/components/watermark/watermark.tsx +165 -0
- package/src/utils/cn.ts +6 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { Flex } from './flex';
|
|
3
|
+
import { Button } from '@/components/button/button';
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof Flex> = {
|
|
6
|
+
title: '布局与容器 · Layout/Flex',
|
|
7
|
+
component: Flex,
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
parameters: {
|
|
10
|
+
docs: {
|
|
11
|
+
description: {
|
|
12
|
+
component:
|
|
13
|
+
'Flex 布局容器 — 把 Tailwind flex 的常用配置(对齐 / 间距 / 换行 / 方向 / 渲染元素)收敛为枚举。等价 antd `Flex`(v5.10+),与 Space 互补:Flex 偏完整布局容器,Space 偏 inline 小集合。视觉走 OpenTrek tokens,所有样式来自 `@teamix-evo/design`,无 mock。',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
argTypes: {
|
|
18
|
+
direction: {
|
|
19
|
+
control: 'inline-radio',
|
|
20
|
+
options: ['row', 'column', 'row-reverse', 'column-reverse'],
|
|
21
|
+
},
|
|
22
|
+
gap: { control: 'select', options: ['none', 'xs', 'sm', 'default', 'lg', 'xl'] },
|
|
23
|
+
align: {
|
|
24
|
+
control: 'inline-radio',
|
|
25
|
+
options: ['start', 'center', 'end', 'baseline', 'stretch'],
|
|
26
|
+
},
|
|
27
|
+
justify: {
|
|
28
|
+
control: 'select',
|
|
29
|
+
options: ['start', 'center', 'end', 'between', 'around', 'evenly'],
|
|
30
|
+
},
|
|
31
|
+
wrap: { control: 'boolean' },
|
|
32
|
+
inline: { control: 'boolean' },
|
|
33
|
+
},
|
|
34
|
+
args: {
|
|
35
|
+
direction: 'row',
|
|
36
|
+
gap: 'default',
|
|
37
|
+
align: 'stretch',
|
|
38
|
+
justify: 'start',
|
|
39
|
+
wrap: false,
|
|
40
|
+
inline: false,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export default meta;
|
|
45
|
+
type Story = StoryObj<typeof Flex>;
|
|
46
|
+
|
|
47
|
+
const swatch = (label: string) => (
|
|
48
|
+
<div className="grid h-12 w-20 place-items-center rounded-md border bg-muted text-xs">
|
|
49
|
+
{label}
|
|
50
|
+
</div>
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
export const Playground: Story = {
|
|
54
|
+
render: (args) => (
|
|
55
|
+
<Flex {...args} className="min-h-32 rounded-md border bg-card p-4">
|
|
56
|
+
{swatch('A')}
|
|
57
|
+
{swatch('B')}
|
|
58
|
+
{swatch('C')}
|
|
59
|
+
</Flex>
|
|
60
|
+
),
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const Header: Story = {
|
|
64
|
+
parameters: { controls: { disable: true } },
|
|
65
|
+
render: () => (
|
|
66
|
+
<Flex as="header" justify="between" align="center" className="rounded-md border bg-card px-6 py-3">
|
|
67
|
+
<span className="font-semibold">Logo</span>
|
|
68
|
+
<Flex gap="sm">
|
|
69
|
+
<a href="#" className="text-sm hover:underline">首页</a>
|
|
70
|
+
<a href="#" className="text-sm hover:underline">文档</a>
|
|
71
|
+
<a href="#" className="text-sm hover:underline">价格</a>
|
|
72
|
+
</Flex>
|
|
73
|
+
<Button size="sm">登录</Button>
|
|
74
|
+
</Flex>
|
|
75
|
+
),
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export const ColumnStack: Story = {
|
|
79
|
+
parameters: { controls: { disable: true } },
|
|
80
|
+
render: () => (
|
|
81
|
+
<Flex direction="column" gap="sm" className="w-80 rounded-md border bg-card p-6">
|
|
82
|
+
<span className="text-lg font-semibold">标题</span>
|
|
83
|
+
<span className="text-sm text-muted-foreground">这是一段描述文字</span>
|
|
84
|
+
<Button>操作</Button>
|
|
85
|
+
</Flex>
|
|
86
|
+
),
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const Toolbar: Story = {
|
|
90
|
+
parameters: { controls: { disable: true } },
|
|
91
|
+
render: () => (
|
|
92
|
+
<Flex justify="end" gap="sm" className="rounded-md border bg-card p-3">
|
|
93
|
+
<Button variant="outline">取消</Button>
|
|
94
|
+
<Button>提交</Button>
|
|
95
|
+
</Flex>
|
|
96
|
+
),
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const WrapCloud: Story = {
|
|
100
|
+
parameters: { controls: { disable: true } },
|
|
101
|
+
render: () => (
|
|
102
|
+
<Flex wrap gap="sm" className="w-96 rounded-md border bg-card p-3">
|
|
103
|
+
{['React', 'Vue', 'Svelte', 'Solid', 'Angular', 'Lit', 'Qwik', 'Astro', 'Next', 'Remix', 'Nuxt', 'Gatsby'].map(
|
|
104
|
+
(t) => (
|
|
105
|
+
<span key={t} className="rounded-md border bg-muted px-2 py-0.5 text-xs">
|
|
106
|
+
{t}
|
|
107
|
+
</span>
|
|
108
|
+
),
|
|
109
|
+
)}
|
|
110
|
+
</Flex>
|
|
111
|
+
),
|
|
112
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import { cn } from '@/utils/cn';
|
|
4
|
+
|
|
5
|
+
const gapMap = {
|
|
6
|
+
none: 'gap-0',
|
|
7
|
+
xs: 'gap-1',
|
|
8
|
+
sm: 'gap-2',
|
|
9
|
+
default: 'gap-4',
|
|
10
|
+
lg: 'gap-6',
|
|
11
|
+
xl: 'gap-8',
|
|
12
|
+
} as const;
|
|
13
|
+
|
|
14
|
+
const alignMap = {
|
|
15
|
+
start: 'items-start',
|
|
16
|
+
center: 'items-center',
|
|
17
|
+
end: 'items-end',
|
|
18
|
+
baseline: 'items-baseline',
|
|
19
|
+
stretch: 'items-stretch',
|
|
20
|
+
} as const;
|
|
21
|
+
|
|
22
|
+
const justifyMap = {
|
|
23
|
+
start: 'justify-start',
|
|
24
|
+
center: 'justify-center',
|
|
25
|
+
end: 'justify-end',
|
|
26
|
+
between: 'justify-between',
|
|
27
|
+
around: 'justify-around',
|
|
28
|
+
evenly: 'justify-evenly',
|
|
29
|
+
} as const;
|
|
30
|
+
|
|
31
|
+
export interface FlexProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
32
|
+
/**
|
|
33
|
+
* 方向(antd `vertical` 并集) — `row`(默认)/ `column` 直观可读;antd `vertical` boolean 映射为 `column`。
|
|
34
|
+
* @default "row"
|
|
35
|
+
*/
|
|
36
|
+
direction?: 'row' | 'column' | 'row-reverse' | 'column-reverse';
|
|
37
|
+
/**
|
|
38
|
+
* 子项之间的间距档位(走 design 间距刻度,不接受任意 number)。
|
|
39
|
+
* @default "default"
|
|
40
|
+
*/
|
|
41
|
+
gap?: 'none' | 'xs' | 'sm' | 'default' | 'lg' | 'xl';
|
|
42
|
+
/**
|
|
43
|
+
* 副轴对齐方式。
|
|
44
|
+
* @default "stretch"
|
|
45
|
+
*/
|
|
46
|
+
align?: keyof typeof alignMap;
|
|
47
|
+
/**
|
|
48
|
+
* 主轴对齐方式。
|
|
49
|
+
* @default "start"
|
|
50
|
+
*/
|
|
51
|
+
justify?: keyof typeof justifyMap;
|
|
52
|
+
/**
|
|
53
|
+
* 是否允许换行(antd `wrap` 并集)。
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
56
|
+
wrap?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* inline-flex 而非 block-flex。
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
61
|
+
inline?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* 渲染元素(antd `component` 并集) — 支持 `section / header / aside / main / nav` 等语义标签。
|
|
64
|
+
* @default "div"
|
|
65
|
+
*/
|
|
66
|
+
as?: keyof Pick<
|
|
67
|
+
React.JSX.IntrinsicElements,
|
|
68
|
+
'div' | 'section' | 'header' | 'footer' | 'aside' | 'main' | 'nav' | 'article'
|
|
69
|
+
>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Flex 布局容器 — antd 独有补足。**等价 antd `Flex`**(v5.10+),提供 Tailwind flex 的语义封装,
|
|
74
|
+
* 把常用对齐 / 间距 / 换行 / 方向 / 渲染元素收敛为枚举,避免散落的 className 反复手写。
|
|
75
|
+
*
|
|
76
|
+
* 与 `Space` 区别:Flex 偏向**完整布局容器**(页头、卡片体、整页),Space 偏向 inline 小集合。
|
|
77
|
+
*/
|
|
78
|
+
const Flex = React.forwardRef<HTMLDivElement, FlexProps>(
|
|
79
|
+
(
|
|
80
|
+
{
|
|
81
|
+
direction = 'row',
|
|
82
|
+
gap = 'default',
|
|
83
|
+
align = 'stretch',
|
|
84
|
+
justify = 'start',
|
|
85
|
+
wrap = false,
|
|
86
|
+
inline = false,
|
|
87
|
+
as = 'div',
|
|
88
|
+
className,
|
|
89
|
+
...props
|
|
90
|
+
},
|
|
91
|
+
ref,
|
|
92
|
+
) => {
|
|
93
|
+
const Tag = as as React.ElementType;
|
|
94
|
+
const directionClass =
|
|
95
|
+
direction === 'row'
|
|
96
|
+
? 'flex-row'
|
|
97
|
+
: direction === 'column'
|
|
98
|
+
? 'flex-col'
|
|
99
|
+
: direction === 'row-reverse'
|
|
100
|
+
? 'flex-row-reverse'
|
|
101
|
+
: 'flex-col-reverse';
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<Tag
|
|
105
|
+
ref={ref}
|
|
106
|
+
className={cn(
|
|
107
|
+
inline ? 'inline-flex' : 'flex',
|
|
108
|
+
directionClass,
|
|
109
|
+
gapMap[gap],
|
|
110
|
+
alignMap[align],
|
|
111
|
+
justifyMap[justify],
|
|
112
|
+
wrap && 'flex-wrap',
|
|
113
|
+
className,
|
|
114
|
+
)}
|
|
115
|
+
{...props}
|
|
116
|
+
/>
|
|
117
|
+
);
|
|
118
|
+
},
|
|
119
|
+
);
|
|
120
|
+
Flex.displayName = 'Flex';
|
|
121
|
+
|
|
122
|
+
export { Flex };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: float-button
|
|
3
|
+
name: FloatButton
|
|
4
|
+
type: component
|
|
5
|
+
category: navigation
|
|
6
|
+
since: 0.1.0
|
|
7
|
+
package: "@teamix-evo/ui"
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# FloatButton
|
|
11
|
+
|
|
12
|
+
悬浮按钮 — antd 独有补足。**等价 antd `FloatButton`**(v5.0 加入,取代旧 `BackTop`)。`position: fixed` 在右下角的强主张操作按钮:回到顶部、客服入口、新建按钮。配 `FloatButtonGroup` 纵向堆叠多个,`FloatButtonBackTop` 是预置的"回到顶部"快捷件。
|
|
13
|
+
|
|
14
|
+
## When to use
|
|
15
|
+
|
|
16
|
+
- "回到顶部"(`FloatButtonBackTop`)
|
|
17
|
+
- 客服 / 反馈入口
|
|
18
|
+
- 新建按钮(创建任务 / 写文章)
|
|
19
|
+
- 移动端的"快速操作"(配 badge 显示未读数)
|
|
20
|
+
|
|
21
|
+
## When NOT to use
|
|
22
|
+
|
|
23
|
+
- 表单内的提交按钮 → 普通 `Button block`
|
|
24
|
+
- 列表行末操作 → 普通 `Button` / `DropdownMenu`
|
|
25
|
+
- 多个无关操作堆在右下:容易遮挡内容,> 3 个 FloatButton 时换 SpeedDial 模式
|
|
26
|
+
|
|
27
|
+
<!-- auto:props:begin -->
|
|
28
|
+
| 名称 | 类型 | 默认值 | 必填 | 说明 |
|
|
29
|
+
| --- | --- | --- | --- | --- |
|
|
30
|
+
| `icon` | `React.ReactNode` | – | – | 图标(antd `icon` 并集)。 |
|
|
31
|
+
| `variant` | `'primary' \| 'default'` | `"primary"` | – | 视觉风格 — `primary` 主色填充;`default` 灰色轮廓。 |
|
|
32
|
+
| `shape` | `'circle' \| 'square'` | `"circle"` | – | 形状 — `circle`(默认)圆形;`square` 方形圆角。 |
|
|
33
|
+
| `badge` | `React.ReactNode` | – | – | 触发徽标(antd `badge` 并集) — 简短数字 / 字符。 |
|
|
34
|
+
<!-- auto:props:end -->
|
|
35
|
+
|
|
36
|
+
<!-- auto:deps:begin -->
|
|
37
|
+
### 同库依赖
|
|
38
|
+
|
|
39
|
+
> `teamix-evo ui add float-button` 时,以下 entry 会被自动连带安装(无需手动 add)。
|
|
40
|
+
|
|
41
|
+
| Entry | 类型 | 描述 |
|
|
42
|
+
| --- | --- | --- |
|
|
43
|
+
| `cn` | util | Tailwind className 合并工具(clsx + tailwind-merge) |
|
|
44
|
+
|
|
45
|
+
### npm 依赖
|
|
46
|
+
|
|
47
|
+
> 业务侧需要先 `pnpm add` / `npm install` 这些包。CLI 在 `ui add` 完成后会列出此提示。
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pnpm add lucide-react@^0.460.0
|
|
51
|
+
```
|
|
52
|
+
<!-- auto:deps:end -->
|
|
53
|
+
|
|
54
|
+
## AI 生成纪律
|
|
55
|
+
|
|
56
|
+
- **多个 FloatButton 必用 `FloatButtonGroup`** — 单独散落会层级 / 位置冲突
|
|
57
|
+
- **`shape="circle"`(默认)+ icon-only** 视觉最干净 — 文字 + 圆形会拥挤
|
|
58
|
+
- **`badge`** 只显示 ≤ 2 位数字 / 文字(`99+` / `New`)— 长内容塞不下
|
|
59
|
+
- **`FloatButtonBackTop` 默认滚动 > 200px 才显示** — 短页面不会出现,符合用户预期
|
|
60
|
+
- **不要给 FloatButton 加 dropdown 菜单**:用 antd 的 `FloatButton.Menu` 思路时,改用 `DropdownMenu` 包 trigger
|
|
61
|
+
- **z-index 默认 40** — 比 toast 低、比常规 dialog 略低;需要覆盖 Dialog 时自行 className 调
|
|
62
|
+
|
|
63
|
+
## Examples
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
import {
|
|
67
|
+
FloatButton,
|
|
68
|
+
FloatButtonGroup,
|
|
69
|
+
FloatButtonBackTop,
|
|
70
|
+
} from '@/components/ui/float-button';
|
|
71
|
+
import { MessageCircle, Plus } from 'lucide-react';
|
|
72
|
+
|
|
73
|
+
// 仅回到顶部
|
|
74
|
+
<FloatButtonBackTop />
|
|
75
|
+
|
|
76
|
+
// 多按钮组
|
|
77
|
+
<FloatButtonGroup>
|
|
78
|
+
<FloatButton icon={<MessageCircle className="size-5" />} aria-label="客服" badge="3" />
|
|
79
|
+
<FloatButton variant="default" icon={<Plus className="size-5" />} aria-label="新建" />
|
|
80
|
+
<FloatButtonBackTop />
|
|
81
|
+
</FloatButtonGroup>
|
|
82
|
+
|
|
83
|
+
// 自定义位置
|
|
84
|
+
<FloatButtonGroup right={48} bottom={48}>
|
|
85
|
+
<FloatButton icon={<Plus className="size-5" />} aria-label="新建" />
|
|
86
|
+
</FloatButtonGroup>
|
|
87
|
+
```
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { MessageCircle, Plus } from 'lucide-react';
|
|
3
|
+
import {
|
|
4
|
+
FloatButton,
|
|
5
|
+
FloatButtonGroup,
|
|
6
|
+
FloatButtonBackTop,
|
|
7
|
+
} from './float-button';
|
|
8
|
+
|
|
9
|
+
const meta: Meta<typeof FloatButton> = {
|
|
10
|
+
title: '导航 · Navigation/FloatButton',
|
|
11
|
+
component: FloatButton,
|
|
12
|
+
tags: ['autodocs'],
|
|
13
|
+
parameters: {
|
|
14
|
+
docs: {
|
|
15
|
+
description: {
|
|
16
|
+
component:
|
|
17
|
+
'悬浮按钮 — position: fixed 在右下角的强主张操作按钮(回到顶部 / 客服 / 新建)。配 FloatButtonGroup 堆叠多个,FloatButtonBackTop 是预置的"回到顶部"。等价 antd `FloatButton`(v5.0,替代旧 BackTop)。视觉走 OpenTrek tokens,所有样式来自 `@teamix-evo/design`,无 mock。',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default meta;
|
|
24
|
+
type Story = StoryObj<typeof FloatButton>;
|
|
25
|
+
|
|
26
|
+
export const Playground: Story = {
|
|
27
|
+
parameters: { controls: { disable: true } },
|
|
28
|
+
render: () => (
|
|
29
|
+
<div className="relative h-72 overflow-hidden rounded-md border">
|
|
30
|
+
<div className="p-4 text-sm text-muted-foreground">
|
|
31
|
+
← 右下角是 FloatButton 演示
|
|
32
|
+
</div>
|
|
33
|
+
<div className="absolute bottom-3 right-3">
|
|
34
|
+
<FloatButton icon={<Plus className="size-5" />} aria-label="新建" />
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
),
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const Group: Story = {
|
|
41
|
+
parameters: { controls: { disable: true } },
|
|
42
|
+
render: () => (
|
|
43
|
+
<div className="relative h-96 overflow-hidden rounded-md border">
|
|
44
|
+
<div className="p-4 text-sm text-muted-foreground">右下角浮动按钮组</div>
|
|
45
|
+
<div className="absolute bottom-6 right-6 flex flex-col items-end gap-3">
|
|
46
|
+
<FloatButton
|
|
47
|
+
icon={<MessageCircle className="size-5" />}
|
|
48
|
+
aria-label="客服"
|
|
49
|
+
badge="3"
|
|
50
|
+
/>
|
|
51
|
+
<FloatButton
|
|
52
|
+
variant="default"
|
|
53
|
+
icon={<Plus className="size-5" />}
|
|
54
|
+
aria-label="新建"
|
|
55
|
+
/>
|
|
56
|
+
</div>
|
|
57
|
+
</div>
|
|
58
|
+
),
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const BackTopReal: Story = {
|
|
62
|
+
parameters: { controls: { disable: true } },
|
|
63
|
+
render: () => (
|
|
64
|
+
<>
|
|
65
|
+
<div className="text-sm text-muted-foreground">向下滚动 200px 查看回到顶部按钮:</div>
|
|
66
|
+
<div className="mt-3 space-y-3">
|
|
67
|
+
{Array.from({ length: 30 }).map((_, i) => (
|
|
68
|
+
<div key={i} className="rounded-md border bg-muted/30 p-6">
|
|
69
|
+
占位段落 {i + 1}
|
|
70
|
+
</div>
|
|
71
|
+
))}
|
|
72
|
+
</div>
|
|
73
|
+
<FloatButtonGroup>
|
|
74
|
+
<FloatButtonBackTop />
|
|
75
|
+
</FloatButtonGroup>
|
|
76
|
+
</>
|
|
77
|
+
),
|
|
78
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ArrowUp } from 'lucide-react';
|
|
3
|
+
|
|
4
|
+
import { cn } from '@/utils/cn';
|
|
5
|
+
|
|
6
|
+
export interface FloatButtonProps
|
|
7
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
8
|
+
/**
|
|
9
|
+
* 图标(antd `icon` 并集)。
|
|
10
|
+
*/
|
|
11
|
+
icon?: React.ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* 视觉风格 — `primary` 主色填充;`default` 灰色轮廓。
|
|
14
|
+
* @default "primary"
|
|
15
|
+
*/
|
|
16
|
+
variant?: 'primary' | 'default';
|
|
17
|
+
/**
|
|
18
|
+
* 形状 — `circle`(默认)圆形;`square` 方形圆角。
|
|
19
|
+
* @default "circle"
|
|
20
|
+
*/
|
|
21
|
+
shape?: 'circle' | 'square';
|
|
22
|
+
/**
|
|
23
|
+
* 触发徽标(antd `badge` 并集) — 简短数字 / 字符。
|
|
24
|
+
*/
|
|
25
|
+
badge?: React.ReactNode;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 悬浮按钮 — antd 独有补足。**等价 antd `FloatButton`**(v5.0 加入,替代旧 `BackTop`)。
|
|
30
|
+
* 默认 `position: fixed` 在右下角,典型用例:回到顶部、客服入口、新建按钮。
|
|
31
|
+
*
|
|
32
|
+
* **多个 FloatButton 请用 `FloatButtonGroup` 包裹**(纵向堆叠 + 间距统一)。
|
|
33
|
+
*/
|
|
34
|
+
const FloatButton = React.forwardRef<HTMLButtonElement, FloatButtonProps>(
|
|
35
|
+
(
|
|
36
|
+
{
|
|
37
|
+
icon,
|
|
38
|
+
variant = 'primary',
|
|
39
|
+
shape = 'circle',
|
|
40
|
+
badge,
|
|
41
|
+
className,
|
|
42
|
+
children,
|
|
43
|
+
...props
|
|
44
|
+
},
|
|
45
|
+
ref,
|
|
46
|
+
) => (
|
|
47
|
+
<button
|
|
48
|
+
ref={ref}
|
|
49
|
+
type="button"
|
|
50
|
+
className={cn(
|
|
51
|
+
'relative inline-flex size-12 items-center justify-center transition-all',
|
|
52
|
+
'shadow-lg hover:shadow-xl active:scale-95',
|
|
53
|
+
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
54
|
+
shape === 'circle' ? 'rounded-full' : 'rounded-md',
|
|
55
|
+
variant === 'primary'
|
|
56
|
+
? 'bg-primary text-primary-foreground hover:bg-primary/90'
|
|
57
|
+
: 'border border-border bg-background text-foreground hover:bg-accent',
|
|
58
|
+
'disabled:cursor-not-allowed disabled:opacity-50',
|
|
59
|
+
className,
|
|
60
|
+
)}
|
|
61
|
+
{...props}
|
|
62
|
+
>
|
|
63
|
+
{icon ?? children}
|
|
64
|
+
{badge != null ? (
|
|
65
|
+
<span className="absolute -right-1 -top-1 flex h-5 min-w-[1.25rem] items-center justify-center rounded-full bg-destructive px-1 text-[10px] font-medium leading-none text-destructive-foreground">
|
|
66
|
+
{badge}
|
|
67
|
+
</span>
|
|
68
|
+
) : null}
|
|
69
|
+
</button>
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
FloatButton.displayName = 'FloatButton';
|
|
73
|
+
|
|
74
|
+
// ─── FloatButtonGroup(纵向堆叠)─────────────────────────────────────────
|
|
75
|
+
|
|
76
|
+
export interface FloatButtonGroupProps
|
|
77
|
+
extends React.HTMLAttributes<HTMLDivElement> {
|
|
78
|
+
/**
|
|
79
|
+
* 距视口右侧的距离(像素)。
|
|
80
|
+
* @default 24
|
|
81
|
+
*/
|
|
82
|
+
right?: number;
|
|
83
|
+
/**
|
|
84
|
+
* 距视口底部的距离(像素)。
|
|
85
|
+
* @default 24
|
|
86
|
+
*/
|
|
87
|
+
bottom?: number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const FloatButtonGroup = React.forwardRef<HTMLDivElement, FloatButtonGroupProps>(
|
|
91
|
+
({ right = 24, bottom = 24, className, style, ...props }, ref) => (
|
|
92
|
+
<div
|
|
93
|
+
ref={ref}
|
|
94
|
+
className={cn(
|
|
95
|
+
'fixed z-40 flex flex-col items-end gap-3',
|
|
96
|
+
className,
|
|
97
|
+
)}
|
|
98
|
+
style={{ right, bottom, ...style }}
|
|
99
|
+
{...props}
|
|
100
|
+
/>
|
|
101
|
+
),
|
|
102
|
+
);
|
|
103
|
+
FloatButtonGroup.displayName = 'FloatButtonGroup';
|
|
104
|
+
|
|
105
|
+
// ─── FloatButtonBackTop(antd `FloatButton.BackTop` 等价)──────────────
|
|
106
|
+
|
|
107
|
+
export interface FloatButtonBackTopProps
|
|
108
|
+
extends Omit<FloatButtonProps, 'icon' | 'onClick'> {
|
|
109
|
+
/**
|
|
110
|
+
* 滚动到此偏移量(px)以下时隐藏;为 0 始终显示。
|
|
111
|
+
* @default 200
|
|
112
|
+
*/
|
|
113
|
+
visibilityHeight?: number;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const FloatButtonBackTop = React.forwardRef<
|
|
117
|
+
HTMLButtonElement,
|
|
118
|
+
FloatButtonBackTopProps
|
|
119
|
+
>(({ visibilityHeight = 200, ...rest }, ref) => {
|
|
120
|
+
const [visible, setVisible] = React.useState(visibilityHeight === 0);
|
|
121
|
+
|
|
122
|
+
React.useEffect(() => {
|
|
123
|
+
if (typeof window === 'undefined') return;
|
|
124
|
+
const update = () => setVisible(window.scrollY > visibilityHeight);
|
|
125
|
+
update();
|
|
126
|
+
window.addEventListener('scroll', update, { passive: true });
|
|
127
|
+
return () => window.removeEventListener('scroll', update);
|
|
128
|
+
}, [visibilityHeight]);
|
|
129
|
+
|
|
130
|
+
if (!visible) return null;
|
|
131
|
+
return (
|
|
132
|
+
<FloatButton
|
|
133
|
+
ref={ref}
|
|
134
|
+
icon={<ArrowUp className="size-5" />}
|
|
135
|
+
onClick={() => window.scrollTo({ top: 0, behavior: 'smooth' })}
|
|
136
|
+
aria-label="回到顶部"
|
|
137
|
+
{...rest}
|
|
138
|
+
/>
|
|
139
|
+
);
|
|
140
|
+
});
|
|
141
|
+
FloatButtonBackTop.displayName = 'FloatButtonBackTop';
|
|
142
|
+
|
|
143
|
+
export { FloatButton, FloatButtonGroup, FloatButtonBackTop };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: form
|
|
3
|
+
name: Form
|
|
4
|
+
type: component
|
|
5
|
+
category: form
|
|
6
|
+
since: 0.1.0
|
|
7
|
+
package: "@teamix-evo/ui"
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Form
|
|
11
|
+
|
|
12
|
+
表单 — 基于 [`react-hook-form`](https://react-hook-form.com/),shadcn 标准 7 件套(`Form / FormField / FormItem / FormLabel / FormControl / FormDescription / FormMessage`)。
|
|
13
|
+
**配合 [`zod`](https://zod.dev/) + `@hookform/resolvers/zod` 做 schema 校验**(行业惯例)。
|
|
14
|
+
|
|
15
|
+
## When to use
|
|
16
|
+
|
|
17
|
+
- 任何表单(登录、注册、设置、复杂数据填报)
|
|
18
|
+
- 跨字段联动 / 条件校验
|
|
19
|
+
- 异步校验(用户名查重)
|
|
20
|
+
|
|
21
|
+
## When NOT to use
|
|
22
|
+
|
|
23
|
+
- 单字段查询框 → `Input + onSubmit`
|
|
24
|
+
- 一次性确认 → `AlertDialog` 单按钮
|
|
25
|
+
- 无校验的"轻量提交" → 直接 `<form>` + 状态变量
|
|
26
|
+
|
|
27
|
+
## Props
|
|
28
|
+
|
|
29
|
+
> 以下表格由 `pnpm --filter @teamix-evo/ui gen:meta` 自动生成。`Form` 是 `FormProvider` 别名,直接接受 `useForm()` 返回值的所有方法;不存在专门的 props 表 —下表代表 `FormItem` 的 props 作为 docs anchor,实际用法见 Examples。
|
|
30
|
+
|
|
31
|
+
<!-- auto:props:begin -->
|
|
32
|
+
| 名称 | 类型 | 默认值 | 必填 | 说明 |
|
|
33
|
+
| --- | --- | --- | --- | --- |
|
|
34
|
+
| `children` | `React.ReactNode` | – | – | 表单内容 — 通常是 `<form>` + `<FormField>` 列表。 |
|
|
35
|
+
<!-- auto:props:end -->
|
|
36
|
+
|
|
37
|
+
## 依赖
|
|
38
|
+
|
|
39
|
+
> 以下表格由 `pnpm --filter @teamix-evo/ui gen:meta` 自动生成,数据源是 [`manifest.json`](../../../manifest.json)。**手工编辑 marker 之间的内容会在下次生成时被覆盖**。
|
|
40
|
+
|
|
41
|
+
<!-- auto:deps:begin -->
|
|
42
|
+
### 同库依赖
|
|
43
|
+
|
|
44
|
+
> `teamix-evo ui add form` 时,以下 entry 会被自动连带安装(无需手动 add)。
|
|
45
|
+
|
|
46
|
+
| Entry | 类型 | 描述 |
|
|
47
|
+
| --- | --- | --- |
|
|
48
|
+
| `cn` | util | Tailwind className 合并工具(clsx + tailwind-merge) |
|
|
49
|
+
| `label` | component | 表单字段标签 — Radix Label 包装,补 antd Form.Item 风格的 required / disabled 显式视觉 |
|
|
50
|
+
|
|
51
|
+
### npm 依赖
|
|
52
|
+
|
|
53
|
+
> 业务侧需要先 `pnpm add` / `npm install` 这些包。CLI 在 `ui add` 完成后会列出此提示。
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pnpm add react-hook-form@^7.50.0 @hookform/resolvers@^3.0.0 zod@^3.22.0 @radix-ui/react-label@^2.1.0 @radix-ui/react-slot@^1.1.0
|
|
57
|
+
```
|
|
58
|
+
<!-- auto:deps:end -->
|
|
59
|
+
|
|
60
|
+
> 完整子组件:`Form` / `FormField` / `FormItem` / `FormLabel` / `FormControl` / `FormDescription` / `FormMessage`,配合 `useFormField()` hook。
|
|
61
|
+
|
|
62
|
+
## AI 生成纪律
|
|
63
|
+
|
|
64
|
+
- **`Form` 必包 `useForm()`**:`<Form {...form}>...</Form>`,把整个 form instance 散开传入(FormProvider 期望)
|
|
65
|
+
- **每个字段必有 `<FormField name="..." control={form.control} render={({ field }) => <FormItem>...</FormItem>} />`**:不要直接渲染 input 不走 Field,会失去校验关联
|
|
66
|
+
- **`<FormControl>` 只放真正的输入控件**:input / textarea / Select / Checkbox 等;Slot 模式自动注入 id / aria-describedby / aria-invalid
|
|
67
|
+
- **错误消息走 `<FormMessage />`**:不要手写 `{errors.x?.message}` — FormMessage 自动连接 fieldState
|
|
68
|
+
- **schema 优先**:用 zod 写 schema → `useForm({ resolver: zodResolver(schema) })`;校验逻辑集中在 schema,不要散在 input 上
|
|
69
|
+
- **提交后保留状态**:`form.reset()` 重置;**不要**手动清空每个字段
|
|
70
|
+
- **不要嵌套 Form**:嵌套会破坏 React Context
|
|
71
|
+
|
|
72
|
+
## Examples
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
import { useForm } from 'react-hook-form';
|
|
76
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
77
|
+
import { z } from 'zod';
|
|
78
|
+
import {
|
|
79
|
+
Form, FormField, FormItem, FormLabel, FormControl,
|
|
80
|
+
FormDescription, FormMessage,
|
|
81
|
+
} from '@/components/ui/form';
|
|
82
|
+
import { Input } from '@/components/ui/input';
|
|
83
|
+
import { Button } from '@/components/ui/button';
|
|
84
|
+
|
|
85
|
+
const schema = z.object({
|
|
86
|
+
username: z.string().min(2, '至少 2 个字符'),
|
|
87
|
+
email: z.string().email('请输入有效邮箱'),
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
function MyForm() {
|
|
91
|
+
const form = useForm<z.infer<typeof schema>>({
|
|
92
|
+
resolver: zodResolver(schema),
|
|
93
|
+
defaultValues: { username: '', email: '' },
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<Form {...form}>
|
|
98
|
+
<form onSubmit={form.handleSubmit((v) => console.log(v))} className="space-y-4">
|
|
99
|
+
<FormField
|
|
100
|
+
control={form.control}
|
|
101
|
+
name="username"
|
|
102
|
+
render={({ field }) => (
|
|
103
|
+
<FormItem>
|
|
104
|
+
<FormLabel required>用户名</FormLabel>
|
|
105
|
+
<FormControl>
|
|
106
|
+
<Input placeholder="lyca" {...field} />
|
|
107
|
+
</FormControl>
|
|
108
|
+
<FormDescription>2~16 个字符。</FormDescription>
|
|
109
|
+
<FormMessage />
|
|
110
|
+
</FormItem>
|
|
111
|
+
)}
|
|
112
|
+
/>
|
|
113
|
+
<FormField
|
|
114
|
+
control={form.control}
|
|
115
|
+
name="email"
|
|
116
|
+
render={({ field }) => (
|
|
117
|
+
<FormItem>
|
|
118
|
+
<FormLabel required>邮箱</FormLabel>
|
|
119
|
+
<FormControl>
|
|
120
|
+
<Input type="email" placeholder="you@example.com" {...field} />
|
|
121
|
+
</FormControl>
|
|
122
|
+
<FormMessage />
|
|
123
|
+
</FormItem>
|
|
124
|
+
)}
|
|
125
|
+
/>
|
|
126
|
+
<Button type="submit">提交</Button>
|
|
127
|
+
</form>
|
|
128
|
+
</Form>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
```
|