@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,4 +1,4 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
2
|
import { Slash } from 'lucide-react';
|
|
3
3
|
import {
|
|
4
4
|
Breadcrumb,
|
|
@@ -9,11 +9,25 @@ import {
|
|
|
9
9
|
BreadcrumbSeparator,
|
|
10
10
|
BreadcrumbEllipsis,
|
|
11
11
|
} from './breadcrumb';
|
|
12
|
+
import {
|
|
13
|
+
DropdownMenu,
|
|
14
|
+
DropdownMenuContent,
|
|
15
|
+
DropdownMenuItem,
|
|
16
|
+
DropdownMenuTrigger,
|
|
17
|
+
} from '@/components/dropdown-menu/dropdown-menu';
|
|
12
18
|
|
|
13
19
|
const meta: Meta<typeof Breadcrumb> = {
|
|
14
20
|
title: '导航 · Navigation/Breadcrumb',
|
|
15
21
|
component: Breadcrumb,
|
|
16
22
|
tags: ['autodocs'],
|
|
23
|
+
parameters: {
|
|
24
|
+
docs: {
|
|
25
|
+
description: {
|
|
26
|
+
component:
|
|
27
|
+
'面包屑 —— 在多层级页面中显示当前位置并提供回溯路径。shadcn 纯组合原子(`Breadcrumb` / `BreadcrumbList` / `BreadcrumbItem` / `BreadcrumbLink` / `BreadcrumbPage` / `BreadcrumbSeparator` / `BreadcrumbEllipsis`) + 对齐 antd `Breadcrumb` 的 `separator` 自定义并集,差异点是不收 antd `routes` / `itemRender` 数组式 API,改走 children 组合 + `asChild` 适配 React Router / Next.js `<Link>`:`asChild`、`separator`(默认 `ChevronRight`)、`BreadcrumbEllipsis` 折叠。视觉走 OpenTrek semantic tokens,字号 `text-sm`、普通项 `text-muted-foreground`、当前项 `text-foreground`、链接 hover 升至 `text-foreground`,所有样式来自 `@teamix-evo/tokens`,无 mock。',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
17
31
|
};
|
|
18
32
|
|
|
19
33
|
export default meta;
|
|
@@ -40,7 +54,15 @@ export const Default: Story = {
|
|
|
40
54
|
};
|
|
41
55
|
|
|
42
56
|
export const CustomSeparator: Story = {
|
|
43
|
-
parameters: {
|
|
57
|
+
parameters: {
|
|
58
|
+
controls: { disable: true },
|
|
59
|
+
docs: {
|
|
60
|
+
description: {
|
|
61
|
+
story:
|
|
62
|
+
'通过 `<BreadcrumbSeparator>` 的 children 覆盖默认 `ChevronRight`,可换为 `Slash` / 文字 / 任意 ReactNode。',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
44
66
|
render: () => (
|
|
45
67
|
<Breadcrumb>
|
|
46
68
|
<BreadcrumbList>
|
|
@@ -50,6 +72,12 @@ export const CustomSeparator: Story = {
|
|
|
50
72
|
<BreadcrumbSeparator>
|
|
51
73
|
<Slash />
|
|
52
74
|
</BreadcrumbSeparator>
|
|
75
|
+
<BreadcrumbItem>
|
|
76
|
+
<BreadcrumbLink href="/projects">项目</BreadcrumbLink>
|
|
77
|
+
</BreadcrumbItem>
|
|
78
|
+
<BreadcrumbSeparator>
|
|
79
|
+
<span>·</span>
|
|
80
|
+
</BreadcrumbSeparator>
|
|
53
81
|
<BreadcrumbItem>
|
|
54
82
|
<BreadcrumbPage>当前页</BreadcrumbPage>
|
|
55
83
|
</BreadcrumbItem>
|
|
@@ -58,8 +86,16 @@ export const CustomSeparator: Story = {
|
|
|
58
86
|
),
|
|
59
87
|
};
|
|
60
88
|
|
|
61
|
-
export const
|
|
62
|
-
parameters: {
|
|
89
|
+
export const Collapsed: Story = {
|
|
90
|
+
parameters: {
|
|
91
|
+
controls: { disable: true },
|
|
92
|
+
docs: {
|
|
93
|
+
description: {
|
|
94
|
+
story:
|
|
95
|
+
'层级超过 4 级时使用 `<BreadcrumbEllipsis />` 折叠中间项,避免横向空间撑爆;可叠加 `DropdownMenu` 在悬停时展开完整路径。',
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
63
99
|
render: () => (
|
|
64
100
|
<Breadcrumb>
|
|
65
101
|
<BreadcrumbList>
|
|
@@ -82,3 +118,90 @@ export const Ellipsis: Story = {
|
|
|
82
118
|
</Breadcrumb>
|
|
83
119
|
),
|
|
84
120
|
};
|
|
121
|
+
|
|
122
|
+
export const MaxNodeCollapse: Story = {
|
|
123
|
+
parameters: {
|
|
124
|
+
controls: { disable: true },
|
|
125
|
+
docs: {
|
|
126
|
+
description: {
|
|
127
|
+
story:
|
|
128
|
+
'对齐旧库 `maxNode` 自动折叠能力 — 把 `<BreadcrumbEllipsis />` 包到 `<DropdownMenu>` 触发器里,点击 `…` 弹出被折叠层级列表(单击跳转)。组合优于专门 prop:可任意控制弹层位置 / 触发方式 / 自定义弹出 UI。',
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
render: () => {
|
|
133
|
+
const all = [
|
|
134
|
+
{ label: '首页', href: '/' },
|
|
135
|
+
{ label: 'Whatever', href: '/whatever' },
|
|
136
|
+
{ label: 'All Categories', href: '/all' },
|
|
137
|
+
{ label: "Women's Clothing", href: '/women' },
|
|
138
|
+
{ label: 'Blouses & Shirts', href: '/blouses' },
|
|
139
|
+
];
|
|
140
|
+
const head = all[0]!;
|
|
141
|
+
const middle = all.slice(1, -1);
|
|
142
|
+
return (
|
|
143
|
+
<Breadcrumb>
|
|
144
|
+
<BreadcrumbList>
|
|
145
|
+
<BreadcrumbItem>
|
|
146
|
+
<BreadcrumbLink href={head.href}>{head.label}</BreadcrumbLink>
|
|
147
|
+
</BreadcrumbItem>
|
|
148
|
+
<BreadcrumbSeparator />
|
|
149
|
+
<BreadcrumbItem>
|
|
150
|
+
<DropdownMenu>
|
|
151
|
+
<DropdownMenuTrigger
|
|
152
|
+
aria-label="展开折叠层级"
|
|
153
|
+
className="rounded-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
|
154
|
+
>
|
|
155
|
+
<BreadcrumbEllipsis />
|
|
156
|
+
</DropdownMenuTrigger>
|
|
157
|
+
<DropdownMenuContent align="start">
|
|
158
|
+
{middle.map((it) => (
|
|
159
|
+
<DropdownMenuItem key={it.href} asChild>
|
|
160
|
+
<a href={it.href}>{it.label}</a>
|
|
161
|
+
</DropdownMenuItem>
|
|
162
|
+
))}
|
|
163
|
+
</DropdownMenuContent>
|
|
164
|
+
</DropdownMenu>
|
|
165
|
+
</BreadcrumbItem>
|
|
166
|
+
<BreadcrumbSeparator />
|
|
167
|
+
<BreadcrumbItem>
|
|
168
|
+
<BreadcrumbPage>T-shirts</BreadcrumbPage>
|
|
169
|
+
</BreadcrumbItem>
|
|
170
|
+
</BreadcrumbList>
|
|
171
|
+
</Breadcrumb>
|
|
172
|
+
);
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export const WithRouterLink: Story = {
|
|
177
|
+
parameters: {
|
|
178
|
+
controls: { disable: true },
|
|
179
|
+
docs: {
|
|
180
|
+
description: {
|
|
181
|
+
story:
|
|
182
|
+
'通过 `asChild` 把 `BreadcrumbLink` 替换为路由组件(此处用 `<a>` 演示),保持视觉与无障碍语义一致。',
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
render: () => (
|
|
187
|
+
<Breadcrumb>
|
|
188
|
+
<BreadcrumbList>
|
|
189
|
+
<BreadcrumbItem>
|
|
190
|
+
<BreadcrumbLink asChild>
|
|
191
|
+
<a href="/">首页</a>
|
|
192
|
+
</BreadcrumbLink>
|
|
193
|
+
</BreadcrumbItem>
|
|
194
|
+
<BreadcrumbSeparator />
|
|
195
|
+
<BreadcrumbItem>
|
|
196
|
+
<BreadcrumbLink asChild>
|
|
197
|
+
<a href="/orgs">组织</a>
|
|
198
|
+
</BreadcrumbLink>
|
|
199
|
+
</BreadcrumbItem>
|
|
200
|
+
<BreadcrumbSeparator />
|
|
201
|
+
<BreadcrumbItem>
|
|
202
|
+
<BreadcrumbPage>成员管理</BreadcrumbPage>
|
|
203
|
+
</BreadcrumbItem>
|
|
204
|
+
</BreadcrumbList>
|
|
205
|
+
</Breadcrumb>
|
|
206
|
+
),
|
|
207
|
+
};
|
|
@@ -6,14 +6,19 @@ import { cn } from '@/utils/cn';
|
|
|
6
6
|
|
|
7
7
|
export interface BreadcrumbProps extends React.ComponentPropsWithoutRef<'nav'> {
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* 自定义全局分隔符(antd `separator` 并集)。仅作类型层占位 —
|
|
10
|
+
* 实际渲染由 `<BreadcrumbSeparator>` 控制,默认 lucide `ChevronRight`,
|
|
11
|
+
* 通过 `<BreadcrumbSeparator>{节点}</BreadcrumbSeparator>` 覆盖单个分隔符。
|
|
12
|
+
* @default <ChevronRight />
|
|
11
13
|
*/
|
|
12
14
|
separator?: React.ReactNode;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
const Breadcrumb = React.forwardRef<HTMLElement, BreadcrumbProps>(
|
|
16
|
-
|
|
18
|
+
// separator 仅作 API 占位,不下传到 DOM,避免触发未知属性警告。
|
|
19
|
+
({ separator: _separator, ...props }, ref) => (
|
|
20
|
+
<nav ref={ref} aria-label="breadcrumb" {...props} />
|
|
21
|
+
),
|
|
17
22
|
);
|
|
18
23
|
Breadcrumb.displayName = 'Breadcrumb';
|
|
19
24
|
|
|
@@ -24,7 +29,7 @@ const BreadcrumbList = React.forwardRef<
|
|
|
24
29
|
<ol
|
|
25
30
|
ref={ref}
|
|
26
31
|
className={cn(
|
|
27
|
-
'flex flex-wrap items-center gap-1.5 text-
|
|
32
|
+
'flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground sm:gap-2.5',
|
|
28
33
|
className,
|
|
29
34
|
)}
|
|
30
35
|
{...props}
|
|
@@ -46,7 +51,10 @@ BreadcrumbItem.displayName = 'BreadcrumbItem';
|
|
|
46
51
|
|
|
47
52
|
export interface BreadcrumbLinkProps
|
|
48
53
|
extends React.ComponentPropsWithoutRef<'a'> {
|
|
49
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* 用 Slot 渲染为子元素(常配合 React Router `<Link>` / Next.js `<Link>`)。
|
|
56
|
+
* @default false
|
|
57
|
+
*/
|
|
50
58
|
asChild?: boolean;
|
|
51
59
|
}
|
|
52
60
|
|
|
@@ -56,7 +64,10 @@ const BreadcrumbLink = React.forwardRef<HTMLAnchorElement, BreadcrumbLinkProps>(
|
|
|
56
64
|
return (
|
|
57
65
|
<Comp
|
|
58
66
|
ref={ref}
|
|
59
|
-
className={cn(
|
|
67
|
+
className={cn(
|
|
68
|
+
'text-xs text-muted-foreground transition-colors hover:text-foreground',
|
|
69
|
+
className,
|
|
70
|
+
)}
|
|
60
71
|
{...props}
|
|
61
72
|
/>
|
|
62
73
|
);
|
|
@@ -73,7 +84,7 @@ const BreadcrumbPage = React.forwardRef<
|
|
|
73
84
|
role="link"
|
|
74
85
|
aria-disabled="true"
|
|
75
86
|
aria-current="page"
|
|
76
|
-
className={cn('font-normal text-foreground', className)}
|
|
87
|
+
className={cn('text-xs font-normal text-foreground', className)}
|
|
77
88
|
{...props}
|
|
78
89
|
/>
|
|
79
90
|
));
|
|
@@ -87,7 +98,10 @@ const BreadcrumbSeparator = ({
|
|
|
87
98
|
<li
|
|
88
99
|
role="presentation"
|
|
89
100
|
aria-hidden="true"
|
|
90
|
-
className={cn(
|
|
101
|
+
className={cn(
|
|
102
|
+
'inline-flex items-center text-muted-foreground [&>svg]:size-3.5',
|
|
103
|
+
className,
|
|
104
|
+
)}
|
|
91
105
|
{...props}
|
|
92
106
|
>
|
|
93
107
|
{children ?? <ChevronRight />}
|
|
@@ -1,28 +1,34 @@
|
|
|
1
1
|
---
|
|
2
2
|
id: button
|
|
3
3
|
name: Button
|
|
4
|
+
displayName: 按钮
|
|
4
5
|
type: component
|
|
5
|
-
category:
|
|
6
|
+
category: general
|
|
6
7
|
since: 0.1.0
|
|
7
|
-
package:
|
|
8
|
+
package: '@teamix-evo/ui'
|
|
8
9
|
---
|
|
9
10
|
|
|
10
|
-
# Button
|
|
11
|
+
# Button 按钮
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
按钮文本、aria 状态由消费方提供;视觉与可访问性由组件保障。
|
|
13
|
+
Button 按钮 —— 触发即时动作的最基础交互原子(提交、删除、跳转、加载)。基于 shadcn/ui 实现 + cloud-design 能力并集:`variant`(7 档形态)、`color`(ADR 0021 语义色双 prop)、`size`(sm/md/lg/icon,可由 `<ButtonGroup size>` 注入)、`shape`(default/round/circle/square)、`loading`(spinner + 自动 disabled + aria-busy)、`icon` + `iconRight`(双 slot)、`block`(撑满)、`asChild`(渲染为任意元素)、`disabledTooltip`(禁用解释)。**组件合一**:`ButtonGroup` + `ButtonGroupText` 同文件导出,等价 antd `Space.Compact`,支持 SplitButton、Toolbar、Input addon 等组合形态,通过 `<ButtonGroup size>` + React.Context 自顶向下注入子 Button 尺寸。
|
|
14
14
|
|
|
15
15
|
## When to use
|
|
16
16
|
|
|
17
17
|
- 表单提交、对话框确认、列表行操作等触发性交互
|
|
18
|
-
- 需要明确反馈"
|
|
19
|
-
- 需要纯图标按钮时(用 `size="icon"` + `shape="circle"` 组合)
|
|
18
|
+
- 需要明确反馈"按下 → 处理中 → 完成"过程的场景(用 `loading`)
|
|
19
|
+
- 需要纯图标按钮时(用 `size="icon"` + `shape="circle"` / `"square"` 组合)
|
|
20
|
+
- 需要 prefix + suffix 双图标时(用 `icon` + `iconRight` 双 slot)
|
|
21
|
+
- 需要 warning + outline 等"语义 × 视觉"双维度表达 → 用 `variant="outline" color="destructive"`(ADR 0021)
|
|
22
|
+
- 禁用按钮需要解释原因 → 用 `disabled` + `disabledTooltip`
|
|
23
|
+
- **SplitButton / Toolbar / Input addon 等组合** → 用 `ButtonGroup` 包裹
|
|
20
24
|
|
|
21
25
|
## When NOT to use
|
|
22
26
|
|
|
23
27
|
- 仅做导航而无副作用 → 用 `<a>` 或路由 `Link`(必要时配 `variant="link"` 视觉)
|
|
24
28
|
- 切换布尔状态 → 用 `Switch` / `Toggle`,不要用按钮模拟
|
|
25
29
|
- 需要承载多行说明文字 → 用 `Card` 等容器组件
|
|
30
|
+
- 需要全屏阻塞加载 → 用 `Spinner` + 遮罩,不要用 `loading` 撑大按钮
|
|
31
|
+
- 互斥单选切换 → `ToggleGroup`(语义更强),不要用 `ButtonGroup` 模拟
|
|
26
32
|
|
|
27
33
|
## Props
|
|
28
34
|
|
|
@@ -31,14 +37,17 @@ package: "@teamix-evo/ui"
|
|
|
31
37
|
<!-- auto:props:begin -->
|
|
32
38
|
| 名称 | 类型 | 默认值 | 必填 | 说明 |
|
|
33
39
|
| --- | --- | --- | --- | --- |
|
|
34
|
-
| `variant` | `
|
|
35
|
-
| `
|
|
36
|
-
| `
|
|
40
|
+
| `variant` | `ButtonVariant` | `"default"` | – | 视觉风格,语义按 design token 走。 |
|
|
41
|
+
| `color` | `ButtonColor` | `"default"` | – | 语义色(ADR 0021)。与 `variant` 双 prop 组合表达"语义 × 视觉"两个维度, 例:`variant="outline" color="destructive"` 实现旧库 warning+outline 形态; `variant="ghost" color="destructive"` 实现轻量危险删除按钮。 |
|
|
42
|
+
| `size` | `ButtonSize` | `"default"` | – | 尺寸。`md` 与 `default` 等价,`icon` 为正方形纯图标按钮。 若包在 `<ButtonGroup size="..">` 中且本地未显式传值,自动继承 group 的 size。 |
|
|
43
|
+
| `shape` | `ButtonShape` | `"default"` | – | 形状。`circle` / `square` 必须配 `size="icon"`。 |
|
|
37
44
|
| `block` | `boolean` | `false` | – | `true` 时撑满父容器宽度。 |
|
|
38
|
-
| `asChild` | `boolean` | `false` | – | 用 Radix Slot 模式渲染为子元素;此时 `loading` / `icon` 被忽略。 |
|
|
39
|
-
| `loading` | `boolean` | `false` | – | 显示自旋 spinner,自动 disabled
|
|
40
|
-
| `icon` | `React.ReactNode` | – | – |
|
|
41
|
-
| `
|
|
45
|
+
| `asChild` | `boolean` | `false` | – | 用 Radix Slot 模式渲染为子元素;此时 `loading` / `icon` / `iconRight` 被忽略。 |
|
|
46
|
+
| `loading` | `boolean` | `false` | – | 显示自旋 spinner,自动 `disabled` + `aria-busy=true`,保留视觉宽度。 |
|
|
47
|
+
| `icon` | `React.ReactNode` | – | – | 文本左侧图标。推荐 `lucide-react`。loading 时被 spinner 替换。 |
|
|
48
|
+
| `iconRight` | `React.ReactNode` | – | – | 文本右侧图标。推荐 `lucide-react`。 |
|
|
49
|
+
| `iconPosition` | `'start' \| 'end'` | `"start"` | – | 兼容旧 API:`icon` 相对文本的位置;新代码请直接使用 `icon` / `iconRight` 双 slot。 |
|
|
50
|
+
| `disabledTooltip` | `React.ReactNode` | – | – | `disabled=true` 时的禁用解释文本。仅在 `disabled` 同时存在时生效: 内部包一层 `cursor-not-allowed` wrapper + Tooltip,把 button pointer-events 关闭后由 wrapper 拾取 hover。 不传则保持原生 disabled 行为。 |
|
|
42
51
|
| `children` | `React.ReactNode` | – | – | 按钮文本 / 内容。 |
|
|
43
52
|
<!-- auto:props:end -->
|
|
44
53
|
|
|
@@ -54,13 +63,14 @@ package: "@teamix-evo/ui"
|
|
|
54
63
|
| Entry | 类型 | 描述 |
|
|
55
64
|
| --- | --- | --- |
|
|
56
65
|
| `cn` | util | Tailwind className 合并工具(clsx + tailwind-merge) |
|
|
66
|
+
| `tooltip` | component | 文字提示气泡 — Radix Tooltip + antd arrow/placement(side) 并集 + cloud-design Balloon 双变体(default 深底 / light 白底) + 一行 wrapper API |
|
|
57
67
|
|
|
58
68
|
### npm 依赖
|
|
59
69
|
|
|
60
70
|
> 业务侧需要先 `pnpm add` / `npm install` 这些包。CLI 在 `ui add` 完成后会列出此提示。
|
|
61
71
|
|
|
62
72
|
```bash
|
|
63
|
-
pnpm add @radix-ui/react-slot@^1.1.0 class-variance-authority@^0.7.0 lucide-react@^0.460.0
|
|
73
|
+
pnpm add @radix-ui/react-slot@^1.1.0 @radix-ui/react-tooltip@^1.1.0 class-variance-authority@^0.7.0 lucide-react@^0.460.0
|
|
64
74
|
```
|
|
65
75
|
<!-- auto:deps:end -->
|
|
66
76
|
|
|
@@ -69,11 +79,17 @@ pnpm add @radix-ui/react-slot@^1.1.0 class-variance-authority@^0.7.0 lucide-reac
|
|
|
69
79
|
## AI 生成纪律
|
|
70
80
|
|
|
71
81
|
- **variant 语义**:危险动作(删除/重置)用 `destructive`;次要动作(取消)用 `secondary` 或 `ghost`;表单主操作用 `default`;**不要**用 inline 任意值(如 `bg-[#ff0000]`)。
|
|
82
|
+
- **color 双 prop(ADR 0021)**:语义色与视觉风格正交 —— 旧库 `warning + outline` 用 `variant="outline" color="destructive"` 表达,**不要**新增 `warning` variant;同理 `variant="ghost" color="destructive"` = 轻量删除按钮。
|
|
72
83
|
- **icon 来源**:固定从 `lucide-react` import,**不要**内联 SVG,不要混用其他 icon 库。
|
|
73
|
-
-
|
|
74
|
-
- **
|
|
84
|
+
- **双 slot 优于 iconPosition**:新代码用 `icon` + `iconRight` 双 slot;`iconPosition` 仅为兼容旧调用保留,**不要**在新代码中使用。
|
|
85
|
+
- **loading + disabled**:写 `loading` 即可,**不要**额外手动加 `disabled`,组件已自动处理 `aria-busy`。
|
|
86
|
+
- **disabledTooltip 必须配 disabled**:仅在 `disabled=true` 时生效,不要单独使用;**不要**用 `title` 原生 attr 模拟,会失去样式与 a11y。
|
|
87
|
+
- **shape="circle" / "square"**:独立图标按钮必须配 `size="icon"`;SplitButton trigger 可仅用 `shape="square"` 不传 size,从 ButtonGroup 继承尺寸。
|
|
88
|
+
- **icon-only 必带 `aria-label`**:无 children 仅图标的按钮必须传 `aria-label` 给读屏。
|
|
75
89
|
- **block**:`true` 时按钮撑满,**不要**再用 `className="w-full"` 重复。
|
|
76
|
-
- **
|
|
90
|
+
- **size 别用任意值**:用枚举档位(`sm`/`md`/`lg`/`icon`),**不要**写 `className="h-[30px]"`,会破坏 24/32/36 三档体系的视觉一致性(同行 Input/Select 等表单原子混排时高度对不齐)。
|
|
91
|
+
- **圆角靠 cva**:不要在外部传 `className="rounded-xl"` 覆盖默认圆角,默认 `rounded-md`(Tailwind v4 标准 namespace,uni-manager 下 = 2px / opentrek 下 = 6px) 已对齐主题语义。不使用自定义 `--radius-button` 组件级别名 token。
|
|
92
|
+
- **asChild 互斥**:仅当渲染为 `<a>` / `<Link>` 等其他元素时启用,且**不要**与 `loading` / `icon` / `iconRight` 同时使用,会被忽略。
|
|
77
93
|
|
|
78
94
|
## Examples
|
|
79
95
|
|
|
@@ -84,15 +100,236 @@ pnpm add @radix-ui/react-slot@^1.1.0 class-variance-authority@^0.7.0 lucide-reac
|
|
|
84
100
|
// 危险 + 加载
|
|
85
101
|
<Button variant="destructive" loading>删除中</Button>
|
|
86
102
|
|
|
87
|
-
//
|
|
88
|
-
<Button icon={<
|
|
103
|
+
// ADR 0021 双 prop —— warning + outline 形态
|
|
104
|
+
<Button variant="outline" color="destructive" icon={<Trash />}>删除</Button>
|
|
89
105
|
|
|
90
|
-
//
|
|
106
|
+
// 禁用 + 解释文案
|
|
107
|
+
<Button disabled disabledTooltip="无权限操作,请联系管理员">发布</Button>
|
|
108
|
+
|
|
109
|
+
// 双 slot 图标
|
|
110
|
+
<Button icon={<Search />} iconRight={<ArrowRight />}>搜索文档</Button>
|
|
111
|
+
|
|
112
|
+
// 圆形 / 方形图标按钮
|
|
91
113
|
<Button size="icon" shape="circle" variant="ghost" icon={<X />} aria-label="关闭" />
|
|
114
|
+
<Button size="icon" shape="square" variant="outline" icon={<Search />} aria-label="搜索" />
|
|
92
115
|
|
|
93
116
|
// 块级
|
|
94
117
|
<Button block>登录</Button>
|
|
95
118
|
|
|
119
|
+
// 三档尺寸(uni-manager: 24/32/36)
|
|
120
|
+
<Button size="sm">紧凑</Button>
|
|
121
|
+
<Button size="md">默认</Button>
|
|
122
|
+
<Button size="lg">强调</Button>
|
|
123
|
+
|
|
96
124
|
// 作为链接
|
|
97
125
|
<Button asChild variant="link"><a href="/docs">查看文档</a></Button>
|
|
98
126
|
```
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## ButtonGroup 按钮组
|
|
131
|
+
|
|
132
|
+
按钮组 — **等价 antd `Space.Compact`**(v6 替代旧 `Button.Group`)+ **cloud-design `SplitButton` 形态并集**。把多个按钮 / 输入框"粘"在一起共享边线,典型场景:**SplitButton**(主按钮 + 右侧 ChevronDown 下拉箭头按钮 + DropdownMenu 触发)、Toolbar、Input + Button 拼装。配 `ButtonGroupText` 渲染只读 addon 文本。通过 `size` prop + React.Context 把尺寸下发给未显式传 size 的子 Button。
|
|
133
|
+
|
|
134
|
+
### When to use
|
|
135
|
+
|
|
136
|
+
- **SplitButton**(主操作 + 右侧下拉箭头)— 默认主动作 + 备选动作集合(发布/保存/编辑等)
|
|
137
|
+
- Toolbar(同语义按钮集合,如 "上一页 / 下一页 / 跳转")
|
|
138
|
+
- Input + 按钮拼装(搜索框、单位选择)
|
|
139
|
+
- 多档切换显示(配 `Toggle` 也可,但 ToggleGroup 更专精)
|
|
140
|
+
|
|
141
|
+
### When NOT to use
|
|
142
|
+
|
|
143
|
+
- 互斥单选切换 → `ToggleGroup`(语义更强)
|
|
144
|
+
- 不相干的按钮 → 普通 `Button` + flex gap
|
|
145
|
+
|
|
146
|
+
### Props
|
|
147
|
+
|
|
148
|
+
| 名称 | 类型 | 默认值 | 必填 | 说明 |
|
|
149
|
+
| ------------- | ---------------------------- | -------------- | ---- | ------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
150
|
+
| `orientation` | `'horizontal' \| 'vertical'` | `"horizontal"` | – | 排列方向。 |
|
|
151
|
+
| `attached` | `boolean` | `true` | – | 是否把按钮"粘"在一起去除边距(antd `Space.Compact` 等价行为)— `false` 时按钮间留 8px gap。 |
|
|
152
|
+
| `size` | `ButtonSize` | – | – | 统一下发给子 Button 的尺寸;子 Button 若显式传了 `size` 则以子值优先。通过 React.Context 注入,跨 Slot 透传无效(asChild 自定义渲染不会拿到)。 |
|
|
153
|
+
|
|
154
|
+
### AI 生成纪律
|
|
155
|
+
|
|
156
|
+
- **`attached=true`(默认)子项之间边线共享**:第一项 / 最后一项保留外侧圆角,中间项去除圆角;**不要**在内部再设 `rounded`
|
|
157
|
+
- **混用 Input + Button**:把 Input 直接放进 ButtonGroup,它的 `rounded-md` 也会被组件圈圆角(无需特殊处理)
|
|
158
|
+
- **`ButtonGroupText`** 用于只读 addon(`https://` 前缀、`/月` 后缀);**不要**把它当按钮点击
|
|
159
|
+
- **vertical 模式** 适合工具栏侧边小集合,horizontal 是默认推荐
|
|
160
|
+
- **size 下发优先级**:`<ButtonGroup size="sm">` 注入 sm,子 Button 显式传 `size` 时以子值优先,Context 不强制覆盖
|
|
161
|
+
- **不要**在 ButtonGroup 内放 spinner / icon-only 与文字按钮混排时,高度需要靠 button `size` 对齐 — 子项尺寸应一致;**推荐**用 `<ButtonGroup size>` 统一注入而不是逐个传
|
|
162
|
+
|
|
163
|
+
### Examples
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
import { Button, ButtonGroup, ButtonGroupText } from '@/components/ui/button';
|
|
167
|
+
import { Input } from '@/components/ui/input';
|
|
168
|
+
import {
|
|
169
|
+
DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem,
|
|
170
|
+
} from '@/components/ui/dropdown-menu';
|
|
171
|
+
import { ChevronDown } from 'lucide-react';
|
|
172
|
+
|
|
173
|
+
// Split button (纯形态 - 仅 icon 占位)
|
|
174
|
+
<ButtonGroup>
|
|
175
|
+
<Button>保存</Button>
|
|
176
|
+
<Button shape="square" icon={<ChevronDown />} aria-label="更多" />
|
|
177
|
+
</ButtonGroup>
|
|
178
|
+
|
|
179
|
+
// Split button + DropdownMenu 完整形态
|
|
180
|
+
<ButtonGroup>
|
|
181
|
+
<Button>发布</Button>
|
|
182
|
+
<DropdownMenu>
|
|
183
|
+
<DropdownMenuTrigger asChild>
|
|
184
|
+
<Button shape="square" icon={<ChevronDown />} aria-label="更多发布选项" />
|
|
185
|
+
</DropdownMenuTrigger>
|
|
186
|
+
<DropdownMenuContent align="end">
|
|
187
|
+
<DropdownMenuItem>保存为草稿</DropdownMenuItem>
|
|
188
|
+
<DropdownMenuItem>定时发布</DropdownMenuItem>
|
|
189
|
+
</DropdownMenuContent>
|
|
190
|
+
</DropdownMenu>
|
|
191
|
+
</ButtonGroup>
|
|
192
|
+
|
|
193
|
+
// 通过 size 注入,子 Button 自动继承
|
|
194
|
+
<ButtonGroup size="sm">
|
|
195
|
+
<Button variant="outline">继承 sm</Button>
|
|
196
|
+
<Button variant="outline">继承 sm</Button>
|
|
197
|
+
<Button variant="outline" size="lg">显式 lg(覆盖 Context)</Button>
|
|
198
|
+
</ButtonGroup>
|
|
199
|
+
|
|
200
|
+
// Toolbar
|
|
201
|
+
<ButtonGroup>
|
|
202
|
+
<Button variant="outline">上一页</Button>
|
|
203
|
+
<Button variant="outline">1 / 10</Button>
|
|
204
|
+
<Button variant="outline">下一页</Button>
|
|
205
|
+
</ButtonGroup>
|
|
206
|
+
|
|
207
|
+
// 带 addon 文本
|
|
208
|
+
<ButtonGroup>
|
|
209
|
+
<ButtonGroupText>https://</ButtonGroupText>
|
|
210
|
+
<Input defaultValue="example.com" className="rounded-l-none" />
|
|
211
|
+
<Button>访问</Button>
|
|
212
|
+
</ButtonGroup>
|
|
213
|
+
|
|
214
|
+
// 不粘连(留间距)
|
|
215
|
+
<ButtonGroup attached={false}>
|
|
216
|
+
<Button variant="outline">取消</Button>
|
|
217
|
+
<Button>确定</Button>
|
|
218
|
+
</ButtonGroup>
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## SplitButton 形态 — 旧库 API → 新组合映射
|
|
224
|
+
|
|
225
|
+
新库 **不提供独立的 `SplitButton` 组件**。这是主动决策 — 旧库 cloud-design / antd `Dropdown.Button` 本质上是 `ButtonGroup attached + Button + DropdownMenu` 的组合,因此面向业务只暴露组合写法可以:
|
|
226
|
+
|
|
227
|
+
- 统一与其他 SplitButton-like 组合(Input + Button addon 、Toolbar)的结构语法
|
|
228
|
+
- 遵循 P1 “三层对齐”的原子/合成分层,不增加 wrapper 级套娃
|
|
229
|
+
- 业务侧保留 DropdownMenu 子项类型全控(Item / CheckboxItem / RadioItem / Label / Separator 任意组装)
|
|
230
|
+
|
|
231
|
+
以下是旧库 `SplitButton` 全 API 到新组合的逐项映射(拷贝可用):
|
|
232
|
+
|
|
233
|
+
| 旧库 API · cloud-design SplitButton | 新库组合写法 |
|
|
234
|
+
| -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
235
|
+
| `size: 'small' \| 'medium' \| 'large'` | `<ButtonGroup size="sm" \| "md" \| "lg">` — 注入子 Button |
|
|
236
|
+
| `type: 'normal' \| 'primary' \| 'secondary'` | `<Button variant="default" \| "secondary">`(primary == default,遵循 shadcn 语义) |
|
|
237
|
+
| `label` | `<Button>{label}</Button>` 的 children |
|
|
238
|
+
| `component: 'button' \| 'a'` | `<Button asChild>` + `<a href />` |
|
|
239
|
+
| `leftButtonProps` | 主 `<Button {...leftButtonProps}>` 直接 spread |
|
|
240
|
+
| `triggerProps` | `<DropdownMenuTrigger asChild><Button {...triggerProps} /></DropdownMenuTrigger>` |
|
|
241
|
+
| `defaultSelectedKeys` | `<DropdownMenuCheckboxItem defaultChecked>` / `<DropdownMenuRadioGroup defaultValue>` |
|
|
242
|
+
| `selectedKeys`(受控) | `<DropdownMenuCheckboxItem checked onCheckedChange>` / `<DropdownMenuRadioGroup value onValueChange>` |
|
|
243
|
+
| `selectMode: 'single' \| 'multiple'` | `single` → `RadioGroup` + `RadioItem`;`multiple` → `CheckboxItem` |
|
|
244
|
+
| `onSelect` / `onItemClick` | `<DropdownMenuItem onSelect>`(Radix 在 keyboard / click 都触发) |
|
|
245
|
+
| `visible` / `defaultVisible` | `<DropdownMenu open \| defaultOpen>` |
|
|
246
|
+
| `onVisibleChange` | `<DropdownMenu onOpenChange>` |
|
|
247
|
+
| `popupAlign` | `<DropdownMenuContent align="start" \| "center" \| "end">` |
|
|
248
|
+
| `popupStyle` / `popupClassName` | `<DropdownMenuContent style className>` |
|
|
249
|
+
| `popupProps` | `<DropdownMenuContent {...popupProps}>` 直接 spread |
|
|
250
|
+
| `menuProps` | 以各 `<DropdownMenu*>` 子项的 props 明确表达(避免黑盒透传) |
|
|
251
|
+
| `autoWidth`(默认 true) | `<DropdownMenuContent style={{ minWidth: 'var(--radix-dropdown-menu-trigger-width)' }}>` — 读 Radix 暴露的 CSS 变量,只在需要时显式指定,默认遵 shadcn `min-w-[8rem]`(主动选 style 而非 Tailwind arbitrary,避免 `no-arbitrary-tw-value` 告警) |
|
|
252
|
+
|
|
253
|
+
### 不修复清单(旧库能力不迁移的决策)
|
|
254
|
+
|
|
255
|
+
| 旧库能力 | 决策 | 理由 |
|
|
256
|
+
| --------------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------- |
|
|
257
|
+
| `popupTriggerType: 'hover'` | **不补** | Radix DropdownMenu 不原生支持 hover 触发(设计上不符合无障碍/移动端语义)。业务需 hover 菜单请改用 `NavigationMenu` / `HoverCard` |
|
|
258
|
+
| `ghost: 'light' \| 'dark'` | **不补 prop** | ghost variant 靠主题作用域适配 — 黑底区域套 `[data-theme='dark']`,亮底不动。旧库双 prop 是主题能力不足时代的补丁 |
|
|
259
|
+
| `followTrigger`(随滚动) | **不补** | Radix Portal 默认随触发路径滚动定位(`Floating UI` 多策略),无需额外 prop |
|
|
260
|
+
| 独立 `<SplitButton>` 导出名 | **不加** | 保留组合式 — 低抽象、高透明、与 Toolbar / Input addon 保持同一结构语法 |
|
|
261
|
+
|
|
262
|
+
### Examples
|
|
263
|
+
|
|
264
|
+
```tsx
|
|
265
|
+
import { Button, ButtonGroup } from '@/components/ui/button';
|
|
266
|
+
import {
|
|
267
|
+
DropdownMenu, DropdownMenuTrigger, DropdownMenuContent,
|
|
268
|
+
DropdownMenuItem, DropdownMenuSeparator,
|
|
269
|
+
DropdownMenuCheckboxItem,
|
|
270
|
+
DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuLabel,
|
|
271
|
+
} from '@/components/ui/dropdown-menu';
|
|
272
|
+
import { ChevronDown } from 'lucide-react';
|
|
273
|
+
|
|
274
|
+
// 完整形态(默认 click)
|
|
275
|
+
<ButtonGroup>
|
|
276
|
+
<Button>发布</Button>
|
|
277
|
+
<DropdownMenu>
|
|
278
|
+
<DropdownMenuTrigger asChild>
|
|
279
|
+
<Button shape="square" icon={<ChevronDown />} aria-label="更多发布选项" />
|
|
280
|
+
</DropdownMenuTrigger>
|
|
281
|
+
<DropdownMenuContent align="end">
|
|
282
|
+
<DropdownMenuItem>保存为草稿</DropdownMenuItem>
|
|
283
|
+
<DropdownMenuItem>定时发布</DropdownMenuItem>
|
|
284
|
+
<DropdownMenuSeparator />
|
|
285
|
+
<DropdownMenuItem>发布到多个渠道…</DropdownMenuItem>
|
|
286
|
+
</DropdownMenuContent>
|
|
287
|
+
</DropdownMenu>
|
|
288
|
+
</ButtonGroup>
|
|
289
|
+
|
|
290
|
+
// 多选形态(旧库 selectMode="multiple" 等价)
|
|
291
|
+
<ButtonGroup>
|
|
292
|
+
<Button>发布到 N 个渠道</Button>
|
|
293
|
+
<DropdownMenu>
|
|
294
|
+
<DropdownMenuTrigger asChild>
|
|
295
|
+
<Button shape="square" icon={<ChevronDown />} aria-label="选择发布渠道" />
|
|
296
|
+
</DropdownMenuTrigger>
|
|
297
|
+
<DropdownMenuContent align="end">
|
|
298
|
+
<DropdownMenuLabel>发布渠道</DropdownMenuLabel>
|
|
299
|
+
<DropdownMenuSeparator />
|
|
300
|
+
<DropdownMenuCheckboxItem checked={web} onCheckedChange={setWeb}>Web 站点</DropdownMenuCheckboxItem>
|
|
301
|
+
<DropdownMenuCheckboxItem checked={mobile} onCheckedChange={setMobile}>移动端</DropdownMenuCheckboxItem>
|
|
302
|
+
</DropdownMenuContent>
|
|
303
|
+
</DropdownMenu>
|
|
304
|
+
</ButtonGroup>
|
|
305
|
+
|
|
306
|
+
// 单选形态(旧库 selectMode="single" 等价)
|
|
307
|
+
<ButtonGroup>
|
|
308
|
+
<Button>部署到 {envLabel}</Button>
|
|
309
|
+
<DropdownMenu>
|
|
310
|
+
<DropdownMenuTrigger asChild>
|
|
311
|
+
<Button shape="square" icon={<ChevronDown />} aria-label="切换环境" />
|
|
312
|
+
</DropdownMenuTrigger>
|
|
313
|
+
<DropdownMenuContent align="end">
|
|
314
|
+
<DropdownMenuRadioGroup value={env} onValueChange={setEnv}>
|
|
315
|
+
<DropdownMenuRadioItem value="dev">开发</DropdownMenuRadioItem>
|
|
316
|
+
<DropdownMenuRadioItem value="staging">预发</DropdownMenuRadioItem>
|
|
317
|
+
<DropdownMenuRadioItem value="prod">生产</DropdownMenuRadioItem>
|
|
318
|
+
</DropdownMenuRadioGroup>
|
|
319
|
+
</DropdownMenuContent>
|
|
320
|
+
</DropdownMenu>
|
|
321
|
+
</ButtonGroup>
|
|
322
|
+
|
|
323
|
+
// autoWidth(弹层宽度跟随触发按钮)—默认不启,需要时读 Radix CSS 变量(主动选 style 避免 Tailwind arbitrary value 告警):
|
|
324
|
+
<DropdownMenuContent style={{ minWidth: 'var(--radix-dropdown-menu-trigger-width)' }}>
|
|
325
|
+
...
|
|
326
|
+
</DropdownMenuContent>
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### AI 生成纪律补充(SplitButton 专项)
|
|
330
|
+
|
|
331
|
+
- **主按钮与下拉 trigger 的 `variant` 必须一致**(同为 `default` 或同为 `outline`),否则 attached 粘连后边线/背景错位,反衬能力下降
|
|
332
|
+
- **下拉箭头 trigger 必须传 `aria-label`**(例 `"更多发布选项"`)— icon-only 读屏友好
|
|
333
|
+
- **取消 trigger 残留 focus ring** 已在 [`dropdown-menu.tsx`](../dropdown-menu/dropdown-menu.tsx) 默认处理(`onCloseAutoFocus` 默认 preventDefault),业务侧不需手动覆盖
|
|
334
|
+
- **不要用 `<Button onClick>` 手控打开下拉** — 用 `<DropdownMenuTrigger asChild>` 包裹让 Radix 接管键盘/aria 状态
|
|
335
|
+
- **不要提取 `<SplitButton>` wrapper** — 违背该决策(本章开头说明),需复用请抽成业务项目内部的联合 hook 而非 UI 库 entry
|