@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,81 @@
|
|
|
1
|
+
### 反馈
|
|
2
|
+
|
|
3
|
+
# 消息通知 Notify
|
|
4
|
+
|
|
5
|
+
主动操作后显示的反馈信息横条,可采用方法调用或者组件调用的方式
|
|
6
|
+
|
|
7
|
+
======
|
|
8
|
+
|
|
9
|
+
> 属性/Props
|
|
10
|
+
|
|
11
|
+
|参数|描述|类型|默认值|
|
|
12
|
+
|----------|-------------|------|------|
|
|
13
|
+
|className|自定义类名|string|-|
|
|
14
|
+
|style|自定义样式|CSSProperties|-|
|
|
15
|
+
|content|需要展示的内容|ReactNode|-|
|
|
16
|
+
|type|通知类型|"success" \| "error" \| "warn" \| "info"|"info"|
|
|
17
|
+
|visible|是否显示通知|boolean|false|
|
|
18
|
+
|close|控制通知关闭的事件|() =\> void|-|
|
|
19
|
+
|onClose|通知关闭时的回调函数|() =\> void|-|
|
|
20
|
+
|getContainer|将通知放入某个模块|() =\> HTMLElement|-|
|
|
21
|
+
|transitionDuration|动画的执行时间 (单位ms)|number|300|
|
|
22
|
+
|duration|通知自动关闭时延 (单位ms) 设置为0时不会自动关闭|number|3000|
|
|
23
|
+
|
|
24
|
+
> 引用/Refs
|
|
25
|
+
|
|
26
|
+
|参数|描述|类型|
|
|
27
|
+
|----------|-------------|------|
|
|
28
|
+
|dom|最外层dom元素|HTMLElement|
|
|
29
|
+
|updateLayout|更新元素布局|() =\> void|
|
|
30
|
+
|
|
31
|
+
> 方法/Methods
|
|
32
|
+
|
|
33
|
+
|方法名|描述|类型|
|
|
34
|
+
|----------|-------------|------|
|
|
35
|
+
|info|展示常规通知|(config: string \| NotifyProps) =\> \{ update: (config: NotifyProps) =\> void; close: () =\> void \}|
|
|
36
|
+
|success|展示成功通知|(config: string \| NotifyProps) =\> \{ update: (config: NotifyProps) =\> void; close: () =\> void \}|
|
|
37
|
+
|error|展示错误的通知|(config: string \| NotifyProps) =\> \{ update: (config: NotifyProps) =\> void; close: () =\> void \}|
|
|
38
|
+
|warn|展示警告的通知|(config: string \| NotifyProps) =\> \{ update: (config: NotifyProps) =\> void; close: () =\> void \}|
|
|
39
|
+
|
|
40
|
+
> NotifyType
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
"success" | "error" | "warn" | "info"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
> GlobalContextParams
|
|
47
|
+
|
|
48
|
+
|参数|描述|类型|默认值|
|
|
49
|
+
|----------|-------------|------|------|
|
|
50
|
+
|prefixCls|组件类名前缀|string|"arco"|
|
|
51
|
+
|system|手动控制当前所在系统,传入后将直接使用传入的值,ssr场景需指定系统初始值时适用|"" \| "pc" \| "android" \| "ios"|""|
|
|
52
|
+
|useDarkMode|是否监听系统原生的暗黑模式变化(prefers\-color\-scheme: dark)以判断是否切为暗黑模式|boolean|false|
|
|
53
|
+
|isDarkMode|是否处于暗黑模式,指定后以指定的值为准|boolean|false|
|
|
54
|
+
|darkModeSelector|当处于暗黑模式时,body上挂载的类名,为空值时不挂载类名|string|"arco-theme-dark"|
|
|
55
|
+
|theme|主题变量,传入后将在线替换css变量,需设置less变量 @use\-css\-vars: 1|Record\<string, string\>|-|
|
|
56
|
+
|locale|国际化语言包配置|ILocale|-|
|
|
57
|
+
|useRtl|是否使用Rtl模式|boolean|false|
|
|
58
|
+
|onDarkModeChange|当系统原生暗黑模式发生变化时触发,useDarkMode=true 时有效|(isDark: boolean) =\> void|-|
|
|
59
|
+
|createRoot|React19 修改了 createRoot 的引入路径,导致组件内部无法直接引入(低react版本会找不到模块)。因此使用 react 19 的用户需从外部传入 createRoot 方法|CreateRootFnType|-|
|
|
60
|
+
|
|
61
|
+
> ILocale
|
|
62
|
+
|
|
63
|
+
|参数|描述|类型|
|
|
64
|
+
|----------|-------------|------|
|
|
65
|
+
|locale|语言类型|string|
|
|
66
|
+
|LoadMore|-|\{ loadMoreText: string; loadingText: string; noDataText: string; failLoadText: string; prepareScrollText: string; prepareClickText: string; \}|
|
|
67
|
+
|Picker|-|\{ okText: string; cancelText: string; \}|
|
|
68
|
+
|Tag|-|\{ addTag: string; \}|
|
|
69
|
+
|Dialog|-|\{ okText: string; cancelText: string; \}|
|
|
70
|
+
|SwipeLoad|-|\{ normalText: string; activeText: string; \}|
|
|
71
|
+
|PullRefresh|-|\{ loadingText: string; pullingText: string; finishText: string; loosingText: string; \}|
|
|
72
|
+
|DropdownMenu|-|\{ select: string; \}|
|
|
73
|
+
|Pagination|-|\{ previousPage: string; nextPage: string; \}|
|
|
74
|
+
|Image|-|\{ loadError: string; \}|
|
|
75
|
+
|ImagePicker|-|\{ loadError: string; \}|
|
|
76
|
+
|SearchBar|-|\{ placeholder: string; cancelBtn: string; \}|
|
|
77
|
+
|Stepper|-|\{ minusButtonName: string; addButtonName: string; \}|
|
|
78
|
+
|Keyboard|-|\{ confirm: string; \}|
|
|
79
|
+
|Form|-|\{ required: string; type: \{ email: string; url: string; string: string; number: string; array: string; object: string; boolean: string; \}; number: \{ min: string; max: string; equal: string; range: string; positive: string; negative: string; \}; \.\.\. 4 more \.\.\.; pickerDefaultHint: string; \}|
|
|
80
|
+
|NavBar|-|\{ backBtnAriaLabel: string; \}|
|
|
81
|
+
|Uploader|-|\{ uploadBtn: string; retryUpload: string; \}|
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import React, { useRef, forwardRef, Ref, useImperativeHandle, useEffect, useState } from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import { componentWrapper, nextTick } from '@arco-design/mobile-utils';
|
|
4
|
+
import { ContextLayout, CompWithGlobalContext } from '../context-provider';
|
|
5
|
+
import { NotifyProps, NotifyRef } from './type';
|
|
6
|
+
import { getStyleWithVendor, useUpdateEffect } from '../_helpers';
|
|
7
|
+
import { NotifyBaseProps, notify } from './methods';
|
|
8
|
+
|
|
9
|
+
export * from './type';
|
|
10
|
+
|
|
11
|
+
const Notify = forwardRef((props: NotifyProps, ref: Ref<NotifyRef>) => {
|
|
12
|
+
const {
|
|
13
|
+
className = '',
|
|
14
|
+
style,
|
|
15
|
+
visible = false,
|
|
16
|
+
transitionDuration = 300,
|
|
17
|
+
content,
|
|
18
|
+
duration = 3000,
|
|
19
|
+
onClose,
|
|
20
|
+
type = 'info',
|
|
21
|
+
close,
|
|
22
|
+
getContainer,
|
|
23
|
+
} = props;
|
|
24
|
+
const domRef = useRef<HTMLDivElement>(null);
|
|
25
|
+
const innerRef = useRef<HTMLDivElement>(null);
|
|
26
|
+
const closeTimerRef = useRef<number | undefined>(undefined);
|
|
27
|
+
const onCloseTimeRef = useRef<number | undefined>(undefined);
|
|
28
|
+
const [hasTrans, setHasTrans] = useState(!visible);
|
|
29
|
+
const [innerHeight, setInnerHeight] = useState(0);
|
|
30
|
+
|
|
31
|
+
useImperativeHandle(ref, () => ({
|
|
32
|
+
dom: domRef.current,
|
|
33
|
+
updateLayout,
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
function startCloseTimer() {
|
|
37
|
+
if (duration) {
|
|
38
|
+
clearTimeout(closeTimerRef.current);
|
|
39
|
+
closeTimerRef.current = window.setTimeout(() => {
|
|
40
|
+
close?.();
|
|
41
|
+
}, duration);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function updateLayout() {
|
|
46
|
+
if (innerRef.current) {
|
|
47
|
+
const { height } = innerRef.current.getBoundingClientRect();
|
|
48
|
+
setInnerHeight(height);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
visible && updateLayout();
|
|
54
|
+
visible && startCloseTimer();
|
|
55
|
+
return () => {
|
|
56
|
+
visible && clearTimeout(closeTimerRef.current);
|
|
57
|
+
};
|
|
58
|
+
}, [visible, duration]);
|
|
59
|
+
|
|
60
|
+
useUpdateEffect(() => {
|
|
61
|
+
if (!visible) {
|
|
62
|
+
onCloseTimeRef.current = window.setTimeout(() => {
|
|
63
|
+
onClose && onClose();
|
|
64
|
+
}, transitionDuration);
|
|
65
|
+
}
|
|
66
|
+
}, [visible]);
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
nextTick(() => {
|
|
70
|
+
setHasTrans(true);
|
|
71
|
+
});
|
|
72
|
+
return () => {
|
|
73
|
+
clearTimeout(onCloseTimeRef.current);
|
|
74
|
+
};
|
|
75
|
+
}, []);
|
|
76
|
+
|
|
77
|
+
function renderComponent(prefixClass: string) {
|
|
78
|
+
return content ? (
|
|
79
|
+
<div
|
|
80
|
+
className={`${prefixClass}-content ${
|
|
81
|
+
visible
|
|
82
|
+
? `${prefixClass}-content-transition-Y0`
|
|
83
|
+
: `${prefixClass}-content-transition-Y100`
|
|
84
|
+
}`}
|
|
85
|
+
ref={innerRef}
|
|
86
|
+
style={{
|
|
87
|
+
...(hasTrans
|
|
88
|
+
? getStyleWithVendor({
|
|
89
|
+
transitionDuration: `${transitionDuration}ms`,
|
|
90
|
+
})
|
|
91
|
+
: {}),
|
|
92
|
+
}}
|
|
93
|
+
>
|
|
94
|
+
{content}
|
|
95
|
+
</div>
|
|
96
|
+
) : null;
|
|
97
|
+
}
|
|
98
|
+
const render = prefixCls => {
|
|
99
|
+
return (
|
|
100
|
+
<div
|
|
101
|
+
className={`${prefixCls}-notify ${prefixCls}-notify-${type} ${className}`}
|
|
102
|
+
style={{
|
|
103
|
+
...style,
|
|
104
|
+
...(hasTrans
|
|
105
|
+
? getStyleWithVendor({
|
|
106
|
+
transitionDuration: `${transitionDuration}ms`,
|
|
107
|
+
})
|
|
108
|
+
: {}),
|
|
109
|
+
height: visible ? innerHeight : 0,
|
|
110
|
+
}}
|
|
111
|
+
ref={domRef}
|
|
112
|
+
>
|
|
113
|
+
{renderComponent(`${prefixCls}-notify`)}
|
|
114
|
+
</div>
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
return (
|
|
118
|
+
<ContextLayout>
|
|
119
|
+
{({ prefixCls }) =>
|
|
120
|
+
getContainer
|
|
121
|
+
? ReactDOM.createPortal(render(prefixCls), getContainer())
|
|
122
|
+
: render(prefixCls)
|
|
123
|
+
}
|
|
124
|
+
</ContextLayout>
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
export function methodsGenerator<P extends NotifyBaseProps>(Comp: React.FC<P>) {
|
|
129
|
+
return {
|
|
130
|
+
/**
|
|
131
|
+
* 展示常规通知
|
|
132
|
+
* @desc {en} Show regular notification
|
|
133
|
+
* @param {string | NotifyProps} config
|
|
134
|
+
* @returns {{ update: (config: NotifyProps) => void; close: () => void }}
|
|
135
|
+
*/
|
|
136
|
+
info: notify(Comp),
|
|
137
|
+
/**
|
|
138
|
+
* 展示成功通知
|
|
139
|
+
* @desc {en} Show success notification
|
|
140
|
+
* @param {string | NotifyProps} config
|
|
141
|
+
* @returns {{ update: (config: NotifyProps) => void; close: () => void }}
|
|
142
|
+
*/
|
|
143
|
+
success: notify(Comp, 'success'),
|
|
144
|
+
/**
|
|
145
|
+
* 展示错误的通知
|
|
146
|
+
* @desc {en} Show error notification
|
|
147
|
+
* @param {string | NotifyProps} config
|
|
148
|
+
* @returns {{ update: (config: NotifyProps) => void; close: () => void }}
|
|
149
|
+
*/
|
|
150
|
+
error: notify(Comp, 'error'),
|
|
151
|
+
/**
|
|
152
|
+
* 展示警告的通知
|
|
153
|
+
* @desc {en} Show warning notification
|
|
154
|
+
* @param {string | NotifyProps} config
|
|
155
|
+
* @returns {{ update: (config: NotifyProps) => void; close: () => void }}
|
|
156
|
+
*/
|
|
157
|
+
warn: notify(Comp, 'warn'),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const NotifyWithGlobalContext = CompWithGlobalContext(Notify);
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* 主动操作后显示的反馈信息横条,可采用方法调用或者组件调用的方式
|
|
165
|
+
* @en The feedback information bar displayed after active operation can be called by method or by component.
|
|
166
|
+
* @type 反馈
|
|
167
|
+
* @type_en Feedback
|
|
168
|
+
* @name 消息通知
|
|
169
|
+
* @name_en Notify
|
|
170
|
+
*/
|
|
171
|
+
export default componentWrapper(Notify, methodsGenerator(NotifyWithGlobalContext));
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { nextTick } from '@arco-design/mobile-utils';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ReactDOMRender } from '../_helpers/render';
|
|
4
|
+
import { GlobalContextParams } from '../context-provider';
|
|
5
|
+
|
|
6
|
+
export interface NotifyBaseProps {
|
|
7
|
+
getContainer?: () => HTMLElement;
|
|
8
|
+
onClose?: (scene?: string) => void;
|
|
9
|
+
content?: React.ReactNode;
|
|
10
|
+
visible?: boolean;
|
|
11
|
+
close?: (e) => void;
|
|
12
|
+
type?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function notify<P extends NotifyBaseProps>(Component: React.FC<P>, type?: string) {
|
|
16
|
+
type Config = Omit<P, 'visible' | 'close'>;
|
|
17
|
+
return (originConfig: string | Config, context?: GlobalContextParams) => {
|
|
18
|
+
const config =
|
|
19
|
+
typeof originConfig === 'string'
|
|
20
|
+
? ({
|
|
21
|
+
content: originConfig,
|
|
22
|
+
type: 'info',
|
|
23
|
+
} as Config)
|
|
24
|
+
: originConfig;
|
|
25
|
+
if (type !== void 0) {
|
|
26
|
+
config.type = type;
|
|
27
|
+
}
|
|
28
|
+
const div = document.createElement('div');
|
|
29
|
+
const { getContainer } = config;
|
|
30
|
+
if (getContainer) {
|
|
31
|
+
getContainer().appendChild(div);
|
|
32
|
+
} else {
|
|
33
|
+
document.body.appendChild(div);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const { render, unmount } = new ReactDOMRender(Component, div, context);
|
|
37
|
+
|
|
38
|
+
function destroy() {
|
|
39
|
+
const { onClose } = config;
|
|
40
|
+
onClose && onClose();
|
|
41
|
+
unmount();
|
|
42
|
+
if (div.parentNode) {
|
|
43
|
+
div.parentNode.removeChild(div);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let dynamicProps = {
|
|
48
|
+
...config,
|
|
49
|
+
close,
|
|
50
|
+
onClose: destroy,
|
|
51
|
+
getContainer: () => div,
|
|
52
|
+
visible: false,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
let leaving = false;
|
|
56
|
+
|
|
57
|
+
function update(newConfig: Config) {
|
|
58
|
+
dynamicProps = {
|
|
59
|
+
...dynamicProps,
|
|
60
|
+
...newConfig,
|
|
61
|
+
};
|
|
62
|
+
render(dynamicProps);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function close() {
|
|
66
|
+
leaving = true;
|
|
67
|
+
dynamicProps.visible = false;
|
|
68
|
+
render(dynamicProps);
|
|
69
|
+
}
|
|
70
|
+
render(dynamicProps);
|
|
71
|
+
|
|
72
|
+
nextTick(() => {
|
|
73
|
+
if (leaving) return;
|
|
74
|
+
dynamicProps.visible = true;
|
|
75
|
+
render(dynamicProps);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
update,
|
|
80
|
+
close,
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
### 导航
|
|
2
|
+
|
|
3
|
+
# 分页器 Pagination
|
|
4
|
+
|
|
5
|
+
用于数据分页,为完全受控组件
|
|
6
|
+
|
|
7
|
+
======
|
|
8
|
+
|
|
9
|
+
> 属性/Props
|
|
10
|
+
|
|
11
|
+
|参数|描述|类型|默认值|
|
|
12
|
+
|----------|-------------|------|------|
|
|
13
|
+
|className|自定义类名|string|-|
|
|
14
|
+
|style|自定义样式|CSSProperties|-|
|
|
15
|
+
|type|分页器翻页区域样式类型,button表示按钮式分页器,text表示文本式分页器,none表示仅保留页码不含翻页区域|"button" \| "text" \| "none"|"button"|
|
|
16
|
+
|icon|是否需要展示图标|ReactNode \| \[\.\.\.\]|false|
|
|
17
|
+
|justify|翻页按钮水平位置,side表示两端对齐,center表示居中对齐|"center" \| "side"|"side"|
|
|
18
|
+
|current|当前页码|number|1|
|
|
19
|
+
|pageSize|每页条数|number|10|
|
|
20
|
+
|total|数据总条数|number|0|
|
|
21
|
+
|hideOnOnePage|只有一页时是否隐藏分页器|boolean|false|
|
|
22
|
+
|nextFieldType|下一页样式,primary表示高亮|"default" \| "primary"|"default"|
|
|
23
|
+
|prevFieldText|上一页文本|string|"上一页"|
|
|
24
|
+
|nextFieldText|下一页文本|string|"下一页"|
|
|
25
|
+
|renderPrevField|渲染前翻页按钮|(data: IPaginationDataParams) =\> ReactNode|-|
|
|
26
|
+
|renderNextField|渲染后翻页按钮|(data: IPaginationDataParams) =\> ReactNode|-|
|
|
27
|
+
|onChange|点击前/后翻页按钮时调用|(data: IPaginationDataParams) =\> void|-|
|
|
28
|
+
|
|
29
|
+
> 引用/Refs
|
|
30
|
+
|
|
31
|
+
|参数|描述|类型|
|
|
32
|
+
|----------|-------------|------|
|
|
33
|
+
|dom|最外层元素 DOM|HTMLDivElement|
|
|
34
|
+
|
|
35
|
+
> IPaginationDataParams
|
|
36
|
+
|
|
37
|
+
|参数|描述|类型|
|
|
38
|
+
|----------|-------------|------|
|
|
39
|
+
|current|当前页|number|
|
|
40
|
+
|pageSize|每页条数|number|
|
|
41
|
+
|pageNum|总页数|number|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
export default function Arrow() {
|
|
4
|
+
return (
|
|
5
|
+
<svg width="2" height="14" viewBox="3 0 2 14" fill="none" style={{ overflow: 'visible' }}>
|
|
6
|
+
<path
|
|
7
|
+
fillRule="evenodd"
|
|
8
|
+
clipRule="evenodd"
|
|
9
|
+
d="M7.40514 12.7583C7.6004 12.563 7.6004 12.2465 7.40514 12.0512L2.40095 7.04701L7.36396 2.084C7.55922 1.88874 7.55922 1.57216 7.36396 1.37689L7.01041 1.02334C6.81515 0.828077 6.49856 0.828077 6.3033 1.02334L0.646447 6.68019C0.470402 6.85624 0.453075 7.1309 0.594469 7.32636C0.617837 7.37275 0.64889 7.41626 0.687628 7.455L6.34448 13.1119C6.53974 13.3071 6.85633 13.3071 7.05159 13.1119L7.40514 12.7583Z"
|
|
10
|
+
fill="currentColor"
|
|
11
|
+
/>
|
|
12
|
+
</svg>
|
|
13
|
+
);
|
|
14
|
+
}
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
useRef,
|
|
3
|
+
forwardRef,
|
|
4
|
+
Ref,
|
|
5
|
+
useImperativeHandle,
|
|
6
|
+
useMemo,
|
|
7
|
+
ReactNode,
|
|
8
|
+
useContext,
|
|
9
|
+
} from 'react';
|
|
10
|
+
import { cls } from '@arco-design/mobile-utils';
|
|
11
|
+
import { GlobalContext } from '../context-provider';
|
|
12
|
+
import { useSystem } from '../_helpers';
|
|
13
|
+
import Arrow from './arrow';
|
|
14
|
+
|
|
15
|
+
export interface IPaginationDataParams {
|
|
16
|
+
/**
|
|
17
|
+
* 当前页
|
|
18
|
+
* @en Current page
|
|
19
|
+
*/
|
|
20
|
+
current: number;
|
|
21
|
+
/**
|
|
22
|
+
* 每页条数
|
|
23
|
+
* @en Number of items per page
|
|
24
|
+
*/
|
|
25
|
+
pageSize: number;
|
|
26
|
+
/**
|
|
27
|
+
* 总页数
|
|
28
|
+
* @en Total number of pages
|
|
29
|
+
*/
|
|
30
|
+
pageNum: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface PaginationProps {
|
|
34
|
+
/**
|
|
35
|
+
* 自定义类名
|
|
36
|
+
* @en Custom classname
|
|
37
|
+
*/
|
|
38
|
+
className?: string;
|
|
39
|
+
/**
|
|
40
|
+
* 自定义样式
|
|
41
|
+
* @en Custom style
|
|
42
|
+
*/
|
|
43
|
+
style?: React.CSSProperties;
|
|
44
|
+
/**
|
|
45
|
+
* 分页器翻页区域样式类型,button表示按钮式分页器,text表示文本式分页器,none表示仅保留页码不含翻页区域
|
|
46
|
+
* @en The style type of the page turning area of the pagination, and none means that only the page number is kept without the page turning area
|
|
47
|
+
* @default "button"
|
|
48
|
+
*/
|
|
49
|
+
type?: 'button' | 'text' | 'none';
|
|
50
|
+
/**
|
|
51
|
+
* 是否需要展示图标
|
|
52
|
+
* @en Whether to show the icon
|
|
53
|
+
* @default false
|
|
54
|
+
*/
|
|
55
|
+
icon?: boolean | ReactNode | [ReactNode, ReactNode];
|
|
56
|
+
/**
|
|
57
|
+
* 翻页按钮水平位置,side表示两端对齐,center表示居中对齐
|
|
58
|
+
* @en The horizontal position of the page turning button, side means both ends are aligned, center means center alignment
|
|
59
|
+
* @default "side"
|
|
60
|
+
*/
|
|
61
|
+
justify?: 'center' | 'side';
|
|
62
|
+
/**
|
|
63
|
+
* 当前页码
|
|
64
|
+
* @en Current page
|
|
65
|
+
* @default 1
|
|
66
|
+
*/
|
|
67
|
+
current?: number;
|
|
68
|
+
/**
|
|
69
|
+
* 每页条数
|
|
70
|
+
* @en Number of items per page
|
|
71
|
+
* @default 10
|
|
72
|
+
*/
|
|
73
|
+
pageSize?: number;
|
|
74
|
+
/**
|
|
75
|
+
* 数据总条数
|
|
76
|
+
* @en Total number of data source
|
|
77
|
+
* @default 0
|
|
78
|
+
*/
|
|
79
|
+
total?: number;
|
|
80
|
+
/**
|
|
81
|
+
* 只有一页时是否隐藏分页器
|
|
82
|
+
* @en Whether to hide the pager when there is only one page
|
|
83
|
+
* @default false
|
|
84
|
+
*/
|
|
85
|
+
hideOnOnePage?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* 下一页样式,primary表示高亮
|
|
88
|
+
* @en Style of next page button, primary means highlight
|
|
89
|
+
* @default "default"
|
|
90
|
+
*/
|
|
91
|
+
nextFieldType?: 'default' | 'primary';
|
|
92
|
+
/**
|
|
93
|
+
* 上一页文本
|
|
94
|
+
* @en Previous page text
|
|
95
|
+
* @default "上一页"
|
|
96
|
+
* @default_en "Previous"
|
|
97
|
+
*/
|
|
98
|
+
prevFieldText?: string;
|
|
99
|
+
/**
|
|
100
|
+
* 下一页文本
|
|
101
|
+
* @en Next page text
|
|
102
|
+
* @default "下一页"
|
|
103
|
+
* @default_en "Next"
|
|
104
|
+
*/
|
|
105
|
+
nextFieldText?: string;
|
|
106
|
+
/**
|
|
107
|
+
* 渲染前翻页按钮
|
|
108
|
+
* @en Custom render previous page button
|
|
109
|
+
*/
|
|
110
|
+
renderPrevField?: (data: IPaginationDataParams) => ReactNode;
|
|
111
|
+
/**
|
|
112
|
+
* 渲染后翻页按钮
|
|
113
|
+
* @en Custom render next page button
|
|
114
|
+
*/
|
|
115
|
+
renderNextField?: (data: IPaginationDataParams) => ReactNode;
|
|
116
|
+
/**
|
|
117
|
+
* 点击前/后翻页按钮时调用
|
|
118
|
+
* @en Callback called when the previous/next page button is clicked
|
|
119
|
+
*/
|
|
120
|
+
onChange?: (data: IPaginationDataParams) => void;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface PaginationRef {
|
|
124
|
+
/**
|
|
125
|
+
* 最外层元素 DOM
|
|
126
|
+
* @en The outermost element DOM
|
|
127
|
+
*/
|
|
128
|
+
dom: HTMLDivElement | null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 用于数据分页,为完全受控组件
|
|
133
|
+
* @en The pagination component is used for data paging and is a fully controlled component.
|
|
134
|
+
* @type 导航
|
|
135
|
+
* @type_en Navigation
|
|
136
|
+
* @name 分页器
|
|
137
|
+
* @name_en Pagination
|
|
138
|
+
*/
|
|
139
|
+
const Pagination = forwardRef((props: PaginationProps, ref: Ref<PaginationRef>) => {
|
|
140
|
+
const { prefixCls, locale } = useContext(GlobalContext);
|
|
141
|
+
const {
|
|
142
|
+
className = '',
|
|
143
|
+
style,
|
|
144
|
+
current = 1,
|
|
145
|
+
pageSize = 10,
|
|
146
|
+
total = 5,
|
|
147
|
+
icon = false,
|
|
148
|
+
justify = 'side',
|
|
149
|
+
hideOnOnePage = false,
|
|
150
|
+
nextFieldType = 'default',
|
|
151
|
+
renderPrevField,
|
|
152
|
+
renderNextField,
|
|
153
|
+
type = 'default',
|
|
154
|
+
prevFieldText = locale?.Pagination.previousPage,
|
|
155
|
+
nextFieldText = locale?.Pagination.nextPage,
|
|
156
|
+
onChange,
|
|
157
|
+
} = props;
|
|
158
|
+
const system = useSystem();
|
|
159
|
+
const pageNum = useMemo(() => Math.ceil(total / pageSize), [total, pageSize]);
|
|
160
|
+
const domRef = useRef<HTMLDivElement | null>(null);
|
|
161
|
+
|
|
162
|
+
useImperativeHandle(ref, () => ({
|
|
163
|
+
dom: domRef.current,
|
|
164
|
+
}));
|
|
165
|
+
|
|
166
|
+
const iconRender = (iconType: 'prev' | 'next') => {
|
|
167
|
+
if (iconType === 'prev') {
|
|
168
|
+
if (Array.isArray(icon) && Boolean(icon.length)) {
|
|
169
|
+
return <span className="btn-icon">{icon[0]}</span>;
|
|
170
|
+
}
|
|
171
|
+
if (Object.prototype.toString.call(icon) === '[object Object]') {
|
|
172
|
+
return <span className="btn-icon">{icon}</span>;
|
|
173
|
+
}
|
|
174
|
+
return icon ? (
|
|
175
|
+
<span className="btn-icon">
|
|
176
|
+
<Arrow />
|
|
177
|
+
</span>
|
|
178
|
+
) : null;
|
|
179
|
+
}
|
|
180
|
+
if (Array.isArray(icon) && Boolean(icon.length)) {
|
|
181
|
+
return <span className="btn-icon">{icon.length >= 2 ? icon[1] : icon[0]}</span>;
|
|
182
|
+
}
|
|
183
|
+
if (Object.prototype.toString.call(icon) === '[object Object]') {
|
|
184
|
+
return <span className="btn-icon next">{icon}</span>;
|
|
185
|
+
}
|
|
186
|
+
return icon ? (
|
|
187
|
+
<span className="btn-icon next">
|
|
188
|
+
<Arrow />
|
|
189
|
+
</span>
|
|
190
|
+
) : null;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const prevRender = (prefix: string) => {
|
|
194
|
+
if (type === 'none') {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
const prevFieldCls = cls(`${prefix}-prev-field`, { [`flex-${justify}`]: true });
|
|
198
|
+
if (typeof renderPrevField === 'undefined') {
|
|
199
|
+
return (
|
|
200
|
+
<div className={prevFieldCls}>
|
|
201
|
+
<div
|
|
202
|
+
className={cls(`${prefix}-field`, 'prev', {
|
|
203
|
+
text: type === 'text',
|
|
204
|
+
button: type !== 'text',
|
|
205
|
+
disabled: current === 1,
|
|
206
|
+
})}
|
|
207
|
+
onClick={() => {
|
|
208
|
+
if (current <= 1) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
onChange?.({ pageSize, pageNum, current: Math.max(1, current - 1) });
|
|
212
|
+
}}
|
|
213
|
+
>
|
|
214
|
+
{iconRender('prev')}
|
|
215
|
+
{Boolean(prevFieldText) && (
|
|
216
|
+
<span className="btn-text">{prevFieldText}</span>
|
|
217
|
+
)}
|
|
218
|
+
</div>
|
|
219
|
+
</div>
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
return (
|
|
223
|
+
<div className={prevFieldCls}>
|
|
224
|
+
{renderPrevField ? renderPrevField({ current, pageSize, pageNum }) : null}
|
|
225
|
+
</div>
|
|
226
|
+
);
|
|
227
|
+
};
|
|
228
|
+
const nextRender = (prefix: string) => {
|
|
229
|
+
if (type === 'none') {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const nextFieldCls = cls(`${prefix}-next-field`, { [`flex-${justify}`]: true });
|
|
234
|
+
if (typeof renderNextField === 'undefined') {
|
|
235
|
+
return (
|
|
236
|
+
<div className={nextFieldCls}>
|
|
237
|
+
<div
|
|
238
|
+
className={cls(`${prefix}-field`, 'next', {
|
|
239
|
+
text: type === 'text',
|
|
240
|
+
button: type !== 'text',
|
|
241
|
+
[nextFieldType === 'default' ? type : 'primary']: current < pageNum,
|
|
242
|
+
disabled: current >= pageNum,
|
|
243
|
+
})}
|
|
244
|
+
onClick={() => {
|
|
245
|
+
if (current >= pageNum) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
onChange?.({
|
|
249
|
+
pageSize,
|
|
250
|
+
pageNum,
|
|
251
|
+
current: Math.min(current + 1, pageNum),
|
|
252
|
+
});
|
|
253
|
+
}}
|
|
254
|
+
>
|
|
255
|
+
{Boolean(nextFieldText) && (
|
|
256
|
+
<span className="btn-text">{nextFieldText}</span>
|
|
257
|
+
)}
|
|
258
|
+
{iconRender('next')}
|
|
259
|
+
</div>
|
|
260
|
+
</div>
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
const nextItem = renderNextField && renderNextField({ current, pageSize, pageNum });
|
|
264
|
+
return <div className={nextFieldCls}>{nextItem}</div>;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
const prefix = `${prefixCls}-pagination`;
|
|
268
|
+
return !(hideOnOnePage && pageNum === 1) ? (
|
|
269
|
+
<div
|
|
270
|
+
ref={domRef}
|
|
271
|
+
className={cls(
|
|
272
|
+
prefix,
|
|
273
|
+
system,
|
|
274
|
+
{
|
|
275
|
+
[`${prefix}-simple`]: type === 'none',
|
|
276
|
+
},
|
|
277
|
+
className,
|
|
278
|
+
)}
|
|
279
|
+
style={style}
|
|
280
|
+
>
|
|
281
|
+
{prevRender(prefix)}
|
|
282
|
+
<div className={`${prefix}-item`}>
|
|
283
|
+
<span className={`${prefix}-item-active`}>{current}</span> / {pageNum}
|
|
284
|
+
</div>
|
|
285
|
+
{nextRender(prefix)}
|
|
286
|
+
</div>
|
|
287
|
+
) : (
|
|
288
|
+
<div className={cls(prefix, className)} />
|
|
289
|
+
);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
export default Pagination;
|