myshell-react-lib 0.1.5 → 0.1.7
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/dist/index.cjs +50 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -2
- package/src/common/assets/audio-playing.json +0 -3657
- package/src/common/constants/constants.ts +0 -24
- package/src/common/constants/types/common.ts +0 -10
- package/src/common/hooks/useAudioPlayer.tsx +0 -198
- package/src/common/hooks/useDevice.ts +0 -26
- package/src/common/hooks/useNativeBridge.ts +0 -42
- package/src/common/hooks/useNotification.tsx +0 -179
- package/src/common/hooks/useWindowWidth.ts +0 -19
- package/src/common/utils/common-helper.ts +0 -81
- package/src/components/ItemDemo.tsx +0 -15
- package/src/components/accordion.tsx +0 -126
- package/src/components/alert-dialog.tsx +0 -148
- package/src/components/alert.tsx +0 -65
- package/src/components/aspect-ratio.tsx +0 -7
- package/src/components/audio-player.tsx +0 -60
- package/src/components/audio-playing.tsx +0 -33
- package/src/components/avatar.tsx +0 -133
- package/src/components/badge.tsx +0 -67
- package/src/components/button/button.styles.ts +0 -258
- package/src/components/button/button.tsx +0 -215
- package/src/components/button/icon-button.styles.ts +0 -103
- package/src/components/button/icon-button.tsx +0 -100
- package/src/components/button/index.tsx +0 -3
- package/src/components/button/link-button.tsx +0 -184
- package/src/components/cascader.tsx +0 -175
- package/src/components/checkbox.tsx +0 -135
- package/src/components/command.tsx +0 -155
- package/src/components/context-menu.tsx +0 -198
- package/src/components/count-down.tsx +0 -83
- package/src/components/custom-notification.tsx +0 -95
- package/src/components/dialog.tsx +0 -158
- package/src/components/drawer.tsx +0 -116
- package/src/components/dropdown-menu.tsx +0 -196
- package/src/components/energy-progress.tsx +0 -55
- package/src/components/form.tsx +0 -201
- package/src/components/group.tsx +0 -9
- package/src/components/guide.tsx +0 -243
- package/src/components/icon.tsx +0 -96
- package/src/components/icons/index.tsx +0 -13
- package/src/components/icons/outline/ArrowLeftIcon.tsx +0 -28
- package/src/components/icons/outline/ArrowUpTrayIcon.tsx +0 -28
- package/src/components/icons/outline/CheckCircleIcon.tsx +0 -27
- package/src/components/icons/outline/ConfigIcon.tsx +0 -42
- package/src/components/icons/outline/DownIcon.tsx +0 -18
- package/src/components/icons/outline/FilterIcon.tsx +0 -20
- package/src/components/icons/outline/PencilSquareIcon.tsx +0 -28
- package/src/components/icons/outline/WindowIcon.tsx +0 -26
- package/src/components/icons/solid/CaretDownIcon.tsx +0 -22
- package/src/components/icons/solid/CodeIcon.tsx +0 -25
- package/src/components/icons/solid/DragIcon.tsx +0 -24
- package/src/components/icons/solid/PhoneIcon.tsx +0 -29
- package/src/components/icons/solid/RectangleGroupIcon.tsx +0 -26
- package/src/components/image.tsx +0 -152
- package/src/components/input.tsx +0 -118
- package/src/components/label.tsx +0 -26
- package/src/components/link.tsx +0 -123
- package/src/components/marquee/index.css +0 -15
- package/src/components/marquee/marquee.tsx +0 -220
- package/src/components/masonry.tsx +0 -138
- package/src/components/menubar.tsx +0 -234
- package/src/components/mobile/m-tooltip.tsx +0 -34
- package/src/components/modal.tsx +0 -561
- package/src/components/navigation-bar.tsx +0 -100
- package/src/components/number-input.tsx +0 -143
- package/src/components/page-content.tsx +0 -16
- package/src/components/popover.tsx +0 -191
- package/src/components/progress.tsx +0 -80
- package/src/components/radio-group.tsx +0 -44
- package/src/components/scroll-area.tsx +0 -49
- package/src/components/search-bar.tsx +0 -140
- package/src/components/secondary-navigation-bar.tsx +0 -328
- package/src/components/select.tsx +0 -273
- package/src/components/separator.tsx +0 -31
- package/src/components/sheet.tsx +0 -143
- package/src/components/skeleton.tsx +0 -20
- package/src/components/slider.tsx +0 -160
- package/src/components/spinner.tsx +0 -50
- package/src/components/swiper/index.module.scss +0 -88
- package/src/components/swiper/index.tsx +0 -319
- package/src/components/switch.tsx +0 -67
- package/src/components/tabs.tsx +0 -325
- package/src/components/textarea.tsx +0 -71
- package/src/components/toast/toast.tsx +0 -182
- package/src/components/toast/toaster.tsx +0 -160
- package/src/components/toast/use-toast.tsx +0 -248
- package/src/components/toggle-group.tsx +0 -64
- package/src/components/toggle.tsx +0 -46
- package/src/components/tooltip.tsx +0 -283
- package/src/components/typography.tsx +0 -437
- package/src/index.ts +0 -70
- package/src/lib/utils.ts +0 -62
- package/src/stories/Accordion.stories.tsx +0 -64
- package/src/stories/AccordionItem.stories.tsx +0 -48
- package/src/stories/Avatar.stories.ts +0 -58
- package/src/stories/Badge.stories.tsx +0 -40
- package/src/stories/BannerSwiper.stories.tsx +0 -102
- package/src/stories/Button.stories.tsx +0 -543
- package/src/stories/Checkbox.stories.tsx +0 -161
- package/src/stories/Configure.mdx +0 -341
- package/src/stories/CssProperties.mdx +0 -30
- package/src/stories/Description.stories.ts +0 -70
- package/src/stories/Display.stories.ts +0 -64
- package/src/stories/FeaturedSwiper.stories.tsx +0 -6978
- package/src/stories/GridSwiper.stories.tsx +0 -1407
- package/src/stories/Guide.stories.tsx +0 -247
- package/src/stories/Heading.stories.ts +0 -89
- package/src/stories/Icon.stories.ts +0 -77
- package/src/stories/IconButton.stories.tsx +0 -301
- package/src/stories/IconTextButton.stories.ts +0 -59
- package/src/stories/Image.stories.ts +0 -55
- package/src/stories/Input.stories.tsx +0 -203
- package/src/stories/Modal.stories.tsx +0 -144
- package/src/stories/NavigationBar.stories.tsx +0 -81
- package/src/stories/Notification.stories.tsx +0 -276
- package/src/stories/Popover.stories.tsx +0 -100
- package/src/stories/SearchBar.stories.ts +0 -43
- package/src/stories/SecondaryNavigationBar.stories.tsx +0 -199
- package/src/stories/Select.stories.tsx +0 -107
- package/src/stories/Separator.stories.tsx +0 -49
- package/src/stories/Spinner.stories.tsx +0 -48
- package/src/stories/SubHeading.stories.ts +0 -64
- package/src/stories/Swich.stories.tsx +0 -69
- package/src/stories/Tabs.stories.tsx +0 -90
- package/src/stories/Text.stories.ts +0 -78
- package/src/stories/Textarea.stories.tsx +0 -155
- package/src/stories/Toast.stories.tsx +0 -424
- package/src/stories/Tooltip.stories.tsx +0 -244
- package/src/stories/ViewAutoSwiper.stories.tsx +0 -1408
- package/src/styles/components-dark.scss +0 -212
- package/src/styles/components-light.scss +0 -210
- package/src/styles/design-dark.scss +0 -330
- package/src/styles/design-light.scss +0 -345
- package/src/styles/design2-dark.scss +0 -319
- package/src/styles/design2-light.scss +0 -364
- package/src/styles/font.css +0 -19
- package/src/styles/global.scss +0 -251
- package/src/styles/md-viewer.scss +0 -155
- package/src/styles/new-tokens.scss +0 -255
- package/src/styles/tokens.scss +0 -401
- package/src/types/scss.d.ts +0 -24
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import { fn } from '@storybook/test';
|
|
3
|
-
|
|
4
|
-
import { Text } from '@/components/typography';
|
|
5
|
-
|
|
6
|
-
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
|
|
7
|
-
const meta = {
|
|
8
|
-
title: 'Components/文字排版/Text-文字',
|
|
9
|
-
component: Text,
|
|
10
|
-
parameters: {
|
|
11
|
-
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
|
|
12
|
-
layout: 'centered',
|
|
13
|
-
},
|
|
14
|
-
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
|
15
|
-
tags: ['autodocs'],
|
|
16
|
-
|
|
17
|
-
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
|
|
18
|
-
args: {
|
|
19
|
-
size: 'lg',
|
|
20
|
-
weight: 'regular',
|
|
21
|
-
color: 'default',
|
|
22
|
-
children: 'Body/lg/Regular',
|
|
23
|
-
underline: false,
|
|
24
|
-
strikethrough: false,
|
|
25
|
-
strong: false,
|
|
26
|
-
italic: false,
|
|
27
|
-
},
|
|
28
|
-
argTypes: {
|
|
29
|
-
// 定义size为select类型的控件
|
|
30
|
-
size: {
|
|
31
|
-
control: 'select',
|
|
32
|
-
options: ['lg', 'sm'],
|
|
33
|
-
},
|
|
34
|
-
weight: {
|
|
35
|
-
control: 'select',
|
|
36
|
-
options: ['regular', 'medium', 'semibold'],
|
|
37
|
-
},
|
|
38
|
-
// 定义color为select类型的控件
|
|
39
|
-
color: {
|
|
40
|
-
control: 'select',
|
|
41
|
-
options: [
|
|
42
|
-
'default',
|
|
43
|
-
'subtle',
|
|
44
|
-
'subtler',
|
|
45
|
-
'subtlest',
|
|
46
|
-
'disabled',
|
|
47
|
-
'static',
|
|
48
|
-
'static-black',
|
|
49
|
-
'brand',
|
|
50
|
-
'critical',
|
|
51
|
-
'critical-bolder',
|
|
52
|
-
'warning',
|
|
53
|
-
'warning-bolder',
|
|
54
|
-
'success',
|
|
55
|
-
'success-bolder',
|
|
56
|
-
],
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
// 定义lineClamp为select类型的控件
|
|
60
|
-
lineClamp: {
|
|
61
|
-
control: 'select',
|
|
62
|
-
options: [1, 2, 3, 4, 5, 6],
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
} satisfies Meta<typeof Text>;
|
|
66
|
-
|
|
67
|
-
export default meta;
|
|
68
|
-
// export const Default: StoryObj<typeof meta> = {
|
|
69
|
-
// // 这里不需要设置 args,因为它会继承 meta 中的 args
|
|
70
|
-
// };
|
|
71
|
-
type Story = StoryObj<typeof meta>;
|
|
72
|
-
|
|
73
|
-
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
|
|
74
|
-
export const Demo: Story = {
|
|
75
|
-
args: {
|
|
76
|
-
...meta.args, // 继承默认参数
|
|
77
|
-
},
|
|
78
|
-
};
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import React, { useState } from 'react';
|
|
3
|
-
|
|
4
|
-
import { Button } from '../components/button';
|
|
5
|
-
import { Textarea } from '../components/textarea';
|
|
6
|
-
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
|
|
7
|
-
const meta = {
|
|
8
|
-
title: 'Components/表单/Textarea-输入框',
|
|
9
|
-
component: Textarea,
|
|
10
|
-
parameters: {
|
|
11
|
-
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
|
|
12
|
-
layout: 'centered',
|
|
13
|
-
},
|
|
14
|
-
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
|
15
|
-
tags: ['autodocs'],
|
|
16
|
-
|
|
17
|
-
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
|
|
18
|
-
args: {
|
|
19
|
-
placeholder: 'Search Myshell',
|
|
20
|
-
},
|
|
21
|
-
argTypes: {
|
|
22
|
-
// 定义size为select类型的控件
|
|
23
|
-
value: {
|
|
24
|
-
control: 'text',
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
} satisfies Meta<typeof Textarea>;
|
|
28
|
-
|
|
29
|
-
export default meta;
|
|
30
|
-
// export const Default: StoryObj<typeof meta> = {
|
|
31
|
-
// // 这里不需要设置 args,因为它会继承 meta 中的 args
|
|
32
|
-
// };
|
|
33
|
-
type Story = StoryObj<typeof meta>;
|
|
34
|
-
|
|
35
|
-
const FormErrorDemo = () => {
|
|
36
|
-
const [formData, setFormData] = useState({
|
|
37
|
-
desc: '',
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// 存储每个字段的错误信息
|
|
41
|
-
const [errors, setErrors] = useState({
|
|
42
|
-
desc: '',
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// 触发验证的状态(仅在提交后激活)
|
|
46
|
-
const [isValidating, setIsValidating] = useState(false);
|
|
47
|
-
|
|
48
|
-
const handleChange = (e) => {
|
|
49
|
-
const { name, value } = e.target;
|
|
50
|
-
setFormData({
|
|
51
|
-
...formData,
|
|
52
|
-
[name]: value,
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// 如果已经在验证状态,即时验证
|
|
56
|
-
if (isValidating) {
|
|
57
|
-
validateField(name, value);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const validateField = (name, value) => {
|
|
62
|
-
let errorMessage = '';
|
|
63
|
-
|
|
64
|
-
switch (name) {
|
|
65
|
-
case 'desc':
|
|
66
|
-
if (!value.trim()) {
|
|
67
|
-
errorMessage = '描述不能为空';
|
|
68
|
-
} else if (value.length < 10) {
|
|
69
|
-
errorMessage = '描述至少需要3个字符';
|
|
70
|
-
}
|
|
71
|
-
break;
|
|
72
|
-
default:
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
setErrors((prev) => ({
|
|
77
|
-
...prev,
|
|
78
|
-
[name]: errorMessage,
|
|
79
|
-
}));
|
|
80
|
-
|
|
81
|
-
return !errorMessage;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const validateForm = () => {
|
|
85
|
-
const descValid = validateField('desc', formData.desc);
|
|
86
|
-
|
|
87
|
-
return descValid;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const handleSubmit = (e) => {
|
|
91
|
-
e.preventDefault();
|
|
92
|
-
setIsValidating(true);
|
|
93
|
-
|
|
94
|
-
if (validateForm()) {
|
|
95
|
-
// 表单验证通过,可以提交
|
|
96
|
-
console.log('表单提交成功:', formData);
|
|
97
|
-
// 这里可以添加提交逻辑
|
|
98
|
-
} else {
|
|
99
|
-
console.log('表单验证失败');
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
return (
|
|
104
|
-
<div className="space-y-4 w-full max-w-md">
|
|
105
|
-
<form onSubmit={handleSubmit}>
|
|
106
|
-
<div className="mb-4">
|
|
107
|
-
<Textarea
|
|
108
|
-
name="desc"
|
|
109
|
-
placeholder="描述"
|
|
110
|
-
value={formData.desc}
|
|
111
|
-
onChange={handleChange}
|
|
112
|
-
aria-invalid={!!errors.desc}
|
|
113
|
-
/>
|
|
114
|
-
{errors.desc && (
|
|
115
|
-
<p className="mt-1 text-sm text-Colors-Text-Critical-Default">
|
|
116
|
-
{errors.desc}
|
|
117
|
-
</p>
|
|
118
|
-
)}
|
|
119
|
-
</div>
|
|
120
|
-
|
|
121
|
-
<div className="flex space-x-4">
|
|
122
|
-
<Button type="submit">提交表单</Button>
|
|
123
|
-
<Button
|
|
124
|
-
type="button"
|
|
125
|
-
variant="secondary"
|
|
126
|
-
onClick={() => {
|
|
127
|
-
setFormData({ desc: '' });
|
|
128
|
-
setErrors({ desc: '' });
|
|
129
|
-
setIsValidating(false);
|
|
130
|
-
}}
|
|
131
|
-
>
|
|
132
|
-
重置
|
|
133
|
-
</Button>
|
|
134
|
-
<Button
|
|
135
|
-
type="button"
|
|
136
|
-
variant="secondary"
|
|
137
|
-
onClick={() => {
|
|
138
|
-
setFormData({
|
|
139
|
-
desc: 'te', // 故意设置错误的值
|
|
140
|
-
});
|
|
141
|
-
setIsValidating(true);
|
|
142
|
-
validateForm();
|
|
143
|
-
}}
|
|
144
|
-
>
|
|
145
|
-
触发错误状态
|
|
146
|
-
</Button>
|
|
147
|
-
</div>
|
|
148
|
-
</form>
|
|
149
|
-
</div>
|
|
150
|
-
);
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
export const 表单验证: Story = {
|
|
154
|
-
render: () => <FormErrorDemo />,
|
|
155
|
-
};
|
|
@@ -1,424 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import React, { useState } from 'react';
|
|
3
|
-
import { Button } from '../components/button';
|
|
4
|
-
import { Toaster } from '../components/toast/toaster';
|
|
5
|
-
import { useToast } from '../components/toast/use-toast';
|
|
6
|
-
|
|
7
|
-
// 创建一个简单的代码预览组件
|
|
8
|
-
const CodePreview = ({ code }: { code: string }) => {
|
|
9
|
-
return (
|
|
10
|
-
<div className="w-full bg-neutral-100 dark:bg-neutral-900 p-4 rounded-md overflow-auto max-h-[400px] mt-4">
|
|
11
|
-
<pre className="text-sm font-mono whitespace-pre-wrap break-words text-neutral-800 dark:text-neutral-200">
|
|
12
|
-
<code>{code}</code>
|
|
13
|
-
</pre>
|
|
14
|
-
</div>
|
|
15
|
-
);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// 创建一个带有代码展示功能的Demo组件
|
|
19
|
-
const DemoWithCode = ({
|
|
20
|
-
children,
|
|
21
|
-
code,
|
|
22
|
-
}: {
|
|
23
|
-
children: React.ReactNode;
|
|
24
|
-
code: string;
|
|
25
|
-
}) => {
|
|
26
|
-
const [showCode, setShowCode] = useState(false);
|
|
27
|
-
return (
|
|
28
|
-
<div className="border rounded-md p-4 mb-6 w-[60vw]">
|
|
29
|
-
<div className="mb-1">{children}</div>
|
|
30
|
-
{showCode && <CodePreview code={code} />}
|
|
31
|
-
<div className="mt-1 flex justify-end">
|
|
32
|
-
<Button
|
|
33
|
-
variant="secondary"
|
|
34
|
-
size={'sm'}
|
|
35
|
-
onClick={() => {
|
|
36
|
-
setShowCode(!showCode);
|
|
37
|
-
}}
|
|
38
|
-
>
|
|
39
|
-
{showCode ? 'hide code' : 'show code'}
|
|
40
|
-
</Button>
|
|
41
|
-
</div>
|
|
42
|
-
</div>
|
|
43
|
-
);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const ToastDemo = ({
|
|
47
|
-
variant,
|
|
48
|
-
actions,
|
|
49
|
-
type,
|
|
50
|
-
}: {
|
|
51
|
-
variant?: 'info' | 'success' | 'warning' | 'error';
|
|
52
|
-
id?: string;
|
|
53
|
-
actions?: {
|
|
54
|
-
dismissText?: string;
|
|
55
|
-
view?: string;
|
|
56
|
-
viewUrl?: string;
|
|
57
|
-
};
|
|
58
|
-
type?: string;
|
|
59
|
-
}) => {
|
|
60
|
-
const { toast } = useToast();
|
|
61
|
-
|
|
62
|
-
const showToast = () => {
|
|
63
|
-
if (actions) {
|
|
64
|
-
toast({
|
|
65
|
-
variant,
|
|
66
|
-
title: `${
|
|
67
|
-
variant
|
|
68
|
-
? variant.charAt(0).toUpperCase() + variant.slice(1)
|
|
69
|
-
: 'Default'
|
|
70
|
-
} Toast`,
|
|
71
|
-
description:
|
|
72
|
-
'Check out the all new dashboard view. Pages and exports now load faster. ',
|
|
73
|
-
actions,
|
|
74
|
-
});
|
|
75
|
-
} else {
|
|
76
|
-
toast({
|
|
77
|
-
variant,
|
|
78
|
-
title: `${
|
|
79
|
-
variant
|
|
80
|
-
? variant.charAt(0).toUpperCase() + variant.slice(1)
|
|
81
|
-
: 'Default'
|
|
82
|
-
} Toast`,
|
|
83
|
-
description:
|
|
84
|
-
'Check out the all new dashboard view. Pages and exports now load faster. ',
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
return (
|
|
90
|
-
<div className="flex flex-col space-y-2">
|
|
91
|
-
<Button onClick={showToast}>显示{type || variant || '带操作'}通知</Button>
|
|
92
|
-
<Toaster />
|
|
93
|
-
</div>
|
|
94
|
-
);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
// 示例代码
|
|
98
|
-
const infoToastCode = `
|
|
99
|
-
import { useToast } from '../components/toast/use-toast';
|
|
100
|
-
import { Toaster } from '../components/toast/toaster';
|
|
101
|
-
import { Button } from '../components/button';
|
|
102
|
-
|
|
103
|
-
function InfoToastExample() {
|
|
104
|
-
const { toast } = useToast();
|
|
105
|
-
|
|
106
|
-
const showToast = () => {
|
|
107
|
-
toast({
|
|
108
|
-
variant: 'info',
|
|
109
|
-
title: '信息通知',
|
|
110
|
-
description: '这是一条信息通知,用于展示一般信息。',
|
|
111
|
-
});
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
return (
|
|
115
|
-
<>
|
|
116
|
-
<Button onClick={showToast}>显示信息通知</Button>
|
|
117
|
-
<Toaster />
|
|
118
|
-
</>
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
`;
|
|
122
|
-
|
|
123
|
-
const successToastCode = `
|
|
124
|
-
import { useToast } from '../components/toast/use-toast';
|
|
125
|
-
import { Toaster } from '../components/toast/toaster';
|
|
126
|
-
import { Button } from '../components/button';
|
|
127
|
-
|
|
128
|
-
function SuccessToastExample() {
|
|
129
|
-
const { toast } = useToast();
|
|
130
|
-
|
|
131
|
-
const showToast = () => {
|
|
132
|
-
toast({
|
|
133
|
-
variant: 'success',
|
|
134
|
-
title: '成功通知',
|
|
135
|
-
description: '操作已成功完成!',
|
|
136
|
-
});
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
return (
|
|
140
|
-
<>
|
|
141
|
-
<Button onClick={showToast}>显示成功通知</Button>
|
|
142
|
-
<Toaster />
|
|
143
|
-
</>
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
`;
|
|
147
|
-
|
|
148
|
-
const warningToastCode = `
|
|
149
|
-
import { useToast } from '../components/toast/use-toast';
|
|
150
|
-
import { Toaster } from '../components/toast/toaster';
|
|
151
|
-
import { Button } from '../components/button';
|
|
152
|
-
|
|
153
|
-
function WarningToastExample() {
|
|
154
|
-
const { toast } = useToast();
|
|
155
|
-
|
|
156
|
-
const showToast = () => {
|
|
157
|
-
toast({
|
|
158
|
-
variant: 'warning',
|
|
159
|
-
title: '警告通知',
|
|
160
|
-
description: '请注意,这是一个警告提示。',
|
|
161
|
-
});
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
return (
|
|
165
|
-
<>
|
|
166
|
-
<Button onClick={showToast}>显示警告通知</Button>
|
|
167
|
-
<Toaster />
|
|
168
|
-
</>
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
`;
|
|
172
|
-
|
|
173
|
-
const errorToastCode = `
|
|
174
|
-
import { useToast } from '../components/toast/use-toast';
|
|
175
|
-
import { Toaster } from '../components/toast/toaster';
|
|
176
|
-
import { Button } from '../components/button';
|
|
177
|
-
|
|
178
|
-
function ErrorToastExample() {
|
|
179
|
-
const { toast } = useToast();
|
|
180
|
-
|
|
181
|
-
const showToast = () => {
|
|
182
|
-
toast({
|
|
183
|
-
variant: 'error',
|
|
184
|
-
title: '错误通知',
|
|
185
|
-
description: '操作失败,请重试。',
|
|
186
|
-
});
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
return (
|
|
190
|
-
<>
|
|
191
|
-
<Button onClick={showToast}>显示错误通知</Button>
|
|
192
|
-
<Toaster />
|
|
193
|
-
</>
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
`;
|
|
197
|
-
|
|
198
|
-
const toastCode = `
|
|
199
|
-
import { useToast } from '../components/toast/use-toast';
|
|
200
|
-
import { Toaster } from '../components/toast/toaster';
|
|
201
|
-
import { Button } from '../components/button';
|
|
202
|
-
|
|
203
|
-
function toastExample() {
|
|
204
|
-
const { toast } = useToast();
|
|
205
|
-
|
|
206
|
-
const showToast = () => {
|
|
207
|
-
toast({
|
|
208
|
-
title: '带操作通知',
|
|
209
|
-
description: '这是一个带操作类型的通知提示',
|
|
210
|
-
actions: {
|
|
211
|
-
dismissText: '取消',
|
|
212
|
-
view: '查看',
|
|
213
|
-
viewUrl: 'https://app.myshell.ai',
|
|
214
|
-
},
|
|
215
|
-
});
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
return (
|
|
219
|
-
<>
|
|
220
|
-
<Button onClick={showToast}>显示带操作通知</Button>
|
|
221
|
-
<Toaster />
|
|
222
|
-
</>
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
`;
|
|
226
|
-
|
|
227
|
-
const viewToastCode = `
|
|
228
|
-
import { useToast } from '../components/toast/use-toast';
|
|
229
|
-
import { Toaster } from '../components/toast/toaster';
|
|
230
|
-
import { Button } from '../components/button';
|
|
231
|
-
|
|
232
|
-
function toastExample() {
|
|
233
|
-
const { toast } = useToast();
|
|
234
|
-
|
|
235
|
-
const showToast = () => {
|
|
236
|
-
toast({
|
|
237
|
-
title: '带操作通知',
|
|
238
|
-
description: '这是一个带操作类型的通知提示',
|
|
239
|
-
actions: {
|
|
240
|
-
view: '查看',
|
|
241
|
-
viewUrl: 'https://app.myshell.ai',
|
|
242
|
-
},
|
|
243
|
-
});
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
return (
|
|
247
|
-
<>
|
|
248
|
-
<Button onClick={showToast}>显示带操作通知</Button>
|
|
249
|
-
<Toaster />
|
|
250
|
-
</>
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
`;
|
|
254
|
-
|
|
255
|
-
const positionToastCode = `
|
|
256
|
-
import { useToast } from '../components/toast/use-toast';
|
|
257
|
-
import { Toaster } from '../components/toast/toaster';
|
|
258
|
-
import { Button } from '../components/button';
|
|
259
|
-
|
|
260
|
-
function PositionToastExample() {
|
|
261
|
-
const { toast } = useToast();
|
|
262
|
-
|
|
263
|
-
const showAllPositionToasts = () => {
|
|
264
|
-
// 显示8个不同位置的通知
|
|
265
|
-
const positions = [
|
|
266
|
-
'top-left',
|
|
267
|
-
'top-center',
|
|
268
|
-
'top-right',
|
|
269
|
-
'bottom-left',
|
|
270
|
-
'bottom-center',
|
|
271
|
-
'bottom-right',
|
|
272
|
-
'left-center',
|
|
273
|
-
'right-center',
|
|
274
|
-
];
|
|
275
|
-
|
|
276
|
-
positions.forEach((position, index) => {
|
|
277
|
-
setTimeout(() => {
|
|
278
|
-
toast({
|
|
279
|
-
variant: 'info',
|
|
280
|
-
title: \`\${position} 通知\`,
|
|
281
|
-
description: '这是一个示例通知,展示不同位置的Toast效果',
|
|
282
|
-
position: position,
|
|
283
|
-
});
|
|
284
|
-
}, index * 300); // 每300ms显示一个通知
|
|
285
|
-
});
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
const showToast = (position) => {
|
|
289
|
-
toast({
|
|
290
|
-
variant: 'info',
|
|
291
|
-
title: \`\${position} 通知\`,
|
|
292
|
-
description: '这是一个示例通知,展示不同位置的Toast效果',
|
|
293
|
-
position: position,
|
|
294
|
-
});
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
return (
|
|
298
|
-
<div className="flex flex-col gap-4">
|
|
299
|
-
<div className="grid grid-cols-3 gap-4">
|
|
300
|
-
<Button onClick={() => showToast('top-left')}>左上角</Button>
|
|
301
|
-
<Button onClick={() => showToast('top-center')}>顶部居中</Button>
|
|
302
|
-
<Button onClick={() => showToast('top-right')}>右上角</Button>
|
|
303
|
-
<Button onClick={() => showToast('left-center')}>左侧居中</Button>
|
|
304
|
-
<div></div>
|
|
305
|
-
<Button onClick={() => showToast('right-center')}>右侧居中</Button>
|
|
306
|
-
<Button onClick={() => showToast('bottom-left')}>左下角</Button>
|
|
307
|
-
<Button onClick={() => showToast('bottom-center')}>底部居中</Button>
|
|
308
|
-
<Button onClick={() => showToast('bottom-right')}>右下角</Button>
|
|
309
|
-
</div>
|
|
310
|
-
<Toaster />
|
|
311
|
-
</div>
|
|
312
|
-
);
|
|
313
|
-
}`;
|
|
314
|
-
|
|
315
|
-
// 位置示例组件
|
|
316
|
-
const PositionToastDemo = () => {
|
|
317
|
-
const { toast, dismiss } = useToast();
|
|
318
|
-
|
|
319
|
-
// 清除所有Toast通知
|
|
320
|
-
const clearAllToasts = () => {
|
|
321
|
-
dismiss();
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
const showToast = (
|
|
325
|
-
position:
|
|
326
|
-
| 'top-left'
|
|
327
|
-
| 'top-center'
|
|
328
|
-
| 'top-right'
|
|
329
|
-
| 'bottom-left'
|
|
330
|
-
| 'bottom-center'
|
|
331
|
-
| 'bottom-right'
|
|
332
|
-
| 'left-center'
|
|
333
|
-
| 'right-center'
|
|
334
|
-
) => {
|
|
335
|
-
// 不再清除之前的Toast
|
|
336
|
-
|
|
337
|
-
// 创建新的Toast,明确设置position
|
|
338
|
-
toast({
|
|
339
|
-
variant: 'info',
|
|
340
|
-
title: `${position} 通知`,
|
|
341
|
-
description: '这是一个示例通知,展示不同位置的Toast效果',
|
|
342
|
-
position: position,
|
|
343
|
-
});
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
return (
|
|
347
|
-
<div className="flex flex-col items-center justify-center gap-4 h-[800px] w-full">
|
|
348
|
-
<div className="grid grid-cols-3 gap-4">
|
|
349
|
-
<Button onClick={() => showToast('top-left')}>左上角</Button>
|
|
350
|
-
<Button onClick={() => showToast('top-center')}>顶部居中</Button>
|
|
351
|
-
<Button onClick={() => showToast('top-right')}>右上角</Button>
|
|
352
|
-
<Button onClick={() => showToast('left-center')}>左侧居中</Button>
|
|
353
|
-
<Button onClick={() => clearAllToasts()}>清除所有通知</Button>
|
|
354
|
-
<Button onClick={() => showToast('right-center')}>右侧居中</Button>
|
|
355
|
-
<Button onClick={() => showToast('bottom-left')}>左下角</Button>
|
|
356
|
-
<Button onClick={() => showToast('bottom-center')}>底部居中</Button>
|
|
357
|
-
<Button onClick={() => showToast('bottom-right')}>右下角</Button>
|
|
358
|
-
</div>
|
|
359
|
-
<Toaster />
|
|
360
|
-
</div>
|
|
361
|
-
);
|
|
362
|
-
};
|
|
363
|
-
|
|
364
|
-
const meta = {
|
|
365
|
-
title: 'Components/反馈/Toast-警报通知',
|
|
366
|
-
component: Toaster,
|
|
367
|
-
parameters: {
|
|
368
|
-
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
|
|
369
|
-
layout: 'centered',
|
|
370
|
-
},
|
|
371
|
-
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
|
372
|
-
tags: ['autodocs'],
|
|
373
|
-
argTypes: {},
|
|
374
|
-
} satisfies Meta<typeof Toaster>;
|
|
375
|
-
|
|
376
|
-
export default meta;
|
|
377
|
-
type Story = StoryObj<typeof meta>;
|
|
378
|
-
|
|
379
|
-
export const 警报通知: Story = {
|
|
380
|
-
render: () => (
|
|
381
|
-
<>
|
|
382
|
-
<DemoWithCode code={infoToastCode}>
|
|
383
|
-
<ToastDemo variant="info" id="info" />
|
|
384
|
-
</DemoWithCode>
|
|
385
|
-
<DemoWithCode code={successToastCode}>
|
|
386
|
-
<ToastDemo variant="success" />
|
|
387
|
-
</DemoWithCode>
|
|
388
|
-
<DemoWithCode code={warningToastCode}>
|
|
389
|
-
<ToastDemo variant="warning" />
|
|
390
|
-
</DemoWithCode>
|
|
391
|
-
<DemoWithCode code={errorToastCode}>
|
|
392
|
-
<ToastDemo variant="error" />
|
|
393
|
-
</DemoWithCode>
|
|
394
|
-
<DemoWithCode code={toastCode}>
|
|
395
|
-
<ToastDemo
|
|
396
|
-
variant="info"
|
|
397
|
-
actions={{
|
|
398
|
-
dismissText: '取消',
|
|
399
|
-
view: '查看',
|
|
400
|
-
viewUrl: 'https://app.myshell.ai',
|
|
401
|
-
}}
|
|
402
|
-
/>
|
|
403
|
-
</DemoWithCode>
|
|
404
|
-
<DemoWithCode code={viewToastCode}>
|
|
405
|
-
<ToastDemo
|
|
406
|
-
type="hide dismiss"
|
|
407
|
-
variant="info"
|
|
408
|
-
actions={{
|
|
409
|
-
view: '查看',
|
|
410
|
-
viewUrl: 'https://app.myshell.ai',
|
|
411
|
-
}}
|
|
412
|
-
/>
|
|
413
|
-
</DemoWithCode>
|
|
414
|
-
</>
|
|
415
|
-
),
|
|
416
|
-
};
|
|
417
|
-
|
|
418
|
-
export const 不同位置的通知: Story = {
|
|
419
|
-
render: () => (
|
|
420
|
-
<DemoWithCode code={positionToastCode}>
|
|
421
|
-
<PositionToastDemo />
|
|
422
|
-
</DemoWithCode>
|
|
423
|
-
),
|
|
424
|
-
};
|