@douyinfe/semi-ui 2.1.6-alpha.0 → 2.2.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 (85) hide show
  1. package/_base/_story/a11y.jsx +1302 -0
  2. package/_base/_story/a11y.scss +49 -0
  3. package/_base/_story/index.stories.js +3 -1
  4. package/_utils/index.ts +2 -1
  5. package/cascader/__test__/cascader.test.js +221 -0
  6. package/cascader/_story/cascader.stories.js +138 -0
  7. package/cascader/index.tsx +37 -21
  8. package/cascader/item.tsx +4 -2
  9. package/datePicker/__test__/datePicker.test.js +67 -2
  10. package/datePicker/_story/datePicker.stories.js +3 -1
  11. package/datePicker/_story/v2/YearButton.jsx +17 -0
  12. package/datePicker/_story/v2/index.js +1 -0
  13. package/datePicker/monthsGrid.tsx +12 -1
  14. package/datePicker/navigation.tsx +55 -29
  15. package/descriptions/__test__/descriptions.test.js +27 -1
  16. package/descriptions/_story/descriptions.stories.js +52 -2
  17. package/descriptions/item.tsx +1 -1
  18. package/dist/css/semi.css +38 -20
  19. package/dist/css/semi.min.css +1 -1
  20. package/dist/umd/semi-ui.js +699 -160
  21. package/dist/umd/semi-ui.js.map +1 -1
  22. package/dist/umd/semi-ui.min.js +1 -1
  23. package/dist/umd/semi-ui.min.js.map +1 -1
  24. package/lib/cjs/_utils/index.d.ts +1 -0
  25. package/lib/cjs/_utils/index.js +3 -2
  26. package/lib/cjs/cascader/index.d.ts +7 -0
  27. package/lib/cjs/cascader/index.js +35 -22
  28. package/lib/cjs/cascader/item.d.ts +2 -0
  29. package/lib/cjs/cascader/item.js +4 -2
  30. package/lib/cjs/datePicker/monthsGrid.d.ts +1 -0
  31. package/lib/cjs/datePicker/monthsGrid.js +6 -0
  32. package/lib/cjs/datePicker/navigation.js +47 -7
  33. package/lib/cjs/descriptions/item.js +1 -1
  34. package/lib/cjs/form/baseForm.d.ts +6 -1
  35. package/lib/cjs/form/field.d.ts +6 -1
  36. package/lib/cjs/locale/source/es.d.ts +7 -0
  37. package/lib/cjs/locale/source/es.js +168 -0
  38. package/lib/cjs/rating/item.js +1 -1
  39. package/lib/cjs/select/index.d.ts +9 -0
  40. package/lib/cjs/select/index.js +10 -8
  41. package/lib/cjs/timeline/item.d.ts +3 -0
  42. package/lib/cjs/timeline/item.js +10 -4
  43. package/lib/cjs/typography/title.d.ts +1 -1
  44. package/lib/cjs/upload/fileCard.d.ts +2 -0
  45. package/lib/cjs/upload/fileCard.js +70 -45
  46. package/lib/cjs/upload/index.d.ts +23 -2
  47. package/lib/cjs/upload/index.js +133 -25
  48. package/lib/cjs/upload/interface.d.ts +3 -0
  49. package/lib/es/_utils/index.d.ts +1 -0
  50. package/lib/es/_utils/index.js +3 -2
  51. package/lib/es/cascader/index.d.ts +7 -0
  52. package/lib/es/cascader/index.js +34 -25
  53. package/lib/es/cascader/item.d.ts +2 -0
  54. package/lib/es/cascader/item.js +4 -2
  55. package/lib/es/datePicker/monthsGrid.d.ts +1 -0
  56. package/lib/es/datePicker/monthsGrid.js +6 -0
  57. package/lib/es/datePicker/navigation.js +48 -8
  58. package/lib/es/descriptions/item.js +1 -1
  59. package/lib/es/form/baseForm.d.ts +6 -1
  60. package/lib/es/form/field.d.ts +6 -1
  61. package/lib/es/locale/source/es.d.ts +7 -0
  62. package/lib/es/locale/source/es.js +157 -0
  63. package/lib/es/rating/item.js +1 -1
  64. package/lib/es/select/index.d.ts +9 -0
  65. package/lib/es/select/index.js +14 -8
  66. package/lib/es/timeline/item.d.ts +3 -0
  67. package/lib/es/timeline/item.js +9 -4
  68. package/lib/es/typography/title.d.ts +1 -1
  69. package/lib/es/upload/fileCard.d.ts +2 -0
  70. package/lib/es/upload/fileCard.js +69 -44
  71. package/lib/es/upload/index.d.ts +23 -2
  72. package/lib/es/upload/index.js +133 -24
  73. package/lib/es/upload/interface.d.ts +3 -0
  74. package/locale/source/es.ts +160 -0
  75. package/package.json +8 -8
  76. package/popover/Arrow.tsx +1 -1
  77. package/rating/item.tsx +1 -1
  78. package/select/_story/select.stories.js +25 -0
  79. package/select/index.tsx +17 -6
  80. package/timeline/_story/timeline.stories.js +50 -0
  81. package/timeline/item.tsx +7 -2
  82. package/upload/__test__/upload.test.js +50 -1
  83. package/upload/fileCard.tsx +110 -95
  84. package/upload/index.tsx +147 -53
  85. package/upload/interface.ts +3 -0
package/upload/index.tsx CHANGED
@@ -3,7 +3,7 @@ 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 } from 'lodash';
6
- import UploadFoundation, { BaseFileItem, UploadAdapter, BeforeUploadObjectResult, AfterUploadResult } from '@douyinfe/semi-foundation/upload/foundation';
6
+ import UploadFoundation, { CustomFile, UploadAdapter, BeforeUploadObjectResult, AfterUploadResult } from '@douyinfe/semi-foundation/upload/foundation';
7
7
  import { strings, cssClasses } from '@douyinfe/semi-foundation/upload/constants';
8
8
  import FileCard from './fileCard';
9
9
  import BaseComponent, { ValidateStatus } from '../_base/baseComponent';
@@ -64,7 +64,10 @@ export interface UploadProps {
64
64
  prompt?: ReactNode;
65
65
  promptPosition?: PromptPositionType;
66
66
  renderFileItem?: (renderFileItemProps: RenderFileItemProps) => ReactNode;
67
+ renderPicInfo?: (renderFileItemProps: RenderFileItemProps) => ReactNode;
68
+ renderThumbnail?: (renderFileItemProps: RenderFileItemProps) => ReactNode;
67
69
  showClear?: boolean;
70
+ showPicInfo?: boolean; // Show pic info in picture wall
68
71
  showReplace?: boolean; // Display replacement function
69
72
  showRetry?: boolean;
70
73
  showUploadList?: boolean;
@@ -133,7 +136,10 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
133
136
  prompt: PropTypes.node,
134
137
  promptPosition: PropTypes.oneOf<UploadProps['promptPosition']>(strings.PROMPT_POSITION),
135
138
  renderFileItem: PropTypes.func,
139
+ renderPicInfo: PropTypes.func,
140
+ renderThumbnail: PropTypes.func,
136
141
  showClear: PropTypes.bool,
142
+ showPicInfo: PropTypes.bool,
137
143
  showReplace: PropTypes.bool,
138
144
  showRetry: PropTypes.bool,
139
145
  showUploadList: PropTypes.bool, // whether to show fileList
@@ -168,6 +174,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
168
174
  onSuccess: noop,
169
175
  promptPosition: 'right' as const,
170
176
  showClear: true,
177
+ showPicInfo: false,
171
178
  showReplace: false,
172
179
  showRetry: true,
173
180
  showUploadList: true,
@@ -297,14 +304,29 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
297
304
  this.foundation.handleRemove(fileItem);
298
305
  };
299
306
 
307
+ /**
308
+ * ref method
309
+ * insert files at index
310
+ * @param files Array<CustomFile>
311
+ * @param index number
312
+ * @returns
313
+ */
314
+ insert = (files: Array<CustomFile>, index: number): void => {
315
+ return this.foundation.insertFileToList(files, index);
316
+ }
317
+
318
+ /**
319
+ * ref method
320
+ * manual upload by user
321
+ */
300
322
  upload = (): void => {
301
323
  const { fileList } = this.state;
302
324
  this.foundation.startUpload(fileList);
303
325
  };
304
326
 
305
327
  renderFile = (file: FileItem, index: number, locale: Locale['Upload']): ReactNode => {
306
- const { name, status, validateMessage, _sizeInvalid } = file;
307
- const { previewFile, listType, itemStyle, showRetry, renderFileItem, disabled, onPreviewClick, showReplace } = this.props;
328
+ const { name, status, validateMessage, _sizeInvalid, uid } = file;
329
+ const { previewFile, listType, itemStyle, showRetry, showPicInfo, renderPicInfo, renderFileItem, renderThumbnail, disabled, onPreviewClick, showReplace } = this.props;
308
330
  const onRemove = (): void => this.remove(file);
309
331
  const onRetry = (): void => {
310
332
  this.foundation.retry(file);
@@ -318,10 +340,14 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
318
340
  listType,
319
341
  onRemove,
320
342
  onRetry,
321
- key: `${name}${index}`,
343
+ index,
344
+ key: uid || `${name}${index}`,
322
345
  showRetry: typeof file.showRetry !== 'undefined' ? file.showRetry : showRetry,
323
346
  style: itemStyle,
324
347
  disabled,
348
+ showPicInfo,
349
+ renderPicInfo,
350
+ renderThumbnail,
325
351
  showReplace: typeof file.showReplace !== 'undefined' ? file.showReplace : showReplace,
326
352
  onReplace,
327
353
  onPreviewClick: typeof onPreviewClick !== 'undefined' ? (): void => this.foundation.handlePreviewClick(file) : undefined,
@@ -343,17 +369,54 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
343
369
  };
344
370
 
345
371
  renderFileList = (): ReactNode => {
346
- const { showUploadList, listType, limit, disabled, children } = this.props;
347
- const { fileList: stateFileList } = this.state;
372
+ const { listType } = this.props;
373
+ if (listType === strings.FILE_LIST_PIC) {
374
+ return this.renderFileListPic();
375
+ }
376
+
377
+ if (listType === strings.FILE_LIST_DEFAULT) {
378
+ return this.renderFileListDefault();
379
+ }
380
+
381
+ return null;
382
+ };
383
+
384
+ renderFileListPic = () => {
385
+ const { showUploadList, limit, disabled, children, draggable } = this.props;
386
+ const { fileList: stateFileList, dragAreaStatus } = this.state;
348
387
  const fileList = this.props.fileList || stateFileList;
349
- const isPicType = listType === strings.FILE_LIST_PIC;
350
- const showAddTriggerInList = isPicType && (limit ? limit > fileList.length : true);
351
- const uploadAddCls = cls(`${prefixCls }-add`, {
352
- [`${prefixCls }-picture-add`]: isPicType,
353
- [`${prefixCls}-picture-add-disabled`]: disabled
388
+ const showAddTriggerInList = limit ? limit > fileList.length : true;
389
+ const dragAreaBaseCls = `${prefixCls}-drag-area`;
390
+ const uploadAddCls = cls(`${prefixCls}-add`, {
391
+ [`${prefixCls}-picture-add`]: true,
392
+ [`${prefixCls}-picture-add-disabled`]: disabled,
354
393
  });
394
+ const fileListCls = cls(`${prefixCls}-file-list`, {
395
+ [`${prefixCls}-picture-file-list`]: true,
396
+ });
397
+ const dragAreaCls = cls({
398
+ [`${dragAreaBaseCls}-legal`]: dragAreaStatus === strings.DRAG_AREA_LEGAL,
399
+ [`${dragAreaBaseCls}-illegal`]: dragAreaStatus === strings.DRAG_AREA_ILLEGAL
400
+ });
401
+ const mainCls = `${prefixCls}-file-list-main`;
402
+ const addContentProps = {
403
+ className: uploadAddCls,
404
+ onClick: this.onClick,
405
+ };
406
+ const containerProps = {
407
+ className: fileListCls
408
+ };
409
+ const draggableProps = {
410
+ onDrop: this.onDrop,
411
+ onDragOver: this.onDragOver,
412
+ onDragLeave: this.onDragLeave,
413
+ onDragEnter: this.onDragEnter,
414
+ };
415
+ if (draggable) {
416
+ Object.assign(addContentProps, draggableProps, { className: cls(uploadAddCls, dragAreaCls) });
417
+ }
355
418
  const addContent = (
356
- <div className={uploadAddCls} onClick={this.onClick}>
419
+ <div {...addContentProps}>
357
420
  {children}
358
421
  </div>
359
422
  );
@@ -365,23 +428,46 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
365
428
  return null;
366
429
  }
367
430
 
368
- const fileListCls = cls(`${prefixCls }-file-list`, {
369
- [`${prefixCls }-picture-file-list`]: isPicType,
370
- });
371
- const titleCls = `${prefixCls }-file-list-title`;
372
- const mainCls = `${prefixCls }-file-list-main`;
373
- const showTitle = limit !== 1 && fileList.length && listType !== strings.FILE_LIST_PIC;
431
+ return (
432
+ <LocaleConsumer componentName="Upload">
433
+ {(locale: Locale['Upload']) => (
434
+ <div {...containerProps}>
435
+ <div className={mainCls}>
436
+ {fileList.map((file, index) => this.renderFile(file, index, locale))}
437
+ {showAddTriggerInList ? addContent : null}
438
+ </div>
439
+ </div>
440
+ )}
441
+ </LocaleConsumer>
442
+ );
443
+ }
444
+
445
+ renderFileListDefault = () => {
446
+ const { showUploadList, limit, disabled } = this.props;
447
+ const { fileList: stateFileList } = this.state;
448
+ const fileList = this.props.fileList || stateFileList;
449
+ const fileListCls = cls(`${prefixCls}-file-list`);
450
+ const titleCls = `${prefixCls}-file-list-title`;
451
+ const mainCls = `${prefixCls}-file-list-main`;
452
+ const showTitle = limit !== 1 && fileList.length;
374
453
  const showClear = this.props.showClear && !disabled;
454
+ const containerProps = {
455
+ className: fileListCls
456
+ };
457
+
458
+ if (!showUploadList || !fileList.length) {
459
+ return null;
460
+ }
375
461
 
376
462
  return (
377
463
  <LocaleConsumer componentName="Upload">
378
- {(locale: Locale['Upload']): ReactNode => (
379
- <div className={fileListCls}>
464
+ {(locale: Locale['Upload']) => (
465
+ <div {...containerProps}>
380
466
  {showTitle ? (
381
467
  <div className={titleCls}>
382
- <span className={`${titleCls }-choosen`}>{locale.selectedFiles}</span>
468
+ <span className={`${titleCls}-choosen`}>{locale.selectedFiles}</span>
383
469
  {showClear ? (
384
- <span onClick={this.clear} className={`${titleCls }-clear`}>
470
+ <span onClick={this.clear} className={`${titleCls}-clear`}>
385
471
  {locale.clear}
386
472
  </span>
387
473
  ) : null}
@@ -390,13 +476,12 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
390
476
 
391
477
  <div className={mainCls}>
392
478
  {fileList.map((file, index) => this.renderFile(file, index, locale))}
393
- {showAddTriggerInList ? addContent : null}
394
479
  </div>
395
480
  </div>
396
481
  )}
397
482
  </LocaleConsumer>
398
483
  );
399
- };
484
+ }
400
485
 
401
486
  onDrop = (e: DragEvent<HTMLDivElement>): void => {
402
487
  this.foundation.handleDrop(e);
@@ -415,14 +500,30 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
415
500
  this.foundation.handleDragEnter(e);
416
501
  };
417
502
 
503
+ renderAddContent = () => {
504
+ const { draggable, children, listType } = this.props;
505
+ const uploadAddCls = cls(`${prefixCls}-add`);
506
+ if (listType === strings.FILE_LIST_PIC) {
507
+ return null;
508
+ }
509
+ if (draggable) {
510
+ return this.renderDragArea();
511
+ }
512
+ return (
513
+ <div className={uploadAddCls} onClick={this.onClick}>
514
+ {children}
515
+ </div>
516
+ );
517
+ }
518
+
418
519
  renderDragArea = (): ReactNode => {
419
520
  const { dragAreaStatus } = this.state;
420
521
  const { children, dragIcon, dragMainText, dragSubText } = this.props;
421
- const dragAreaBaseCls = `${prefixCls }-drag-area`;
522
+ const dragAreaBaseCls = `${prefixCls}-drag-area`;
422
523
  const dragAreaCls = cls(dragAreaBaseCls, {
423
- [`${dragAreaBaseCls }-legal`]: dragAreaStatus === strings.DRAG_AREA_LEGAL,
424
- [`${dragAreaBaseCls }-illegal`]: dragAreaStatus === strings.DRAG_AREA_ILLEGAL,
425
- [`${dragAreaBaseCls }-custom`]: children,
524
+ [`${dragAreaBaseCls}-legal`]: dragAreaStatus === strings.DRAG_AREA_LEGAL,
525
+ [`${dragAreaBaseCls}-illegal`]: dragAreaStatus === strings.DRAG_AREA_ILLEGAL,
526
+ [`${dragAreaBaseCls}-custom`]: children,
426
527
  });
427
528
 
428
529
  return (
@@ -440,20 +541,20 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
440
541
  children
441
542
  ) : (
442
543
  <>
443
- <div className={`${dragAreaBaseCls }-icon`}>
544
+ <div className={`${dragAreaBaseCls}-icon`}>
444
545
  {dragIcon || <IconUpload size="extra-large" />}
445
546
  </div>
446
- <div className={`${dragAreaBaseCls }-text`}>
447
- <div className={`${dragAreaBaseCls }-main-text`}>
547
+ <div className={`${dragAreaBaseCls}-text`}>
548
+ <div className={`${dragAreaBaseCls}-main-text`}>
448
549
  {dragMainText || locale.mainText}
449
550
  </div>
450
- <div className={`${dragAreaBaseCls }-sub-text`}>{dragSubText}</div>
451
- <div className={`${dragAreaBaseCls }-tips`}>
551
+ <div className={`${dragAreaBaseCls}-sub-text`}>{dragSubText}</div>
552
+ <div className={`${dragAreaBaseCls}-tips`}>
452
553
  {dragAreaStatus === strings.DRAG_AREA_LEGAL && (
453
- <span className={`${dragAreaBaseCls }-tips-legal`}>{locale.legalTips}</span>
554
+ <span className={`${dragAreaBaseCls}-tips-legal`}>{locale.legalTips}</span>
454
555
  )}
455
556
  {dragAreaStatus === strings.DRAG_AREA_ILLEGAL && (
456
- <span className={`${dragAreaBaseCls }-tips-illegal`}>
557
+ <span className={`${dragAreaBaseCls}-tips-illegal`}>
457
558
  {locale.illegalTips}
458
559
  </span>
459
560
  )}
@@ -485,27 +586,20 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
485
586
  directory,
486
587
  } = this.props;
487
588
  const uploadCls = cls(prefixCls, {
488
- [`${prefixCls }-picture`]: listType === strings.FILE_LIST_PIC,
489
- [`${prefixCls }-disabled`]: disabled,
490
- [`${prefixCls }-default`]: validateStatus === 'default',
491
- [`${prefixCls }-error`]: validateStatus === 'error',
492
- [`${prefixCls }-warning`]: validateStatus === 'warning',
493
- [`${prefixCls }-success`]: validateStatus === 'success',
589
+ [`${prefixCls}-picture`]: listType === strings.FILE_LIST_PIC,
590
+ [`${prefixCls}-disabled`]: disabled,
591
+ [`${prefixCls}-default`]: validateStatus === 'default',
592
+ [`${prefixCls}-error`]: validateStatus === 'error',
593
+ [`${prefixCls}-warning`]: validateStatus === 'warning',
594
+ [`${prefixCls}-success`]: validateStatus === 'success',
494
595
  }, className);
495
- const uploadAddCls = cls(`${prefixCls }-add`);
496
- const inputCls = cls(`${prefixCls }-hidden-input`);
497
- const inputReplaceCls = cls(`${prefixCls }-hidden-input-replace`);
498
- const promptCls = cls(`${prefixCls }-prompt`);
499
- const validateMsgCls = cls(`${prefixCls }-validate-message`);
596
+ const inputCls = cls(`${prefixCls}-hidden-input`);
597
+ const inputReplaceCls = cls(`${prefixCls}-hidden-input-replace`);
598
+ const promptCls = cls(`${prefixCls}-prompt`);
599
+ const validateMsgCls = cls(`${prefixCls}-validate-message`);
500
600
 
501
601
  const dirProps = directory ? { directory: 'directory', webkitdirectory: 'webkitdirectory' } : {};
502
602
 
503
- const addContent =
504
- listType !== strings.FILE_LIST_PIC ? (
505
- <div className={uploadAddCls} onClick={this.onClick}>
506
- {children}
507
- </div>
508
- ) : null;
509
603
  return (
510
604
  <div className={uploadCls} style={style} x-prompt-pos={promptPosition}>
511
605
  <input
@@ -532,7 +626,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
532
626
  className={inputReplaceCls}
533
627
  ref={this.replaceInputRef}
534
628
  />
535
- {draggable ? this.renderDragArea() : addContent}
629
+ {this.renderAddContent()}
536
630
  {prompt ? <div className={promptCls}>{prompt}</div> : null}
537
631
 
538
632
  {validateMessage ? <div className={validateMsgCls}>{validateMessage}</div> : null}
@@ -45,12 +45,15 @@ export interface FileItem extends BaseFileItem {
45
45
  }
46
46
 
47
47
  export interface RenderFileItemProps extends FileItem {
48
+ index?: number;
48
49
  previewFile?: (fileItem: RenderFileItemProps) => ReactNode;
49
50
  listType: UploadListType;
50
51
  onRemove: (props: RenderFileItemProps, e: MouseEvent) => void;
51
52
  onRetry: (props: RenderFileItemProps, e: MouseEvent) => void;
52
53
  onReplace: (props: RenderFileItemProps, e: MouseEvent) => void;
53
54
  key: string;
55
+ showPicInfo?: boolean;
56
+ renderPicInfo?: (renderFileItemProps: RenderFileItemProps) => ReactNode;
54
57
  showRetry: boolean;
55
58
  showReplace: boolean;
56
59
  style?: CSSProperties;