@douyinfe/semi-ui 2.12.1-alpha.2 → 2.13.0-beta.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.
Files changed (224) hide show
  1. package/autoComplete/_story/autoComplete.stories.js +0 -1
  2. package/autoComplete/index.tsx +1 -1
  3. package/avatar/index.tsx +2 -2
  4. package/backtop/index.tsx +7 -11
  5. package/badge/index.tsx +1 -1
  6. package/banner/index.tsx +5 -5
  7. package/breadcrumb/index.tsx +3 -5
  8. package/button/Button.tsx +8 -10
  9. package/card/index.tsx +41 -43
  10. package/carousel/CarouselArrow.tsx +0 -2
  11. package/carousel/index.tsx +0 -1
  12. package/cascader/index.tsx +123 -101
  13. package/cascader/item.tsx +1 -1
  14. package/checkbox/checkbox.tsx +28 -20
  15. package/checkbox/checkboxInner.tsx +11 -1
  16. package/collapsible/index.tsx +1 -8
  17. package/datePicker/dateInput.tsx +0 -1
  18. package/datePicker/datePicker.tsx +5 -13
  19. package/dist/css/semi.css +9 -1
  20. package/dist/css/semi.min.css +1 -1
  21. package/dist/umd/semi-ui.js +5372 -3695
  22. package/dist/umd/semi-ui.js.map +1 -1
  23. package/dist/umd/semi-ui.min.js +1 -1
  24. package/dist/umd/semi-ui.min.js.map +1 -1
  25. package/divider/index.tsx +4 -8
  26. package/dropdown/index.tsx +1 -1
  27. package/empty/index.tsx +5 -13
  28. package/form/hoc/withField.tsx +1 -1
  29. package/form/label.tsx +1 -1
  30. package/grid/col.tsx +1 -1
  31. package/grid/row.tsx +1 -1
  32. package/iconButton/index.tsx +1 -2
  33. package/input/index.tsx +11 -38
  34. package/inputNumber/__test__/inputNumber.test.js +2 -3
  35. package/inputNumber/_story/inputNumber.stories.js +53 -0
  36. package/inputNumber/index.tsx +0 -4
  37. package/lib/cjs/autoComplete/index.js +1 -1
  38. package/lib/cjs/avatar/index.js +2 -4
  39. package/lib/cjs/backtop/index.js +1 -2
  40. package/lib/cjs/badge/index.js +1 -2
  41. package/lib/cjs/banner/index.js +4 -9
  42. package/lib/cjs/breadcrumb/index.js +3 -4
  43. package/lib/cjs/button/Button.d.ts +1 -1
  44. package/lib/cjs/button/Button.js +3 -13
  45. package/lib/cjs/button/index.d.ts +1 -1
  46. package/lib/cjs/card/index.js +5 -10
  47. package/lib/cjs/carousel/CarouselArrow.js +2 -6
  48. package/lib/cjs/carousel/CarouselIndicator.d.ts +1 -1
  49. package/lib/cjs/carousel/index.d.ts +1 -1
  50. package/lib/cjs/carousel/index.js +1 -2
  51. package/lib/cjs/cascader/index.js +6 -9
  52. package/lib/cjs/cascader/item.js +1 -2
  53. package/lib/cjs/checkbox/checkbox.d.ts +3 -2
  54. package/lib/cjs/checkbox/checkbox.js +33 -15
  55. package/lib/cjs/checkbox/checkboxInner.d.ts +6 -0
  56. package/lib/cjs/checkbox/checkboxInner.js +14 -4
  57. package/lib/cjs/collapsible/index.js +1 -2
  58. package/lib/cjs/datePicker/dateInput.d.ts +1 -1
  59. package/lib/cjs/datePicker/dateInput.js +1 -2
  60. package/lib/cjs/datePicker/datePicker.d.ts +1 -1
  61. package/lib/cjs/datePicker/datePicker.js +2 -4
  62. package/lib/cjs/datePicker/monthsGrid.d.ts +1 -1
  63. package/lib/cjs/divider/index.js +1 -2
  64. package/lib/cjs/dropdown/index.js +1 -2
  65. package/lib/cjs/empty/index.js +4 -8
  66. package/lib/cjs/form/baseForm.d.ts +1 -1
  67. package/lib/cjs/form/field.d.ts +1 -1
  68. package/lib/cjs/form/hoc/withField.js +1 -2
  69. package/lib/cjs/form/label.js +1 -2
  70. package/lib/cjs/grid/col.js +1 -2
  71. package/lib/cjs/grid/row.js +1 -2
  72. package/lib/cjs/iconButton/index.js +1 -3
  73. package/lib/cjs/input/index.js +5 -9
  74. package/lib/cjs/inputNumber/index.js +0 -4
  75. package/lib/cjs/list/index.js +3 -6
  76. package/lib/cjs/modal/ConfirmModal.js +1 -2
  77. package/lib/cjs/modal/Modal.js +2 -6
  78. package/lib/cjs/modal/ModalContent.js +6 -13
  79. package/lib/cjs/notification/notice.js +3 -6
  80. package/lib/cjs/pagination/index.js +2 -4
  81. package/lib/cjs/popconfirm/index.js +3 -6
  82. package/lib/cjs/popover/index.d.ts +1 -0
  83. package/lib/cjs/radio/radio.d.ts +1 -1
  84. package/lib/cjs/radio/radio.js +2 -4
  85. package/lib/cjs/radio/radioGroup.d.ts +1 -1
  86. package/lib/cjs/rating/item.js +1 -2
  87. package/lib/cjs/scrollList/index.js +3 -6
  88. package/lib/cjs/select/index.js +4 -8
  89. package/lib/cjs/select/option.js +1 -2
  90. package/lib/cjs/sideSheet/SideSheetContent.js +3 -6
  91. package/lib/cjs/skeleton/index.js +1 -3
  92. package/lib/cjs/space/index.js +1 -2
  93. package/lib/cjs/spin/index.js +3 -7
  94. package/lib/cjs/switch/index.js +4 -6
  95. package/lib/cjs/table/Table.js +3 -6
  96. package/lib/cjs/tabs/TabBar.js +1 -2
  97. package/lib/cjs/tabs/TabPane.js +2 -5
  98. package/lib/cjs/tagInput/index.d.ts +6 -1
  99. package/lib/cjs/tagInput/index.js +42 -10
  100. package/lib/cjs/timePicker/Combobox.js +1 -3
  101. package/lib/cjs/timePicker/TimePicker.d.ts +2 -2
  102. package/lib/cjs/timePicker/TimeShape.d.ts +1 -1
  103. package/lib/cjs/timePicker/index.d.ts +2 -2
  104. package/lib/cjs/toast/toast.js +3 -6
  105. package/lib/cjs/transfer/index.js +1 -2
  106. package/lib/cjs/tree/treeNode.js +1 -2
  107. package/lib/cjs/treeSelect/index.js +3 -6
  108. package/lib/cjs/typography/base.d.ts +1 -1
  109. package/lib/cjs/typography/base.js +1 -2
  110. package/lib/cjs/typography/paragraph.d.ts +1 -1
  111. package/lib/cjs/typography/text.d.ts +1 -1
  112. package/lib/cjs/typography/title.d.ts +2 -2
  113. package/lib/cjs/upload/index.d.ts +2 -2
  114. package/lib/cjs/upload/index.js +6 -13
  115. package/lib/es/autoComplete/index.js +1 -1
  116. package/lib/es/avatar/index.js +2 -4
  117. package/lib/es/backtop/index.js +1 -2
  118. package/lib/es/badge/index.js +1 -2
  119. package/lib/es/banner/index.js +4 -9
  120. package/lib/es/breadcrumb/index.js +3 -4
  121. package/lib/es/button/Button.d.ts +1 -1
  122. package/lib/es/button/Button.js +3 -11
  123. package/lib/es/button/index.d.ts +1 -1
  124. package/lib/es/card/index.js +5 -10
  125. package/lib/es/carousel/CarouselArrow.js +2 -6
  126. package/lib/es/carousel/CarouselIndicator.d.ts +1 -1
  127. package/lib/es/carousel/index.d.ts +1 -1
  128. package/lib/es/carousel/index.js +1 -2
  129. package/lib/es/cascader/index.js +6 -9
  130. package/lib/es/cascader/item.js +1 -2
  131. package/lib/es/checkbox/checkbox.d.ts +3 -2
  132. package/lib/es/checkbox/checkbox.js +33 -15
  133. package/lib/es/checkbox/checkboxInner.d.ts +6 -0
  134. package/lib/es/checkbox/checkboxInner.js +14 -4
  135. package/lib/es/collapsible/index.js +1 -2
  136. package/lib/es/datePicker/dateInput.d.ts +1 -1
  137. package/lib/es/datePicker/dateInput.js +1 -2
  138. package/lib/es/datePicker/datePicker.d.ts +1 -1
  139. package/lib/es/datePicker/datePicker.js +2 -4
  140. package/lib/es/datePicker/monthsGrid.d.ts +1 -1
  141. package/lib/es/divider/index.js +1 -2
  142. package/lib/es/dropdown/index.js +1 -2
  143. package/lib/es/empty/index.js +4 -8
  144. package/lib/es/form/baseForm.d.ts +1 -1
  145. package/lib/es/form/field.d.ts +1 -1
  146. package/lib/es/form/hoc/withField.js +1 -2
  147. package/lib/es/form/label.js +1 -2
  148. package/lib/es/grid/col.js +1 -2
  149. package/lib/es/grid/row.js +1 -2
  150. package/lib/es/iconButton/index.js +1 -3
  151. package/lib/es/input/index.js +5 -9
  152. package/lib/es/inputNumber/index.js +0 -4
  153. package/lib/es/list/index.js +3 -6
  154. package/lib/es/modal/ConfirmModal.js +1 -2
  155. package/lib/es/modal/Modal.js +2 -6
  156. package/lib/es/modal/ModalContent.js +6 -13
  157. package/lib/es/notification/notice.js +3 -6
  158. package/lib/es/pagination/index.js +2 -4
  159. package/lib/es/popconfirm/index.js +3 -6
  160. package/lib/es/popover/index.d.ts +1 -0
  161. package/lib/es/radio/radio.d.ts +1 -1
  162. package/lib/es/radio/radio.js +2 -4
  163. package/lib/es/radio/radioGroup.d.ts +1 -1
  164. package/lib/es/rating/item.js +1 -2
  165. package/lib/es/scrollList/index.js +3 -6
  166. package/lib/es/select/index.js +4 -8
  167. package/lib/es/select/option.js +1 -2
  168. package/lib/es/sideSheet/SideSheetContent.js +3 -6
  169. package/lib/es/skeleton/index.js +1 -3
  170. package/lib/es/space/index.js +1 -2
  171. package/lib/es/spin/index.js +3 -7
  172. package/lib/es/switch/index.js +4 -6
  173. package/lib/es/table/Table.js +3 -6
  174. package/lib/es/tabs/TabBar.js +1 -2
  175. package/lib/es/tabs/TabPane.js +2 -5
  176. package/lib/es/tagInput/index.d.ts +6 -1
  177. package/lib/es/tagInput/index.js +41 -10
  178. package/lib/es/timePicker/Combobox.js +1 -3
  179. package/lib/es/timePicker/TimePicker.d.ts +2 -2
  180. package/lib/es/timePicker/TimeShape.d.ts +1 -1
  181. package/lib/es/timePicker/index.d.ts +2 -2
  182. package/lib/es/toast/toast.js +3 -6
  183. package/lib/es/transfer/index.js +1 -2
  184. package/lib/es/tree/treeNode.js +1 -2
  185. package/lib/es/treeSelect/index.js +3 -6
  186. package/lib/es/typography/base.d.ts +1 -1
  187. package/lib/es/typography/base.js +1 -2
  188. package/lib/es/typography/paragraph.d.ts +1 -1
  189. package/lib/es/typography/text.d.ts +1 -1
  190. package/lib/es/typography/title.d.ts +2 -2
  191. package/lib/es/upload/index.d.ts +2 -2
  192. package/lib/es/upload/index.js +6 -13
  193. package/list/index.tsx +4 -16
  194. package/modal/ConfirmModal.tsx +1 -1
  195. package/modal/Modal.tsx +0 -2
  196. package/modal/ModalContent.tsx +14 -27
  197. package/notification/notice.tsx +4 -16
  198. package/package.json +9 -9
  199. package/pagination/index.tsx +2 -16
  200. package/popconfirm/index.tsx +3 -11
  201. package/popover/index.tsx +1 -1
  202. package/radio/radio.tsx +2 -10
  203. package/rating/item.tsx +1 -1
  204. package/scrollList/index.tsx +3 -19
  205. package/select/_story/select.stories.js +11 -0
  206. package/select/index.tsx +4 -12
  207. package/select/option.tsx +1 -5
  208. package/sideSheet/SideSheetContent.tsx +3 -3
  209. package/skeleton/index.tsx +1 -1
  210. package/space/index.tsx +1 -1
  211. package/spin/index.tsx +9 -15
  212. package/switch/index.tsx +14 -9
  213. package/table/Table.tsx +3 -5
  214. package/tabs/TabBar.tsx +1 -1
  215. package/tabs/TabPane.tsx +4 -9
  216. package/tagInput/index.tsx +38 -11
  217. package/timePicker/Combobox.tsx +1 -6
  218. package/toast/toast.tsx +3 -3
  219. package/transfer/index.tsx +0 -1
  220. package/tree/treeNode.tsx +1 -1
  221. package/treeSelect/index.tsx +3 -15
  222. package/typography/base.tsx +1 -1
  223. package/upload/index.tsx +38 -107
  224. package/yarn-error.log +0 -26235
@@ -13,6 +13,7 @@ import { cssClasses, strings } from '@douyinfe/semi-foundation/tagInput/constant
13
13
  import '@douyinfe/semi-foundation/tagInput/tagInput.scss';
14
14
  import TagInputFoundation, { TagInputAdapter } from '@douyinfe/semi-foundation/tagInput/foundation';
15
15
  import { ArrayElement } from '../_base/base';
16
+ import { isSemiIcon } from '../_utils';
16
17
  import BaseComponent from '../_base/baseComponent';
17
18
  import Tag from '../tag';
18
19
  import Input from '../input';
@@ -47,6 +48,8 @@ export interface TagInputProps {
47
48
  onKeyDown?: (e: React.MouseEvent<HTMLInputElement>) => void;
48
49
  onRemove?: (removedValue: string, idx: number) => void;
49
50
  placeholder?: string;
51
+ insetLabel?: React.ReactNode;
52
+ insetLabelId?: string;
50
53
  prefix?: React.ReactNode;
51
54
  renderTagItem?: (value: string, index: number) => React.ReactNode;
52
55
  separator?: string | string[] | null;
@@ -129,6 +132,8 @@ class TagInput extends BaseComponent<TagInputProps, TagInputState> {
129
132
  };
130
133
 
131
134
  inputRef: React.RefObject<HTMLInputElement>;
135
+ foundation: TagInputFoundation;
136
+
132
137
  constructor(props: TagInputProps) {
133
138
  super(props);
134
139
  this.foundation = new TagInputFoundation(this.adapter);
@@ -170,6 +175,15 @@ class TagInput extends BaseComponent<TagInputProps, TagInputState> {
170
175
  setFocusing: (focusing: boolean) => {
171
176
  this.setState({ focusing });
172
177
  },
178
+ toggleFocusing: (isFocus: boolean) => {
179
+ const input = this.inputRef && this.inputRef.current;
180
+ if (isFocus) {
181
+ input && input.focus();
182
+ } else {
183
+ input && input.blur();
184
+ }
185
+ this.setState({ focusing: isFocus });
186
+ },
173
187
  setHovering: (hovering: boolean) => {
174
188
  this.setState({ hovering });
175
189
  },
@@ -240,6 +254,15 @@ class TagInput extends BaseComponent<TagInputProps, TagInputState> {
240
254
  this.foundation.handleInputMouseEnter();
241
255
  };
242
256
 
257
+ handleClickPrefixOrSuffix = (e: React.MouseEvent<HTMLInputElement>) => {
258
+ this.foundation.handleClickPrefixOrSuffix(e);
259
+ };
260
+
261
+ handlePreventMouseDown = (e: React.MouseEvent<HTMLInputElement>) => {
262
+ this.foundation.handlePreventMouseDown(e);
263
+ };
264
+
265
+
243
266
  renderClearBtn() {
244
267
  const { hovering, tagsArray, inputValue } = this.state;
245
268
  const { showClear, disabled } = this.props;
@@ -248,11 +271,11 @@ class TagInput extends BaseComponent<TagInputProps, TagInputState> {
248
271
  });
249
272
  if (showClear) {
250
273
  return (
251
- <div
274
+ <div
252
275
  role="button"
253
- tabIndex={0}
254
- aria-label="Clear TagInput value"
255
- className={clearCls}
276
+ tabIndex={0}
277
+ aria-label="Clear TagInput value"
278
+ className={clearCls}
256
279
  onClick={e => this.handleClearBtn(e)}
257
280
  onKeyPress={e => this.handleClearEnterPress(e)}
258
281
  >
@@ -264,16 +287,19 @@ class TagInput extends BaseComponent<TagInputProps, TagInputState> {
264
287
  }
265
288
 
266
289
  renderPrefix() {
267
- const { prefix } = this.props;
268
- if (isNull(prefix) || isUndefined(prefix)) {
290
+ const { prefix, insetLabel, insetLabelId } = this.props;
291
+ const labelNode = prefix || insetLabel;
292
+ if (isNull(labelNode) || isUndefined(labelNode)) {
269
293
  return null;
270
294
  }
271
295
  const prefixWrapperCls = cls(`${prefixCls}-prefix`, {
272
- [`${prefixCls}-prefix-text`]: prefix && isString(prefix),
296
+ [`${prefixCls}-inset-label`]: insetLabel,
297
+ [`${prefixCls}-prefix-text`]: labelNode && isString(labelNode),
273
298
  // eslint-disable-next-line max-len
274
- [`${prefixCls}-prefix-icon`]: React.isValidElement(prefix) && !(prefix && isString(prefix)),
299
+ [`${prefixCls}-prefix-icon`]: isSemiIcon(labelNode),
275
300
  });
276
- return <div className={prefixWrapperCls} x-semi-prop="prefix">{prefix}</div>;
301
+ // eslint-disable-next-line jsx-a11y/no-static-element-interactions,jsx-a11y/click-events-have-key-events
302
+ return <div className={prefixWrapperCls} onMouseDown={this.handlePreventMouseDown} onClick={this.handleClickPrefixOrSuffix} id={insetLabelId}>{labelNode}</div>;
277
303
  }
278
304
 
279
305
  renderSuffix() {
@@ -284,9 +310,10 @@ class TagInput extends BaseComponent<TagInputProps, TagInputState> {
284
310
  const suffixWrapperCls = cls(`${prefixCls}-suffix`, {
285
311
  [`${prefixCls}-suffix-text`]: suffix && isString(suffix),
286
312
  // eslint-disable-next-line max-len
287
- [`${prefixCls}-suffix-icon`]: React.isValidElement(suffix) && !(suffix && isString(suffix)),
313
+ [`${prefixCls}-suffix-icon`]: isSemiIcon(suffix),
288
314
  });
289
- return <div className={suffixWrapperCls} x-semi-prop="suffix">{suffix}</div>;
315
+ // eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
316
+ return <div className={suffixWrapperCls} onMouseDown={this.handlePreventMouseDown} onClick={this.handleClickPrefixOrSuffix}>{suffix}</div>;
290
317
  }
291
318
 
292
319
  renderTags() {
@@ -317,12 +317,7 @@ class Combobox extends BaseComponent<ComboboxProps, ComboboxState> {
317
317
  return (
318
318
  <LocaleConsumer componentName="TimePicker">
319
319
  {(locale: Locale['TimePicker'], localeCode: Locale['code']) => (
320
- <ScrollList
321
- header={panelHeader}
322
- footer={panelFooter}
323
- x-semi-header-alias="panelHeader"
324
- x-semi-footer-alias="panelFooter"
325
- >
320
+ <ScrollList header={panelHeader} footer={panelFooter}>
326
321
  {this.renderAMPMSelect(locale, localeCode)}
327
322
  {this.renderHourSelect(value.getHours(), locale)}
328
323
  {this.renderMinuteSelect(value.getMinutes(), locale)}
package/toast/toast.tsx CHANGED
@@ -120,7 +120,7 @@ class Toast extends BaseComponent<ToastReactProps, ToastState> {
120
120
  const btnSize = 'small';
121
121
  return (
122
122
  <div
123
- role="alert"
123
+ role='alert'
124
124
  aria-label={`${type ? type : 'default'} type`}
125
125
  className={toastCls}
126
126
  style={style}
@@ -129,7 +129,7 @@ class Toast extends BaseComponent<ToastReactProps, ToastState> {
129
129
  >
130
130
  <div className={`${prefixCls}-content`}>
131
131
  {this.renderIcon()}
132
- <span className={`${prefixCls}-content-text`} style={textStyle} x-semi-prop="content">
132
+ <span className={`${prefixCls}-content-text`} style={textStyle}>
133
133
  {content}
134
134
  </span>
135
135
  {showClose && (
@@ -137,7 +137,7 @@ class Toast extends BaseComponent<ToastReactProps, ToastState> {
137
137
  <Button
138
138
  onClick={e => this.close(e)}
139
139
  type="tertiary"
140
- icon={<IconClose x-semi-prop="icon" />}
140
+ icon={<IconClose />}
141
141
  theme={btnTheme}
142
142
  size={btnSize}
143
143
  />
@@ -353,7 +353,6 @@ class Transfer extends BaseComponent<TransferProps, TransferState> {
353
353
  checked={checked}
354
354
  role="listitem"
355
355
  onChange={() => this.onSelectOrRemove(item)}
356
- x-semi-children-alias={`dataSource[${index}].label`}
357
356
  >
358
357
  {item.label}
359
358
  </Checkbox>
package/tree/treeNode.tsx CHANGED
@@ -269,7 +269,7 @@ export default class TreeNode extends PureComponent<TreeNodeProps, TreeNodeState
269
269
  });
270
270
  return (
271
271
  <ul className={wrapperCls}>
272
- <li className={`${prefixcls}-label ${prefixcls}-label-empty`} x-semi-prop="emptyContent">
272
+ <li className={`${prefixcls}-label ${prefixcls}-label-empty`}>
273
273
  {emptyContent}
274
274
  </li>
275
275
  </ul>
@@ -646,11 +646,7 @@ class TreeSelect extends BaseComponent<TreeSelectProps, TreeSelectState> {
646
646
  [`${prefixcls}-suffix-text`]: suffix && isString(suffix),
647
647
  [`${prefixcls}-suffix-icon`]: isSemiIcon(suffix),
648
648
  });
649
- return (
650
- <div className={suffixWrapperCls} x-semi-prop="suffix">
651
- {suffix}
652
- </div>
653
- );
649
+ return <div className={suffixWrapperCls}>{suffix}</div>;
654
650
  };
655
651
 
656
652
  renderPrefix = () => {
@@ -664,11 +660,7 @@ class TreeSelect extends BaseComponent<TreeSelectProps, TreeSelectState> {
664
660
  [`${prefixcls}-prefix-icon`]: isSemiIcon(labelNode),
665
661
  });
666
662
 
667
- return (
668
- <div className={prefixWrapperCls} id={insetLabelId} x-semi-prop="prefix,insetLabel">
669
- {labelNode}
670
- </div>
671
- );
663
+ return <div className={prefixWrapperCls} id={insetLabelId}>{labelNode}</div>;
672
664
  };
673
665
 
674
666
  renderContent = () => {
@@ -875,11 +867,7 @@ class TreeSelect extends BaseComponent<TreeSelectProps, TreeSelectState> {
875
867
  if (showClearBtn) {
876
868
  return null;
877
869
  }
878
- return arrowIcon ? (
879
- <div className={cls(`${prefixcls}-arrow`)} x-semi-prop="arrowIcon">
880
- {arrowIcon}
881
- </div>
882
- ) : null;
870
+ return arrowIcon ? <div className={cls(`${prefixcls}-arrow`)}>{arrowIcon}</div> : null;
883
871
  };
884
872
 
885
873
  renderClearBtn = () => {
@@ -526,7 +526,7 @@ export default class Base extends Component<BaseTypographyProps, BaseTypographyS
526
526
  }
527
527
  const iconSize: Size = size === 'small' ? 'small' : 'default';
528
528
  return (
529
- <span className={`${prefixCls}-icon`} x-semi-prop="icon">
529
+ <span className={`${prefixCls}-icon`}>
530
530
  {isSemiIcon(icon) ? React.cloneElement((icon as React.ReactElement), { size: iconSize }) : icon}
531
531
  </span>
532
532
  );
package/upload/index.tsx CHANGED
@@ -3,54 +3,25 @@ import React, { ReactNode, CSSProperties, RefObject, ChangeEvent, DragEvent } fr
3
3
  import cls from 'classnames';
4
4
  import PropTypes from 'prop-types';
5
5
  import { noop, pick } from 'lodash';
6
- import UploadFoundation, {
7
- CustomFile,
8
- UploadAdapter,
9
- BeforeUploadObjectResult,
10
- AfterUploadResult,
11
- } from '@douyinfe/semi-foundation/upload/foundation';
6
+ import UploadFoundation, { CustomFile, UploadAdapter, BeforeUploadObjectResult, AfterUploadResult } from '@douyinfe/semi-foundation/upload/foundation';
12
7
  import { strings, cssClasses } from '@douyinfe/semi-foundation/upload/constants';
13
8
  import FileCard from './fileCard';
14
9
  import BaseComponent, { ValidateStatus } from '../_base/baseComponent';
15
10
  import LocaleConsumer from '../locale/localeConsumer';
16
11
  import { IconUpload } from '@douyinfe/semi-icons';
17
- import {
18
- FileItem,
19
- RenderFileItemProps,
20
- UploadListType,
21
- PromptPositionType,
22
- BeforeUploadProps,
23
- AfterUploadProps,
24
- OnChangeProps,
25
- customRequestArgs,
26
- CustomError,
27
- } from './interface';
12
+ import { FileItem, RenderFileItemProps, UploadListType, PromptPositionType, BeforeUploadProps, AfterUploadProps, OnChangeProps, customRequestArgs, CustomError } from './interface';
28
13
  import { Locale } from '../locale/interface';
29
14
  import '@douyinfe/semi-foundation/upload/upload.scss';
30
15
 
31
16
  const prefixCls = cssClasses.PREFIX;
32
17
 
33
- export {
34
- FileItem,
35
- RenderFileItemProps,
36
- UploadListType,
37
- PromptPositionType,
38
- BeforeUploadProps,
39
- AfterUploadProps,
40
- OnChangeProps,
41
- customRequestArgs,
42
- CustomError,
43
- BeforeUploadObjectResult,
44
- AfterUploadResult,
45
- };
18
+ export { FileItem, RenderFileItemProps, UploadListType, PromptPositionType, BeforeUploadProps, AfterUploadProps, OnChangeProps, customRequestArgs, CustomError, BeforeUploadObjectResult, AfterUploadResult };
46
19
 
47
20
  export interface UploadProps {
48
21
  accept?: string;
49
22
  action: string;
50
23
  afterUpload?: (object: AfterUploadProps) => AfterUploadResult;
51
- beforeUpload?: (
52
- object: BeforeUploadProps
53
- ) => BeforeUploadObjectResult | Promise<BeforeUploadObjectResult> | boolean;
24
+ beforeUpload?: (object: BeforeUploadProps) => BeforeUploadObjectResult | Promise<BeforeUploadObjectResult> | boolean;
54
25
  beforeClear?: (fileList: Array<FileItem>) => boolean | Promise<boolean>;
55
26
  beforeRemove?: (file: FileItem, fileList: Array<FileItem>) => boolean | Promise<boolean>;
56
27
  capture?: boolean | 'user' | 'environment' | undefined;
@@ -143,7 +114,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
143
114
  fileList: PropTypes.array, // files had been uploaded
144
115
  fileName: PropTypes.string, // same as name, to avoid props conflict in Form.Upload
145
116
  headers: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
146
- hotSpotLocation: PropTypes.oneOf(['start', 'end']),
117
+ hotSpotLocation: PropTypes.oneOf(['start','end']),
147
118
  itemStyle: PropTypes.object,
148
119
  limit: PropTypes.number, // 最大允许上传文件个数
149
120
  listType: PropTypes.oneOf<UploadProps['listType']>(strings.LIST_TYPE),
@@ -247,7 +218,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
247
218
  const { fileList } = props;
248
219
  if ('fileList' in props) {
249
220
  return {
250
- fileList: fileList || [],
221
+ fileList: fileList || []
251
222
  };
252
223
  }
253
224
  return null;
@@ -257,8 +228,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
257
228
  return {
258
229
  ...super.adapter,
259
230
  notifyFileSelect: (files): void => this.props.onFileChange(files),
260
- notifyError: (error, fileInstance, fileList, xhr): void =>
261
- this.props.onError(error, fileInstance, fileList, xhr),
231
+ notifyError: (error, fileInstance, fileList, xhr): void => this.props.onError(error, fileInstance, fileList, xhr),
262
232
  notifySuccess: (responseBody, file, fileList): void => this.props.onSuccess(responseBody, file, fileList),
263
233
  notifyProgress: (percent, file, fileList): void => this.props.onProgress(percent, file, fileList),
264
234
  notifyRemove: (file, fileList, fileItem): void => this.props.onRemove(file, fileList, fileItem),
@@ -271,25 +241,19 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
271
241
  this.setState({ fileList });
272
242
  }
273
243
  },
274
- notifyBeforeUpload: ({
275
- file,
276
- fileList,
277
- }): boolean | BeforeUploadObjectResult | Promise<BeforeUploadObjectResult> =>
278
- this.props.beforeUpload({ file, fileList }),
279
- notifyAfterUpload: ({ response, file, fileList }): AfterUploadResult =>
280
- this.props.afterUpload({ response, file, fileList }),
244
+ notifyBeforeUpload: ({ file, fileList }): boolean | BeforeUploadObjectResult | Promise<BeforeUploadObjectResult> => this.props.beforeUpload({ file, fileList }),
245
+ notifyAfterUpload: ({ response, file, fileList }): AfterUploadResult => this.props.afterUpload({ response, file, fileList }),
281
246
  resetInput: (): void => {
282
247
  this.setState(prevState => ({
283
- inputKey: Math.random(),
248
+ inputKey: Math.random()
284
249
  }));
285
250
  },
286
251
  resetReplaceInput: (): void => {
287
252
  this.setState(prevState => ({
288
- replaceInputKey: Math.random(),
253
+ replaceInputKey: Math.random()
289
254
  }));
290
255
  },
291
- updateDragAreaStatus: (dragAreaStatus: string): void =>
292
- this.setState({ dragAreaStatus } as { dragAreaStatus: 'default' | 'legal' | 'illegal' }),
256
+ updateDragAreaStatus: (dragAreaStatus: string): void => this.setState({ dragAreaStatus } as { dragAreaStatus: 'default' | 'legal' | 'illegal' }),
293
257
  notifyChange: ({ currentFile, fileList }): void => this.props.onChange({ currentFile, fileList }),
294
258
  updateLocalUrls: (urls): void => this.setState({ localUrls: urls }),
295
259
  notifyClear: (): void => this.props.onClear(),
@@ -331,6 +295,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
331
295
  this.setState({ replaceIdx: index }, () => {
332
296
  this.replaceInputRef.current.click();
333
297
  });
298
+
334
299
  };
335
300
 
336
301
  onReplaceChange = (e: ChangeEvent<HTMLInputElement>): void => {
@@ -351,11 +316,11 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
351
316
  * insert files at index
352
317
  * @param files Array<CustomFile>
353
318
  * @param index number
354
- * @returns
319
+ * @returns
355
320
  */
356
321
  insert = (files: Array<CustomFile>, index: number): void => {
357
322
  return this.foundation.insertFileToList(files, index);
358
- };
323
+ }
359
324
 
360
325
  /**
361
326
  * ref method
@@ -368,19 +333,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
368
333
 
369
334
  renderFile = (file: FileItem, index: number, locale: Locale['Upload']): ReactNode => {
370
335
  const { name, status, validateMessage, _sizeInvalid, uid } = file;
371
- const {
372
- previewFile,
373
- listType,
374
- itemStyle,
375
- showPicInfo,
376
- renderPicInfo,
377
- renderPicPreviewIcon,
378
- renderFileOperation,
379
- renderFileItem,
380
- renderThumbnail,
381
- disabled,
382
- onPreviewClick,
383
- } = this.props;
336
+ const { previewFile, listType, itemStyle, showPicInfo, renderPicInfo, renderPicPreviewIcon, renderFileOperation, renderFileItem, renderThumbnail, disabled, onPreviewClick } = this.props;
384
337
  const onRemove = (): void => this.remove(file);
385
338
  const onRetry = (): void => {
386
339
  this.foundation.retry(file);
@@ -405,10 +358,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
405
358
  renderFileOperation,
406
359
  renderThumbnail,
407
360
  onReplace,
408
- onPreviewClick:
409
- typeof onPreviewClick !== 'undefined'
410
- ? (): void => this.foundation.handlePreviewClick(file)
411
- : undefined,
361
+ onPreviewClick: typeof onPreviewClick !== 'undefined' ? (): void => this.foundation.handlePreviewClick(file) : undefined,
412
362
  };
413
363
 
414
364
  if (status === strings.FILE_STATUS_UPLOAD_FAIL && !validateMessage) {
@@ -454,7 +404,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
454
404
  });
455
405
  const dragAreaCls = cls({
456
406
  [`${dragAreaBaseCls}-legal`]: dragAreaStatus === strings.DRAG_AREA_LEGAL,
457
- [`${dragAreaBaseCls}-illegal`]: dragAreaStatus === strings.DRAG_AREA_ILLEGAL,
407
+ [`${dragAreaBaseCls}-illegal`]: dragAreaStatus === strings.DRAG_AREA_ILLEGAL
458
408
  });
459
409
  const mainCls = `${prefixCls}-file-list-main`;
460
410
  const addContentProps = {
@@ -463,7 +413,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
463
413
  onClick: this.onClick,
464
414
  };
465
415
  const containerProps = {
466
- className: fileListCls,
416
+ className: fileListCls
467
417
  };
468
418
  const draggableProps = {
469
419
  onDrop: this.onDrop,
@@ -475,7 +425,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
475
425
  Object.assign(addContentProps, draggableProps, { className: cls(uploadAddCls, dragAreaCls) });
476
426
  }
477
427
  const addContent = (
478
- <div {...addContentProps} x-semi-prop="children">
428
+ <div {...addContentProps}>
479
429
  {children}
480
430
  </div>
481
431
  );
@@ -500,7 +450,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
500
450
  )}
501
451
  </LocaleConsumer>
502
452
  );
503
- };
453
+ }
504
454
 
505
455
  renderFileListDefault = () => {
506
456
  const { showUploadList, limit, disabled } = this.props;
@@ -512,7 +462,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
512
462
  const showTitle = limit !== 1 && fileList.length;
513
463
  const showClear = this.props.showClear && !disabled;
514
464
  const containerProps = {
515
- className: fileListCls,
465
+ className: fileListCls
516
466
  };
517
467
 
518
468
  if (!showUploadList || !fileList.length) {
@@ -527,12 +477,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
527
477
  <div className={titleCls}>
528
478
  <span className={`${titleCls}-choosen`}>{locale.selectedFiles}</span>
529
479
  {showClear ? (
530
- <span
531
- role="button"
532
- tabIndex={0}
533
- onClick={this.clear}
534
- className={`${titleCls}-clear`}
535
- >
480
+ <span role="button" tabIndex={0} onClick={this.clear} className={`${titleCls}-clear`}>
536
481
  {locale.clear}
537
482
  </span>
538
483
  ) : null}
@@ -546,7 +491,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
546
491
  )}
547
492
  </LocaleConsumer>
548
493
  );
549
- };
494
+ }
550
495
 
551
496
  onDrop = (e: DragEvent<HTMLDivElement>): void => {
552
497
  this.foundation.handleDrop(e);
@@ -579,7 +524,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
579
524
  {children}
580
525
  </div>
581
526
  );
582
- };
527
+ }
583
528
 
584
529
  renderDragArea = (): ReactNode => {
585
530
  const { dragAreaStatus } = this.state;
@@ -609,16 +554,14 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
609
554
  children
610
555
  ) : (
611
556
  <>
612
- <div className={`${dragAreaBaseCls}-icon`} x-semi-prop="dragIcon">
557
+ <div className={`${dragAreaBaseCls}-icon`}>
613
558
  {dragIcon || <IconUpload size="extra-large" />}
614
559
  </div>
615
560
  <div className={`${dragAreaBaseCls}-text`}>
616
- <div className={`${dragAreaBaseCls}-main-text`} x-semi-prop="dragMainText">
561
+ <div className={`${dragAreaBaseCls}-main-text`}>
617
562
  {dragMainText || locale.mainText}
618
563
  </div>
619
- <div className={`${dragAreaBaseCls}-sub-text`} x-semi-prop="dragSubText">
620
- {dragSubText}
621
- </div>
564
+ <div className={`${dragAreaBaseCls}-sub-text`}>{dragSubText}</div>
622
565
  <div className={`${dragAreaBaseCls}-tips`}>
623
566
  {dragAreaStatus === strings.DRAG_AREA_LEGAL && (
624
567
  <span className={`${dragAreaBaseCls}-tips-legal`}>{locale.legalTips}</span>
@@ -655,18 +598,14 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
655
598
  validateStatus,
656
599
  directory,
657
600
  } = this.props;
658
- const uploadCls = cls(
659
- prefixCls,
660
- {
661
- [`${prefixCls}-picture`]: listType === strings.FILE_LIST_PIC,
662
- [`${prefixCls}-disabled`]: disabled,
663
- [`${prefixCls}-default`]: validateStatus === 'default',
664
- [`${prefixCls}-error`]: validateStatus === 'error',
665
- [`${prefixCls}-warning`]: validateStatus === 'warning',
666
- [`${prefixCls}-success`]: validateStatus === 'success',
667
- },
668
- className
669
- );
601
+ const uploadCls = cls(prefixCls, {
602
+ [`${prefixCls}-picture`]: listType === strings.FILE_LIST_PIC,
603
+ [`${prefixCls}-disabled`]: disabled,
604
+ [`${prefixCls}-default`]: validateStatus === 'default',
605
+ [`${prefixCls}-error`]: validateStatus === 'error',
606
+ [`${prefixCls}-warning`]: validateStatus === 'warning',
607
+ [`${prefixCls}-success`]: validateStatus === 'success',
608
+ }, className);
670
609
  const inputCls = cls(`${prefixCls}-hidden-input`);
671
610
  const inputReplaceCls = cls(`${prefixCls}-hidden-input-replace`);
672
611
  const promptCls = cls(`${prefixCls}-prompt`);
@@ -701,17 +640,9 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
701
640
  ref={this.replaceInputRef}
702
641
  />
703
642
  {this.renderAddContent()}
704
- {prompt ? (
705
- <div className={promptCls} x-semi-prop="prompt">
706
- {prompt}
707
- </div>
708
- ) : null}
643
+ {prompt ? <div className={promptCls}>{prompt}</div> : null}
709
644
 
710
- {validateMessage ? (
711
- <div className={validateMsgCls} x-semi-prop="validateMessage">
712
- {validateMessage}
713
- </div>
714
- ) : null}
645
+ {validateMessage ? <div className={validateMsgCls}>{validateMessage}</div> : null}
715
646
  {this.renderFileList()}
716
647
  </div>
717
648
  );