@douyinfe/semi-ui 2.11.2 → 2.12.0-alpha.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.
- package/avatar/index.tsx +2 -2
- package/backtop/index.tsx +11 -7
- package/badge/index.tsx +1 -1
- package/banner/index.tsx +5 -5
- package/breadcrumb/index.tsx +5 -3
- package/button/Button.tsx +10 -8
- package/card/index.tsx +43 -41
- package/carousel/CarouselArrow.tsx +2 -0
- package/carousel/index.tsx +1 -0
- package/cascader/index.tsx +101 -123
- package/cascader/item.tsx +1 -1
- package/checkbox/checkbox.tsx +13 -2
- package/collapsible/index.tsx +8 -1
- package/datePicker/dateInput.tsx +1 -0
- package/datePicker/datePicker.tsx +13 -5
- package/dist/css/semi.css +33 -0
- package/dist/css/semi.min.css +1 -1
- package/dist/umd/semi-ui.js +694 -384
- package/dist/umd/semi-ui.js.map +1 -1
- package/dist/umd/semi-ui.min.js +1 -1
- package/dist/umd/semi-ui.min.js.map +1 -1
- package/divider/index.tsx +8 -4
- package/dropdown/index.tsx +1 -1
- package/empty/index.tsx +13 -5
- package/form/_story/FormSubmit/index.tsx +45 -0
- package/form/_story/form.stories.js +2 -1
- package/form/hoc/withField.tsx +1 -1
- package/form/label.tsx +1 -1
- package/grid/col.tsx +1 -1
- package/grid/row.tsx +1 -1
- package/iconButton/index.tsx +2 -1
- package/input/index.tsx +38 -11
- package/lib/cjs/avatar/index.js +4 -2
- package/lib/cjs/backtop/index.js +2 -1
- package/lib/cjs/badge/index.js +2 -1
- package/lib/cjs/banner/index.js +9 -4
- package/lib/cjs/breadcrumb/index.js +4 -3
- package/lib/cjs/button/Button.js +13 -3
- package/lib/cjs/card/index.js +10 -5
- package/lib/cjs/carousel/CarouselArrow.js +6 -2
- package/lib/cjs/carousel/index.js +2 -1
- package/lib/cjs/cascader/index.js +9 -6
- package/lib/cjs/cascader/item.js +2 -1
- package/lib/cjs/checkbox/checkbox.js +8 -4
- package/lib/cjs/collapsible/index.js +2 -1
- package/lib/cjs/datePicker/dateInput.d.ts +1 -1
- package/lib/cjs/datePicker/dateInput.js +2 -1
- package/lib/cjs/datePicker/datePicker.d.ts +1 -1
- package/lib/cjs/datePicker/datePicker.js +4 -2
- package/lib/cjs/datePicker/monthsGrid.d.ts +2 -2
- package/lib/cjs/divider/index.js +2 -1
- package/lib/cjs/dropdown/index.js +2 -1
- package/lib/cjs/empty/index.js +8 -4
- package/lib/cjs/form/baseForm.d.ts +1 -1
- package/lib/cjs/form/field.d.ts +1 -1
- package/lib/cjs/form/hoc/withField.js +2 -1
- package/lib/cjs/form/label.js +2 -1
- package/lib/cjs/grid/col.js +2 -1
- package/lib/cjs/grid/row.js +2 -1
- package/lib/cjs/iconButton/index.js +3 -1
- package/lib/cjs/input/index.js +9 -5
- package/lib/cjs/list/index.js +6 -3
- package/lib/cjs/modal/ConfirmModal.js +2 -1
- package/lib/cjs/modal/Modal.js +6 -2
- package/lib/cjs/modal/ModalContent.js +13 -6
- package/lib/cjs/notification/notice.js +6 -3
- package/lib/cjs/pagination/index.js +4 -2
- package/lib/cjs/popconfirm/index.js +6 -3
- package/lib/cjs/radio/radio.d.ts +1 -1
- package/lib/cjs/radio/radio.js +4 -2
- package/lib/cjs/radio/radioGroup.d.ts +1 -1
- package/lib/cjs/rating/item.js +2 -1
- package/lib/cjs/scrollList/index.js +6 -3
- package/lib/cjs/select/index.js +9 -5
- package/lib/cjs/select/option.js +2 -1
- package/lib/cjs/sideSheet/SideSheetContent.js +6 -3
- package/lib/cjs/skeleton/index.js +3 -1
- package/lib/cjs/slider/index.js +9 -5
- package/lib/cjs/space/index.js +2 -1
- package/lib/cjs/spin/index.js +7 -3
- package/lib/cjs/switch/index.js +6 -4
- package/lib/cjs/table/Table.d.ts +1 -1
- package/lib/cjs/table/Table.js +6 -3
- package/lib/cjs/tabs/TabBar.d.ts +1 -0
- package/lib/cjs/tabs/TabBar.js +10 -2
- package/lib/cjs/tabs/TabPane.js +7 -3
- package/lib/cjs/tabs/index.js +2 -1
- package/lib/cjs/tabs/interface.d.ts +1 -0
- package/lib/cjs/tag/index.d.ts +2 -0
- package/lib/cjs/tag/index.js +60 -11
- package/lib/cjs/tag/interface.d.ts +1 -0
- package/lib/cjs/tagInput/index.js +7 -4
- package/lib/cjs/timePicker/Combobox.js +3 -1
- package/lib/cjs/toast/toast.js +6 -3
- package/lib/cjs/transfer/index.js +2 -1
- package/lib/cjs/tree/treeNode.js +2 -1
- package/lib/cjs/treeSelect/index.js +9 -6
- package/lib/cjs/typography/base.js +2 -1
- package/lib/cjs/typography/title.d.ts +1 -1
- package/lib/cjs/upload/index.d.ts +1 -1
- package/lib/cjs/upload/index.js +13 -6
- package/lib/es/avatar/index.js +4 -2
- package/lib/es/backtop/index.js +2 -1
- package/lib/es/badge/index.js +2 -1
- package/lib/es/banner/index.js +9 -4
- package/lib/es/breadcrumb/index.js +4 -3
- package/lib/es/button/Button.js +11 -3
- package/lib/es/card/index.js +10 -5
- package/lib/es/carousel/CarouselArrow.js +6 -2
- package/lib/es/carousel/index.js +2 -1
- package/lib/es/cascader/index.js +9 -6
- package/lib/es/cascader/item.js +2 -1
- package/lib/es/checkbox/checkbox.js +8 -4
- package/lib/es/collapsible/index.js +2 -1
- package/lib/es/datePicker/dateInput.d.ts +1 -1
- package/lib/es/datePicker/dateInput.js +2 -1
- package/lib/es/datePicker/datePicker.d.ts +1 -1
- package/lib/es/datePicker/datePicker.js +4 -2
- package/lib/es/datePicker/monthsGrid.d.ts +2 -2
- package/lib/es/divider/index.js +2 -1
- package/lib/es/dropdown/index.js +2 -1
- package/lib/es/empty/index.js +8 -4
- package/lib/es/form/baseForm.d.ts +1 -1
- package/lib/es/form/field.d.ts +1 -1
- package/lib/es/form/hoc/withField.js +2 -1
- package/lib/es/form/label.js +2 -1
- package/lib/es/grid/col.js +2 -1
- package/lib/es/grid/row.js +2 -1
- package/lib/es/iconButton/index.js +3 -1
- package/lib/es/input/index.js +9 -5
- package/lib/es/list/index.js +6 -3
- package/lib/es/modal/ConfirmModal.js +2 -1
- package/lib/es/modal/Modal.js +6 -2
- package/lib/es/modal/ModalContent.js +13 -6
- package/lib/es/notification/notice.js +6 -3
- package/lib/es/pagination/index.js +4 -2
- package/lib/es/popconfirm/index.js +6 -3
- package/lib/es/radio/radio.d.ts +1 -1
- package/lib/es/radio/radio.js +4 -2
- package/lib/es/radio/radioGroup.d.ts +1 -1
- package/lib/es/rating/item.js +2 -1
- package/lib/es/scrollList/index.js +6 -3
- package/lib/es/select/index.js +9 -5
- package/lib/es/select/option.js +2 -1
- package/lib/es/sideSheet/SideSheetContent.js +6 -3
- package/lib/es/skeleton/index.js +3 -1
- package/lib/es/slider/index.js +9 -5
- package/lib/es/space/index.js +2 -1
- package/lib/es/spin/index.js +7 -3
- package/lib/es/switch/index.js +6 -4
- package/lib/es/table/Table.d.ts +1 -1
- package/lib/es/table/Table.js +6 -3
- package/lib/es/tabs/TabBar.d.ts +1 -0
- package/lib/es/tabs/TabBar.js +10 -2
- package/lib/es/tabs/TabPane.js +7 -3
- package/lib/es/tabs/index.js +2 -1
- package/lib/es/tabs/interface.d.ts +1 -0
- package/lib/es/tag/index.d.ts +2 -0
- package/lib/es/tag/index.js +56 -9
- package/lib/es/tag/interface.d.ts +1 -0
- package/lib/es/tagInput/index.js +7 -4
- package/lib/es/timePicker/Combobox.js +3 -1
- package/lib/es/toast/toast.js +6 -3
- package/lib/es/transfer/index.js +2 -1
- package/lib/es/tree/treeNode.js +2 -1
- package/lib/es/treeSelect/index.js +8 -5
- package/lib/es/typography/base.js +2 -1
- package/lib/es/typography/title.d.ts +1 -1
- package/lib/es/upload/index.d.ts +1 -1
- package/lib/es/upload/index.js +13 -6
- package/list/index.tsx +16 -4
- package/modal/ConfirmModal.tsx +1 -1
- package/modal/Modal.tsx +2 -0
- package/modal/ModalContent.tsx +33 -21
- package/notification/notice.tsx +16 -4
- package/package.json +9 -9
- package/pagination/index.tsx +16 -2
- package/popconfirm/index.tsx +11 -3
- package/radio/radio.tsx +10 -2
- package/rating/item.tsx +1 -1
- package/scrollList/index.tsx +19 -3
- package/select/index.tsx +13 -6
- package/select/option.tsx +5 -1
- package/sideSheet/SideSheetContent.tsx +3 -3
- package/skeleton/index.tsx +1 -1
- package/slider/index.tsx +5 -3
- package/space/index.tsx +1 -1
- package/spin/index.tsx +15 -9
- package/switch/index.tsx +9 -14
- package/table/Table.tsx +5 -3
- package/table/_story/v2/index.js +2 -1
- package/table/_story/v2/radioRowSelection.tsx +107 -0
- package/tabs/TabBar.tsx +8 -1
- package/tabs/TabPane.tsx +10 -4
- package/tabs/index.tsx +2 -1
- package/tabs/interface.ts +1 -0
- package/tag/index.tsx +32 -2
- package/tag/interface.ts +1 -0
- package/tagInput/index.tsx +3 -2
- package/timePicker/Combobox.tsx +6 -1
- package/toast/toast.tsx +3 -3
- package/transfer/index.tsx +1 -0
- package/tree/treeNode.tsx +1 -1
- package/treeSelect/index.tsx +16 -4
- package/typography/base.tsx +1 -1
- package/upload/index.tsx +107 -38
package/tag/index.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
1
2
|
/* eslint-disable no-unused-vars */
|
|
2
3
|
/* eslint-disable max-len */
|
|
3
4
|
import React, { Component } from 'react';
|
|
@@ -7,7 +8,9 @@ import { cssClasses, strings } from '@douyinfe/semi-foundation/tag/constants';
|
|
|
7
8
|
import Avatar from '../avatar/index';
|
|
8
9
|
import { IconClose } from '@douyinfe/semi-icons';
|
|
9
10
|
import { TagProps, TagSize, TagColor, TagType } from './interface';
|
|
11
|
+
import { handlePrevent } from '@douyinfe/semi-foundation/utils/a11y';
|
|
10
12
|
import '@douyinfe/semi-foundation/tag/tag.scss';
|
|
13
|
+
import { isString } from 'lodash';
|
|
11
14
|
|
|
12
15
|
export * from './interface';
|
|
13
16
|
|
|
@@ -50,6 +53,7 @@ export default class Tag extends Component<TagProps, TagState> {
|
|
|
50
53
|
className: PropTypes.string,
|
|
51
54
|
avatarSrc: PropTypes.string,
|
|
52
55
|
avatarShape: PropTypes.oneOf(avatarShapeSet),
|
|
56
|
+
'aria-label': PropTypes.string,
|
|
53
57
|
};
|
|
54
58
|
|
|
55
59
|
constructor(props: TagProps) {
|
|
@@ -58,6 +62,7 @@ export default class Tag extends Component<TagProps, TagState> {
|
|
|
58
62
|
visible: true,
|
|
59
63
|
};
|
|
60
64
|
this.close = this.close.bind(this);
|
|
65
|
+
this.handleKeyDown = this.handleKeyDown.bind(this);
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
// any other way to achieve this?
|
|
@@ -88,6 +93,26 @@ export default class Tag extends Component<TagProps, TagState> {
|
|
|
88
93
|
this.setVisible(false);
|
|
89
94
|
}
|
|
90
95
|
|
|
96
|
+
handleKeyDown(event: any) {
|
|
97
|
+
const { closable, onClick } = this.props;
|
|
98
|
+
switch (event.key) {
|
|
99
|
+
case "Backspace":
|
|
100
|
+
case "Delete":
|
|
101
|
+
closable && this.close(event, this.props.children);
|
|
102
|
+
handlePrevent(event);
|
|
103
|
+
break;
|
|
104
|
+
case "Enter":
|
|
105
|
+
onClick(event);
|
|
106
|
+
handlePrevent(event);
|
|
107
|
+
break;
|
|
108
|
+
case 'Escape':
|
|
109
|
+
event.target.blur();
|
|
110
|
+
break;
|
|
111
|
+
default:
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
91
116
|
renderAvatar() {
|
|
92
117
|
const { avatarShape, avatarSrc } = this.props;
|
|
93
118
|
const avatar = <Avatar src={avatarSrc} shape={avatarShape} />;
|
|
@@ -95,10 +120,13 @@ export default class Tag extends Component<TagProps, TagState> {
|
|
|
95
120
|
}
|
|
96
121
|
|
|
97
122
|
render() {
|
|
98
|
-
const { children, size, color, closable, visible, onClose, className, type, avatarSrc, avatarShape, ...attr } = this.props;
|
|
123
|
+
const { children, size, color, closable, visible, onClose, onClick, className, type, avatarSrc, avatarShape, ...attr } = this.props;
|
|
99
124
|
const { visible: isVisible } = this.state;
|
|
125
|
+
const clickable = onClick !== Tag.defaultProps.onClick || closable;
|
|
126
|
+
const a11yProps = { role: 'button', tabIndex: 0, onKeyDown: this.handleKeyDown };
|
|
100
127
|
const baseProps = {
|
|
101
128
|
...attr,
|
|
129
|
+
onClick,
|
|
102
130
|
className: classNames(
|
|
103
131
|
prefixCls,
|
|
104
132
|
{
|
|
@@ -114,13 +142,15 @@ export default class Tag extends Component<TagProps, TagState> {
|
|
|
114
142
|
className
|
|
115
143
|
),
|
|
116
144
|
};
|
|
145
|
+
const wrapProps = clickable ? ({ ...baseProps, ...a11yProps }) : baseProps;
|
|
117
146
|
const closeIcon = closable ? (
|
|
147
|
+
// eslint-disable-next-line jsx-a11y/click-events-have-key-events
|
|
118
148
|
<div className={`${prefixCls}-close`} onClick={e => this.close(e, children)}>
|
|
119
149
|
<IconClose size="small" />
|
|
120
150
|
</div>
|
|
121
151
|
) : null;
|
|
122
152
|
return (
|
|
123
|
-
<div {...
|
|
153
|
+
<div aria-label={this.props['aria-label'] || isString(children) ? `${closable ? 'Closable ' : ''}Tag: ${children}` : '' } {...wrapProps}>
|
|
124
154
|
<div className={`${prefixCls}-content`}>
|
|
125
155
|
{avatarSrc ? this.renderAvatar() : null}
|
|
126
156
|
{children}
|
package/tag/interface.ts
CHANGED
package/tagInput/index.tsx
CHANGED
|
@@ -273,7 +273,7 @@ class TagInput extends BaseComponent<TagInputProps, TagInputState> {
|
|
|
273
273
|
// eslint-disable-next-line max-len
|
|
274
274
|
[`${prefixCls}-prefix-icon`]: React.isValidElement(prefix) && !(prefix && isString(prefix)),
|
|
275
275
|
});
|
|
276
|
-
return <div className={prefixWrapperCls}>{prefix}</div>;
|
|
276
|
+
return <div className={prefixWrapperCls} x-semi-prop="prefix">{prefix}</div>;
|
|
277
277
|
}
|
|
278
278
|
|
|
279
279
|
renderSuffix() {
|
|
@@ -286,7 +286,7 @@ class TagInput extends BaseComponent<TagInputProps, TagInputState> {
|
|
|
286
286
|
// eslint-disable-next-line max-len
|
|
287
287
|
[`${prefixCls}-suffix-icon`]: React.isValidElement(suffix) && !(suffix && isString(suffix)),
|
|
288
288
|
});
|
|
289
|
-
return <div className={suffixWrapperCls}>{suffix}</div>;
|
|
289
|
+
return <div className={suffixWrapperCls} x-semi-prop="suffix">{suffix}</div>;
|
|
290
290
|
}
|
|
291
291
|
|
|
292
292
|
renderTags() {
|
|
@@ -328,6 +328,7 @@ class TagInput extends BaseComponent<TagInputProps, TagInputState> {
|
|
|
328
328
|
closable={!disabled}
|
|
329
329
|
key={`${index}${value}`}
|
|
330
330
|
visible
|
|
331
|
+
aria-label={`${!disabled ? 'Closable ' : ''}Tag: ${value}`}
|
|
331
332
|
>
|
|
332
333
|
<Paragraph
|
|
333
334
|
className={typoCls}
|
package/timePicker/Combobox.tsx
CHANGED
|
@@ -317,7 +317,12 @@ class Combobox extends BaseComponent<ComboboxProps, ComboboxState> {
|
|
|
317
317
|
return (
|
|
318
318
|
<LocaleConsumer componentName="TimePicker">
|
|
319
319
|
{(locale: Locale['TimePicker'], localeCode: Locale['code']) => (
|
|
320
|
-
<ScrollList
|
|
320
|
+
<ScrollList
|
|
321
|
+
header={panelHeader}
|
|
322
|
+
footer={panelFooter}
|
|
323
|
+
x-semi-header-alias="panelHeader"
|
|
324
|
+
x-semi-footer-alias="panelFooter"
|
|
325
|
+
>
|
|
321
326
|
{this.renderAMPMSelect(locale, localeCode)}
|
|
322
327
|
{this.renderHourSelect(value.getHours(), locale)}
|
|
323
328
|
{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=
|
|
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}>
|
|
132
|
+
<span className={`${prefixCls}-content-text`} style={textStyle} x-semi-prop="content">
|
|
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 />}
|
|
140
|
+
icon={<IconClose x-semi-prop="icon" />}
|
|
141
141
|
theme={btnTheme}
|
|
142
142
|
size={btnSize}
|
|
143
143
|
/>
|
package/transfer/index.tsx
CHANGED
|
@@ -353,6 +353,7 @@ 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`}
|
|
356
357
|
>
|
|
357
358
|
{item.label}
|
|
358
359
|
</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`}>
|
|
272
|
+
<li className={`${prefixcls}-label ${prefixcls}-label-empty`} x-semi-prop="emptyContent">
|
|
273
273
|
{emptyContent}
|
|
274
274
|
</li>
|
|
275
275
|
</ul>
|
package/treeSelect/index.tsx
CHANGED
|
@@ -646,7 +646,11 @@ 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
|
|
649
|
+
return (
|
|
650
|
+
<div className={suffixWrapperCls} x-semi-prop="suffix">
|
|
651
|
+
{suffix}
|
|
652
|
+
</div>
|
|
653
|
+
);
|
|
650
654
|
};
|
|
651
655
|
|
|
652
656
|
renderPrefix = () => {
|
|
@@ -660,7 +664,11 @@ class TreeSelect extends BaseComponent<TreeSelectProps, TreeSelectState> {
|
|
|
660
664
|
[`${prefixcls}-prefix-icon`]: isSemiIcon(labelNode),
|
|
661
665
|
});
|
|
662
666
|
|
|
663
|
-
return
|
|
667
|
+
return (
|
|
668
|
+
<div className={prefixWrapperCls} id={insetLabelId} x-semi-prop="prefix,insetLabel">
|
|
669
|
+
{labelNode}
|
|
670
|
+
</div>
|
|
671
|
+
);
|
|
664
672
|
};
|
|
665
673
|
|
|
666
674
|
renderContent = () => {
|
|
@@ -731,7 +739,7 @@ class TreeSelect extends BaseComponent<TreeSelectProps, TreeSelectState> {
|
|
|
731
739
|
let renderKeys = [];
|
|
732
740
|
if (checkRelation === 'related') {
|
|
733
741
|
renderKeys = normalizeKeyList([...checkedKeys], keyEntities, leafOnly);
|
|
734
|
-
} else if (checkRelation === 'unRelated') {
|
|
742
|
+
} else if (checkRelation === 'unRelated' && Object.keys(keyEntities).length > 0) {
|
|
735
743
|
renderKeys = [...realCheckedKeys];
|
|
736
744
|
}
|
|
737
745
|
const tagList: Array<React.ReactNode> = [];
|
|
@@ -867,7 +875,11 @@ class TreeSelect extends BaseComponent<TreeSelectProps, TreeSelectState> {
|
|
|
867
875
|
if (showClearBtn) {
|
|
868
876
|
return null;
|
|
869
877
|
}
|
|
870
|
-
return arrowIcon ?
|
|
878
|
+
return arrowIcon ? (
|
|
879
|
+
<div className={cls(`${prefixcls}-arrow`)} x-semi-prop="arrowIcon">
|
|
880
|
+
{arrowIcon}
|
|
881
|
+
</div>
|
|
882
|
+
) : null;
|
|
871
883
|
};
|
|
872
884
|
|
|
873
885
|
renderClearBtn = () => {
|
package/typography/base.tsx
CHANGED
|
@@ -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`}>
|
|
529
|
+
<span className={`${prefixCls}-icon`} x-semi-prop="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,25 +3,54 @@ 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, {
|
|
6
|
+
import UploadFoundation, {
|
|
7
|
+
CustomFile,
|
|
8
|
+
UploadAdapter,
|
|
9
|
+
BeforeUploadObjectResult,
|
|
10
|
+
AfterUploadResult,
|
|
11
|
+
} from '@douyinfe/semi-foundation/upload/foundation';
|
|
7
12
|
import { strings, cssClasses } from '@douyinfe/semi-foundation/upload/constants';
|
|
8
13
|
import FileCard from './fileCard';
|
|
9
14
|
import BaseComponent, { ValidateStatus } from '../_base/baseComponent';
|
|
10
15
|
import LocaleConsumer from '../locale/localeConsumer';
|
|
11
16
|
import { IconUpload } from '@douyinfe/semi-icons';
|
|
12
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
FileItem,
|
|
19
|
+
RenderFileItemProps,
|
|
20
|
+
UploadListType,
|
|
21
|
+
PromptPositionType,
|
|
22
|
+
BeforeUploadProps,
|
|
23
|
+
AfterUploadProps,
|
|
24
|
+
OnChangeProps,
|
|
25
|
+
customRequestArgs,
|
|
26
|
+
CustomError,
|
|
27
|
+
} from './interface';
|
|
13
28
|
import { Locale } from '../locale/interface';
|
|
14
29
|
import '@douyinfe/semi-foundation/upload/upload.scss';
|
|
15
30
|
|
|
16
31
|
const prefixCls = cssClasses.PREFIX;
|
|
17
32
|
|
|
18
|
-
export {
|
|
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
|
+
};
|
|
19
46
|
|
|
20
47
|
export interface UploadProps {
|
|
21
48
|
accept?: string;
|
|
22
49
|
action: string;
|
|
23
50
|
afterUpload?: (object: AfterUploadProps) => AfterUploadResult;
|
|
24
|
-
beforeUpload?: (
|
|
51
|
+
beforeUpload?: (
|
|
52
|
+
object: BeforeUploadProps
|
|
53
|
+
) => BeforeUploadObjectResult | Promise<BeforeUploadObjectResult> | boolean;
|
|
25
54
|
beforeClear?: (fileList: Array<FileItem>) => boolean | Promise<boolean>;
|
|
26
55
|
beforeRemove?: (file: FileItem, fileList: Array<FileItem>) => boolean | Promise<boolean>;
|
|
27
56
|
capture?: boolean | 'user' | 'environment' | undefined;
|
|
@@ -114,7 +143,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
|
|
|
114
143
|
fileList: PropTypes.array, // files had been uploaded
|
|
115
144
|
fileName: PropTypes.string, // same as name, to avoid props conflict in Form.Upload
|
|
116
145
|
headers: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
|
117
|
-
hotSpotLocation: PropTypes.oneOf(['start','end']),
|
|
146
|
+
hotSpotLocation: PropTypes.oneOf(['start', 'end']),
|
|
118
147
|
itemStyle: PropTypes.object,
|
|
119
148
|
limit: PropTypes.number, // 最大允许上传文件个数
|
|
120
149
|
listType: PropTypes.oneOf<UploadProps['listType']>(strings.LIST_TYPE),
|
|
@@ -218,7 +247,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
|
|
|
218
247
|
const { fileList } = props;
|
|
219
248
|
if ('fileList' in props) {
|
|
220
249
|
return {
|
|
221
|
-
fileList: fileList || []
|
|
250
|
+
fileList: fileList || [],
|
|
222
251
|
};
|
|
223
252
|
}
|
|
224
253
|
return null;
|
|
@@ -228,7 +257,8 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
|
|
|
228
257
|
return {
|
|
229
258
|
...super.adapter,
|
|
230
259
|
notifyFileSelect: (files): void => this.props.onFileChange(files),
|
|
231
|
-
notifyError: (error, fileInstance, fileList, xhr): void =>
|
|
260
|
+
notifyError: (error, fileInstance, fileList, xhr): void =>
|
|
261
|
+
this.props.onError(error, fileInstance, fileList, xhr),
|
|
232
262
|
notifySuccess: (responseBody, file, fileList): void => this.props.onSuccess(responseBody, file, fileList),
|
|
233
263
|
notifyProgress: (percent, file, fileList): void => this.props.onProgress(percent, file, fileList),
|
|
234
264
|
notifyRemove: (file, fileList, fileItem): void => this.props.onRemove(file, fileList, fileItem),
|
|
@@ -241,19 +271,25 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
|
|
|
241
271
|
this.setState({ fileList });
|
|
242
272
|
}
|
|
243
273
|
},
|
|
244
|
-
notifyBeforeUpload: ({
|
|
245
|
-
|
|
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 }),
|
|
246
281
|
resetInput: (): void => {
|
|
247
282
|
this.setState(prevState => ({
|
|
248
|
-
inputKey: Math.random()
|
|
283
|
+
inputKey: Math.random(),
|
|
249
284
|
}));
|
|
250
285
|
},
|
|
251
286
|
resetReplaceInput: (): void => {
|
|
252
287
|
this.setState(prevState => ({
|
|
253
|
-
replaceInputKey: Math.random()
|
|
288
|
+
replaceInputKey: Math.random(),
|
|
254
289
|
}));
|
|
255
290
|
},
|
|
256
|
-
updateDragAreaStatus: (dragAreaStatus: string): void =>
|
|
291
|
+
updateDragAreaStatus: (dragAreaStatus: string): void =>
|
|
292
|
+
this.setState({ dragAreaStatus } as { dragAreaStatus: 'default' | 'legal' | 'illegal' }),
|
|
257
293
|
notifyChange: ({ currentFile, fileList }): void => this.props.onChange({ currentFile, fileList }),
|
|
258
294
|
updateLocalUrls: (urls): void => this.setState({ localUrls: urls }),
|
|
259
295
|
notifyClear: (): void => this.props.onClear(),
|
|
@@ -295,7 +331,6 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
|
|
|
295
331
|
this.setState({ replaceIdx: index }, () => {
|
|
296
332
|
this.replaceInputRef.current.click();
|
|
297
333
|
});
|
|
298
|
-
|
|
299
334
|
};
|
|
300
335
|
|
|
301
336
|
onReplaceChange = (e: ChangeEvent<HTMLInputElement>): void => {
|
|
@@ -316,11 +351,11 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
|
|
|
316
351
|
* insert files at index
|
|
317
352
|
* @param files Array<CustomFile>
|
|
318
353
|
* @param index number
|
|
319
|
-
* @returns
|
|
354
|
+
* @returns
|
|
320
355
|
*/
|
|
321
356
|
insert = (files: Array<CustomFile>, index: number): void => {
|
|
322
357
|
return this.foundation.insertFileToList(files, index);
|
|
323
|
-
}
|
|
358
|
+
};
|
|
324
359
|
|
|
325
360
|
/**
|
|
326
361
|
* ref method
|
|
@@ -333,7 +368,19 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
|
|
|
333
368
|
|
|
334
369
|
renderFile = (file: FileItem, index: number, locale: Locale['Upload']): ReactNode => {
|
|
335
370
|
const { name, status, validateMessage, _sizeInvalid, uid } = file;
|
|
336
|
-
const {
|
|
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;
|
|
337
384
|
const onRemove = (): void => this.remove(file);
|
|
338
385
|
const onRetry = (): void => {
|
|
339
386
|
this.foundation.retry(file);
|
|
@@ -358,7 +405,10 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
|
|
|
358
405
|
renderFileOperation,
|
|
359
406
|
renderThumbnail,
|
|
360
407
|
onReplace,
|
|
361
|
-
onPreviewClick:
|
|
408
|
+
onPreviewClick:
|
|
409
|
+
typeof onPreviewClick !== 'undefined'
|
|
410
|
+
? (): void => this.foundation.handlePreviewClick(file)
|
|
411
|
+
: undefined,
|
|
362
412
|
};
|
|
363
413
|
|
|
364
414
|
if (status === strings.FILE_STATUS_UPLOAD_FAIL && !validateMessage) {
|
|
@@ -404,7 +454,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
|
|
|
404
454
|
});
|
|
405
455
|
const dragAreaCls = cls({
|
|
406
456
|
[`${dragAreaBaseCls}-legal`]: dragAreaStatus === strings.DRAG_AREA_LEGAL,
|
|
407
|
-
[`${dragAreaBaseCls}-illegal`]: dragAreaStatus === strings.DRAG_AREA_ILLEGAL
|
|
457
|
+
[`${dragAreaBaseCls}-illegal`]: dragAreaStatus === strings.DRAG_AREA_ILLEGAL,
|
|
408
458
|
});
|
|
409
459
|
const mainCls = `${prefixCls}-file-list-main`;
|
|
410
460
|
const addContentProps = {
|
|
@@ -413,7 +463,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
|
|
|
413
463
|
onClick: this.onClick,
|
|
414
464
|
};
|
|
415
465
|
const containerProps = {
|
|
416
|
-
className: fileListCls
|
|
466
|
+
className: fileListCls,
|
|
417
467
|
};
|
|
418
468
|
const draggableProps = {
|
|
419
469
|
onDrop: this.onDrop,
|
|
@@ -425,7 +475,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
|
|
|
425
475
|
Object.assign(addContentProps, draggableProps, { className: cls(uploadAddCls, dragAreaCls) });
|
|
426
476
|
}
|
|
427
477
|
const addContent = (
|
|
428
|
-
<div {...addContentProps}>
|
|
478
|
+
<div {...addContentProps} x-semi-prop="children">
|
|
429
479
|
{children}
|
|
430
480
|
</div>
|
|
431
481
|
);
|
|
@@ -450,7 +500,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
|
|
|
450
500
|
)}
|
|
451
501
|
</LocaleConsumer>
|
|
452
502
|
);
|
|
453
|
-
}
|
|
503
|
+
};
|
|
454
504
|
|
|
455
505
|
renderFileListDefault = () => {
|
|
456
506
|
const { showUploadList, limit, disabled } = this.props;
|
|
@@ -462,7 +512,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
|
|
|
462
512
|
const showTitle = limit !== 1 && fileList.length;
|
|
463
513
|
const showClear = this.props.showClear && !disabled;
|
|
464
514
|
const containerProps = {
|
|
465
|
-
className: fileListCls
|
|
515
|
+
className: fileListCls,
|
|
466
516
|
};
|
|
467
517
|
|
|
468
518
|
if (!showUploadList || !fileList.length) {
|
|
@@ -477,7 +527,12 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
|
|
|
477
527
|
<div className={titleCls}>
|
|
478
528
|
<span className={`${titleCls}-choosen`}>{locale.selectedFiles}</span>
|
|
479
529
|
{showClear ? (
|
|
480
|
-
<span
|
|
530
|
+
<span
|
|
531
|
+
role="button"
|
|
532
|
+
tabIndex={0}
|
|
533
|
+
onClick={this.clear}
|
|
534
|
+
className={`${titleCls}-clear`}
|
|
535
|
+
>
|
|
481
536
|
{locale.clear}
|
|
482
537
|
</span>
|
|
483
538
|
) : null}
|
|
@@ -491,7 +546,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
|
|
|
491
546
|
)}
|
|
492
547
|
</LocaleConsumer>
|
|
493
548
|
);
|
|
494
|
-
}
|
|
549
|
+
};
|
|
495
550
|
|
|
496
551
|
onDrop = (e: DragEvent<HTMLDivElement>): void => {
|
|
497
552
|
this.foundation.handleDrop(e);
|
|
@@ -524,7 +579,7 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
|
|
|
524
579
|
{children}
|
|
525
580
|
</div>
|
|
526
581
|
);
|
|
527
|
-
}
|
|
582
|
+
};
|
|
528
583
|
|
|
529
584
|
renderDragArea = (): ReactNode => {
|
|
530
585
|
const { dragAreaStatus } = this.state;
|
|
@@ -554,14 +609,16 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
|
|
|
554
609
|
children
|
|
555
610
|
) : (
|
|
556
611
|
<>
|
|
557
|
-
<div className={`${dragAreaBaseCls}-icon`}>
|
|
612
|
+
<div className={`${dragAreaBaseCls}-icon`} x-semi-prop="dragIcon">
|
|
558
613
|
{dragIcon || <IconUpload size="extra-large" />}
|
|
559
614
|
</div>
|
|
560
615
|
<div className={`${dragAreaBaseCls}-text`}>
|
|
561
|
-
<div className={`${dragAreaBaseCls}-main-text`}>
|
|
616
|
+
<div className={`${dragAreaBaseCls}-main-text`} x-semi-prop="dragMainText">
|
|
562
617
|
{dragMainText || locale.mainText}
|
|
563
618
|
</div>
|
|
564
|
-
<div className={`${dragAreaBaseCls}-sub-text`}
|
|
619
|
+
<div className={`${dragAreaBaseCls}-sub-text`} x-semi-prop="dragSubText">
|
|
620
|
+
{dragSubText}
|
|
621
|
+
</div>
|
|
565
622
|
<div className={`${dragAreaBaseCls}-tips`}>
|
|
566
623
|
{dragAreaStatus === strings.DRAG_AREA_LEGAL && (
|
|
567
624
|
<span className={`${dragAreaBaseCls}-tips-legal`}>{locale.legalTips}</span>
|
|
@@ -598,14 +655,18 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
|
|
|
598
655
|
validateStatus,
|
|
599
656
|
directory,
|
|
600
657
|
} = this.props;
|
|
601
|
-
const uploadCls = cls(
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
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
|
+
);
|
|
609
670
|
const inputCls = cls(`${prefixCls}-hidden-input`);
|
|
610
671
|
const inputReplaceCls = cls(`${prefixCls}-hidden-input-replace`);
|
|
611
672
|
const promptCls = cls(`${prefixCls}-prompt`);
|
|
@@ -640,9 +701,17 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
|
|
|
640
701
|
ref={this.replaceInputRef}
|
|
641
702
|
/>
|
|
642
703
|
{this.renderAddContent()}
|
|
643
|
-
{prompt ?
|
|
704
|
+
{prompt ? (
|
|
705
|
+
<div className={promptCls} x-semi-prop="prompt">
|
|
706
|
+
{prompt}
|
|
707
|
+
</div>
|
|
708
|
+
) : null}
|
|
644
709
|
|
|
645
|
-
{validateMessage ?
|
|
710
|
+
{validateMessage ? (
|
|
711
|
+
<div className={validateMsgCls} x-semi-prop="validateMessage">
|
|
712
|
+
{validateMessage}
|
|
713
|
+
</div>
|
|
714
|
+
) : null}
|
|
646
715
|
{this.renderFileList()}
|
|
647
716
|
</div>
|
|
648
717
|
);
|