@ecoding/components.antd 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
export interface IModalProps {
|
|
3
|
+
key?: string;
|
|
4
|
+
id?: string;
|
|
3
5
|
className?: string;
|
|
4
6
|
open?: boolean;
|
|
5
7
|
bodyStyle?: React.CSSProperties;
|
|
@@ -19,6 +21,32 @@ export interface IModalProps {
|
|
|
19
21
|
addonBefore?: React.ReactNode;
|
|
20
22
|
addonAfter?: React.ReactNode;
|
|
21
23
|
}
|
|
24
|
+
export declare class Modals extends React.Component<IModalProps> {
|
|
25
|
+
static defaultProps: {
|
|
26
|
+
className: string;
|
|
27
|
+
open: boolean;
|
|
28
|
+
bodyStyle: {};
|
|
29
|
+
width: string;
|
|
30
|
+
zIndex: number;
|
|
31
|
+
mask: boolean;
|
|
32
|
+
title: string;
|
|
33
|
+
okType: string;
|
|
34
|
+
okText: string;
|
|
35
|
+
cancelText: string;
|
|
36
|
+
closable: boolean;
|
|
37
|
+
footer: string;
|
|
38
|
+
onOk: () => Promise<void>;
|
|
39
|
+
onCancel: () => Promise<void>;
|
|
40
|
+
component: null;
|
|
41
|
+
};
|
|
42
|
+
state: {
|
|
43
|
+
loading: boolean;
|
|
44
|
+
open: boolean | undefined;
|
|
45
|
+
};
|
|
46
|
+
cancel: () => void;
|
|
47
|
+
ok: () => void;
|
|
48
|
+
render(): JSX.Element;
|
|
49
|
+
}
|
|
22
50
|
declare const _default: {
|
|
23
51
|
show(props?: IModalProps): void;
|
|
24
52
|
hide(props?: IModalProps): void;
|
package/lib/core/modal/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Modal, Button } from 'antd';
|
|
3
|
-
import
|
|
4
|
-
const
|
|
5
|
-
class Modals extends React.Component {
|
|
3
|
+
import InjectNotification from '../../helpers/inject.notification';
|
|
4
|
+
const timeout = 300;
|
|
5
|
+
export class Modals extends React.Component {
|
|
6
6
|
constructor() {
|
|
7
7
|
super(...arguments);
|
|
8
8
|
this.state = {
|
|
9
9
|
loading: false,
|
|
10
|
-
open:
|
|
10
|
+
open: this.props.open
|
|
11
11
|
};
|
|
12
12
|
this.cancel = () => {
|
|
13
13
|
if (this.state.loading) {
|
|
@@ -18,7 +18,9 @@ class Modals extends React.Component {
|
|
|
18
18
|
this.setState({
|
|
19
19
|
open: false
|
|
20
20
|
});
|
|
21
|
-
|
|
21
|
+
setTimeout(() => {
|
|
22
|
+
InjectNotification.removeNotice(this.props.id);
|
|
23
|
+
}, timeout);
|
|
22
24
|
});
|
|
23
25
|
};
|
|
24
26
|
this.ok = () => {
|
|
@@ -33,8 +35,10 @@ class Modals extends React.Component {
|
|
|
33
35
|
loading: false,
|
|
34
36
|
open: false
|
|
35
37
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
InjectNotification.removeNotice(this.props.id);
|
|
40
|
+
this.props.onOkAfter && this.props.onOkAfter(res);
|
|
41
|
+
}, timeout);
|
|
38
42
|
})
|
|
39
43
|
.catch(() => {
|
|
40
44
|
this.setState({
|
|
@@ -45,24 +49,55 @@ class Modals extends React.Component {
|
|
|
45
49
|
}
|
|
46
50
|
render() {
|
|
47
51
|
// if (!this.props.visible) return null;
|
|
48
|
-
return (React.createElement(Modal, { className: this.props.className, open: this.state.open, bodyStyle: this.props.bodyStyle, width: this.props.width, zIndex: this.props.zIndex, mask: this.props.mask, title: this.props.title, closable: this.props.closable, onCancel: this.cancel, footer: this.props.footer === null ? null : this.props.footer ? (this.props.footer) : (React.createElement(React.Fragment, null,
|
|
52
|
+
return (React.createElement(Modal, { className: this.props.className, open: this.state.open, bodyStyle: this.props.bodyStyle, width: this.props.width, zIndex: this.props.zIndex, mask: this.props.mask, title: this.props.title, closable: this.props.closable, onCancel: this.cancel, centered: true, destroyOnClose: true, keyboard: false, footer: this.props.footer === null ? null : this.props.footer ? (this.props.footer) : (React.createElement(React.Fragment, null,
|
|
49
53
|
this.props.addonBefore ? this.props.addonBefore : null,
|
|
50
54
|
React.createElement(Button, { key: "back", onClick: this.cancel }, this.props.cancelText),
|
|
51
55
|
React.createElement(Button, { key: "submit", type: this.props.okType, loading: this.state.loading, onClick: this.ok }, this.props.okText),
|
|
52
|
-
this.props.addonAfter ? this.props.addonAfter : null))
|
|
56
|
+
this.props.addonAfter ? this.props.addonAfter : null)) }, this.props.component ? this.props.component : null));
|
|
53
57
|
}
|
|
54
58
|
}
|
|
55
59
|
Modals.defaultProps = {
|
|
56
|
-
|
|
60
|
+
className: "g-modals",
|
|
61
|
+
open: false,
|
|
62
|
+
bodyStyle: {},
|
|
63
|
+
width: "80vw",
|
|
64
|
+
zIndex: 950,
|
|
65
|
+
mask: true,
|
|
66
|
+
title: "标题",
|
|
67
|
+
okType: "primary",
|
|
68
|
+
okText: "保存",
|
|
69
|
+
cancelText: "取消",
|
|
70
|
+
closable: true,
|
|
71
|
+
footer: "",
|
|
72
|
+
onOk: function () {
|
|
73
|
+
return Promise.resolve();
|
|
74
|
+
},
|
|
75
|
+
onCancel: function () {
|
|
76
|
+
return Promise.resolve();
|
|
77
|
+
},
|
|
78
|
+
component: null
|
|
57
79
|
};
|
|
58
80
|
export default {
|
|
59
81
|
show(props = {}) {
|
|
60
|
-
|
|
61
|
-
|
|
82
|
+
props.open = true;
|
|
83
|
+
props.id = props.id || props.key || "modals";
|
|
84
|
+
if (props.footer !== null && !props.footer) {
|
|
85
|
+
props.footer = "";
|
|
86
|
+
}
|
|
87
|
+
if (!props.okText) {
|
|
88
|
+
props.okText = "保存";
|
|
89
|
+
}
|
|
90
|
+
if (!props.cancelText) {
|
|
91
|
+
props.cancelText = "取消";
|
|
62
92
|
}
|
|
63
|
-
|
|
93
|
+
InjectNotification.notice(React.createElement(Modals, Object.assign({}, props, { key: props.id })));
|
|
64
94
|
},
|
|
65
95
|
hide(props = {}) {
|
|
66
|
-
|
|
96
|
+
props.open = false;
|
|
97
|
+
props.footer = "";
|
|
98
|
+
props.id = props.id || "modals";
|
|
99
|
+
setTimeout(() => {
|
|
100
|
+
InjectNotification.removeNotice(props.id);
|
|
101
|
+
}, timeout);
|
|
67
102
|
}
|
|
68
103
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
interface IState {
|
|
3
|
+
notices: React.Attributes[];
|
|
4
|
+
target: HTMLElement | null;
|
|
5
|
+
}
|
|
6
|
+
declare class InjectNotification extends React.Component<any, IState> {
|
|
7
|
+
static notice(component: any): void;
|
|
8
|
+
static removeNotice(key: any): void;
|
|
9
|
+
constructor(props: any);
|
|
10
|
+
add(notice: React.Attributes): void;
|
|
11
|
+
remove(key: string): void;
|
|
12
|
+
getNoticeList(): React.Attributes[];
|
|
13
|
+
componentDidMount(): void;
|
|
14
|
+
render(): React.ReactPortal | null;
|
|
15
|
+
}
|
|
16
|
+
export default InjectNotification;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { createPortal } from "react-dom";
|
|
3
|
+
import EventEmitter from "@ecoding/helper.event";
|
|
4
|
+
const instanceEvent = new EventEmitter();
|
|
5
|
+
// notification是父组件容器,通过其方法做额外渲染到 body 上的react节点
|
|
6
|
+
// 是动态插入和删除DOM节点的核心
|
|
7
|
+
class InjectNotification extends React.Component {
|
|
8
|
+
static notice(component) {
|
|
9
|
+
instanceEvent.emit("InjectNotification/SHOW", component);
|
|
10
|
+
}
|
|
11
|
+
static removeNotice(key) {
|
|
12
|
+
instanceEvent.emit("InjectNotification/HIDE", key);
|
|
13
|
+
}
|
|
14
|
+
constructor(props) {
|
|
15
|
+
super(props);
|
|
16
|
+
this.state = {
|
|
17
|
+
target: null,
|
|
18
|
+
notices: []
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
// 创建一个监听项
|
|
22
|
+
add(notice) {
|
|
23
|
+
// 添加notice
|
|
24
|
+
// 创造一个不重复的key
|
|
25
|
+
const { notices } = this.state;
|
|
26
|
+
const key = notice.key;
|
|
27
|
+
const index = notices.findIndex(item => item.key === key);
|
|
28
|
+
if (index === -1) {
|
|
29
|
+
// 不存在重复的 添加
|
|
30
|
+
notices.push(notice);
|
|
31
|
+
this.setState({
|
|
32
|
+
notices,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
const temp = notices.splice(index, 1);
|
|
37
|
+
console.log(notices.concat(temp));
|
|
38
|
+
this.setState(Object.assign({}, {
|
|
39
|
+
notices: notices.concat(temp),
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// 删除一个监听项
|
|
44
|
+
remove(key) {
|
|
45
|
+
this.setState(previousState => {
|
|
46
|
+
return {
|
|
47
|
+
notices: previousState.notices.filter(notice => notice.key !== key)
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
getNoticeList() {
|
|
52
|
+
const { notices } = this.state;
|
|
53
|
+
return notices.map((notice, i) => {
|
|
54
|
+
return notice;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
componentDidMount() {
|
|
58
|
+
this.setState({
|
|
59
|
+
target: document.body,
|
|
60
|
+
notices: []
|
|
61
|
+
});
|
|
62
|
+
instanceEvent.on("InjectNotification/SHOW", this.add, this);
|
|
63
|
+
instanceEvent.on("InjectNotification/HIDE", this.remove, this);
|
|
64
|
+
}
|
|
65
|
+
render() {
|
|
66
|
+
const noticesDOM = this.getNoticeList();
|
|
67
|
+
return this.state.target ? createPortal(noticesDOM, this.state.target) : null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export default InjectNotification;
|
|
@@ -8,12 +8,12 @@ declare class Notification extends React.Component<any, IState> {
|
|
|
8
8
|
notice(component: TNotices): void;
|
|
9
9
|
removeNotice(key: string): void;
|
|
10
10
|
destroy(): void;
|
|
11
|
-
component:
|
|
11
|
+
component: React.RefObject<unknown>;
|
|
12
12
|
};
|
|
13
13
|
constructor(props: any);
|
|
14
14
|
add(notice: TNotices): void;
|
|
15
15
|
remove(key: string): void;
|
|
16
|
-
|
|
16
|
+
getNoticeList(): React.Attributes[];
|
|
17
17
|
render(): JSX.Element;
|
|
18
18
|
}
|
|
19
19
|
export default Notification;
|
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import
|
|
1
|
+
import React, { createElement, createRef } from "react";
|
|
2
|
+
import { createRoot } from "react-dom/client";
|
|
3
3
|
// notification是父组件容器,通过其方法做额外渲染到 body 上的react节点
|
|
4
4
|
// 是动态插入和删除DOM节点的核心
|
|
5
5
|
class Notification extends React.Component {
|
|
6
6
|
static newInstance() {
|
|
7
|
-
const
|
|
8
|
-
document.
|
|
9
|
-
const
|
|
7
|
+
const notification = createRef();
|
|
8
|
+
const div = document.createElement("Other");
|
|
9
|
+
const root = createRoot(div);
|
|
10
|
+
root.render(createElement(Notification, { ref: notification }));
|
|
10
11
|
return {
|
|
11
12
|
notice(component) {
|
|
12
|
-
notification.add(component);
|
|
13
|
+
notification.current.add(component);
|
|
13
14
|
},
|
|
14
15
|
removeNotice(key) {
|
|
15
|
-
notification.remove(key);
|
|
16
|
+
notification.current.remove(key);
|
|
16
17
|
},
|
|
17
18
|
destroy() {
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
// unmountComponentAtNode(div);
|
|
20
|
+
root.unmount();
|
|
20
21
|
},
|
|
21
|
-
component: notification
|
|
22
|
+
component: notification,
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
25
|
constructor(props) {
|
|
@@ -38,7 +39,7 @@ class Notification extends React.Component {
|
|
|
38
39
|
// 不存在重复的 添加
|
|
39
40
|
notices.push(notice);
|
|
40
41
|
this.setState({
|
|
41
|
-
notices
|
|
42
|
+
notices,
|
|
42
43
|
});
|
|
43
44
|
}
|
|
44
45
|
}
|
|
@@ -50,14 +51,14 @@ class Notification extends React.Component {
|
|
|
50
51
|
};
|
|
51
52
|
});
|
|
52
53
|
}
|
|
53
|
-
|
|
54
|
+
getNoticeList() {
|
|
54
55
|
const { notices } = this.state;
|
|
55
56
|
return notices.map((notice, i) => {
|
|
56
57
|
return notice;
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
60
|
render() {
|
|
60
|
-
const noticesDOM = this.
|
|
61
|
+
const noticesDOM = this.getNoticeList();
|
|
61
62
|
return (React.createElement(React.Fragment, null, noticesDOM));
|
|
62
63
|
}
|
|
63
64
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecoding/components.antd",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"author": "cxc",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"build": "rm -rf lib && tsc"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
+
"@ecoding/helper.event": ">=0.0.2",
|
|
27
28
|
"@ecoding/helper.is": ">=0.0.4",
|
|
28
29
|
"@ecoding/helper.json": ">=0.0.5",
|
|
29
30
|
"@ecoding/helper.request.hook": ">=0.0.6",
|
|
@@ -31,6 +32,7 @@
|
|
|
31
32
|
"axios": ">=1.1.2"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
35
|
+
"@ecoding/helper.event": "^0.0.2",
|
|
34
36
|
"@ecoding/helper.is": "^0.0.4",
|
|
35
37
|
"@ecoding/helper.json": "^0.0.5",
|
|
36
38
|
"@ecoding/helper.request.hook": "^0.0.6",
|
|
@@ -40,5 +42,5 @@
|
|
|
40
42
|
"dependencies": {
|
|
41
43
|
"react-quill": "^2.0.0"
|
|
42
44
|
},
|
|
43
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "d41d5a815bc583f5499c1d0120a833a0622538f5"
|
|
44
46
|
}
|