myshell-react-lib 0.1.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 +268 -0
- package/dist/assets/audio-playing.json +3657 -0
- package/dist/index.cjs +9654 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1431 -0
- package/dist/index.d.ts +1431 -0
- package/dist/index.js +8788 -0
- package/dist/index.js.map +1 -0
- package/package.json +140 -0
- package/src/common/assets/audio-playing.json +3657 -0
- package/src/common/constants/constants.ts +24 -0
- package/src/common/constants/types/common.ts +10 -0
- package/src/common/hooks/useAudioPlayer.tsx +198 -0
- package/src/common/hooks/useDevice.ts +26 -0
- package/src/common/hooks/useNativeBridge.ts +42 -0
- package/src/common/hooks/useNotification.tsx +179 -0
- package/src/common/hooks/useWindowWidth.ts +19 -0
- package/src/common/utils/common-helper.ts +81 -0
- package/src/components/ItemDemo.tsx +15 -0
- package/src/components/accordion.tsx +126 -0
- package/src/components/alert-dialog.tsx +148 -0
- package/src/components/alert.tsx +65 -0
- package/src/components/aspect-ratio.tsx +7 -0
- package/src/components/audio-player.tsx +58 -0
- package/src/components/avatar.tsx +133 -0
- package/src/components/badge.tsx +65 -0
- package/src/components/button/button.styles.ts +258 -0
- package/src/components/button/button.tsx +215 -0
- package/src/components/button/icon-button.styles.ts +101 -0
- package/src/components/button/icon-button.tsx +100 -0
- package/src/components/button/index.tsx +3 -0
- package/src/components/button/link-button.tsx +184 -0
- package/src/components/cascader.tsx +175 -0
- package/src/components/checkbox.tsx +135 -0
- package/src/components/command.tsx +155 -0
- package/src/components/context-menu.tsx +198 -0
- package/src/components/count-down.tsx +83 -0
- package/src/components/custom-notification.tsx +95 -0
- package/src/components/dialog.tsx +158 -0
- package/src/components/drawer.tsx +116 -0
- package/src/components/dropdown-menu.tsx +196 -0
- package/src/components/energy-progress.tsx +55 -0
- package/src/components/form.tsx +201 -0
- package/src/components/group.tsx +9 -0
- package/src/components/guide.tsx +243 -0
- package/src/components/icon.tsx +89 -0
- package/src/components/icons/outline/DownIcon.tsx +18 -0
- package/src/components/icons/outline/FilterIcon.tsx +21 -0
- package/src/components/icons/outline/arrow-left.tsx +16 -0
- package/src/components/icons/outline/arrow-up-tray.tsx +16 -0
- package/src/components/icons/outline/check-circle.tsx +17 -0
- package/src/components/icons/outline/config.tsx +42 -0
- package/src/components/icons/outline/pencil-square.tsx +16 -0
- package/src/components/icons/outline/trash.tsx +17 -0
- package/src/components/icons/outline/window.tsx +16 -0
- package/src/components/icons/outline/x-circle.tsx +17 -0
- package/src/components/icons/outline/x-mark.tsx +16 -0
- package/src/components/icons/solid/audio-playing.tsx +31 -0
- package/src/components/icons/solid/caret-down.tsx +14 -0
- package/src/components/icons/solid/code.tsx +18 -0
- package/src/components/icons/solid/drag.tsx +14 -0
- package/src/components/icons/solid/phone.tsx +23 -0
- package/src/components/icons/solid/rectangle-group.tsx +14 -0
- package/src/components/image.tsx +151 -0
- package/src/components/input.tsx +118 -0
- package/src/components/label.tsx +26 -0
- package/src/components/link.tsx +123 -0
- package/src/components/marquee/index.css +15 -0
- package/src/components/marquee/marquee.tsx +220 -0
- package/src/components/masonry.tsx +138 -0
- package/src/components/menubar.tsx +234 -0
- package/src/components/mobile/m-tooltip.tsx +34 -0
- package/src/components/modal.tsx +561 -0
- package/src/components/navigation-bar.tsx +100 -0
- package/src/components/number-input.tsx +143 -0
- package/src/components/page-content.tsx +16 -0
- package/src/components/popover.tsx +191 -0
- package/src/components/progress.tsx +80 -0
- package/src/components/radio-group.tsx +44 -0
- package/src/components/scroll-area.tsx +49 -0
- package/src/components/search-bar.tsx +140 -0
- package/src/components/secondary-navigation-bar.tsx +307 -0
- package/src/components/select.tsx +273 -0
- package/src/components/separator.tsx +31 -0
- package/src/components/sheet.tsx +143 -0
- package/src/components/skeleton.tsx +20 -0
- package/src/components/slider.tsx +160 -0
- package/src/components/spinner.tsx +48 -0
- package/src/components/swiper/index.module.scss +88 -0
- package/src/components/swiper/index.tsx +319 -0
- package/src/components/switch.tsx +67 -0
- package/src/components/tabs.tsx +325 -0
- package/src/components/textarea.tsx +71 -0
- package/src/components/toast/toast.tsx +182 -0
- package/src/components/toast/toaster.tsx +160 -0
- package/src/components/toast/use-toast.tsx +248 -0
- package/src/components/toggle-group.tsx +64 -0
- package/src/components/toggle.tsx +46 -0
- package/src/components/tooltip.tsx +283 -0
- package/src/components/typography.tsx +437 -0
- package/src/index.ts +66 -0
- package/src/lib/utils.ts +62 -0
- package/src/stories/Accordion.stories.tsx +64 -0
- package/src/stories/AccordionItem.stories.tsx +48 -0
- package/src/stories/Avatar.stories.ts +58 -0
- package/src/stories/Badge.stories.tsx +40 -0
- package/src/stories/BannerSwiper.stories.tsx +102 -0
- package/src/stories/Button.stories.tsx +543 -0
- package/src/stories/Checkbox.stories.tsx +161 -0
- package/src/stories/Configure.mdx +341 -0
- package/src/stories/CssProperties.mdx +30 -0
- package/src/stories/Description.stories.ts +70 -0
- package/src/stories/Display.stories.ts +64 -0
- package/src/stories/FeaturedSwiper.stories.tsx +6978 -0
- package/src/stories/GridSwiper.stories.tsx +1407 -0
- package/src/stories/Guide.stories.tsx +247 -0
- package/src/stories/Heading.stories.ts +89 -0
- package/src/stories/Icon.stories.ts +77 -0
- package/src/stories/IconButton.stories.tsx +301 -0
- package/src/stories/IconTextButton.stories.ts +59 -0
- package/src/stories/Image.stories.ts +55 -0
- package/src/stories/Input.stories.tsx +203 -0
- package/src/stories/Modal.stories.tsx +144 -0
- package/src/stories/NavigationBar.stories.tsx +81 -0
- package/src/stories/Notification.stories.tsx +276 -0
- package/src/stories/Popover.stories.tsx +100 -0
- package/src/stories/SearchBar.stories.ts +43 -0
- package/src/stories/SecondaryNavigationBar.stories.tsx +199 -0
- package/src/stories/Select.stories.tsx +107 -0
- package/src/stories/Separator.stories.tsx +49 -0
- package/src/stories/Spinner.stories.tsx +48 -0
- package/src/stories/SubHeading.stories.ts +64 -0
- package/src/stories/Swich.stories.tsx +69 -0
- package/src/stories/Tabs.stories.tsx +90 -0
- package/src/stories/Text.stories.ts +78 -0
- package/src/stories/Textarea.stories.tsx +155 -0
- package/src/stories/Toast.stories.tsx +424 -0
- package/src/stories/Tooltip.stories.tsx +244 -0
- package/src/stories/ViewAutoSwiper.stories.tsx +1408 -0
- package/src/styles/components-dark.scss +212 -0
- package/src/styles/components-light.scss +210 -0
- package/src/styles/design-dark.scss +330 -0
- package/src/styles/design-light.scss +345 -0
- package/src/styles/design2-dark.scss +319 -0
- package/src/styles/design2-light.scss +364 -0
- package/src/styles/font.css +19 -0
- package/src/styles/global.scss +251 -0
- package/src/styles/md-viewer.scss +155 -0
- package/src/styles/new-tokens.scss +255 -0
- package/src/styles/tokens.scss +401 -0
- package/src/types/scss.d.ts +24 -0
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
/* eslint-disable no-nested-ternary */
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
import CheckCircleIcon from '@heroicons/react/24/outline/esm/CheckCircleIcon';
|
|
6
|
+
import ExclamationTriangleIcon from '@heroicons/react/24/outline/esm/ExclamationTriangleIcon';
|
|
7
|
+
import InformationCircleIcon from '@heroicons/react/24/outline/esm/InformationCircleIcon';
|
|
8
|
+
import XCircleIcon from '@heroicons/react/24/outline/esm/XCircleIcon';
|
|
9
|
+
import XMarkIcon from '@heroicons/react/24/outline/esm/XMarkIcon';
|
|
10
|
+
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
|
11
|
+
import { FocusScope, FocusScopeProps } from '@radix-ui/react-focus-scope';
|
|
12
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
13
|
+
import * as React from 'react';
|
|
14
|
+
import { Drawer as DrawerPrimitive } from 'vaul';
|
|
15
|
+
|
|
16
|
+
import { cn } from '@/lib/utils';
|
|
17
|
+
|
|
18
|
+
import { Button } from './button/button';
|
|
19
|
+
import { IconButton } from './button/icon-button';
|
|
20
|
+
import { Display, Text } from './typography';
|
|
21
|
+
import { useMedia } from 'react-use';
|
|
22
|
+
|
|
23
|
+
const ModalOverlay = React.forwardRef<
|
|
24
|
+
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
|
25
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
|
|
26
|
+
>(({ className, onClick, ...props }, ref) => (
|
|
27
|
+
<DialogPrimitive.Overlay
|
|
28
|
+
ref={ref}
|
|
29
|
+
className={cn(
|
|
30
|
+
'fixed inset-0 z-50 bg-Colors-Background-Utilities-Overlay data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
|
|
31
|
+
className
|
|
32
|
+
)}
|
|
33
|
+
onClick={(e) => {
|
|
34
|
+
onClick && onClick(e);
|
|
35
|
+
}}
|
|
36
|
+
{...props}
|
|
37
|
+
/>
|
|
38
|
+
));
|
|
39
|
+
ModalOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
|
40
|
+
|
|
41
|
+
const DrawerOverlay = React.forwardRef<
|
|
42
|
+
React.ElementRef<typeof DrawerPrimitive.Overlay>,
|
|
43
|
+
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Overlay>
|
|
44
|
+
>(({ className, ...props }, ref) => (
|
|
45
|
+
<DrawerPrimitive.Overlay
|
|
46
|
+
ref={ref}
|
|
47
|
+
className={cn(
|
|
48
|
+
'fixed inset-0 z-50 bg-Colors-Background-Utilities-Overlay',
|
|
49
|
+
className
|
|
50
|
+
)}
|
|
51
|
+
{...props}
|
|
52
|
+
/>
|
|
53
|
+
));
|
|
54
|
+
|
|
55
|
+
DrawerOverlay.displayName = DrawerPrimitive.Overlay.displayName;
|
|
56
|
+
|
|
57
|
+
const ModalContent = React.forwardRef<
|
|
58
|
+
React.ElementRef<typeof DialogPrimitive.Content>,
|
|
59
|
+
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Content>
|
|
60
|
+
>(({ className, children, ...props }, ref) => (
|
|
61
|
+
<DialogPrimitive.Content
|
|
62
|
+
className={cn(
|
|
63
|
+
'absolute left-1/2 top-1/2 z-50 -translate-x-1/2 -translate-y-1/2 !touch-auto !select-text',
|
|
64
|
+
'duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] focus:outline-none',
|
|
65
|
+
className
|
|
66
|
+
)}
|
|
67
|
+
{...props}
|
|
68
|
+
>
|
|
69
|
+
{children}
|
|
70
|
+
</DialogPrimitive.Content>
|
|
71
|
+
));
|
|
72
|
+
|
|
73
|
+
const ModalRoot: React.FC<
|
|
74
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Dialog>
|
|
75
|
+
> = ({ children, ...props }) => (
|
|
76
|
+
<DialogPrimitive.Dialog {...props}>
|
|
77
|
+
<DialogPrimitive.Portal>{children}</DialogPrimitive.Portal>
|
|
78
|
+
</DialogPrimitive.Dialog>
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const ModalTitle = React.forwardRef<
|
|
82
|
+
React.ElementRef<typeof DialogPrimitive.Title>,
|
|
83
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
|
|
84
|
+
>(({ className, ...props }, ref) => {
|
|
85
|
+
const isMobile = useMedia('(max-width: 768px)');
|
|
86
|
+
|
|
87
|
+
if (isMobile) {
|
|
88
|
+
return (
|
|
89
|
+
<DrawerPrimitive.Title
|
|
90
|
+
ref={ref}
|
|
91
|
+
{...props}
|
|
92
|
+
className={cn(
|
|
93
|
+
'text-xl text-Colors-Text-Default font-medium line-clamp-1',
|
|
94
|
+
className
|
|
95
|
+
)}
|
|
96
|
+
/>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<DialogPrimitive.Title
|
|
102
|
+
ref={ref}
|
|
103
|
+
{...props}
|
|
104
|
+
className={cn(
|
|
105
|
+
'text-xl text-Colors-Text-Default font-medium line-clamp-1',
|
|
106
|
+
className
|
|
107
|
+
)}
|
|
108
|
+
/>
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
ModalTitle.displayName = DialogPrimitive.Title.displayName;
|
|
112
|
+
|
|
113
|
+
const modalVariants = cva('', {
|
|
114
|
+
variants: {
|
|
115
|
+
size: {
|
|
116
|
+
lg: 'w-[750px] max-h-[640px]',
|
|
117
|
+
md: 'w-[620px] max-h-[640px]',
|
|
118
|
+
sm: 'w-[380px] max-h-[640px]',
|
|
119
|
+
},
|
|
120
|
+
zIndex: {
|
|
121
|
+
9: 'z-[9]',
|
|
122
|
+
99: 'z-[99]',
|
|
123
|
+
999: 'z-[999]',
|
|
124
|
+
9999: 'z-[9999]',
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
defaultVariants: {
|
|
128
|
+
size: 'lg',
|
|
129
|
+
zIndex: 99,
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
export type TModalState = 'info' | 'success' | 'warning' | 'error';
|
|
134
|
+
|
|
135
|
+
const Modal: React.FC<
|
|
136
|
+
React.ComponentPropsWithoutRef<typeof ModalRoot> & {
|
|
137
|
+
/**
|
|
138
|
+
* 模态框标题文本
|
|
139
|
+
*/
|
|
140
|
+
title?: string;
|
|
141
|
+
/**
|
|
142
|
+
* 模态框描述文本
|
|
143
|
+
*/
|
|
144
|
+
description?: string;
|
|
145
|
+
/**
|
|
146
|
+
* 点击覆盖层是否关闭模态框
|
|
147
|
+
*/
|
|
148
|
+
overlayClose?: boolean;
|
|
149
|
+
/**
|
|
150
|
+
* 是否隐藏关闭按钮
|
|
151
|
+
*/
|
|
152
|
+
hideClose?: boolean;
|
|
153
|
+
/**
|
|
154
|
+
* 模态框是否仅作为模态框显示(而不是抽屉)
|
|
155
|
+
*/
|
|
156
|
+
modalOnly?: boolean;
|
|
157
|
+
/**
|
|
158
|
+
* 覆盖层的额外类名
|
|
159
|
+
*/
|
|
160
|
+
overlayClassName?: string;
|
|
161
|
+
/**
|
|
162
|
+
* 模态框内容的额外类名
|
|
163
|
+
*/
|
|
164
|
+
contentClassName?: string;
|
|
165
|
+
/**
|
|
166
|
+
* 关闭按钮的额外类名
|
|
167
|
+
*/
|
|
168
|
+
closeClassName?: string;
|
|
169
|
+
/**
|
|
170
|
+
* 图标的额外类名
|
|
171
|
+
*/
|
|
172
|
+
iconClassName?: string;
|
|
173
|
+
/**
|
|
174
|
+
* 模态框是否以全屏显示
|
|
175
|
+
*/
|
|
176
|
+
fullScreen?: boolean;
|
|
177
|
+
/**
|
|
178
|
+
* 焦点范围管理的选项
|
|
179
|
+
*/
|
|
180
|
+
focusScopeOptions?: FocusScopeProps;
|
|
181
|
+
/**
|
|
182
|
+
* 登录模态框的特殊逻辑
|
|
183
|
+
*/
|
|
184
|
+
isLogin?: boolean;
|
|
185
|
+
/**
|
|
186
|
+
* 表示模态框是否为通知
|
|
187
|
+
*/
|
|
188
|
+
isNotification?: boolean;
|
|
189
|
+
/**
|
|
190
|
+
* 模态框的状态(信息、成功、警告、错误)
|
|
191
|
+
*/
|
|
192
|
+
state?: TModalState;
|
|
193
|
+
/**
|
|
194
|
+
* isNotification 的情况下可能会需要
|
|
195
|
+
*/
|
|
196
|
+
showCancel?: boolean;
|
|
197
|
+
/**
|
|
198
|
+
* 是否为水平布局
|
|
199
|
+
*/
|
|
200
|
+
isHorizontal?: boolean;
|
|
201
|
+
/**
|
|
202
|
+
* 确认按钮的加载状态
|
|
203
|
+
*/
|
|
204
|
+
confirmLoading?: boolean;
|
|
205
|
+
/**
|
|
206
|
+
* 取消按钮的文本
|
|
207
|
+
*/
|
|
208
|
+
cancelText?: string;
|
|
209
|
+
/**
|
|
210
|
+
* 确认按钮的文本
|
|
211
|
+
*/
|
|
212
|
+
confirmText?: string;
|
|
213
|
+
/**
|
|
214
|
+
* 是否自动聚焦
|
|
215
|
+
* @default false
|
|
216
|
+
*/
|
|
217
|
+
autoFocus?: string;
|
|
218
|
+
/**
|
|
219
|
+
* 关闭模态框时的回调函数
|
|
220
|
+
*/
|
|
221
|
+
onClose?: () => void;
|
|
222
|
+
/**
|
|
223
|
+
* 确认操作时的回调函数
|
|
224
|
+
*/
|
|
225
|
+
onConfirm?: () => void;
|
|
226
|
+
} & VariantProps<typeof modalVariants>
|
|
227
|
+
> = ({
|
|
228
|
+
title,
|
|
229
|
+
description,
|
|
230
|
+
size = 'lg',
|
|
231
|
+
zIndex = 99,
|
|
232
|
+
hideClose = false,
|
|
233
|
+
overlayClose = true,
|
|
234
|
+
modalOnly = true,
|
|
235
|
+
contentClassName,
|
|
236
|
+
overlayClassName,
|
|
237
|
+
iconClassName,
|
|
238
|
+
closeClassName,
|
|
239
|
+
fullScreen = false,
|
|
240
|
+
focusScopeOptions,
|
|
241
|
+
isLogin = false,
|
|
242
|
+
isNotification = false,
|
|
243
|
+
isHorizontal = false,
|
|
244
|
+
state,
|
|
245
|
+
showCancel = true,
|
|
246
|
+
confirmLoading = false,
|
|
247
|
+
cancelText,
|
|
248
|
+
confirmText,
|
|
249
|
+
children,
|
|
250
|
+
autoFocus = false,
|
|
251
|
+
onClose,
|
|
252
|
+
onConfirm,
|
|
253
|
+
...props
|
|
254
|
+
}) => {
|
|
255
|
+
const isMobile = useMedia('(max-width: 768px)');
|
|
256
|
+
|
|
257
|
+
if (isMobile && !modalOnly && !isNotification) {
|
|
258
|
+
const drawerContent = (
|
|
259
|
+
<DrawerPrimitive.Content
|
|
260
|
+
className={cn(
|
|
261
|
+
'fixed inset-x-0 bottom-0 z-50 h-auto overflow-hidden no-scrollbar border-Colors-Border-Opaque bg-Colors-Background-Normal-Secondary-Alt shadow-modal-default focus:outline-none',
|
|
262
|
+
fullScreen
|
|
263
|
+
? 'rounded-t-none max-h-full'
|
|
264
|
+
: 'rounded-t-2xl max-h-[85vh]',
|
|
265
|
+
contentClassName
|
|
266
|
+
)}
|
|
267
|
+
onOpenAutoFocus={(e) => {
|
|
268
|
+
!autoFocus && e.preventDefault();
|
|
269
|
+
}}
|
|
270
|
+
>
|
|
271
|
+
{title ? (
|
|
272
|
+
<ModalHeader>
|
|
273
|
+
<ModalTitle>{title}</ModalTitle>
|
|
274
|
+
</ModalHeader>
|
|
275
|
+
) : (
|
|
276
|
+
<ModalTitle className="hidden"></ModalTitle>
|
|
277
|
+
)}
|
|
278
|
+
<div
|
|
279
|
+
className={cn(
|
|
280
|
+
isLogin ? 'overflow-y-scroll' : 'overflow-y-auto',
|
|
281
|
+
fullScreen
|
|
282
|
+
? title
|
|
283
|
+
? 'max-h-[calc(100vh-60px)]'
|
|
284
|
+
: 'max-h-[100vh]'
|
|
285
|
+
: title
|
|
286
|
+
? 'max-h-[calc(85vh-60px)]'
|
|
287
|
+
: 'max-h-[85vh]'
|
|
288
|
+
)}
|
|
289
|
+
>
|
|
290
|
+
{children}
|
|
291
|
+
</div>
|
|
292
|
+
{!hideClose && (
|
|
293
|
+
<DrawerPrimitive.Close asChild>
|
|
294
|
+
<div
|
|
295
|
+
className={cn('absolute right-4 top-3', closeClassName)}
|
|
296
|
+
onClick={() => {
|
|
297
|
+
onClose && onClose();
|
|
298
|
+
}}
|
|
299
|
+
>
|
|
300
|
+
<IconButton
|
|
301
|
+
icon={XMarkIcon}
|
|
302
|
+
size="md"
|
|
303
|
+
variant="plain"
|
|
304
|
+
color="default"
|
|
305
|
+
className={iconClassName}
|
|
306
|
+
/>
|
|
307
|
+
<span className="sr-only">Close</span>
|
|
308
|
+
</div>
|
|
309
|
+
</DrawerPrimitive.Close>
|
|
310
|
+
)}
|
|
311
|
+
</DrawerPrimitive.Content>
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
return (
|
|
315
|
+
<DrawerPrimitive.Root
|
|
316
|
+
{...props}
|
|
317
|
+
repositionInputs={false}
|
|
318
|
+
onOpenChange={(open) => {
|
|
319
|
+
if (!open) {
|
|
320
|
+
onClose && onClose();
|
|
321
|
+
}
|
|
322
|
+
}}
|
|
323
|
+
>
|
|
324
|
+
<DrawerPrimitive.Portal>
|
|
325
|
+
<DrawerOverlay
|
|
326
|
+
onClick={() => {
|
|
327
|
+
overlayClose && onClose && onClose();
|
|
328
|
+
}}
|
|
329
|
+
className={overlayClassName}
|
|
330
|
+
/>
|
|
331
|
+
{focusScopeOptions ? (
|
|
332
|
+
<FocusScope {...focusScopeOptions}>{drawerContent}</FocusScope>
|
|
333
|
+
) : (
|
|
334
|
+
drawerContent
|
|
335
|
+
)}
|
|
336
|
+
</DrawerPrimitive.Portal>
|
|
337
|
+
</DrawerPrimitive.Root>
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const renderIcon = (state: TModalState) => {
|
|
342
|
+
switch (state) {
|
|
343
|
+
case 'info':
|
|
344
|
+
return (
|
|
345
|
+
<InformationCircleIcon className="text-cc-Icon-Featured-icon-fg-Info w-6 h-6" />
|
|
346
|
+
);
|
|
347
|
+
case 'success':
|
|
348
|
+
return (
|
|
349
|
+
<CheckCircleIcon className="text-cc-Icon-Featured-icon-fg-Success w-6 h-6" />
|
|
350
|
+
);
|
|
351
|
+
case 'warning':
|
|
352
|
+
return (
|
|
353
|
+
<ExclamationTriangleIcon className="text-cc-Icon-Featured-icon-fg-Warning w-6 h-6" />
|
|
354
|
+
);
|
|
355
|
+
case 'error':
|
|
356
|
+
return (
|
|
357
|
+
<XCircleIcon className="text-cc-Icon-Featured-icon-fg-Error w-6 h-6" />
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
const getBackgroundColor = (state: TModalState) => {
|
|
363
|
+
switch (state) {
|
|
364
|
+
case 'info':
|
|
365
|
+
return 'bg-Colors-Background-Info-Default';
|
|
366
|
+
case 'success':
|
|
367
|
+
return 'bg-Colors-Background-Success-Default';
|
|
368
|
+
case 'warning':
|
|
369
|
+
return 'bg-Colors-Background-Warning-Default';
|
|
370
|
+
case 'error':
|
|
371
|
+
return 'bg-Colors-Background-Critical-Default';
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
const dialogContent = (
|
|
376
|
+
<ModalContent
|
|
377
|
+
className={cn(
|
|
378
|
+
'rounded-2xl border-Colors-Border-Opaque bg-Colors-Background-Normal-Primary-Default shadow-modal-default overflow-hidden',
|
|
379
|
+
!isMobile
|
|
380
|
+
? modalVariants({ size, zIndex })
|
|
381
|
+
: isLogin
|
|
382
|
+
? 'w-[90%]'
|
|
383
|
+
: 'w-[80%]',
|
|
384
|
+
isNotification && 'w-[312px] md:w-[380px]',
|
|
385
|
+
contentClassName
|
|
386
|
+
)}
|
|
387
|
+
onOpenAutoFocus={(e) => {
|
|
388
|
+
!autoFocus && e.preventDefault();
|
|
389
|
+
}}
|
|
390
|
+
>
|
|
391
|
+
{isNotification ? (
|
|
392
|
+
<>
|
|
393
|
+
<ModalHeader className={cn(isNotification && 'border-none !pb-3')}>
|
|
394
|
+
{state && (
|
|
395
|
+
<div
|
|
396
|
+
className={cn(
|
|
397
|
+
'flex items-center justify-center w-10 h-10 rounded-full flex-shrink-0 flex-grow-0',
|
|
398
|
+
getBackgroundColor(state)
|
|
399
|
+
)}
|
|
400
|
+
>
|
|
401
|
+
{renderIcon(state)}
|
|
402
|
+
</div>
|
|
403
|
+
)}
|
|
404
|
+
</ModalHeader>
|
|
405
|
+
<div className="space-y-1.5">
|
|
406
|
+
{title ? (
|
|
407
|
+
<div className="px-5">
|
|
408
|
+
<Display size="sm">{title}</Display>
|
|
409
|
+
</div>
|
|
410
|
+
) : null}
|
|
411
|
+
{children ||
|
|
412
|
+
(description ? (
|
|
413
|
+
<div className="px-5">
|
|
414
|
+
<Text size="sm" weight="regular">
|
|
415
|
+
{description}
|
|
416
|
+
</Text>
|
|
417
|
+
</div>
|
|
418
|
+
) : null)}
|
|
419
|
+
</div>
|
|
420
|
+
|
|
421
|
+
<ModalFooter
|
|
422
|
+
className={cn(
|
|
423
|
+
'gap-x-5 min-h-[76px] p-5 border-none justify-center w-full'
|
|
424
|
+
)}
|
|
425
|
+
>
|
|
426
|
+
{showCancel && (
|
|
427
|
+
<Button variant="tertiary" onClick={onClose} className="flex-1">
|
|
428
|
+
{cancelText || 'Cancel'}
|
|
429
|
+
</Button>
|
|
430
|
+
)}
|
|
431
|
+
|
|
432
|
+
<Button
|
|
433
|
+
variant="primary"
|
|
434
|
+
onClick={onConfirm}
|
|
435
|
+
loading={confirmLoading}
|
|
436
|
+
color={state === 'error' ? 'error' : 'default'}
|
|
437
|
+
className="flex-1"
|
|
438
|
+
>
|
|
439
|
+
{confirmText || 'Confirm'}
|
|
440
|
+
</Button>
|
|
441
|
+
</ModalFooter>
|
|
442
|
+
</>
|
|
443
|
+
) : (
|
|
444
|
+
<>
|
|
445
|
+
{title ? (
|
|
446
|
+
<ModalHeader>
|
|
447
|
+
<ModalTitle>{title}</ModalTitle>
|
|
448
|
+
</ModalHeader>
|
|
449
|
+
) : (
|
|
450
|
+
<ModalTitle className="hidden"></ModalTitle>
|
|
451
|
+
)}
|
|
452
|
+
{children}
|
|
453
|
+
</>
|
|
454
|
+
)}
|
|
455
|
+
|
|
456
|
+
{!hideClose && (
|
|
457
|
+
<DialogPrimitive.Close asChild>
|
|
458
|
+
<div
|
|
459
|
+
onClick={() => {
|
|
460
|
+
onClose && onClose();
|
|
461
|
+
}}
|
|
462
|
+
className={cn(
|
|
463
|
+
'absolute right-4 top-4',
|
|
464
|
+
isNotification && 'top-5',
|
|
465
|
+
closeClassName
|
|
466
|
+
)}
|
|
467
|
+
>
|
|
468
|
+
<IconButton
|
|
469
|
+
icon={XMarkIcon}
|
|
470
|
+
size="md"
|
|
471
|
+
variant="plain"
|
|
472
|
+
color="default"
|
|
473
|
+
className={iconClassName}
|
|
474
|
+
/>
|
|
475
|
+
<span className="sr-only">Close</span>
|
|
476
|
+
</div>
|
|
477
|
+
</DialogPrimitive.Close>
|
|
478
|
+
)}
|
|
479
|
+
</ModalContent>
|
|
480
|
+
);
|
|
481
|
+
|
|
482
|
+
return (
|
|
483
|
+
<ModalRoot {...props}>
|
|
484
|
+
<ModalOverlay
|
|
485
|
+
onClick={() => {
|
|
486
|
+
overlayClose && onClose && onClose();
|
|
487
|
+
}}
|
|
488
|
+
className={overlayClassName}
|
|
489
|
+
/>
|
|
490
|
+
{focusScopeOptions ? (
|
|
491
|
+
<FocusScope {...focusScopeOptions}>{dialogContent}</FocusScope>
|
|
492
|
+
) : (
|
|
493
|
+
dialogContent
|
|
494
|
+
)}
|
|
495
|
+
</ModalRoot>
|
|
496
|
+
);
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
function ModalHeader({
|
|
500
|
+
className,
|
|
501
|
+
children,
|
|
502
|
+
...props
|
|
503
|
+
}: React.HTMLAttributes<HTMLDivElement>) {
|
|
504
|
+
return (
|
|
505
|
+
<div
|
|
506
|
+
className={cn(
|
|
507
|
+
'border-b border-Colors-Border-Default flex flex-col py-4 md:py-5 px-4 justify-center',
|
|
508
|
+
className
|
|
509
|
+
)}
|
|
510
|
+
{...props}
|
|
511
|
+
>
|
|
512
|
+
{children}
|
|
513
|
+
</div>
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
ModalHeader.displayName = 'ModalHeader';
|
|
517
|
+
|
|
518
|
+
function ModalFooter({
|
|
519
|
+
className,
|
|
520
|
+
children,
|
|
521
|
+
...props
|
|
522
|
+
}: React.HTMLAttributes<HTMLDivElement>) {
|
|
523
|
+
return (
|
|
524
|
+
<div
|
|
525
|
+
className={cn(
|
|
526
|
+
'border-t border-Colors-Border-Default flex justify-end p-4',
|
|
527
|
+
className
|
|
528
|
+
)}
|
|
529
|
+
{...props}
|
|
530
|
+
>
|
|
531
|
+
{children}
|
|
532
|
+
</div>
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
ModalFooter.displayName = 'ModalFooter';
|
|
537
|
+
|
|
538
|
+
function ModalBody({
|
|
539
|
+
className,
|
|
540
|
+
children,
|
|
541
|
+
...props
|
|
542
|
+
}: React.HTMLAttributes<HTMLDivElement>) {
|
|
543
|
+
return (
|
|
544
|
+
<div className={cn('py-3', className)} {...props}>
|
|
545
|
+
{children}
|
|
546
|
+
</div>
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
ModalBody.displayName = 'ModalBody';
|
|
551
|
+
|
|
552
|
+
export {
|
|
553
|
+
Modal,
|
|
554
|
+
ModalBody,
|
|
555
|
+
ModalContent,
|
|
556
|
+
ModalFooter,
|
|
557
|
+
ModalHeader,
|
|
558
|
+
ModalOverlay,
|
|
559
|
+
ModalRoot,
|
|
560
|
+
ModalTitle,
|
|
561
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/* eslint-disable react/jsx-no-useless-fragment */
|
|
2
|
+
|
|
3
|
+
import { cn } from '@/lib/utils';
|
|
4
|
+
import { SearchBar } from './search-bar';
|
|
5
|
+
import { Display } from './typography';
|
|
6
|
+
import EnergyProgress from './energy-progress';
|
|
7
|
+
|
|
8
|
+
type INavigationBar = {
|
|
9
|
+
/**
|
|
10
|
+
* 右侧自定义内容
|
|
11
|
+
* ReactNode
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
children?: React.ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* 导航栏title
|
|
17
|
+
* string
|
|
18
|
+
*/
|
|
19
|
+
title?: string;
|
|
20
|
+
/**
|
|
21
|
+
* 是否展示搜索框
|
|
22
|
+
* boolean
|
|
23
|
+
*
|
|
24
|
+
* @default false
|
|
25
|
+
*/
|
|
26
|
+
showSearchBar?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* 搜索框值
|
|
29
|
+
* string
|
|
30
|
+
*/
|
|
31
|
+
searchValue?: string;
|
|
32
|
+
/**
|
|
33
|
+
* 搜索框占位值
|
|
34
|
+
* string
|
|
35
|
+
*/
|
|
36
|
+
searchPlaceholder?: string;
|
|
37
|
+
/**
|
|
38
|
+
* 电量值
|
|
39
|
+
* number
|
|
40
|
+
*/
|
|
41
|
+
energy?: number;
|
|
42
|
+
/**
|
|
43
|
+
* 每日电量值
|
|
44
|
+
* number
|
|
45
|
+
*/
|
|
46
|
+
dailyEnergy?: number;
|
|
47
|
+
onSearchChange?: (value: string) => void;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
function NavigationBar({
|
|
51
|
+
showSearchBar = true,
|
|
52
|
+
searchValue,
|
|
53
|
+
searchPlaceholder,
|
|
54
|
+
title,
|
|
55
|
+
children,
|
|
56
|
+
energy = 0,
|
|
57
|
+
dailyEnergy,
|
|
58
|
+
onSearchChange,
|
|
59
|
+
}: INavigationBar) {
|
|
60
|
+
return (
|
|
61
|
+
<div
|
|
62
|
+
className={cn(
|
|
63
|
+
'relative w-full flex flex-col justify-between items-center px-4 md:px-6'
|
|
64
|
+
)}
|
|
65
|
+
>
|
|
66
|
+
<div className="w-full pt-5 md:pt-6 pb-1 md:pb-3 flex justify-between items-center">
|
|
67
|
+
<div className="flex-1 text-start">
|
|
68
|
+
<Display size="md">{title}</Display>
|
|
69
|
+
</div>
|
|
70
|
+
{children ? (
|
|
71
|
+
<div className="w-fit">{children}</div>
|
|
72
|
+
) : (
|
|
73
|
+
<>
|
|
74
|
+
{dailyEnergy ? (
|
|
75
|
+
<EnergyProgress
|
|
76
|
+
dailyEnergy={dailyEnergy}
|
|
77
|
+
energy={energy}
|
|
78
|
+
className="flex relative items-center flex-shrink-0"
|
|
79
|
+
/>
|
|
80
|
+
) : null}
|
|
81
|
+
</>
|
|
82
|
+
)}
|
|
83
|
+
</div>
|
|
84
|
+
|
|
85
|
+
{showSearchBar && (
|
|
86
|
+
<div className="w-full py-2 md:py-0">
|
|
87
|
+
<SearchBar
|
|
88
|
+
placeholder={searchPlaceholder}
|
|
89
|
+
searchValue={searchValue}
|
|
90
|
+
onSearchChange={(value: string) =>
|
|
91
|
+
onSearchChange && onSearchChange(value)
|
|
92
|
+
}
|
|
93
|
+
/>
|
|
94
|
+
</div>
|
|
95
|
+
)}
|
|
96
|
+
</div>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { NavigationBar };
|