@fjyueke/arco-mcp 1.0.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 +85 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +244 -0
- package/metaData/components/action-sheet/doc.md +102 -0
- package/metaData/components/action-sheet/example/index.tsx +199 -0
- package/metaData/components/action-sheet/example/methods.tsx +6 -0
- package/metaData/components/avatar/doc.md +57 -0
- package/metaData/components/avatar/example/group.tsx +69 -0
- package/metaData/components/avatar/example/index.tsx +196 -0
- package/metaData/components/badge/doc.md +28 -0
- package/metaData/components/badge/example/index.tsx +128 -0
- package/metaData/components/button/doc.md +45 -0
- package/metaData/components/button/example/index.tsx +264 -0
- package/metaData/components/carousel/doc.md +89 -0
- package/metaData/components/carousel/example/index.tsx +1481 -0
- package/metaData/components/cell/doc.md +68 -0
- package/metaData/components/cell/example/arrow.tsx +13 -0
- package/metaData/components/cell/example/cell.tsx +71 -0
- package/metaData/components/cell/example/group.tsx +63 -0
- package/metaData/components/cell/example/index.tsx +19 -0
- package/metaData/components/checkbox/doc.md +91 -0
- package/metaData/components/checkbox/example/checkbox.tsx +158 -0
- package/metaData/components/checkbox/example/group.tsx +103 -0
- package/metaData/components/checkbox/example/index.tsx +25 -0
- package/metaData/components/circle-progress/doc.md +40 -0
- package/metaData/components/circle-progress/example/index.tsx +323 -0
- package/metaData/components/collapse/doc.md +74 -0
- package/metaData/components/collapse/example/collapse.tsx +183 -0
- package/metaData/components/collapse/example/group.tsx +136 -0
- package/metaData/components/collapse/example/index.tsx +16 -0
- package/metaData/components/collapse/example/utils.tsx +20 -0
- package/metaData/components/context-provider/doc.md +44 -0
- package/metaData/components/context-provider/example/index.tsx +208 -0
- package/metaData/components/count-down/doc.md +40 -0
- package/metaData/components/count-down/example/hooks.tsx +118 -0
- package/metaData/components/count-down/example/index.tsx +63 -0
- package/metaData/components/date-picker/doc.md +102 -0
- package/metaData/components/date-picker/example/index.tsx +545 -0
- package/metaData/components/dialog/doc.md +200 -0
- package/metaData/components/dialog/example/index.tsx +328 -0
- package/metaData/components/dialog/example/methods.tsx +56 -0
- package/metaData/components/divider/doc.md +25 -0
- package/metaData/components/divider/example/index.tsx +87 -0
- package/metaData/components/dropdown/doc.md +80 -0
- package/metaData/components/dropdown/example/dropdown.tsx +308 -0
- package/metaData/components/dropdown/example/index.tsx +19 -0
- package/metaData/components/dropdown/example/options.tsx +103 -0
- package/metaData/components/dropdown-menu/doc.md +91 -0
- package/metaData/components/dropdown-menu/example/dropdown-menu.tsx +270 -0
- package/metaData/components/dropdown-menu/example/index.tsx +16 -0
- package/metaData/components/ellipsis/doc.md +33 -0
- package/metaData/components/ellipsis/example/index.tsx +93 -0
- package/metaData/components/ellipsis/example/js-ellipsis.tsx +229 -0
- package/metaData/components/ellipsis/example/native-ellipsis.tsx +48 -0
- package/metaData/components/form/doc.md +90 -0
- package/metaData/components/form/example/form-item-context.tsx +8 -0
- package/metaData/components/form/example/form-item.tsx +378 -0
- package/metaData/components/form/example/index.tsx +87 -0
- package/metaData/components/form/example/linked-container.tsx +66 -0
- package/metaData/components/grid/doc.md +39 -0
- package/metaData/components/grid/example/index.tsx +252 -0
- package/metaData/components/icon/doc.md +15 -0
- package/metaData/components/icon/example/index.tsx +32 -0
- package/metaData/components/image/doc.md +62 -0
- package/metaData/components/image/example/index.tsx +528 -0
- package/metaData/components/image-picker/doc.md +116 -0
- package/metaData/components/image-picker/example/add-icon.tsx +14 -0
- package/metaData/components/image-picker/example/index.tsx +175 -0
- package/metaData/components/image-preview/doc.md +119 -0
- package/metaData/components/image-preview/example/index.tsx +1290 -0
- package/metaData/components/image-preview/example/methods.tsx +72 -0
- package/metaData/components/index-bar/doc.md +83 -0
- package/metaData/components/index-bar/example/group.tsx +93 -0
- package/metaData/components/index-bar/example/index.tsx +271 -0
- package/metaData/components/index-bar/example/side-bar.tsx +82 -0
- package/metaData/components/input/doc.md +60 -0
- package/metaData/components/input/example/hooks.tsx +259 -0
- package/metaData/components/input/example/index.tsx +134 -0
- package/metaData/components/input/example/props.tsx +183 -0
- package/metaData/components/keyboard/doc.md +73 -0
- package/metaData/components/keyboard/example/index.tsx +238 -0
- package/metaData/components/load-more/doc.md +48 -0
- package/metaData/components/load-more/example/index.tsx +395 -0
- package/metaData/components/loading/doc.md +34 -0
- package/metaData/components/loading/example/index.tsx +312 -0
- package/metaData/components/masking/doc.md +93 -0
- package/metaData/components/masking/example/index.tsx +410 -0
- package/metaData/components/masking/example/methods.tsx +88 -0
- package/metaData/components/nav-bar/doc.md +40 -0
- package/metaData/components/nav-bar/example/back-icon.tsx +28 -0
- package/metaData/components/nav-bar/example/index.tsx +305 -0
- package/metaData/components/notice-bar/doc.md +34 -0
- package/metaData/components/notice-bar/example/index.tsx +294 -0
- package/metaData/components/notify/doc.md +81 -0
- package/metaData/components/notify/example/index.tsx +171 -0
- package/metaData/components/notify/example/methods.tsx +83 -0
- package/metaData/components/pagination/doc.md +41 -0
- package/metaData/components/pagination/example/arrow.tsx +14 -0
- package/metaData/components/pagination/example/index.tsx +292 -0
- package/metaData/components/picker/doc.md +89 -0
- package/metaData/components/picker/example/index.tsx +217 -0
- package/metaData/components/picker-view/doc.md +57 -0
- package/metaData/components/picker-view/example/cascader.tsx +141 -0
- package/metaData/components/picker-view/example/index.tsx +297 -0
- package/metaData/components/picker-view/example/multi-picker.tsx +66 -0
- package/metaData/components/picker-view/example/picker-cell.tsx +416 -0
- package/metaData/components/popover/doc.md +144 -0
- package/metaData/components/popover/example/index.tsx +23 -0
- package/metaData/components/popover/example/menu.tsx +145 -0
- package/metaData/components/popover/example/popover-inner.tsx +147 -0
- package/metaData/components/popover/example/popover.tsx +268 -0
- package/metaData/components/popup/doc.md +101 -0
- package/metaData/components/popup/example/index.tsx +125 -0
- package/metaData/components/popup/example/methods.tsx +6 -0
- package/metaData/components/popup-swiper/doc.md +108 -0
- package/metaData/components/popup-swiper/example/index.tsx +332 -0
- package/metaData/components/popup-swiper/example/methods.tsx +6 -0
- package/metaData/components/portal/doc.md +14 -0
- package/metaData/components/portal/example/index.tsx +35 -0
- package/metaData/components/progress/doc.md +42 -0
- package/metaData/components/progress/example/index.tsx +256 -0
- package/metaData/components/pull-refresh/doc.md +37 -0
- package/metaData/components/pull-refresh/example/android-pull-refresh.tsx +260 -0
- package/metaData/components/pull-refresh/example/index.tsx +44 -0
- package/metaData/components/pull-refresh/example/ios-pull-refresh.tsx +216 -0
- package/metaData/components/radio/doc.md +89 -0
- package/metaData/components/radio/example/group.tsx +92 -0
- package/metaData/components/radio/example/index.tsx +25 -0
- package/metaData/components/radio/example/radio.tsx +22 -0
- package/metaData/components/rate/doc.md +33 -0
- package/metaData/components/rate/example/index.tsx +281 -0
- package/metaData/components/search-bar/doc.md +97 -0
- package/metaData/components/search-bar/example/association.tsx +89 -0
- package/metaData/components/search-bar/example/cancel-button.tsx +34 -0
- package/metaData/components/search-bar/example/highlight.tsx +66 -0
- package/metaData/components/search-bar/example/index.tsx +251 -0
- package/metaData/components/show-monitor/doc.md +34 -0
- package/metaData/components/show-monitor/example/index.tsx +646 -0
- package/metaData/components/skeleton/doc.md +101 -0
- package/metaData/components/skeleton/example/elements.tsx +290 -0
- package/metaData/components/skeleton/example/index.tsx +96 -0
- package/metaData/components/skeleton/example/skeleton-context.tsx +7 -0
- package/metaData/components/slider/doc.md +42 -0
- package/metaData/components/slider/example/index.tsx +326 -0
- package/metaData/components/slider/example/marks.tsx +50 -0
- package/metaData/components/slider/example/popover.tsx +38 -0
- package/metaData/components/slider/example/thumb.tsx +48 -0
- package/metaData/components/slider/example/useSliderIcon.tsx +38 -0
- package/metaData/components/slider/example/useSliderInit.tsx +170 -0
- package/metaData/components/stepper/doc.md +46 -0
- package/metaData/components/stepper/example/index.tsx +166 -0
- package/metaData/components/stepper/example/useButtonClick.tsx +74 -0
- package/metaData/components/stepper/example/useInputEvent.tsx +65 -0
- package/metaData/components/stepper/example/useValue.tsx +43 -0
- package/metaData/components/steps/doc.md +57 -0
- package/metaData/components/steps/example/index.tsx +123 -0
- package/metaData/components/steps/example/step.tsx +126 -0
- package/metaData/components/sticky/doc.md +45 -0
- package/metaData/components/sticky/example/index.tsx +430 -0
- package/metaData/components/swipe-action/doc.md +44 -0
- package/metaData/components/swipe-action/example/index.tsx +338 -0
- package/metaData/components/swipe-action/example/item.tsx +40 -0
- package/metaData/components/swipe-load/doc.md +43 -0
- package/metaData/components/swipe-load/example/index.tsx +339 -0
- package/metaData/components/swipe-load/example/type.tsx +153 -0
- package/metaData/components/switch/doc.md +38 -0
- package/metaData/components/switch/example/index.tsx +237 -0
- package/metaData/components/tab-bar/doc.md +57 -0
- package/metaData/components/tab-bar/example/index.tsx +18 -0
- package/metaData/components/tab-bar/example/item.tsx +74 -0
- package/metaData/components/tab-bar/example/tab-bar.tsx +105 -0
- package/metaData/components/tabs/doc.md +187 -0
- package/metaData/components/tabs/example/index.tsx +514 -0
- package/metaData/components/tabs/example/tab-cell-underline.tsx +320 -0
- package/metaData/components/tabs/example/tab-cell.tsx +433 -0
- package/metaData/components/tabs/example/tab-pane.tsx +349 -0
- package/metaData/components/tag/doc.md +80 -0
- package/metaData/components/tag/example/index.tsx +23 -0
- package/metaData/components/tag/example/list.tsx +97 -0
- package/metaData/components/tag/example/tag.tsx +85 -0
- package/metaData/components/textarea/doc.md +67 -0
- package/metaData/components/textarea/example/index.tsx +258 -0
- package/metaData/components/toast/doc.md +90 -0
- package/metaData/components/toast/example/index.tsx +335 -0
- package/metaData/components/toast/example/methods.tsx +87 -0
- package/metaData/components/transition/doc.md +19 -0
- package/metaData/components/transition/example/index.tsx +113 -0
- package/metaData/components/uploader/doc.md +82 -0
- package/metaData/components/uploader/example/index.tsx +208 -0
- package/metaData/components-index.json +242 -0
- package/package.json +56 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import React, { useEffect, forwardRef, Ref, useRef, useImperativeHandle, ReactNode } from 'react';
|
|
2
|
+
import { cls, componentWrapper } from '@arco-design/mobile-utils';
|
|
3
|
+
import { ContextLayout, CompWithGlobalContext } from '../context-provider';
|
|
4
|
+
import Transition from '../transition';
|
|
5
|
+
import IconErrorCircle from '../icon/IconErrorCircle';
|
|
6
|
+
import IconWarnCircle from '../icon/IconWarnCircle';
|
|
7
|
+
import IconSuccessCircle from '../icon/IconSuccessCircle';
|
|
8
|
+
import Portal from '../portal';
|
|
9
|
+
import { ToastBaseProps, toast } from './methods';
|
|
10
|
+
import Loading from '../loading';
|
|
11
|
+
import { usePreventBodyScroll } from '../_helpers';
|
|
12
|
+
|
|
13
|
+
export * from './methods';
|
|
14
|
+
|
|
15
|
+
export type ToastType = 'success' | 'error' | 'warn';
|
|
16
|
+
|
|
17
|
+
export interface ToastProps {
|
|
18
|
+
/**
|
|
19
|
+
* 自定义类名
|
|
20
|
+
* @en Custom classname
|
|
21
|
+
*/
|
|
22
|
+
className?: string;
|
|
23
|
+
/**
|
|
24
|
+
* 提示内容
|
|
25
|
+
* @en Tip content
|
|
26
|
+
*/
|
|
27
|
+
content?: React.ReactNode;
|
|
28
|
+
/**
|
|
29
|
+
* 自动关闭的延时(单位: ms),设置为0则不会自动关闭
|
|
30
|
+
* @en Duration of automatic shutdown (unit: ms), if set to 0, it will not automatically shutdown
|
|
31
|
+
* @default 3000
|
|
32
|
+
*/
|
|
33
|
+
duration?: number;
|
|
34
|
+
/**
|
|
35
|
+
* 自定义图标
|
|
36
|
+
* @en Custom icon
|
|
37
|
+
*/
|
|
38
|
+
icon?: React.ReactNode;
|
|
39
|
+
/**
|
|
40
|
+
* 内容排列布局
|
|
41
|
+
* @en Content layout
|
|
42
|
+
* @default "vertical"
|
|
43
|
+
*/
|
|
44
|
+
layout?: 'vertical' | 'horizontal';
|
|
45
|
+
/**
|
|
46
|
+
* 打开关闭动画执行时长(单位: ms)
|
|
47
|
+
* @en Open and close animation duration (unit: ms)
|
|
48
|
+
* @default 300
|
|
49
|
+
*/
|
|
50
|
+
transitionDuration?: number;
|
|
51
|
+
/**
|
|
52
|
+
* 关闭函数
|
|
53
|
+
* @en Close function
|
|
54
|
+
*/
|
|
55
|
+
close?: () => void;
|
|
56
|
+
/**
|
|
57
|
+
* 关闭后的回调函数
|
|
58
|
+
* @en Callback after closing
|
|
59
|
+
*/
|
|
60
|
+
onClose?: () => void;
|
|
61
|
+
/**
|
|
62
|
+
* 是否为加载态
|
|
63
|
+
* @en Whether it is in the loading state
|
|
64
|
+
*/
|
|
65
|
+
loading?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* 加载图标,传入Icon组件type属性或node
|
|
68
|
+
* @en Loading icon, input the type or node of icon component
|
|
69
|
+
*/
|
|
70
|
+
loadingIcon?: React.ReactNode;
|
|
71
|
+
/**
|
|
72
|
+
* 加载图标内部元素,仅在 loading 为 true 时生效
|
|
73
|
+
* @en Inner element of loading icon, only takes effect when loading is true
|
|
74
|
+
*/
|
|
75
|
+
loadingInner?: string;
|
|
76
|
+
/**
|
|
77
|
+
* 是否禁止toast以外区域的交互
|
|
78
|
+
* @en Whether to prohibit interaction in areas other than toast
|
|
79
|
+
* @default false
|
|
80
|
+
*/
|
|
81
|
+
disableBodyTouch?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* 是否显示toast
|
|
84
|
+
* @en Whether to show toast
|
|
85
|
+
* @default false
|
|
86
|
+
*/
|
|
87
|
+
visible?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* 获取挂载容器
|
|
90
|
+
* @en Get mounted container
|
|
91
|
+
*/
|
|
92
|
+
getContainer?: () => HTMLElement;
|
|
93
|
+
/**
|
|
94
|
+
* toast展示信息类型,不同类型对应不同图标,info表示纯文字信息无图标
|
|
95
|
+
* @en toast displays information types, different types correspond to different icons, info means plain text information without icons
|
|
96
|
+
* @default "info"
|
|
97
|
+
*/
|
|
98
|
+
type?: ToastType | 'info';
|
|
99
|
+
/**
|
|
100
|
+
* toast出现位置
|
|
101
|
+
* @en The direction where the toast appears
|
|
102
|
+
* @default "center"
|
|
103
|
+
*/
|
|
104
|
+
direction?: 'center' | 'top' | 'bottom';
|
|
105
|
+
/**
|
|
106
|
+
* 自定义不同类型对应的不同图标
|
|
107
|
+
* @en Customize different icons corresponding to different types
|
|
108
|
+
*/
|
|
109
|
+
typeIconMap?: Partial<Record<ToastType, ReactNode>>;
|
|
110
|
+
/**
|
|
111
|
+
* 页面初始 overflow 状态,即关闭toast时 overflow 应该还原的状态
|
|
112
|
+
* @en The initial overflow state of the page, that is, the state of overflow should be restored when toast is closed
|
|
113
|
+
* @default 第一个全屏组件(弹窗、toast等)打开时页面overflow值
|
|
114
|
+
* @default_en The page overflow value when the first fullscreen component (popup, toast, etc.) is opened
|
|
115
|
+
*/
|
|
116
|
+
initialBodyOverflow?: string;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface ToastRef {
|
|
120
|
+
/**
|
|
121
|
+
* 最外层元素 DOM
|
|
122
|
+
* @en The outermost element DOM
|
|
123
|
+
*/
|
|
124
|
+
dom: HTMLDivElement | null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const Toast = forwardRef((props: ToastProps, ref: Ref<ToastRef>) => {
|
|
128
|
+
const {
|
|
129
|
+
className,
|
|
130
|
+
getContainer,
|
|
131
|
+
visible = false,
|
|
132
|
+
onClose,
|
|
133
|
+
close,
|
|
134
|
+
type = 'info',
|
|
135
|
+
icon,
|
|
136
|
+
layout = 'vertical',
|
|
137
|
+
duration = 3000,
|
|
138
|
+
transitionDuration = 300,
|
|
139
|
+
content,
|
|
140
|
+
loading = false,
|
|
141
|
+
loadingIcon,
|
|
142
|
+
disableBodyTouch = false,
|
|
143
|
+
loadingInner,
|
|
144
|
+
direction = 'center',
|
|
145
|
+
typeIconMap,
|
|
146
|
+
initialBodyOverflow,
|
|
147
|
+
} = props;
|
|
148
|
+
const closeTimerRef = useRef<number | undefined>(undefined);
|
|
149
|
+
const domRef = useRef<HTMLDivElement | null>(null);
|
|
150
|
+
const wrapDomRef = useRef<HTMLDivElement | null>(null);
|
|
151
|
+
const isInitialMount = useRef(false);
|
|
152
|
+
const hasType = type && type !== 'info';
|
|
153
|
+
|
|
154
|
+
useImperativeHandle(ref, () => ({
|
|
155
|
+
dom: domRef.current,
|
|
156
|
+
}));
|
|
157
|
+
|
|
158
|
+
usePreventBodyScroll(visible, disableBodyTouch, initialBodyOverflow);
|
|
159
|
+
|
|
160
|
+
function handleClose() {
|
|
161
|
+
if (close) {
|
|
162
|
+
close();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function startCloseTimer() {
|
|
167
|
+
if (duration) {
|
|
168
|
+
clearTimeout(closeTimerRef.current);
|
|
169
|
+
|
|
170
|
+
closeTimerRef.current = window.setTimeout(() => {
|
|
171
|
+
handleClose();
|
|
172
|
+
}, duration);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function handleClickMask(e: React.MouseEvent) {
|
|
177
|
+
if (disableBodyTouch) {
|
|
178
|
+
e.preventDefault();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function getTypeIcons() {
|
|
183
|
+
const map = typeIconMap || {};
|
|
184
|
+
const defaultMap = {
|
|
185
|
+
success: <IconSuccessCircle />,
|
|
186
|
+
error: <IconErrorCircle />,
|
|
187
|
+
warn: <IconWarnCircle />,
|
|
188
|
+
};
|
|
189
|
+
return map[type] || defaultMap[type] || null;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
useEffect(() => {
|
|
193
|
+
const mounted = isInitialMount.current;
|
|
194
|
+
if (visible) {
|
|
195
|
+
startCloseTimer();
|
|
196
|
+
} else {
|
|
197
|
+
clearTimeout(closeTimerRef.current);
|
|
198
|
+
if (mounted) {
|
|
199
|
+
setTimeout(() => {
|
|
200
|
+
onClose && onClose();
|
|
201
|
+
}, transitionDuration);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
isInitialMount.current = true;
|
|
205
|
+
}, [visible]);
|
|
206
|
+
|
|
207
|
+
useEffect(() => {
|
|
208
|
+
startCloseTimer();
|
|
209
|
+
}, [duration]);
|
|
210
|
+
|
|
211
|
+
function renderComponent(prefixClass: string) {
|
|
212
|
+
return (
|
|
213
|
+
<div
|
|
214
|
+
className={cls(`${prefixClass}-wrapper`, `from-${direction}`, {
|
|
215
|
+
'no-event': !disableBodyTouch,
|
|
216
|
+
})}
|
|
217
|
+
onClick={handleClickMask}
|
|
218
|
+
ref={wrapDomRef}
|
|
219
|
+
>
|
|
220
|
+
<div
|
|
221
|
+
className={cls(`${prefixClass}-inner`, layout, {
|
|
222
|
+
[`${prefixClass}-inner-mixin`]:
|
|
223
|
+
(loading || hasType || icon) && layout === 'vertical',
|
|
224
|
+
})}
|
|
225
|
+
>
|
|
226
|
+
{loading && (
|
|
227
|
+
<div className={`${prefixClass}-loading-wrapper`}>
|
|
228
|
+
{loadingIcon !== void 0 ? (
|
|
229
|
+
loadingIcon
|
|
230
|
+
) : (
|
|
231
|
+
<Loading
|
|
232
|
+
className="loading-icon"
|
|
233
|
+
type="arc"
|
|
234
|
+
stroke={2}
|
|
235
|
+
radius={loadingInner ? 19 : 11}
|
|
236
|
+
/>
|
|
237
|
+
)}
|
|
238
|
+
{loadingInner ? (
|
|
239
|
+
<span className={`${prefixClass}-loading-inner`}>
|
|
240
|
+
{loadingInner}
|
|
241
|
+
</span>
|
|
242
|
+
) : null}
|
|
243
|
+
</div>
|
|
244
|
+
)}
|
|
245
|
+
{/* success、error、warn */}
|
|
246
|
+
{!loading && hasType ? getTypeIcons() : null}
|
|
247
|
+
{/* Custom icon */}
|
|
248
|
+
{!loading && !hasType && icon ? icon : null}
|
|
249
|
+
{content ? <div className={`${prefixClass}-content`}>{content}</div> : null}
|
|
250
|
+
</div>
|
|
251
|
+
</div>
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return (
|
|
256
|
+
<ContextLayout>
|
|
257
|
+
{({ prefixCls }) => (
|
|
258
|
+
<Portal getContainer={getContainer}>
|
|
259
|
+
<div
|
|
260
|
+
className={cls(`${prefixCls}-toast`, 'all-border-box', className)}
|
|
261
|
+
ref={domRef}
|
|
262
|
+
>
|
|
263
|
+
<Transition
|
|
264
|
+
in={visible}
|
|
265
|
+
timeout={transitionDuration}
|
|
266
|
+
type="fade"
|
|
267
|
+
nodeRef={wrapDomRef}
|
|
268
|
+
>
|
|
269
|
+
{renderComponent(`${prefixCls}-toast`)}
|
|
270
|
+
</Transition>
|
|
271
|
+
</div>
|
|
272
|
+
</Portal>
|
|
273
|
+
)}
|
|
274
|
+
</ContextLayout>
|
|
275
|
+
);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
export function methodsGenerator<P extends ToastBaseProps>(Comp: React.FunctionComponent<P>) {
|
|
279
|
+
return {
|
|
280
|
+
/**
|
|
281
|
+
* 展示常规提示框
|
|
282
|
+
* @desc {en} Show regular toast
|
|
283
|
+
* @param {string | ToastProps} config Configuration
|
|
284
|
+
* @returns {{ update: (config: ToastProps) => void; close: () => void }}
|
|
285
|
+
*/
|
|
286
|
+
toast: toast(Comp),
|
|
287
|
+
/**
|
|
288
|
+
* 展示常规提示框,同 Toast.toast
|
|
289
|
+
* @desc {en} Show regular toast, the same as Toast.toast
|
|
290
|
+
* @param {string | ToastProps} config Configuration
|
|
291
|
+
* @returns {{ update: (config: ToastProps) => void; close: () => void }}
|
|
292
|
+
*/
|
|
293
|
+
info: toast(Comp, 'info'),
|
|
294
|
+
/**
|
|
295
|
+
* 展示成功提示框(含成功icon)
|
|
296
|
+
* @desc {en} Show success prompt toast (including success icon)
|
|
297
|
+
* @param {string | ToastProps} config Configuration
|
|
298
|
+
* @returns {{ update: (config: ToastProps) => void; close: () => void }}
|
|
299
|
+
*/
|
|
300
|
+
success: toast(Comp, 'success'),
|
|
301
|
+
/**
|
|
302
|
+
* 展示错误提示框(含错误icon)
|
|
303
|
+
* @desc {en} Display error prompt toast (including error icon)
|
|
304
|
+
* @param {string | ToastProps} config Configuration
|
|
305
|
+
* @returns {{ update: (config: ToastProps) => void; close: () => void }}
|
|
306
|
+
*/
|
|
307
|
+
error: toast(Comp, 'error'),
|
|
308
|
+
/**
|
|
309
|
+
* 展示加载中提示框(含加载中icon)
|
|
310
|
+
* @desc {en} Display loading prompt toast (including loading icon)
|
|
311
|
+
* @param {string | ToastProps} config Configuration
|
|
312
|
+
* @returns {{ update: (config: ToastProps) => void; close: () => void }}
|
|
313
|
+
*/
|
|
314
|
+
loading: toast(Comp, 'loading'),
|
|
315
|
+
/**
|
|
316
|
+
* 展示警告提示框(含警告icon)
|
|
317
|
+
* @desc {en} Display warning prompt toast (including warning icon)
|
|
318
|
+
* @param {string | ToastProps} config Configuration
|
|
319
|
+
* @returns {{ update: (config: ToastProps) => void; close: () => void }}
|
|
320
|
+
*/
|
|
321
|
+
warn: toast(Comp, 'warn'),
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const ToastWithGlobalContext = CompWithGlobalContext(Toast);
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* 轻提示组件,支持各个场景下调用方法。
|
|
329
|
+
* @en The toast component, supports calling methods in various scenarios.
|
|
330
|
+
* @type 反馈
|
|
331
|
+
* @type_en Feedback
|
|
332
|
+
* @name 轻提示
|
|
333
|
+
* @name_en Toast
|
|
334
|
+
*/
|
|
335
|
+
export default componentWrapper(Toast, methodsGenerator(ToastWithGlobalContext));
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { nextTick } from '@arco-design/mobile-utils';
|
|
3
|
+
import { ReactDOMRender } from '../_helpers/render';
|
|
4
|
+
import { GlobalContextParams } from '../context-provider';
|
|
5
|
+
|
|
6
|
+
export interface ToastBaseProps {
|
|
7
|
+
getContainer?: () => HTMLElement;
|
|
8
|
+
onClose?: (scene?: string) => void;
|
|
9
|
+
content?: React.ReactNode;
|
|
10
|
+
// 强制定义的属性
|
|
11
|
+
visible?: boolean;
|
|
12
|
+
close?: (e) => void;
|
|
13
|
+
type?: string;
|
|
14
|
+
loading?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function toast<P extends ToastBaseProps>(
|
|
18
|
+
Component: React.FunctionComponent<P>,
|
|
19
|
+
type?: string,
|
|
20
|
+
) {
|
|
21
|
+
type Config = Omit<P, 'visible' | 'close'>;
|
|
22
|
+
return (originConfig: string | Config, context?: GlobalContextParams) => {
|
|
23
|
+
const config =
|
|
24
|
+
typeof originConfig === 'string'
|
|
25
|
+
? ({
|
|
26
|
+
content: originConfig,
|
|
27
|
+
type: 'info',
|
|
28
|
+
} as Config)
|
|
29
|
+
: originConfig;
|
|
30
|
+
|
|
31
|
+
if (type !== void 0) {
|
|
32
|
+
config.type = type;
|
|
33
|
+
config.loading = type === 'loading';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const div = document.createElement('div');
|
|
37
|
+
document.body.appendChild(div);
|
|
38
|
+
const { render, unmount } = new ReactDOMRender(Component, div, context);
|
|
39
|
+
|
|
40
|
+
function destroy() {
|
|
41
|
+
const { onClose } = config;
|
|
42
|
+
onClose && onClose();
|
|
43
|
+
unmount();
|
|
44
|
+
if (div.parentNode) {
|
|
45
|
+
div.parentNode.removeChild(div);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let dynamicProps = {
|
|
50
|
+
...config,
|
|
51
|
+
close,
|
|
52
|
+
getContainer: () => div,
|
|
53
|
+
onClose: destroy,
|
|
54
|
+
visible: false,
|
|
55
|
+
};
|
|
56
|
+
let leaving = false;
|
|
57
|
+
|
|
58
|
+
function update(newConfig: Config) {
|
|
59
|
+
dynamicProps = {
|
|
60
|
+
...dynamicProps,
|
|
61
|
+
...newConfig,
|
|
62
|
+
};
|
|
63
|
+
render(dynamicProps);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function close() {
|
|
67
|
+
leaving = true;
|
|
68
|
+
dynamicProps.visible = false;
|
|
69
|
+
render(dynamicProps);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
render(dynamicProps);
|
|
73
|
+
nextTick(() => {
|
|
74
|
+
// 在即将打开时发现已经调用了close则取消打开操作
|
|
75
|
+
// @en When it is about to be opened, it is found that close has been called and the open operation is canceled
|
|
76
|
+
if (leaving) return;
|
|
77
|
+
dynamicProps.visible = true;
|
|
78
|
+
render(dynamicProps);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
update,
|
|
83
|
+
close,
|
|
84
|
+
hide: close,
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
### 其他
|
|
2
|
+
|
|
3
|
+
# 动画过渡 Transition
|
|
4
|
+
|
|
5
|
+
react-transition-group/CSSTransition 的简单封装。
|
|
6
|
+
|
|
7
|
+
======
|
|
8
|
+
|
|
9
|
+
> 属性/Props
|
|
10
|
+
|
|
11
|
+
|参数|描述|类型|默认值|
|
|
12
|
+
|----------|-------------|------|------|
|
|
13
|
+
|children|待执行动画内容|ReactNode|-|
|
|
14
|
+
|type|待执行动画css类名|string|必填|
|
|
15
|
+
|in|内容是否可见|boolean|必填|
|
|
16
|
+
|timeout|执行动画时间|number \| \{ appear?: number; enter?: number; exit?: number; \}|必填|
|
|
17
|
+
|mountOnEnter|是否在打开时再加载内容|boolean|true|
|
|
18
|
+
|unmountOnExit|是否在退出时卸载内容|boolean|true|
|
|
19
|
+
|transitionVarType|动画时长变量标识|string|type 属性值|
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { CSSProperties, ReactElement, ReactNode } from 'react';
|
|
2
|
+
import React, { cloneElement, useMemo } from 'react';
|
|
3
|
+
import type { CSSTransitionProps } from 'react-transition-group/CSSTransition';
|
|
4
|
+
import CSSTransition from 'react-transition-group/CSSTransition';
|
|
5
|
+
import { ContextLayout } from '../context-provider';
|
|
6
|
+
|
|
7
|
+
export type TransitionProps = Omit<CSSTransitionProps, 'timeout'> & {
|
|
8
|
+
/**
|
|
9
|
+
* 待执行动画内容
|
|
10
|
+
* @en Animation content to be executed
|
|
11
|
+
*/
|
|
12
|
+
children?: ReactNode;
|
|
13
|
+
/**
|
|
14
|
+
* 待执行动画css类名
|
|
15
|
+
* @en Css classname of the animation to be executed
|
|
16
|
+
*/
|
|
17
|
+
type: string;
|
|
18
|
+
/**
|
|
19
|
+
* 内容是否可见
|
|
20
|
+
* @en Whether the content is visible
|
|
21
|
+
*/
|
|
22
|
+
in: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* 执行动画时间
|
|
25
|
+
* @en Execute animation time
|
|
26
|
+
*/
|
|
27
|
+
timeout: number | { appear?: number; enter?: number; exit?: number };
|
|
28
|
+
/**
|
|
29
|
+
* 是否在打开时再加载内容
|
|
30
|
+
* @en Whether to reload content when it is opened
|
|
31
|
+
* @default true
|
|
32
|
+
*/
|
|
33
|
+
mountOnEnter?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* 是否在退出时卸载内容
|
|
36
|
+
* @en Whether to unmount content on exit
|
|
37
|
+
* @default true
|
|
38
|
+
*/
|
|
39
|
+
unmountOnExit?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* 动画时长变量标识
|
|
42
|
+
* @en Animation duration variable identifier
|
|
43
|
+
* @default type 属性值
|
|
44
|
+
*/
|
|
45
|
+
transitionVarType?: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const DEFAULT_TIMEOUT = 300;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* react-transition-group/CSSTransition 的简单封装。
|
|
52
|
+
* @en Simple wrapper for react-transition-group/CSSTransition.
|
|
53
|
+
* @type 其他
|
|
54
|
+
* @type_en Others
|
|
55
|
+
* @name 动画过渡
|
|
56
|
+
* @name_en Transition
|
|
57
|
+
*/
|
|
58
|
+
export default function Transition(props: TransitionProps) {
|
|
59
|
+
const {
|
|
60
|
+
children = <div />,
|
|
61
|
+
type,
|
|
62
|
+
in: transIn,
|
|
63
|
+
timeout = DEFAULT_TIMEOUT,
|
|
64
|
+
mountOnEnter = true,
|
|
65
|
+
unmountOnExit = true,
|
|
66
|
+
transitionVarType,
|
|
67
|
+
...restProps
|
|
68
|
+
} = props;
|
|
69
|
+
const varPrefix = `builtin-transition-${transitionVarType || type}`;
|
|
70
|
+
|
|
71
|
+
// 计算动画时长,支持对象形式的 timeout
|
|
72
|
+
const getDuration = (phase: 'appear' | 'enter' | 'exit') => {
|
|
73
|
+
if (typeof timeout === 'number') {
|
|
74
|
+
return timeout;
|
|
75
|
+
}
|
|
76
|
+
return timeout[phase] || DEFAULT_TIMEOUT;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// 生成 CSS 变量样式
|
|
80
|
+
const cssVariables = useMemo(() => {
|
|
81
|
+
const enterDuration = getDuration('enter');
|
|
82
|
+
const exitDuration = getDuration('exit');
|
|
83
|
+
const appearDuration = getDuration('appear');
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
[`--${varPrefix}-enter-duration`]: `${enterDuration}ms`,
|
|
87
|
+
[`--${varPrefix}-exit-duration`]: `${exitDuration}ms`,
|
|
88
|
+
[`--${varPrefix}-appear-duration`]: `${appearDuration}ms`,
|
|
89
|
+
} as CSSProperties;
|
|
90
|
+
}, [timeout, varPrefix]);
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<ContextLayout>
|
|
94
|
+
{({ prefixCls }) => (
|
|
95
|
+
<CSSTransition
|
|
96
|
+
in={transIn}
|
|
97
|
+
timeout={timeout}
|
|
98
|
+
classNames={`${prefixCls}-${type}`}
|
|
99
|
+
mountOnEnter={mountOnEnter}
|
|
100
|
+
unmountOnExit={unmountOnExit}
|
|
101
|
+
{...restProps}
|
|
102
|
+
>
|
|
103
|
+
{cloneElement(children as ReactElement, {
|
|
104
|
+
style: {
|
|
105
|
+
...cssVariables,
|
|
106
|
+
...(children as ReactElement)?.props?.style,
|
|
107
|
+
},
|
|
108
|
+
})}
|
|
109
|
+
</CSSTransition>
|
|
110
|
+
)}
|
|
111
|
+
</ContextLayout>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
### 数据录入
|
|
2
|
+
|
|
3
|
+
# 文件上传 Uploader
|
|
4
|
+
|
|
5
|
+
文件上传组件
|
|
6
|
+
|
|
7
|
+
======
|
|
8
|
+
|
|
9
|
+
> 属性/Props
|
|
10
|
+
|
|
11
|
+
|参数|描述|类型|默认值|
|
|
12
|
+
|----------|-------------|------|------|
|
|
13
|
+
|className|自定义类名|string|-|
|
|
14
|
+
|style|自定义样式|CSSProperties|-|
|
|
15
|
+
|accept|可以选择的文件类型|string|undefined|
|
|
16
|
+
|multiple|是否支持多选|boolean|-|
|
|
17
|
+
|capture|文件选取模式 File selection mode \[capture MDN\](https://developer\.mozilla\.org/en\-US/docs/Web/HTML/Attributes/capture)|string \| boolean|-|
|
|
18
|
+
|hideStatus|是否隐藏文件上传状态|boolean|false|
|
|
19
|
+
|alwaysShowSelect|是否总是展示选择Icon,默认情况下当文件数量超出limit值时会自动隐藏选择Icon|boolean|false|
|
|
20
|
+
|disabled|禁用选择和删除图片|boolean|-|
|
|
21
|
+
|renderDeleteArea|自定义删除区域|(fileItem: FileItem, index: number) =\> ReactNode|-|
|
|
22
|
+
|renderLoadedArea|自定义上传成功区域|(fileItem: FileItem, index: number) =\> ReactNode|-|
|
|
23
|
+
|renderLoadingArea|自定义上传中区域|(fileItem: FileItem, index: number) =\> ReactNode|-|
|
|
24
|
+
|renderErrorArea|自定义上传失败区域|(fileItem: FileItem, index: number) =\> ReactNode|-|
|
|
25
|
+
|renderFileIndexArea|自定义文件索引区域|(fileItem: FileItem, index: number) =\> ReactNode|-|
|
|
26
|
+
|renderUploadArea|自定义上传按钮区域|() =\> ReactNode|-|
|
|
27
|
+
|renderFileList|自定义上传文件列表展示|(methods: FileListMethods) =\> ReactNode|-|
|
|
28
|
+
|upload|上传方法|(file: CommonFileItem) =\> Promise\<CommonFileItem\>|-|
|
|
29
|
+
|onChange|已选文件列表发生变化|(fileList: CommonFileItem\[\]) =\> void|-|
|
|
30
|
+
|maxSize|文件大小限制,单位为K|number|-|
|
|
31
|
+
|onMaxSizeExceed|文件超过限制大小|(file: File) =\> void|-|
|
|
32
|
+
|limit|最多选择文件数,超出数量自动隐藏上传按钮,0表示不做限制|number|0|
|
|
33
|
+
|onLimitExceed|选择文件数超过限制|(files: File\[\]) =\> void|-|
|
|
34
|
+
|files|已选择文件列表|CommonFileItem\[\]|必填|
|
|
35
|
+
|onDeleteClick|删除点击事件|(index: number) =\> void|-|
|
|
36
|
+
|onUploadClick|上传文件点击事件|() =\> void|-|
|
|
37
|
+
|selectAdapter|文件选择适配器|() =\> Promise\<SelectCallback\>|-|
|
|
38
|
+
|onClick|文件点击|(e: MouseEvent\<HTMLElement, MouseEvent\>, file: CommonFileItem, index: number) =\> void|-|
|
|
39
|
+
|onLongPress|文件长按事件|(e: TouchEvent\<HTMLElement\>, file: CommonFileItem, index: number) =\> void|-|
|
|
40
|
+
|
|
41
|
+
> 引用/Refs
|
|
42
|
+
|
|
43
|
+
|参数|描述|类型|
|
|
44
|
+
|----------|-------------|------|
|
|
45
|
+
|dom|最外层 DOM 元素|HTMLDivElement|
|
|
46
|
+
|
|
47
|
+
> FileItem
|
|
48
|
+
|
|
49
|
+
|参数|描述|类型|默认值|
|
|
50
|
+
|----------|-------------|------|------|
|
|
51
|
+
|file|文件|File|必填|
|
|
52
|
+
|url|文件地址|string|-|
|
|
53
|
+
|status|文件状态|"loaded" \| "loading" \| "error"|以文件自身加载状态而定|
|
|
54
|
+
|
|
55
|
+
> FileListMethods
|
|
56
|
+
|
|
57
|
+
|参数|描述|类型|
|
|
58
|
+
|----------|-------------|------|
|
|
59
|
+
|retryUpload|重新上传|(index: number) =\> void|
|
|
60
|
+
|deleteFile|删除文件|(index: number) =\> void|
|
|
61
|
+
|
|
62
|
+
> CommonFileItem
|
|
63
|
+
|
|
64
|
+
|参数|描述|类型|默认值|
|
|
65
|
+
|----------|-------------|------|------|
|
|
66
|
+
|url|文件地址|string|-|
|
|
67
|
+
|file|文件|File|-|
|
|
68
|
+
|status|文件状态|"loaded" \| "loading" \| "error"|以文件自身加载状态而定|
|
|
69
|
+
|
|
70
|
+
> SelectCallback
|
|
71
|
+
|
|
72
|
+
|参数|描述|类型|
|
|
73
|
+
|----------|-------------|------|
|
|
74
|
+
|files|文件列表|AdapterFile\[\]|
|
|
75
|
+
|
|
76
|
+
> AdapterFile
|
|
77
|
+
|
|
78
|
+
|参数|描述|类型|
|
|
79
|
+
|----------|-------------|------|
|
|
80
|
+
|url|文件 url|string|
|
|
81
|
+
|size|文件大小|number|
|
|
82
|
+
|name|文件名|string|
|