@cloudbase/weda-ui 0.2.8 → 0.2.12

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.
Files changed (104) hide show
  1. package/package.json +62 -41
  2. package/src/configs/.DS_Store +0 -0
  3. package/src/configs/components/button.json +7 -3
  4. package/src/configs/components/form/richText.json +1 -1
  5. package/src/configs/components/form/uploader.json +29 -1
  6. package/src/configs/components/form/uploaderFile.json +158 -0
  7. package/src/configs/components/image.json +12 -3
  8. package/src/configs/components/link.json +3 -3
  9. package/src/configs/components/richtextview.json +2 -2
  10. package/src/configs/components/scrollVeiw.json +5 -5
  11. package/src/configs/components/swiper.json +6 -6
  12. package/src/configs/components/tabs.json +3 -3
  13. package/src/configs/components/text.json +39 -4
  14. package/src/configs/index.js +6 -5
  15. package/src/mp/components/button/index.js +1 -0
  16. package/src/mp/components/button/index.wxss +8 -0
  17. package/src/mp/components/form/select/index.js +18 -0
  18. package/src/mp/components/form/uploader/index.js +26 -29
  19. package/src/mp/components/form/uploaderFile/index.js +247 -0
  20. package/src/mp/components/form/uploaderFile/index.json +9 -0
  21. package/src/mp/components/form/uploaderFile/index.wxml +46 -0
  22. package/src/mp/components/form/uploaderFile/index.wxss +104 -0
  23. package/src/mp/components/text/index.js +33 -0
  24. package/src/mp/components/text/index.wxml +1 -1
  25. package/src/mp/components/text/index.wxss +18 -0
  26. package/src/mp/index.json +1 -0
  27. package/src/mp/utils/platform.js +20 -0
  28. package/src/mp/utils/tcb.js +11 -0
  29. package/src/web/actions/showModal/{index.jsx → index.tsx} +53 -3
  30. package/src/web/components/auth/index.js +2 -2
  31. package/src/web/components/button/index.css +9 -0
  32. package/src/web/components/button/{index.jsx → index.tsx} +27 -41
  33. package/src/web/components/container/{index.jsx → index.tsx} +6 -10
  34. package/src/web/components/drawer/index.tsx +57 -0
  35. package/src/web/components/form/checkbox/{index.jsx → index.tsx} +24 -48
  36. package/src/web/components/form/enumSelect/MultipleSelect.jsx +89 -0
  37. package/src/web/components/form/enumSelect/NormalSelect.tsx +94 -0
  38. package/src/web/components/form/enumSelect/SelectContainer.jsx +43 -0
  39. package/src/web/components/form/enumSelect/index.jsx +9 -0
  40. package/src/web/components/form/enumSelect/props/defaultProps.js +39 -0
  41. package/src/web/components/form/enumSelect/props/propsTypes.js +50 -0
  42. package/src/web/components/form/form/index.tsx +48 -0
  43. package/src/web/components/form/formcell/{index.jsx → index.tsx} +6 -13
  44. package/src/web/components/form/input/index.css +4 -0
  45. package/src/web/components/form/input/{index.jsx → index.tsx} +33 -67
  46. package/src/web/components/form/radio/{index.jsx → index.tsx} +19 -42
  47. package/src/web/components/form/{renderDecorator.jsx → renderDecorator.tsx} +1 -3
  48. package/src/web/components/form/select/{h5.jsx → h5.tsx} +18 -62
  49. package/src/web/components/form/select/{index.jsx → index.tsx} +51 -94
  50. package/src/web/components/form/select/region/{cities.js → cities.ts} +1 -1
  51. package/src/web/components/form/select/region/{index.js → index.ts} +3 -3
  52. package/src/web/components/form/select/region/{provinces.js → provinces.ts} +1 -1
  53. package/src/web/components/form/select/region/{regions.js → regions.ts} +1 -1
  54. package/src/web/components/form/select/time.jsx +2 -2
  55. package/src/web/components/form/switch/{index.jsx → index.tsx} +30 -47
  56. package/src/web/components/form/textarea/{index.jsx → index.tsx} +22 -55
  57. package/src/web/components/form/tips/{index.jsx → index.tsx} +8 -22
  58. package/src/web/components/form/types.d.ts +12 -0
  59. package/src/web/components/form/uploader/{index.jsx → index.tsx} +16 -14
  60. package/src/web/components/form/uploader/{uploader.h5.jsx → uploader.h5.tsx} +67 -57
  61. package/src/web/components/form/uploader/{uploader.pc.jsx → uploader.pc.tsx} +26 -43
  62. package/src/web/components/form/uploaderFile/fail.svg +12 -0
  63. package/src/web/components/form/uploaderFile/index.css +423 -0
  64. package/src/web/components/form/uploaderFile/index.jsx +30 -0
  65. package/src/web/components/form/uploaderFile/pending.svg +18 -0
  66. package/src/web/components/form/uploaderFile/success.svg +12 -0
  67. package/src/web/components/form/uploaderFile/uploadFile.h5.jsx +562 -0
  68. package/src/web/components/form/uploaderFile/uploadFile.pc.jsx +487 -0
  69. package/src/web/components/image/{image.jsx → image.tsx} +8 -21
  70. package/src/web/components/image/{index.jsx → index.tsx} +22 -37
  71. package/src/web/components/index.js +36 -1
  72. package/src/web/components/link/{index.jsx → index.tsx} +19 -36
  73. package/src/web/components/modal/{index.jsx → index.tsx} +24 -10
  74. package/src/web/components/picker/{datePicker.jsx → datePicker.tsx} +11 -12
  75. package/src/web/components/picker/{picker.jsx → picker.tsx} +7 -10
  76. package/src/web/components/picker/{timePicker.jsx → timePicker.tsx} +8 -16
  77. package/src/web/components/richText/{const.js → const.ts} +0 -0
  78. package/src/web/components/richText/index.jsx +5 -2
  79. package/src/web/components/richTextView/index.tsx +67 -0
  80. package/src/web/components/scrollView/{index.jsx → index.tsx} +18 -33
  81. package/src/web/components/slot/{index.jsx → index.tsx} +8 -9
  82. package/src/web/components/swiper/index.css +1 -1
  83. package/src/web/components/swiper/{index.jsx → index.tsx} +66 -73
  84. package/src/web/components/tabs/index.tsx +33 -0
  85. package/src/web/components/tabs/{tabs.h5.jsx → tabs.h5.tsx} +4 -33
  86. package/src/web/components/tabs/{tabs.pc.jsx → tabs.pc.tsx} +5 -39
  87. package/src/web/components/text/index.css +18 -0
  88. package/src/web/components/text/index.tsx +69 -0
  89. package/src/web/components/uploaderFileView/index.css +11 -0
  90. package/src/web/components/uploaderFileView/index.jsx +75 -0
  91. package/src/web/components/uploaderView/{index.jsx → index.tsx} +12 -15
  92. package/src/web/types.d.ts +20 -0
  93. package/src/web/utils/constant.js +2 -0
  94. package/src/web/utils/loading-fallback.tsx +2 -0
  95. package/src/web/utils/platform.js +77 -6
  96. package/src/web/utils/useSetState.ts +14 -0
  97. package/src/web/utils/useSyncValue.ts +17 -0
  98. package/src/configs/components/button.svg +0 -18
  99. package/src/web/components/drawer/index.jsx +0 -64
  100. package/src/web/components/form/form/index.jsx +0 -76
  101. package/src/web/components/richTextView/index.jsx +0 -89
  102. package/src/web/components/tabs/index.jsx +0 -10
  103. package/src/web/components/text/index.jsx +0 -71
  104. package/src/web/utils/useSyncValue.js +0 -14
@@ -1,4 +1,3 @@
1
- import * as PropTypes from 'prop-types';
2
1
  import * as React from 'react';
3
2
  import weui from '../../../utils/weui';
4
3
  import classNames from '../../../utils/classnames';
@@ -7,6 +6,7 @@ import isObjectEqual from '../../../utils/isObjectEqual';
7
6
  import { useSyncValue } from '../../../utils/useSyncValue';
8
7
  import { isCloudFileID } from '../../../utils/platform';
9
8
  import { IMAGE_TYPES } from './uploader.pc';
9
+ import { CommonFormPropsType } from '../types';
10
10
 
11
11
  const uploadPath = 'weda-uploader';
12
12
  /**
@@ -23,9 +23,10 @@ export function ImageUploaderH5({
23
23
  layout,
24
24
  defaultValue,
25
25
  single = false,
26
+ requiredFlag = false,
26
27
  onChange,
27
28
  style,
28
- }) {
29
+ }: H5UploaderProps) {
29
30
  const cls = classNames({
30
31
  'weda-ui': true,
31
32
  'weui-cells': true,
@@ -39,27 +40,28 @@ export function ImageUploaderH5({
39
40
  const [progress, setProgress] = React.useState(0);
40
41
  const [inputValue, setInputValue] = useSyncValue(defaultValue, isObjectEqual);
41
42
  const fileIdList = React.useMemo(() => {
42
- if( typeof inputValue === 'string') {
43
+ if (typeof inputValue === 'string') {
43
44
  // single = true 传入的是字符串
44
- return [inputValue].filter(i => i.length > 0); // 排除空串
45
+ return [inputValue].filter((i) => i.length > 0); // 排除空串
45
46
  }
46
- if(Array.isArray(inputValue)) {
47
+ if (Array.isArray(inputValue)) {
47
48
  return inputValue;
48
49
  }
49
50
  return [];
50
51
  }, [inputValue]);
51
52
 
52
53
  const finalMaxImgCount = React.useMemo(() => {
53
- if(single) return 1;
54
+ if (single) return 1;
54
55
  return maxUploadCount;
55
56
  }, [single, maxUploadCount]);
56
-
57
+
57
58
  const deleteFile = (url) => {
58
- if(single) {
59
+ if (single) {
59
60
  setInputValue('');
60
61
  return;
61
62
  }
62
- setInputValue((list) => list.filter(f => f !== url));
63
+ // @ts-expect-error list should be array in not single mode
64
+ setInputValue((list: string[]) => list.filter((f) => f !== url));
63
65
  };
64
66
  React.useEffect(() => {
65
67
  if (single) {
@@ -91,8 +93,8 @@ export function ImageUploaderH5({
91
93
  cloudPath,
92
94
  filePath: file,
93
95
  onUploadProgress: onProgress,
94
-
95
96
  });
97
+ // @ts-expect-error TODO
96
98
  fileID && setInputValue((list) => [...list, fileID]);
97
99
  fileID && events.success && events.success({ value: fileID, file });
98
100
  } catch (err) {
@@ -114,8 +116,11 @@ export function ImageUploaderH5({
114
116
  <div className={cls} id={id} style={style}>
115
117
  <div className="weui-cell">
116
118
  <div className="weui-cell__bd">
117
- <div className={classNames("weui-uploader", layout)}>
118
- <div className={classNames("weui-uploader__hd", layout)}>
119
+ <div className={classNames('weui-uploader', layout)}>
120
+ <div className={classNames('weui-uploader__hd', layout)}>
121
+ {requiredFlag && (
122
+ <label className="weda-formcells__flag">*</label>
123
+ )}
119
124
  <p className="weui-uploader__title">{title}</p>
120
125
  <div className="weui-uploader__info">
121
126
  <span id="uploadCount">{fileIdList.length}</span>
@@ -124,40 +129,45 @@ export function ImageUploaderH5({
124
129
  </div>
125
130
  <div className="weui-uploader__bd">
126
131
  <ul className="weui-uploader__files" id="uploaderFiles">
127
- {(fileIdList ?? []).map(f => <SingleImage key={f} src={f} deleteBySrc={deleteFile} />)}
128
- {uploading &&
129
- <li className="weui-uploader__file weui-uploader__file_status" >
130
- <div className="weui-uploader__file-content">
131
- {progress}%
132
- </div>
133
- </li>}
132
+ {(fileIdList ?? []).map((f) => (
133
+ <SingleImage key={f} src={f} deleteBySrc={deleteFile} />
134
+ ))}
135
+ {uploading && (
136
+ <li className="weui-uploader__file weui-uploader__file_status">
137
+ <div className="weui-uploader__file-content">
138
+ {progress}%
139
+ </div>
140
+ </li>
141
+ )}
134
142
  </ul>
135
143
  {(fileIdList.length < maxUploadCount ||
136
144
  (single && fileIdList.length < 1)) && ( // single 模式时,仅当数组为空时显示
137
- <div className="weui-uploader__input-box">
145
+ <div className="weui-uploader__input-box">
138
146
  <input
139
147
  id="uploaderInput"
140
148
  className="weui-uploader__input"
141
149
  type="file"
142
150
  accept={accepts.join(',')}
143
151
  multiple
144
- onChange={e => {
152
+ onChange={(e) => {
145
153
  const files = [...e.target.files];
146
- if (files.some(f => f.size > maxSize * 1024 * 1024)) {
154
+ if (files.some((f) => f.size > maxSize * 1024 * 1024)) {
147
155
  weui.alert('请上传不超过10M的图片');
148
156
  return false;
149
157
  }
150
-
158
+
151
159
  if (files.length > finalMaxImgCount) {
152
160
  // 防止一下子选择过多文件
153
- weui.alert(`最多只能上传${finalMaxImgCount}张图片,请重新选择`);
161
+ weui.alert(
162
+ `最多只能上传${finalMaxImgCount}张图片,请重新选择`
163
+ );
154
164
  return false;
155
165
  }
156
166
  if (fileIdList.length + files.length > finalMaxImgCount) {
157
167
  weui.alert(`最多只能上传${finalMaxImgCount}张图片`);
158
168
  return false;
159
169
  }
160
- files.forEach(f => uploadToTcb(f));
170
+ files.forEach((f) => uploadToTcb(f));
161
171
  }}
162
172
  />
163
173
  </div>
@@ -170,7 +180,12 @@ export function ImageUploaderH5({
170
180
  );
171
181
  }
172
182
 
173
- function SingleImage({src, deleteBySrc}) {
183
+ export interface SingleImageProps {
184
+ src: string;
185
+ deleteBySrc: (url: string) => void;
186
+ }
187
+
188
+ function SingleImage({ src, deleteBySrc }: SingleImageProps) {
174
189
  const [error, setError] = React.useState(false);
175
190
  const cls = classNames({
176
191
  'weui-uploader__file': true,
@@ -187,51 +202,46 @@ function SingleImage({src, deleteBySrc}) {
187
202
  console.error('图片加载失败');
188
203
  }
189
204
  };
190
- if(isCloudFileID(src)) {
205
+ if (isCloudFileID(src)) {
191
206
  getSrc();
192
207
  } else {
193
208
  setRealSrc(src);
194
209
  }
195
210
  }, [src]);
196
211
  const imgStyle = {
197
- backgroundImage: `url(${realSrc})`
198
- };
212
+ backgroundImage: `url(${realSrc})`,
213
+ };
199
214
  const showGallery = () => {
200
215
  const gallery = weui.gallery(realSrc, {
201
- onDelete: function() {
216
+ onDelete: function () {
202
217
  deleteBySrc(src);
203
218
  gallery.hide();
204
- }
219
+ },
205
220
  });
206
221
  };
207
-
222
+
208
223
  return (
209
224
  <li className={cls} style={imgStyle} onClick={showGallery}>
210
- {
211
- error || status ?
212
- <div className="weui-uploader__file-content">
213
- { error ? <i role="img" aria-label="错误" className="weui-icon-warn"></i> : <i className="weui-loading" style={{width: 30, height: 30}}></i> }
214
- </div>
215
- : false
216
- }
225
+ {error || status ? (
226
+ <div className="weui-uploader__file-content">
227
+ {error ? (
228
+ <i role="img" aria-label="错误" className="weui-icon-warn"></i>
229
+ ) : (
230
+ <i className="weui-loading" style={{ width: 30, height: 30 }}></i>
231
+ )}
232
+ </div>
233
+ ) : (
234
+ false
235
+ )}
217
236
  </li>
218
237
  );
219
238
  }
220
- SingleImage.propTypes = {
221
- src: PropTypes.string,
222
- deleteBySrc: PropTypes.func
223
- };
224
- ImageUploaderH5.propTypes = {
225
- id: PropTypes.string,
226
- title: PropTypes.string,
227
- className: PropTypes.string, // 传入类
228
- maxSize: PropTypes.number,
229
- acceptTypes: PropTypes.array,
230
- maxUploadCount: PropTypes.number, // 【上传图片最大数量】
231
- events: PropTypes.objectOf(PropTypes.func), // 事件
232
- style: PropTypes.object,
233
- layout: PropTypes.oneOf(['horizontal', 'vertical']),
234
- defaultValue: PropTypes.oneOfType([PropTypes.array, PropTypes.string]), // 初始值,该参数需配合 formily 使用
235
- single: PropTypes.bool, // 单张上传还是多张上传,对应 onChange 参数为字符串还是字符串数组,value 在处理过程统一转为字符串数组
236
- onChange: PropTypes.objectOf(PropTypes.func), // 值变化,该参数需配合 formily 使用
237
- };
239
+ export interface H5UploaderProps extends CommonFormPropsType {
240
+ title?: string;
241
+ maxSize?: number;
242
+ acceptTypes?: unknown[];
243
+ maxUploadCount?: number;
244
+ defaultValue?: string[] | string; // 初始值,该参数需配合 formily 使用;
245
+ single?: boolean; // 单张上传还是多张上传,对应 onChange 参数为字符串还是字符串数组,value 在处理过程统一转为字符串数组;
246
+ onChange?: (v: any) => void;
247
+ }
@@ -13,7 +13,7 @@ import classNames from '../../../utils/classnames';
13
13
  import { getCloudInstance, getTempFileURL } from '../../../utils/tcb';
14
14
  import { isCloudFileID } from '../../../utils/platform';
15
15
  import isObjectEqual from '../../../utils/isObjectEqual';
16
- import * as PropTypes from 'prop-types';
16
+ import { H5UploaderProps } from './uploader.h5';
17
17
 
18
18
  // 默认组件类前缀
19
19
  export const CLASS_PREFIX = 'weda-uploader-pc';
@@ -80,30 +80,28 @@ export function UploaderPCInner(props) {
80
80
  const [progress, setProgress] = React.useState(0);
81
81
  // 文件列表
82
82
  const [fileIDList, setfileIDList] = React.useState([]);
83
- const prevValueRef = React.useRef();
83
+ const fileRef = React.useRef(fileIDList);
84
+
84
85
  React.useEffect(() => {
85
- if (prevValueRef.current !== defaultValue) {
86
- let initialValue = []
87
- .concat(defaultValue)
88
- .filter((d) => typeof d === 'string' && d !== '');
89
- if (single) {
90
- initialValue = initialValue[0] ? [initialValue[0]] : [];
91
- }
92
- setfileIDList(initialValue);
93
- prevValueRef.current = defaultValue;
86
+ let initialValue = []
87
+ .concat(defaultValue)
88
+ .filter((d) => typeof d === 'string' && d !== '');
89
+ if (single) {
90
+ initialValue = initialValue[0] ? [initialValue[0]] : [];
94
91
  }
95
- }, [defaultValue, maxUploadCount, single]);
96
- const fileRef = React.useRef(fileIDList);
92
+ setfileIDList(initialValue);
93
+ }, []);
97
94
 
98
95
  // 值变化事件
99
96
  React.useEffect(() => {
100
97
  if (!isObjectEqual(fileRef.current, fileIDList)) {
101
- events.change && events.change({ value: fileIDList });
102
98
  if (single) {
103
99
  const file = fileIDList[0] || '';
104
100
  file && onChange && onChange(file);
101
+ events.change && events.change({ value: file });
105
102
  } else {
106
103
  onChange && onChange(fileIDList);
104
+ events.change && events.change({ value: fileIDList });
107
105
  }
108
106
  fileRef.current = fileIDList;
109
107
  }
@@ -229,10 +227,12 @@ export function UploaderPCInner(props) {
229
227
  );
230
228
  }
231
229
 
232
- /**
233
- * 单张图片回显组件
234
- */
235
- export const TcbImage = (props) => {
230
+ export interface TcbImageProps {
231
+ fileID?: string; // 云存储id
232
+ isZoom?: boolean; // 是否点击放大
233
+ onError?: (e: any) => void; // 图片显示错误事件
234
+ }
235
+ export const TcbImage = (props: TcbImageProps) => {
236
236
  const { fileID, isZoom, ...rest } = props;
237
237
  const [src, setSrc] = React.useState('');
238
238
  const [isError, setIsError] = React.useState(false);
@@ -258,6 +258,7 @@ export const TcbImage = (props) => {
258
258
  {...rest}
259
259
  src={src}
260
260
  previewSrc={src}
261
+ /** @ts-expect-error tea imagepreview onError */
261
262
  onError={(e) => {
262
263
  setIsError(true);
263
264
  props?.onError && props.onError(e);
@@ -279,28 +280,10 @@ export const TcbImage = (props) => {
279
280
  ) : null;
280
281
  };
281
282
 
282
- UploaderPCInner.propTypes = {
283
- className: PropTypes.string, // 传入类
284
- title: PropTypes.string, // 官方属性:标题
285
- tips: PropTypes.string, // 官方属性:提示
286
- btnTitle: PropTypes.string, // 官方属性:上传按钮标题
287
- maxUploadCount: PropTypes.number, // 官方属性:上传图片最大数量
288
- maxSize: PropTypes.number, // 官方属性:单个图片大小限制,单位是M
289
- acceptTypes: PropTypes.array, // 官方属性:图片类型,TIF | BMP | JPEG | TIFF | PNG
290
- uploadPath: PropTypes.string, // 上传路径
291
- uploadFileName: PropTypes.string, // 上传文件名称
292
- single: PropTypes.bool, // 单张上传还是多张上传,对应 onChange 参数为字符串还是字符串数组,value 在处理过程统一转为字符串数组
293
- events: PropTypes.objectOf(PropTypes.func), // 事件
294
- value: PropTypes.oneOfType([PropTypes.array, PropTypes.string]), // 初始值,该参数需配合 formily 使用
295
- onChange: PropTypes.objectOf(PropTypes.func), // 值变化,该参数需配合 formily 使用
296
- style: PropTypes.object,
297
- id: PropTypes.string,
298
- layout: PropTypes.oneOf(['horizontal', 'vertical']),
299
- disabled: PropTypes.bool,
300
- };
301
-
302
- TcbImage.propTypes = {
303
- fileID: PropTypes.string, // 云存储id
304
- isZoom: PropTypes.bool, // 是否点击放大
305
- onError: PropTypes.func, // 图片显示错误事件
306
- };
283
+ export interface PropsType extends H5UploaderProps {
284
+ tips?: string;
285
+ value: string | string[];
286
+ btnTitle?: string;
287
+ uploadPath?: string;
288
+ uploadFileName?: string;
289
+ }
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg width="16px" height="16px" viewBox="0 0 14 14" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
+ <title>1.Bace基础/3.Icon图标/操作/move</title>
4
+ <g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
5
+ <g id="画板" transform="translate(-104.000000, -210.000000)">
6
+ <g id="1.Bace基础/3.Icon图标/操作/move" transform="translate(103.000000, 209.000000)">
7
+ <path d="M0,0 L16,0 L16,16 L0,16 L0,0 Z" id="close-circle-filled-(Background)"></path>
8
+ <path d="M8,1 C4.13400912,1 1,4.13400483 1,8 C1,11.8659916 4.13400483,15 8,15 C11.8659916,15 15,11.8659954 15,8 C15,4.13400912 11.8659954,1 8,1 Z M8.00001192,7.29075146 L10.3291178,4.94753814 L11.0383558,5.65250731 L8.70499325,8 L11.0383472,10.3474894 L10.3291082,11.0524578 L8.00001144,8.70925426 L5.6709156,11.0524578 L4.9616766,10.3474884 L7.29503059,8 L4.96166778,5.65250683 L5.67090654,4.94753814 L8.00001192,7.29075146 Z" id="close-circle-filled" fill="#E34D59"></path>
9
+ </g>
10
+ </g>
11
+ </g>
12
+ </svg>