@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,66 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
import { Tour } from './tour';
|
|
4
|
+
import { Button } from '@/components/button/button';
|
|
5
|
+
|
|
6
|
+
const meta: Meta<typeof Tour> = {
|
|
7
|
+
title: '反馈与浮层 · Feedback/Tour',
|
|
8
|
+
component: Tour,
|
|
9
|
+
tags: ['autodocs'],
|
|
10
|
+
parameters: {
|
|
11
|
+
docs: {
|
|
12
|
+
description: {
|
|
13
|
+
component:
|
|
14
|
+
'新手引导 — 多步骤 spotlight + 卡片 + 步进按钮。帮助新用户首次进入页面时了解关键功能位置。等价 antd `Tour`(v5.0+)。业务侧自管"是否首次访问"。视觉走 OpenTrek tokens,所有样式来自 `@teamix-evo/design`,无 mock。',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default meta;
|
|
21
|
+
type Story = StoryObj<typeof Tour>;
|
|
22
|
+
|
|
23
|
+
export const Playground: Story = {
|
|
24
|
+
parameters: { controls: { disable: true } },
|
|
25
|
+
render: () => {
|
|
26
|
+
const a = React.useRef<HTMLButtonElement>(null);
|
|
27
|
+
const b = React.useRef<HTMLButtonElement>(null);
|
|
28
|
+
const [open, setOpen] = React.useState(false);
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<div className="flex flex-col gap-4">
|
|
32
|
+
<Button onClick={() => setOpen(true)}>启动引导</Button>
|
|
33
|
+
<div className="flex gap-2">
|
|
34
|
+
<Button ref={a} variant="outline">
|
|
35
|
+
新建
|
|
36
|
+
</Button>
|
|
37
|
+
<Button ref={b} variant="outline">
|
|
38
|
+
设置
|
|
39
|
+
</Button>
|
|
40
|
+
</div>
|
|
41
|
+
<Tour
|
|
42
|
+
open={open}
|
|
43
|
+
onOpenChange={setOpen}
|
|
44
|
+
steps={[
|
|
45
|
+
{
|
|
46
|
+
target: a,
|
|
47
|
+
title: '从这里新建',
|
|
48
|
+
description: '点击「新建」按钮创建一个新项目',
|
|
49
|
+
placement: 'bottom',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
target: b,
|
|
53
|
+
title: '个性化设置',
|
|
54
|
+
description: '在此调整主题、通知等偏好',
|
|
55
|
+
placement: 'top',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
title: '完成!',
|
|
59
|
+
description: '开始使用吧 🎉',
|
|
60
|
+
},
|
|
61
|
+
]}
|
|
62
|
+
/>
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
},
|
|
66
|
+
};
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { X } from 'lucide-react';
|
|
3
|
+
|
|
4
|
+
import { cn } from '@/utils/cn';
|
|
5
|
+
import { Button } from '@/components/button/button';
|
|
6
|
+
|
|
7
|
+
export interface TourStep {
|
|
8
|
+
/**
|
|
9
|
+
* 目标元素引用 — 可以是 React ref `RefObject` 或返回 element 的函数。
|
|
10
|
+
* 不传则居中显示(无 spotlight)。
|
|
11
|
+
*/
|
|
12
|
+
target?: React.RefObject<HTMLElement | null> | (() => HTMLElement | null);
|
|
13
|
+
/** 步骤标题。 */
|
|
14
|
+
title: React.ReactNode;
|
|
15
|
+
/** 步骤描述。 */
|
|
16
|
+
description?: React.ReactNode;
|
|
17
|
+
/**
|
|
18
|
+
* 弹层相对目标的位置。
|
|
19
|
+
* @default "bottom"
|
|
20
|
+
*/
|
|
21
|
+
placement?: 'top' | 'bottom' | 'left' | 'right';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface TourProps {
|
|
25
|
+
/** 步骤列表(antd `steps` 并集)。 */
|
|
26
|
+
steps: TourStep[];
|
|
27
|
+
/** 受控 open 状态。 */
|
|
28
|
+
open?: boolean;
|
|
29
|
+
/** uncontrolled 初值。 @default false */
|
|
30
|
+
defaultOpen?: boolean;
|
|
31
|
+
/** open 变化回调。 */
|
|
32
|
+
onOpenChange?: (open: boolean) => void;
|
|
33
|
+
/** 当前步骤索引(受控)。 */
|
|
34
|
+
current?: number;
|
|
35
|
+
/** 步骤变化回调。 */
|
|
36
|
+
onChange?: (current: number) => void;
|
|
37
|
+
/** 完成时回调(走到最后一步且点击"完成")。 */
|
|
38
|
+
onFinish?: () => void;
|
|
39
|
+
/** 关闭回调(任意时刻点 X / mask)。 */
|
|
40
|
+
onClose?: () => void;
|
|
41
|
+
/** 是否显示遮罩(antd `mask` 并集)。 @default true */
|
|
42
|
+
mask?: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const SPOTLIGHT_PADDING = 8;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 新手引导 — antd 独有补足。**等价 antd `Tour`**(v5.0+)。多步骤引导(spotlight + 卡片 + 步进按钮),
|
|
49
|
+
* 帮助新用户首次进入页面时了解关键功能位置。
|
|
50
|
+
*
|
|
51
|
+
* **关键约束**:
|
|
52
|
+
* - 目标元素必须**已在 DOM 中**才能定位 spotlight(组件用 `getBoundingClientRect()`)
|
|
53
|
+
* - 不内置首次访问检测 — 由业务侧自行管理"是否第一次"(常配 localStorage)
|
|
54
|
+
*/
|
|
55
|
+
const Tour: React.FC<TourProps> = ({
|
|
56
|
+
steps,
|
|
57
|
+
open,
|
|
58
|
+
defaultOpen = false,
|
|
59
|
+
onOpenChange,
|
|
60
|
+
current,
|
|
61
|
+
onChange,
|
|
62
|
+
onFinish,
|
|
63
|
+
onClose,
|
|
64
|
+
mask = true,
|
|
65
|
+
}) => {
|
|
66
|
+
const isControlledOpen = open !== undefined;
|
|
67
|
+
const [internalOpen, setInternalOpen] = React.useState(defaultOpen);
|
|
68
|
+
const isOpen = isControlledOpen ? open! : internalOpen;
|
|
69
|
+
|
|
70
|
+
const isControlledStep = current !== undefined;
|
|
71
|
+
const [internalStep, setInternalStep] = React.useState(0);
|
|
72
|
+
const step = isControlledStep ? current! : internalStep;
|
|
73
|
+
|
|
74
|
+
const setOpen = (next: boolean) => {
|
|
75
|
+
if (!isControlledOpen) setInternalOpen(next);
|
|
76
|
+
onOpenChange?.(next);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const setStep = (next: number) => {
|
|
80
|
+
if (!isControlledStep) setInternalStep(next);
|
|
81
|
+
onChange?.(next);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const [, force] = React.useReducer((x: number) => x + 1, 0);
|
|
85
|
+
React.useEffect(() => {
|
|
86
|
+
if (!isOpen) return;
|
|
87
|
+
const onResize = () => force();
|
|
88
|
+
window.addEventListener('resize', onResize);
|
|
89
|
+
window.addEventListener('scroll', onResize, { passive: true });
|
|
90
|
+
return () => {
|
|
91
|
+
window.removeEventListener('resize', onResize);
|
|
92
|
+
window.removeEventListener('scroll', onResize);
|
|
93
|
+
};
|
|
94
|
+
}, [isOpen]);
|
|
95
|
+
|
|
96
|
+
if (!isOpen) return null;
|
|
97
|
+
const cur = steps[step];
|
|
98
|
+
if (!cur) return null;
|
|
99
|
+
|
|
100
|
+
const target =
|
|
101
|
+
typeof cur.target === 'function'
|
|
102
|
+
? cur.target()
|
|
103
|
+
: cur.target?.current ?? null;
|
|
104
|
+
|
|
105
|
+
const rect = target?.getBoundingClientRect();
|
|
106
|
+
|
|
107
|
+
const close = () => {
|
|
108
|
+
setOpen(false);
|
|
109
|
+
onClose?.();
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const finish = () => {
|
|
113
|
+
setOpen(false);
|
|
114
|
+
onFinish?.();
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const placement = cur.placement ?? 'bottom';
|
|
118
|
+
const cardStyle: React.CSSProperties = rect
|
|
119
|
+
? (() => {
|
|
120
|
+
const offset = 12;
|
|
121
|
+
switch (placement) {
|
|
122
|
+
case 'top':
|
|
123
|
+
return {
|
|
124
|
+
top: rect.top - offset,
|
|
125
|
+
left: rect.left + rect.width / 2,
|
|
126
|
+
transform: 'translate(-50%, -100%)',
|
|
127
|
+
};
|
|
128
|
+
case 'left':
|
|
129
|
+
return {
|
|
130
|
+
top: rect.top + rect.height / 2,
|
|
131
|
+
left: rect.left - offset,
|
|
132
|
+
transform: 'translate(-100%, -50%)',
|
|
133
|
+
};
|
|
134
|
+
case 'right':
|
|
135
|
+
return {
|
|
136
|
+
top: rect.top + rect.height / 2,
|
|
137
|
+
left: rect.right + offset,
|
|
138
|
+
transform: 'translate(0, -50%)',
|
|
139
|
+
};
|
|
140
|
+
case 'bottom':
|
|
141
|
+
default:
|
|
142
|
+
return {
|
|
143
|
+
top: rect.bottom + offset,
|
|
144
|
+
left: rect.left + rect.width / 2,
|
|
145
|
+
transform: 'translate(-50%, 0)',
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
})()
|
|
149
|
+
: {
|
|
150
|
+
top: '50%',
|
|
151
|
+
left: '50%',
|
|
152
|
+
transform: 'translate(-50%, -50%)',
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<div className="fixed inset-0 z-50">
|
|
157
|
+
{mask ? (
|
|
158
|
+
rect ? (
|
|
159
|
+
<svg
|
|
160
|
+
className="pointer-events-none absolute inset-0 size-full"
|
|
161
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
162
|
+
>
|
|
163
|
+
<defs>
|
|
164
|
+
<mask id="tour-mask">
|
|
165
|
+
<rect width="100%" height="100%" fill="white" />
|
|
166
|
+
<rect
|
|
167
|
+
x={rect.left - SPOTLIGHT_PADDING}
|
|
168
|
+
y={rect.top - SPOTLIGHT_PADDING}
|
|
169
|
+
width={rect.width + SPOTLIGHT_PADDING * 2}
|
|
170
|
+
height={rect.height + SPOTLIGHT_PADDING * 2}
|
|
171
|
+
rx="6"
|
|
172
|
+
fill="black"
|
|
173
|
+
/>
|
|
174
|
+
</mask>
|
|
175
|
+
</defs>
|
|
176
|
+
<rect
|
|
177
|
+
width="100%"
|
|
178
|
+
height="100%"
|
|
179
|
+
fill="rgba(0,0,0,0.5)"
|
|
180
|
+
mask="url(#tour-mask)"
|
|
181
|
+
/>
|
|
182
|
+
</svg>
|
|
183
|
+
) : (
|
|
184
|
+
<div className="absolute inset-0 bg-black/50" onClick={close} />
|
|
185
|
+
)
|
|
186
|
+
) : null}
|
|
187
|
+
|
|
188
|
+
<div
|
|
189
|
+
role="dialog"
|
|
190
|
+
className={cn(
|
|
191
|
+
'absolute w-80 rounded-md border bg-popover p-4 text-popover-foreground shadow-xl',
|
|
192
|
+
)}
|
|
193
|
+
style={cardStyle}
|
|
194
|
+
>
|
|
195
|
+
<div className="flex items-start justify-between gap-2">
|
|
196
|
+
<div className="font-semibold">{cur.title}</div>
|
|
197
|
+
<button
|
|
198
|
+
type="button"
|
|
199
|
+
aria-label="关闭"
|
|
200
|
+
onClick={close}
|
|
201
|
+
className="text-muted-foreground transition-colors hover:text-foreground"
|
|
202
|
+
>
|
|
203
|
+
<X className="size-4" />
|
|
204
|
+
</button>
|
|
205
|
+
</div>
|
|
206
|
+
{cur.description ? (
|
|
207
|
+
<div className="mt-2 text-sm text-muted-foreground">
|
|
208
|
+
{cur.description}
|
|
209
|
+
</div>
|
|
210
|
+
) : null}
|
|
211
|
+
<div className="mt-4 flex items-center justify-between">
|
|
212
|
+
<span className="text-xs tabular-nums text-muted-foreground">
|
|
213
|
+
{step + 1} / {steps.length}
|
|
214
|
+
</span>
|
|
215
|
+
<div className="flex gap-2">
|
|
216
|
+
{step > 0 ? (
|
|
217
|
+
<Button
|
|
218
|
+
variant="outline"
|
|
219
|
+
size="sm"
|
|
220
|
+
onClick={() => setStep(step - 1)}
|
|
221
|
+
>
|
|
222
|
+
上一步
|
|
223
|
+
</Button>
|
|
224
|
+
) : null}
|
|
225
|
+
{step < steps.length - 1 ? (
|
|
226
|
+
<Button size="sm" onClick={() => setStep(step + 1)}>
|
|
227
|
+
下一步
|
|
228
|
+
</Button>
|
|
229
|
+
) : (
|
|
230
|
+
<Button size="sm" onClick={finish}>
|
|
231
|
+
完成
|
|
232
|
+
</Button>
|
|
233
|
+
)}
|
|
234
|
+
</div>
|
|
235
|
+
</div>
|
|
236
|
+
</div>
|
|
237
|
+
</div>
|
|
238
|
+
);
|
|
239
|
+
};
|
|
240
|
+
Tour.displayName = 'Tour';
|
|
241
|
+
|
|
242
|
+
export { Tour };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: transfer
|
|
3
|
+
name: Transfer
|
|
4
|
+
type: component
|
|
5
|
+
category: data-display
|
|
6
|
+
since: 0.1.0
|
|
7
|
+
package: "@teamix-evo/ui"
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Transfer
|
|
11
|
+
|
|
12
|
+
穿梭框 — antd 独有补足。**双侧勾选 + 移动**的批量分配交互(权限分配、字段映射、收件人选择)。受控 `targetKeys` + `onChange` 单一真值,内置全选 / 半选 / 可选搜索 / 禁用项。
|
|
13
|
+
|
|
14
|
+
## When to use
|
|
15
|
+
|
|
16
|
+
- 从大集合中挑选若干成员进入小集合(成员授权、邮件收件人)
|
|
17
|
+
- 字段映射:左侧未映射字段 → 右侧已映射字段
|
|
18
|
+
- 类目选择,可选 + 可移除并存
|
|
19
|
+
|
|
20
|
+
## When NOT to use
|
|
21
|
+
|
|
22
|
+
- 单纯多选 → `Select multiple` / `CheckboxGroup`(轻量)
|
|
23
|
+
- 选项 > 500 — 本组件未做虚拟化,建议改用 `Table` + 行选 + bulk action 模式
|
|
24
|
+
|
|
25
|
+
<!-- auto:props:begin -->
|
|
26
|
+
| 名称 | 类型 | 默认值 | 必填 | 说明 |
|
|
27
|
+
| --- | --- | --- | --- | --- |
|
|
28
|
+
| `dataSource` | `TransferItem[]` | – | ✓ | 全部数据源(左+右合集)。 |
|
|
29
|
+
| `targetKeys` | `string[]` | – | ✓ | 受控:已"穿梭到右侧"的 key 集合(antd `targetKeys` 并集)。 |
|
|
30
|
+
| `onChange` | `(next: string[]) => void` | – | – | 右侧集合变化回调。 |
|
|
31
|
+
| `titles` | `[React.ReactNode, React.ReactNode]` | `["源", "目标"]` | – | 两侧标题(antd `titles` 并集) — `[左, 右]`。 |
|
|
32
|
+
| `showSearch` | `boolean` | `false` | – | 启用搜索(antd `showSearch` 并集) — 两侧各一个输入框。 |
|
|
33
|
+
| `render` | `(item: TransferItem) => React.ReactNode` | – | – | 自定义渲染单项(antd `render` 并集) — 默认渲染 `item.title`。 |
|
|
34
|
+
| `disabled` | `boolean` | – | – | 整体禁用。 |
|
|
35
|
+
| `listHeight` | `number` | `280` | – | 单侧高度(像素)。 |
|
|
36
|
+
| `className` | `string` | – | – | – |
|
|
37
|
+
<!-- auto:props:end -->
|
|
38
|
+
|
|
39
|
+
<!-- auto:deps:begin -->
|
|
40
|
+
### 同库依赖
|
|
41
|
+
|
|
42
|
+
> `teamix-evo ui add transfer` 时,以下 entry 会被自动连带安装(无需手动 add)。
|
|
43
|
+
|
|
44
|
+
| Entry | 类型 | 描述 |
|
|
45
|
+
| --- | --- | --- |
|
|
46
|
+
| `cn` | util | Tailwind className 合并工具(clsx + tailwind-merge) |
|
|
47
|
+
| `button` | component | 通用按钮 — shadcn 实现 + antd 功能扩展(loading / icon / shape / block / dashed variant) |
|
|
48
|
+
| `checkbox` | component | 复选框 — Radix Checkbox(原生 indeterminate)+ antd Checkbox.Group(options 数组驱动) |
|
|
49
|
+
| `input` | component | 文本输入 — shadcn 简洁基底 + antd prefix/suffix/clearable/showCount/addonBefore/addonAfter/size |
|
|
50
|
+
|
|
51
|
+
### npm 依赖
|
|
52
|
+
|
|
53
|
+
> 业务侧需要先 `pnpm add` / `npm install` 这些包。CLI 在 `ui add` 完成后会列出此提示。
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pnpm add lucide-react@^0.460.0
|
|
57
|
+
```
|
|
58
|
+
<!-- auto:deps:end -->
|
|
59
|
+
|
|
60
|
+
## AI 生成纪律
|
|
61
|
+
|
|
62
|
+
- **`targetKeys` 是单一真值**:左侧 = `dataSource \ targetKeys`,右侧 = `targetKeys`;**不要**自己维护两个数组
|
|
63
|
+
- **禁用项不可被移动**:即使被勾选也会被 batch move 跳过(对齐 antd)
|
|
64
|
+
- **搜索仅做客户端字符串匹配**:`title` 为 string 时按子串匹配;ReactNode 时不过滤(消费方请保证 title 是 string 或在 `dataSource` 上做 server-side filter)
|
|
65
|
+
- **不要在 `onChange` 里改 `dataSource`**:dataSource 应稳定,只改 targetKeys
|
|
66
|
+
- **`titles` 必为长度 2 的数组**:`['可选', '已选']` / `['全部成员', '已授权']` 之类语义
|
|
67
|
+
- **大数据量(> 200 项)**:建议改用 `Table` + 行选择 + 批量操作,Transfer 更适合 < 200 项的小集合穿梭
|
|
68
|
+
|
|
69
|
+
## Examples
|
|
70
|
+
|
|
71
|
+
```tsx
|
|
72
|
+
import { Transfer, type TransferItem } from '@/components/ui/transfer';
|
|
73
|
+
import * as React from 'react';
|
|
74
|
+
|
|
75
|
+
const data: TransferItem[] = Array.from({ length: 12 }, (_, i) => ({
|
|
76
|
+
key: String(i),
|
|
77
|
+
title: `成员 ${i + 1}`,
|
|
78
|
+
disabled: i === 0,
|
|
79
|
+
}));
|
|
80
|
+
|
|
81
|
+
const [target, setTarget] = React.useState<string[]>(['2', '4']);
|
|
82
|
+
|
|
83
|
+
<Transfer
|
|
84
|
+
dataSource={data}
|
|
85
|
+
targetKeys={target}
|
|
86
|
+
onChange={setTarget}
|
|
87
|
+
titles={['全部成员', '已授权']}
|
|
88
|
+
showSearch
|
|
89
|
+
/>
|
|
90
|
+
```
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
import { Transfer, type TransferItem } from './transfer';
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof Transfer> = {
|
|
6
|
+
title: '数据展示 · Data Display/Transfer',
|
|
7
|
+
component: Transfer,
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
parameters: {
|
|
10
|
+
docs: {
|
|
11
|
+
description: {
|
|
12
|
+
component:
|
|
13
|
+
'穿梭框 — 双侧勾选 + 移动的批量分配交互(权限分配、字段映射、收件人选择)。受控 targetKeys 单一真值,内置全选 / 半选 / 可选搜索 / 禁用项跳过。视觉走 OpenTrek tokens,等价 antd `Transfer`,所有样式来自 `@teamix-evo/design`,无 mock。',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default meta;
|
|
20
|
+
type Story = StoryObj<typeof Transfer>;
|
|
21
|
+
|
|
22
|
+
const data: TransferItem[] = Array.from({ length: 12 }, (_, i) => ({
|
|
23
|
+
key: String(i),
|
|
24
|
+
title: `成员 ${i + 1}`,
|
|
25
|
+
disabled: i === 0,
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
export const Playground: Story = {
|
|
29
|
+
parameters: { controls: { disable: true } },
|
|
30
|
+
render: () => {
|
|
31
|
+
const [target, setTarget] = React.useState<string[]>(['2', '4']);
|
|
32
|
+
return (
|
|
33
|
+
<Transfer
|
|
34
|
+
dataSource={data}
|
|
35
|
+
targetKeys={target}
|
|
36
|
+
onChange={setTarget}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const WithSearch: Story = {
|
|
43
|
+
parameters: { controls: { disable: true } },
|
|
44
|
+
render: () => {
|
|
45
|
+
const [target, setTarget] = React.useState<string[]>([]);
|
|
46
|
+
return (
|
|
47
|
+
<Transfer
|
|
48
|
+
dataSource={data}
|
|
49
|
+
targetKeys={target}
|
|
50
|
+
onChange={setTarget}
|
|
51
|
+
titles={['全部成员', '已授权']}
|
|
52
|
+
showSearch
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const Disabled: Story = {
|
|
59
|
+
parameters: { controls: { disable: true } },
|
|
60
|
+
render: () => (
|
|
61
|
+
<Transfer
|
|
62
|
+
dataSource={data}
|
|
63
|
+
targetKeys={['1', '3']}
|
|
64
|
+
titles={['只读·左', '只读·右']}
|
|
65
|
+
disabled
|
|
66
|
+
/>
|
|
67
|
+
),
|
|
68
|
+
};
|