@pisell/materials 1.0.923 → 1.0.925
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/build/lowcode/assets-daily.json +11 -11
- package/build/lowcode/assets-dev.json +2 -2
- package/build/lowcode/assets-prod.json +11 -11
- package/build/lowcode/index.js +1 -1
- package/build/lowcode/meta.js +1 -1
- package/build/lowcode/preview.js +8 -8
- package/build/lowcode/render/default/view.css +1 -1
- package/build/lowcode/render/default/view.js +31 -16
- package/build/lowcode/view.css +1 -1
- package/build/lowcode/view.js +34 -19
- package/es/components/batch-editor/index.d.ts +1 -0
- package/es/components/dataSourceComponents/dataSourceTable/filter/index.d.ts +1 -0
- package/es/components/dataSourceComponents/fields/Upload/BaseUpload.js +199 -19
- package/es/components/dataSourceComponents/fields/Upload/CameraPopover.d.ts +6 -0
- package/es/components/dataSourceComponents/fields/Upload/CameraPopover.js +66 -0
- package/es/components/dataSourceComponents/fields/Upload/index.less +35 -3
- package/es/components/dataSourceComponents/fields/Upload/type.d.ts +1 -0
- package/es/components/dataSourceComponents/fields/index.d.ts +3 -3
- package/es/components/pisellCamera/index.d.ts +4 -0
- package/es/components/pisellCamera/index.js +219 -0
- package/es/components/pisellCamera/index.less +120 -0
- package/es/components/pisellToast/index.d.ts +1 -1
- package/es/components/pisellToast/index.js +1 -1
- package/es/components/pisellToast/squareToast/index.d.ts +12 -22
- package/es/components/pisellToast/squareToast/index.js +24 -106
- package/es/components/pisellToast/squareToast/index.less +7 -18
- package/es/components/pisellToast/squareToast/methods.d.ts +13 -0
- package/es/components/pisellToast/squareToast/methods.js +138 -0
- package/es/components/pisellToast/squareToast/renderImperatively.d.ts +31 -0
- package/es/components/pisellToast/squareToast/renderImperatively.js +167 -0
- package/es/components/pisellToast/squareToast/toast.d.ts +23 -0
- package/es/components/pisellToast/squareToast/toast.js +71 -0
- package/es/locales/en-US.d.ts +10 -0
- package/es/locales/en-US.js +13 -1
- package/es/locales/zh-CN.d.ts +10 -0
- package/es/locales/zh-CN.js +13 -1
- package/es/locales/zh-TW.d.ts +10 -0
- package/es/locales/zh-TW.js +13 -1
- package/lib/components/batch-editor/index.d.ts +1 -0
- package/lib/components/dataSourceComponents/dataSourceTable/filter/index.d.ts +1 -0
- package/lib/components/dataSourceComponents/fields/Upload/BaseUpload.js +168 -5
- package/lib/components/dataSourceComponents/fields/Upload/CameraPopover.d.ts +6 -0
- package/lib/components/dataSourceComponents/fields/Upload/CameraPopover.js +95 -0
- package/lib/components/dataSourceComponents/fields/Upload/index.less +35 -3
- package/lib/components/dataSourceComponents/fields/Upload/type.d.ts +1 -0
- package/lib/components/dataSourceComponents/fields/index.d.ts +3 -3
- package/lib/components/pisellCamera/index.d.ts +4 -0
- package/lib/components/pisellCamera/index.js +219 -0
- package/lib/components/pisellCamera/index.less +120 -0
- package/lib/components/pisellToast/index.d.ts +1 -1
- package/lib/components/pisellToast/index.js +2 -2
- package/lib/components/pisellToast/squareToast/index.d.ts +12 -22
- package/lib/components/pisellToast/squareToast/index.js +30 -93
- package/lib/components/pisellToast/squareToast/index.less +7 -18
- package/lib/components/pisellToast/squareToast/methods.d.ts +13 -0
- package/lib/components/pisellToast/squareToast/methods.js +152 -0
- package/lib/components/pisellToast/squareToast/renderImperatively.d.ts +31 -0
- package/lib/components/pisellToast/squareToast/renderImperatively.js +148 -0
- package/lib/components/pisellToast/squareToast/toast.d.ts +23 -0
- package/lib/components/pisellToast/squareToast/toast.js +91 -0
- package/lib/locales/en-US.d.ts +10 -0
- package/lib/locales/en-US.js +13 -1
- package/lib/locales/zh-CN.d.ts +10 -0
- package/lib/locales/zh-CN.js +13 -1
- package/lib/locales/zh-TW.d.ts +10 -0
- package/lib/locales/zh-TW.js +13 -1
- package/lowcode/form-item-upload/meta.ts +20 -5
- package/package.json +4 -3
- package/es/components/pisellToast/squareToast/useToast.d.ts +0 -39
- package/es/components/pisellToast/squareToast/useToast.js +0 -145
- package/lib/components/pisellToast/squareToast/useToast.d.ts +0 -39
- package/lib/components/pisellToast/squareToast/useToast.js +0 -148
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import React, { forwardRef, useImperativeHandle, useRef, useState } from 'react';
|
|
8
|
+
import { Camera } from 'react-camera-pro';
|
|
9
|
+
import { getText } from "../../locales";
|
|
10
|
+
import PisellModal from "../../components/pisellModal";
|
|
11
|
+
import "./index.less";
|
|
12
|
+
var PisellCamera = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
13
|
+
var cameraRef = useRef(null);
|
|
14
|
+
var _useState = useState(false),
|
|
15
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
16
|
+
open = _useState2[0],
|
|
17
|
+
setOpen = _useState2[1];
|
|
18
|
+
var _useState3 = useState(''),
|
|
19
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
20
|
+
photo = _useState4[0],
|
|
21
|
+
setPhoto = _useState4[1];
|
|
22
|
+
var _useState5 = useState(null),
|
|
23
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
24
|
+
cameraAvailable = _useState6[0],
|
|
25
|
+
setCameraAvailable = _useState6[1]; // null: 检测中, true: 可用, false: 不可用
|
|
26
|
+
var uploadFileRef = useRef(null);
|
|
27
|
+
|
|
28
|
+
// Base64转File对象
|
|
29
|
+
var base64ToFile = function base64ToFile(base64String, filename) {
|
|
30
|
+
var _arr$0$match;
|
|
31
|
+
var arr = base64String.split(',');
|
|
32
|
+
var mime = ((_arr$0$match = arr[0].match(/:(.*?);/)) === null || _arr$0$match === void 0 ? void 0 : _arr$0$match[1]) || '';
|
|
33
|
+
var bstr = atob(arr[1]);
|
|
34
|
+
var n = bstr.length;
|
|
35
|
+
var u8arr = new Uint8Array(n);
|
|
36
|
+
while (n--) {
|
|
37
|
+
u8arr[n] = bstr.charCodeAt(n);
|
|
38
|
+
}
|
|
39
|
+
return new File([u8arr], filename, {
|
|
40
|
+
type: mime
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// 拍照并添加到fileList
|
|
45
|
+
var takePhoto = function takePhoto() {
|
|
46
|
+
if (!cameraRef.current || !cameraRef.current.takePhoto) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
var _cameraRef$current, _cameraRef$current$ta;
|
|
51
|
+
var _photo = (_cameraRef$current = cameraRef.current) === null || _cameraRef$current === void 0 || (_cameraRef$current$ta = _cameraRef$current.takePhoto) === null || _cameraRef$current$ta === void 0 ? void 0 : _cameraRef$current$ta.call(_cameraRef$current);
|
|
52
|
+
var timestamp = Date.now();
|
|
53
|
+
var filename = "photo-".concat(timestamp, ".jpg");
|
|
54
|
+
setPhoto(_photo);
|
|
55
|
+
|
|
56
|
+
// 转换为File对象
|
|
57
|
+
var file = base64ToFile(_photo, filename);
|
|
58
|
+
|
|
59
|
+
// 创建符合Antd Upload格式的文件对象
|
|
60
|
+
var uploadFile = {
|
|
61
|
+
uid: timestamp.toString(),
|
|
62
|
+
name: filename,
|
|
63
|
+
status: 'uploading',
|
|
64
|
+
url: _photo,
|
|
65
|
+
// 用于预览
|
|
66
|
+
originFileObj: file,
|
|
67
|
+
// 原始文件对象,用于上传
|
|
68
|
+
thumbUrl: _photo,
|
|
69
|
+
lastModified: Date.now(),
|
|
70
|
+
lastModifiedDate: new Date(),
|
|
71
|
+
type: 'image/jpeg',
|
|
72
|
+
size: file.size
|
|
73
|
+
};
|
|
74
|
+
console.log('takePhoto_uploadFile', uploadFile);
|
|
75
|
+
uploadFileRef.current = uploadFile;
|
|
76
|
+
return uploadFile;
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error('takePhoto_error', error);
|
|
79
|
+
uploadFileRef.current = null;
|
|
80
|
+
setPhoto('');
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var onOpen = function onOpen() {
|
|
85
|
+
setCameraAvailable(null);
|
|
86
|
+
setPhoto('');
|
|
87
|
+
uploadFileRef.current = null;
|
|
88
|
+
setOpen(true);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// 关闭相机弹窗,重置状态
|
|
92
|
+
var onClose = function onClose() {
|
|
93
|
+
cameraRef.current = null;
|
|
94
|
+
uploadFileRef.current = null;
|
|
95
|
+
setOpen(false);
|
|
96
|
+
setPhoto('');
|
|
97
|
+
setCameraAvailable(null);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// 重拍照片
|
|
101
|
+
var onRetakePhoto = function onRetakePhoto() {
|
|
102
|
+
setPhoto('');
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// 使用照片
|
|
106
|
+
var onUsePhoto = function onUsePhoto() {
|
|
107
|
+
var _props$onChange;
|
|
108
|
+
props === null || props === void 0 || (_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, uploadFileRef.current);
|
|
109
|
+
onClose();
|
|
110
|
+
};
|
|
111
|
+
useImperativeHandle(ref, function () {
|
|
112
|
+
return {
|
|
113
|
+
open: onOpen,
|
|
114
|
+
takePhoto: takePhoto,
|
|
115
|
+
isCameraAvailable: function isCameraAvailable() {
|
|
116
|
+
return cameraAvailable;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
console.log('cameraAvailable', cameraAvailable);
|
|
121
|
+
return /*#__PURE__*/React.createElement(PisellModal, {
|
|
122
|
+
open: open,
|
|
123
|
+
onCancel: function onCancel(e) {
|
|
124
|
+
e.stopPropagation();
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
onClose();
|
|
127
|
+
},
|
|
128
|
+
header: false,
|
|
129
|
+
footer: null,
|
|
130
|
+
destroyOnClose: true,
|
|
131
|
+
bodyStyle: {
|
|
132
|
+
padding: 0
|
|
133
|
+
},
|
|
134
|
+
width: '90vw',
|
|
135
|
+
className: "pisell-camera-modal"
|
|
136
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
137
|
+
className: "pisell-camera-container",
|
|
138
|
+
onClick: function onClick(e) {
|
|
139
|
+
e.stopPropagation();
|
|
140
|
+
e.preventDefault();
|
|
141
|
+
}
|
|
142
|
+
}, cameraAvailable === null ?
|
|
143
|
+
/*#__PURE__*/
|
|
144
|
+
// 检测中
|
|
145
|
+
React.createElement("div", {
|
|
146
|
+
className: "pisell-camera-loading"
|
|
147
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
148
|
+
className: "pisell-camera-loading-text"
|
|
149
|
+
}, getText('pisell-camera-checking'))) : cameraAvailable === false ?
|
|
150
|
+
/*#__PURE__*/
|
|
151
|
+
// 无摄像头
|
|
152
|
+
React.createElement("div", {
|
|
153
|
+
className: "pisell-camera-no-camera"
|
|
154
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
155
|
+
className: "pisell-camera-no-camera-icon"
|
|
156
|
+
}, "\uD83D\uDCF7"), /*#__PURE__*/React.createElement("div", {
|
|
157
|
+
className: "pisell-camera-no-camera-text"
|
|
158
|
+
}, getText('pisell-camera-no-camera-accessible')), /*#__PURE__*/React.createElement("div", {
|
|
159
|
+
className: "pisell-camera-no-camera-desc"
|
|
160
|
+
}, getText('pisell-camera-no-camera-desc'))) : null, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Camera, {
|
|
161
|
+
ref: cameraRef,
|
|
162
|
+
errorMessages: {
|
|
163
|
+
// noCameraAccessible: getText('pisell-camera-no-camera-accessible'),
|
|
164
|
+
// permissionDenied: getText('pisell-camera-permission-denied'),
|
|
165
|
+
// switchCamera: getText('pisell-camera-switch-camera'),
|
|
166
|
+
// canvas: getText('pisell-camera-canvas'),
|
|
167
|
+
},
|
|
168
|
+
numberOfCamerasCallback: function numberOfCamerasCallback(numberOfCameras) {
|
|
169
|
+
console.log('numberOfCameras', numberOfCameras);
|
|
170
|
+
if (!cameraRef.current) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (numberOfCameras <= 0) {
|
|
174
|
+
setTimeout(function () {
|
|
175
|
+
setCameraAvailable(function (pre) {
|
|
176
|
+
if (pre === true) {
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
});
|
|
181
|
+
}, 5000);
|
|
182
|
+
} else {
|
|
183
|
+
setCameraAvailable(true);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}), cameraAvailable === true && /*#__PURE__*/React.createElement("div", {
|
|
187
|
+
className: "pisell-camera-action"
|
|
188
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
189
|
+
className: "pisell-camera-action-item",
|
|
190
|
+
onClick: function onClick(e) {
|
|
191
|
+
e.stopPropagation();
|
|
192
|
+
e.preventDefault();
|
|
193
|
+
takePhoto();
|
|
194
|
+
}
|
|
195
|
+
})), photo && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
196
|
+
className: "pisell-camera-photo-container"
|
|
197
|
+
}, /*#__PURE__*/React.createElement("img", {
|
|
198
|
+
src: photo,
|
|
199
|
+
alt: "photo",
|
|
200
|
+
className: "pisell-camera-photo"
|
|
201
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
202
|
+
className: "pisell-camera-photo-img-action"
|
|
203
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
204
|
+
className: "pisell-camera-photo-img-action-item",
|
|
205
|
+
onClick: function onClick(e) {
|
|
206
|
+
e.stopPropagation();
|
|
207
|
+
e.preventDefault();
|
|
208
|
+
onRetakePhoto();
|
|
209
|
+
}
|
|
210
|
+
}, getText('pisell-upload-camera-retake')), /*#__PURE__*/React.createElement("div", {
|
|
211
|
+
className: "pisell-camera-photo-img-action-item",
|
|
212
|
+
onClick: function onClick(e) {
|
|
213
|
+
e.stopPropagation();
|
|
214
|
+
e.preventDefault();
|
|
215
|
+
onUsePhoto();
|
|
216
|
+
}
|
|
217
|
+
}, getText('pisell-upload-camera-use')))))));
|
|
218
|
+
});
|
|
219
|
+
export default PisellCamera;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
.pisell-camera-modal {
|
|
2
|
+
.pisell-camera-container {
|
|
3
|
+
width: 100%;
|
|
4
|
+
height: 90vh;
|
|
5
|
+
display: flex;
|
|
6
|
+
flex-direction: column;
|
|
7
|
+
align-items: center;
|
|
8
|
+
justify-content: center;
|
|
9
|
+
|
|
10
|
+
.pisell-camera-action {
|
|
11
|
+
position: absolute;
|
|
12
|
+
bottom: 0;
|
|
13
|
+
left: 0;
|
|
14
|
+
right: 0;
|
|
15
|
+
height: 100px;
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
justify-content: center;
|
|
19
|
+
|
|
20
|
+
.pisell-camera-action-item {
|
|
21
|
+
width: 60px;
|
|
22
|
+
height: 60px;
|
|
23
|
+
background-color: #fff;
|
|
24
|
+
border-radius: 60px;
|
|
25
|
+
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
|
|
26
|
+
cursor: pointer;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.pisell-camera-photo-container {
|
|
31
|
+
position: absolute;
|
|
32
|
+
top: 0;
|
|
33
|
+
left: 0;
|
|
34
|
+
right: 0;
|
|
35
|
+
bottom: 0;
|
|
36
|
+
width: 100%;
|
|
37
|
+
height: 100%;
|
|
38
|
+
|
|
39
|
+
.pisell-camera-photo {
|
|
40
|
+
width: 100%;
|
|
41
|
+
height: 100%;
|
|
42
|
+
object-fit: cover;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
.pisell-camera-photo-img-action {
|
|
46
|
+
position: absolute;
|
|
47
|
+
bottom: 0;
|
|
48
|
+
left: 0;
|
|
49
|
+
right: 0;
|
|
50
|
+
height: 100px;
|
|
51
|
+
display: flex;
|
|
52
|
+
flex-direction: row;
|
|
53
|
+
align-items: center;
|
|
54
|
+
justify-content: space-between;
|
|
55
|
+
background-color: rgba(0, 0, 0, 0.5);
|
|
56
|
+
|
|
57
|
+
.pisell-camera-photo-img-action-item {
|
|
58
|
+
padding: 20px 60px;
|
|
59
|
+
font-size: 20px;
|
|
60
|
+
color: #fff;
|
|
61
|
+
cursor: pointer;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.pisell-camera-loading {
|
|
66
|
+
position: absolute;
|
|
67
|
+
top: 0;
|
|
68
|
+
left: 0;
|
|
69
|
+
right: 0;
|
|
70
|
+
bottom: 0;
|
|
71
|
+
background-color: transparent;
|
|
72
|
+
display: flex;
|
|
73
|
+
align-items: center;
|
|
74
|
+
justify-content: center;
|
|
75
|
+
|
|
76
|
+
.pisell-camera-loading-text {
|
|
77
|
+
font-size: 18px;
|
|
78
|
+
color: #666;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.pisell-camera-no-camera {
|
|
83
|
+
position: absolute;
|
|
84
|
+
top: 0;
|
|
85
|
+
left: 0;
|
|
86
|
+
right: 0;
|
|
87
|
+
bottom: 0;
|
|
88
|
+
background-color: #ffffff;
|
|
89
|
+
display: flex;
|
|
90
|
+
flex-direction: column;
|
|
91
|
+
align-items: center;
|
|
92
|
+
justify-content: center;
|
|
93
|
+
width: 100%;
|
|
94
|
+
height: 100%;
|
|
95
|
+
background-color: #f5f5f5;
|
|
96
|
+
padding: 40px;
|
|
97
|
+
text-align: center;
|
|
98
|
+
|
|
99
|
+
.pisell-camera-no-camera-icon {
|
|
100
|
+
font-size: 64px;
|
|
101
|
+
margin-bottom: 20px;
|
|
102
|
+
opacity: 0.6;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.pisell-camera-no-camera-text {
|
|
106
|
+
font-size: 20px;
|
|
107
|
+
color: #333;
|
|
108
|
+
margin-bottom: 12px;
|
|
109
|
+
font-weight: 500;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.pisell-camera-no-camera-desc {
|
|
113
|
+
font-size: 14px;
|
|
114
|
+
color: #666;
|
|
115
|
+
line-height: 1.5;
|
|
116
|
+
max-width: 300px;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -13,5 +13,5 @@ export interface PisellToastProps {
|
|
|
13
13
|
onClose?: () => void;
|
|
14
14
|
}
|
|
15
15
|
declare const PisellToast: (props: PisellToastProps) => void;
|
|
16
|
-
export {
|
|
16
|
+
export { useToast } from './squareToast';
|
|
17
17
|
export default PisellToast;
|
|
@@ -1,25 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { clear, show, success, info, loading, fail, hide } from './methods';
|
|
2
2
|
import './index.less';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
duration?: number;
|
|
13
|
-
/** 关闭回调 */
|
|
14
|
-
onClose?: () => void;
|
|
15
|
-
/** 自定义图标 */
|
|
16
|
-
icon?: React.ReactNode;
|
|
17
|
-
/** 自定义样式类名 */
|
|
18
|
-
className?: string;
|
|
19
|
-
/** 自定义样式 */
|
|
20
|
-
style?: React.CSSProperties;
|
|
21
|
-
/** 是否显示遮罩 */
|
|
22
|
-
mask?: boolean;
|
|
3
|
+
interface ToastInstance {
|
|
4
|
+
show: typeof show;
|
|
5
|
+
clear: typeof clear;
|
|
6
|
+
success: typeof success;
|
|
7
|
+
info: typeof info;
|
|
8
|
+
loading: typeof loading;
|
|
9
|
+
fail: typeof fail;
|
|
10
|
+
error: typeof fail;
|
|
11
|
+
hide: typeof hide;
|
|
23
12
|
}
|
|
24
|
-
declare const Toast:
|
|
13
|
+
declare const Toast: ToastInstance;
|
|
14
|
+
export declare const useToast: () => ToastInstance;
|
|
25
15
|
export default Toast;
|
|
@@ -1,110 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
12
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
-
import React, { useEffect, useMemo, useState } from 'react';
|
|
14
|
-
import Modal from "../../modal";
|
|
15
|
-
import Icon from "../../icon";
|
|
16
|
-
import classNames from 'classnames';
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { clear, show, success, info, loading, fail, hide } from "./methods";
|
|
17
3
|
import "./index.less";
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
loading:
|
|
24
|
-
fail:
|
|
4
|
+
var Toast = {
|
|
5
|
+
show: show,
|
|
6
|
+
clear: clear,
|
|
7
|
+
success: success,
|
|
8
|
+
info: info,
|
|
9
|
+
loading: loading,
|
|
10
|
+
fail: fail,
|
|
11
|
+
error: fail,
|
|
12
|
+
hide: hide
|
|
25
13
|
};
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
style = _ref.style;
|
|
40
|
-
var _useState = useState(visible),
|
|
41
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
42
|
-
internalVisible = _useState2[0],
|
|
43
|
-
setInternalVisible = _useState2[1];
|
|
44
|
-
useEffect(function () {
|
|
45
|
-
setInternalVisible(visible);
|
|
46
|
-
}, [visible]);
|
|
47
|
-
useEffect(function () {
|
|
48
|
-
if (internalVisible && duration > 0) {
|
|
49
|
-
var timer = setTimeout(function () {
|
|
50
|
-
handleClose();
|
|
51
|
-
}, duration);
|
|
52
|
-
return function () {
|
|
53
|
-
return clearTimeout(timer);
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
}, [internalVisible, duration]);
|
|
57
|
-
var handleClose = function handleClose() {
|
|
58
|
-
setInternalVisible(false);
|
|
59
|
-
onClose === null || onClose === void 0 || onClose();
|
|
60
|
-
};
|
|
61
|
-
var showIcon = useMemo(function () {
|
|
62
|
-
return icon !== undefined || icons[type];
|
|
63
|
-
}, [type, icon]);
|
|
64
|
-
var renderIcon = function renderIcon() {
|
|
65
|
-
if (icon !== undefined) {
|
|
66
|
-
return icon;
|
|
67
|
-
}
|
|
68
|
-
var iconType = icons[type];
|
|
69
|
-
if (iconType) {
|
|
70
|
-
return /*#__PURE__*/React.createElement(Icon, {
|
|
71
|
-
type: iconType,
|
|
72
|
-
className: "pisell-square-toast-icon pisell-square-toast-icon-".concat(type)
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
return null;
|
|
76
|
-
};
|
|
77
|
-
return /*#__PURE__*/React.createElement(Modal, {
|
|
78
|
-
open: visible,
|
|
79
|
-
footer: null,
|
|
80
|
-
closable: false,
|
|
81
|
-
centered: true,
|
|
82
|
-
maskTransitionName: "",
|
|
83
|
-
transitionName: "",
|
|
84
|
-
getContainer: function getContainer() {
|
|
85
|
-
return document.body;
|
|
86
|
-
},
|
|
87
|
-
wrapClassName: "pisell-square-toast-wrap",
|
|
88
|
-
className: classNames('pisell-square-toast-modal', className),
|
|
89
|
-
width: "auto",
|
|
90
|
-
style: _objectSpread({
|
|
91
|
-
textAlign: 'center'
|
|
92
|
-
}, style),
|
|
93
|
-
bodyStyle: {
|
|
94
|
-
padding: 0
|
|
95
|
-
},
|
|
96
|
-
mask: mask,
|
|
97
|
-
modalRender: function modalRender() {
|
|
98
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
99
|
-
className: "pisell-square-toast ".concat(type ? "pisell-square-toast-".concat(type) : '')
|
|
100
|
-
}, showIcon && /*#__PURE__*/React.createElement("div", {
|
|
101
|
-
className: "pisell-square-toast-icon-wrapper"
|
|
102
|
-
}, renderIcon()), /*#__PURE__*/React.createElement("div", {
|
|
103
|
-
className: "pisell-square-toast-content"
|
|
104
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
105
|
-
className: "pisell-square-toast-message"
|
|
106
|
-
}, message)));
|
|
107
|
-
}
|
|
108
|
-
});
|
|
14
|
+
export var useToast = function useToast() {
|
|
15
|
+
return useMemo(function () {
|
|
16
|
+
return {
|
|
17
|
+
show: show,
|
|
18
|
+
clear: clear,
|
|
19
|
+
success: success,
|
|
20
|
+
info: info,
|
|
21
|
+
loading: loading,
|
|
22
|
+
fail: fail,
|
|
23
|
+
error: fail,
|
|
24
|
+
hide: hide
|
|
25
|
+
};
|
|
26
|
+
}, []);
|
|
109
27
|
};
|
|
110
28
|
export default Toast;
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
.pisell-square-toast-modal {
|
|
6
6
|
pointer-events: none;
|
|
7
7
|
user-select: none;
|
|
8
|
+
min-width: 190px;
|
|
9
|
+
min-height: 74px;
|
|
8
10
|
|
|
9
11
|
// Toast 容器
|
|
10
12
|
.pisell-square-toast {
|
|
@@ -19,7 +21,6 @@
|
|
|
19
21
|
overflow: hidden;
|
|
20
22
|
background: rgba(0, 0, 0, 0.8);
|
|
21
23
|
|
|
22
|
-
// 图标包装器
|
|
23
24
|
.pisell-square-toast-icon-wrapper {
|
|
24
25
|
display: flex;
|
|
25
26
|
align-items: center;
|
|
@@ -43,27 +44,15 @@
|
|
|
43
44
|
|
|
44
45
|
// 内容区域
|
|
45
46
|
.pisell-square-toast-content {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
text-align: center;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// 带图标的样式调整
|
|
55
|
-
&.pisell-square-toast-success,
|
|
56
|
-
&.pisell-square-toast-error,
|
|
57
|
-
&.pisell-square-toast-warning,
|
|
58
|
-
&.pisell-square-toast-fail,
|
|
59
|
-
&.pisell-square-toast-loading {
|
|
60
|
-
min-width: 190px;
|
|
61
|
-
min-height: 74px;
|
|
47
|
+
font-size: 20px;
|
|
48
|
+
line-height: 1.5;
|
|
49
|
+
color: #ffffff;
|
|
50
|
+
text-align: center;
|
|
62
51
|
}
|
|
63
52
|
}
|
|
64
53
|
}
|
|
65
54
|
|
|
66
|
-
// 旋转动画
|
|
55
|
+
// loading 旋转动画
|
|
67
56
|
@keyframes fadenum {
|
|
68
57
|
to {
|
|
69
58
|
transform: rotate(360deg);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ToastProps } from './toast';
|
|
3
|
+
interface ToastInstance {
|
|
4
|
+
close: () => void;
|
|
5
|
+
}
|
|
6
|
+
declare const show: (configOrContent: Partial<ToastProps> | React.ReactNode, duration?: number, onClose?: () => void) => ToastInstance;
|
|
7
|
+
declare const clear: () => void;
|
|
8
|
+
declare const success: (content: React.ReactNode, duration?: number, onClose?: () => void) => ToastInstance;
|
|
9
|
+
declare const info: (content: React.ReactNode, duration?: number, onClose?: () => void) => ToastInstance;
|
|
10
|
+
declare const loading: (content: React.ReactNode, duration?: number, onClose?: () => void) => ToastInstance;
|
|
11
|
+
declare const fail: (content: React.ReactNode, duration?: number, onClose?: () => void) => ToastInstance;
|
|
12
|
+
declare const hide: () => void;
|
|
13
|
+
export { show, clear, success, info, loading, fail, hide };
|