@ecoding/components.antd 0.0.1

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/LICENSE.md ADDED
File without changes
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # `@ecoding/components.layout`
2
+
3
+ > TODO: description
4
+
5
+ ## Usage
6
+
7
+ ```
8
+ const components.layout = require('@ecoding/components.layout');
9
+
10
+ // TODO: DEMONSTRATE API
11
+ ```
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ interface IComfirm {
3
+ title?: string;
4
+ content?: React.ReactNode;
5
+ okText?: string;
6
+ cancelText?: string;
7
+ okType?: "primary" | "default" | "ghost" | "dashed" | "link" | "text" | "danger" | undefined;
8
+ onOk: () => Promise<any>;
9
+ onCancel?: () => Promise<any>;
10
+ }
11
+ declare const confirm: {
12
+ showDelete(opts: IComfirm): void;
13
+ show(opts: IComfirm): void;
14
+ };
15
+ export default confirm;
@@ -0,0 +1,79 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ import { Modal } from 'antd';
12
+ import { ExclamationCircleOutlined } from '@ant-design/icons';
13
+ const confirm = {
14
+ showDelete(opts) {
15
+ let loading = false;
16
+ Modal.confirm({
17
+ okType: 'danger',
18
+ icon: _jsx(ExclamationCircleOutlined, {}),
19
+ title: opts.title || '确定要删除吗?',
20
+ content: opts.content || '',
21
+ okText: opts.okText || '确定',
22
+ cancelText: opts.okText || '取消',
23
+ onOk() {
24
+ loading = true;
25
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
26
+ try {
27
+ yield opts.onOk();
28
+ resolve(true);
29
+ }
30
+ catch (e) {
31
+ loading = false;
32
+ reject(false);
33
+ }
34
+ }));
35
+ },
36
+ onCancel() {
37
+ if (loading) {
38
+ return Promise.reject('正在请求中,不可关闭');
39
+ }
40
+ if (opts.onCancel) {
41
+ return opts.onCancel();
42
+ }
43
+ },
44
+ });
45
+ },
46
+ show(opts) {
47
+ let loading = false;
48
+ Modal.confirm({
49
+ icon: _jsx(ExclamationCircleOutlined, {}),
50
+ title: opts.title || '标题',
51
+ content: opts.content || '',
52
+ okType: opts.okType || 'primary',
53
+ okText: opts.okText || '确定',
54
+ cancelText: opts.okText || '取消',
55
+ onOk() {
56
+ loading = true;
57
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
58
+ try {
59
+ yield opts.onOk();
60
+ resolve(true);
61
+ }
62
+ catch (e) {
63
+ loading = false;
64
+ reject(false);
65
+ }
66
+ }));
67
+ },
68
+ onCancel() {
69
+ if (loading) {
70
+ return Promise.reject('正在请求中,不可关闭');
71
+ }
72
+ if (opts.onCancel) {
73
+ return opts.onCancel();
74
+ }
75
+ },
76
+ });
77
+ }
78
+ };
79
+ export default confirm;
@@ -0,0 +1,8 @@
1
+ interface ILoadingFCProps {
2
+ tip?: string;
3
+ }
4
+ declare const _default: {
5
+ show(props?: ILoadingFCProps): void;
6
+ hide(props?: ILoadingFCProps): void;
7
+ };
8
+ export default _default;
@@ -0,0 +1,41 @@
1
+ import { createElement as _createElement } from "react";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Spin } from 'antd';
4
+ import Notification from '../../helpers/notification';
5
+ const notification = Notification.newInstance();
6
+ const LoadingFC = (props) => {
7
+ const maskStyle = {
8
+ position: 'fixed',
9
+ top: 0,
10
+ right: 0,
11
+ bottom: 0,
12
+ left: 0,
13
+ zIndex: 9001,
14
+ backgroundColor: '#fff',
15
+ height: '100%',
16
+ opacity: 0.45
17
+ };
18
+ const alertStyle = {
19
+ position: 'fixed',
20
+ top: '50%',
21
+ left: '50%',
22
+ maxWidth: 340,
23
+ zIndex: 9002,
24
+ transform: 'translate(-50%, -70%)'
25
+ };
26
+ return (_jsxs(_Fragment, { children: [_jsx("div", { style: maskStyle }), _jsx("div", Object.assign({ style: alertStyle }, { children: _jsx(Spin, { size: "large", tip: props.tip }) }))] }));
27
+ };
28
+ LoadingFC.defaultProps = {
29
+ tip: ''
30
+ };
31
+ export default {
32
+ show(props = {}) {
33
+ if (notification) {
34
+ notification.removeNotice('loading');
35
+ }
36
+ notification.notice(_createElement(LoadingFC, Object.assign({}, props, { key: "loading" })));
37
+ },
38
+ hide(props = {}) {
39
+ notification.removeNotice('loading');
40
+ }
41
+ };
@@ -0,0 +1,15 @@
1
+ interface IToastFCProps {
2
+ mask?: boolean;
3
+ title?: string;
4
+ maskTheme?: string;
5
+ duration?: number;
6
+ auto?: boolean;
7
+ type?: 'error' | 'warning' | 'info' | 'success';
8
+ }
9
+ declare const _default: {
10
+ info(props?: IToastFCProps): void;
11
+ success(props?: IToastFCProps): void;
12
+ warning(props?: IToastFCProps): void;
13
+ error(props?: IToastFCProps): void;
14
+ };
15
+ export default _default;
@@ -0,0 +1,79 @@
1
+ import { createElement as _createElement } from "react";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect } from 'react';
4
+ import { Alert } from 'antd';
5
+ import Notification from '../../helpers/notification';
6
+ const notification = Notification.newInstance();
7
+ var EaskTheme;
8
+ (function (EaskTheme) {
9
+ EaskTheme["dark"] = "#333";
10
+ EaskTheme["light"] = "#fff";
11
+ })(EaskTheme || (EaskTheme = {}));
12
+ const typeMap = {
13
+ error: '错误',
14
+ warning: '警告',
15
+ info: '提示',
16
+ success: '成功'
17
+ };
18
+ const ToastFC = (props) => {
19
+ const maskStyle = {
20
+ position: 'fixed',
21
+ top: 0,
22
+ right: 0,
23
+ bottom: 0,
24
+ left: 0,
25
+ zIndex: 9000,
26
+ height: '100%',
27
+ opacity: 0.45
28
+ };
29
+ const alertStyle = {
30
+ position: 'fixed',
31
+ top: '50%',
32
+ left: '50%',
33
+ maxWidth: 340,
34
+ zIndex: 9001,
35
+ transform: 'translate(-50%, -70%)'
36
+ };
37
+ useEffect(() => {
38
+ if (props.duration === 0) {
39
+ return;
40
+ }
41
+ const timeout = setTimeout(() => {
42
+ if (props.auto) {
43
+ notification.removeNotice('toast');
44
+ }
45
+ }, props.duration);
46
+ return () => {
47
+ clearTimeout(timeout);
48
+ };
49
+ }, []);
50
+ return (_jsxs(_Fragment, { children: [props.mask ? _jsx("div", { style: Object.assign(maskStyle, { backgroundColor: props.maskTheme === 'light' ? EaskTheme.light : EaskTheme.dark }) }) : null, _jsx("div", Object.assign({ style: alertStyle }, { children: _jsx(Alert, { description: props.title, message: typeMap[props.type], type: props.type, showIcon: true, closable: true, onClose: () => notification.removeNotice('toast') }) }))] }));
51
+ };
52
+ ToastFC.defaultProps = {
53
+ mask: false,
54
+ title: '提示',
55
+ maskTheme: 'light',
56
+ duration: 2000,
57
+ auto: true,
58
+ type: 'success'
59
+ };
60
+ const show = (props = {}) => {
61
+ if (notification) {
62
+ notification.removeNotice('toast');
63
+ }
64
+ notification.notice(_createElement(ToastFC, Object.assign({}, props, { key: "toast" })));
65
+ };
66
+ export default {
67
+ info(props = {}) {
68
+ return show(Object.assign(Object.assign({}, props), { type: 'info' }));
69
+ },
70
+ success(props = {}) {
71
+ return show(Object.assign(Object.assign({}, props), { type: 'success' }));
72
+ },
73
+ warning(props = {}) {
74
+ return show(Object.assign(Object.assign({}, props), { type: 'warning' }));
75
+ },
76
+ error(props = {}) {
77
+ return show(Object.assign(Object.assign({}, props), { type: 'error' }));
78
+ },
79
+ };
@@ -0,0 +1,19 @@
1
+ import React from "react";
2
+ declare type TNotices = React.Attributes;
3
+ interface IState {
4
+ notices: TNotices[];
5
+ }
6
+ declare class Notification extends React.Component<any, IState> {
7
+ static newInstance(): {
8
+ notice(component: TNotices): void;
9
+ removeNotice(key: string): void;
10
+ destroy(): void;
11
+ component: any;
12
+ };
13
+ constructor(props: any);
14
+ add(notice: TNotices): void;
15
+ remove(key: string): void;
16
+ getNoticeDOM(): React.Attributes[];
17
+ render(): JSX.Element;
18
+ }
19
+ export default Notification;
@@ -0,0 +1,65 @@
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import React from "react";
3
+ import ReactDOM from "react-dom";
4
+ // notification是父组件容器,通过其方法做额外渲染到 body 上的react节点
5
+ // 是动态插入和删除DOM节点的核心
6
+ class Notification extends React.Component {
7
+ static newInstance() {
8
+ const div = document.createElement("div");
9
+ document.body.appendChild(div);
10
+ const notification = ReactDOM.render(_jsx(Notification, {}), div);
11
+ return {
12
+ notice(component) {
13
+ notification.add(component);
14
+ },
15
+ removeNotice(key) {
16
+ notification.remove(key);
17
+ },
18
+ destroy() {
19
+ ReactDOM.unmountComponentAtNode(div);
20
+ document.body.removeChild(div);
21
+ },
22
+ component: notification
23
+ };
24
+ }
25
+ constructor(props) {
26
+ super(props);
27
+ this.state = {
28
+ notices: []
29
+ };
30
+ }
31
+ // 创建一个监听项
32
+ add(notice) {
33
+ // 添加notice
34
+ // 创造一个不重复的key
35
+ const { notices } = this.state;
36
+ const key = notice.key;
37
+ const temp = notices.filter(item => item.key === key).length;
38
+ if (!temp) {
39
+ // 不存在重复的 添加
40
+ notices.push(notice);
41
+ this.setState({
42
+ notices
43
+ });
44
+ }
45
+ }
46
+ // 删除一个监听项
47
+ remove(key) {
48
+ this.setState(previousState => {
49
+ return {
50
+ notices: previousState.notices.filter(notice => notice.key !== key)
51
+ };
52
+ });
53
+ }
54
+ getNoticeDOM() {
55
+ const { notices } = this.state;
56
+ return notices.map((notice, i) => {
57
+ return notice;
58
+ });
59
+ }
60
+ render() {
61
+ const noticesDOM = this.getNoticeDOM();
62
+ return (_jsx(_Fragment, { children: noticesDOM }));
63
+ }
64
+ }
65
+ export default Notification;
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { default as Toast } from "./core/toast";
2
+ export { default as Loading } from "./core/loading";
3
+ export { default as Confirm } from "./core/confirm";
package/lib/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { default as Toast } from "./core/toast";
2
+ export { default as Loading } from "./core/loading";
3
+ export { default as Confirm } from "./core/confirm";
@@ -0,0 +1,12 @@
1
+ export declare type Types = "react" | "vue" | "pkg";
2
+ export declare type Props = {
3
+ category: Types | null;
4
+ appname: string;
5
+ };
6
+ export interface IBaseFactory {
7
+ prompting?: () => void;
8
+ default?: () => void;
9
+ writing?: () => void;
10
+ install?: () => void;
11
+ end?: () => void;
12
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@ecoding/components.antd",
3
+ "version": "0.0.1",
4
+ "author": "cxc",
5
+ "homepage": "",
6
+ "license": "MIT",
7
+ "directories": {
8
+ "lib": "lib",
9
+ "test": "__tests__"
10
+ },
11
+ "files": [
12
+ "lib"
13
+ ],
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "main": "./lib/index.js",
18
+ "module": "./lib/index.js",
19
+ "typings": "./lib/index.d.ts",
20
+ "scripts": {
21
+ "unlink": "npm unlink",
22
+ "link": "npm link",
23
+ "dev": "tsc -w",
24
+ "build": "rm -rf lib && tsc"
25
+ },
26
+ "gitHead": "db098300a2dd7b59f4d25fecffd878df08b80cc3"
27
+ }