feat: combo组件升级 (#3668)

Co-authored-by: zhangzhulei <zhangzhulei@baidu.com>
This commit is contained in:
dynazhang 2022-03-02 15:33:08 +08:00 committed by GitHub
parent 80bcaf706d
commit 615a3f991c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 20 deletions

View File

@ -783,3 +783,5 @@ combo 还有一个作用是增加层级,比如返回的数据是一个深层
| strictMode | `boolean` | `true` | 默认为严格模式,设置为 false 时,当其他表单项更新是,里面的表单项也可以及时获取,否则不会。 |
| syncFields | `Array<string>` | `[]` | 配置同步字段。只有 `strictMode``false` 时有效。如果 Combo 层级比较深,底层的获取外层的数据可能不同步。但是给 combo 配置这个属性就能同步下来。输入格式:`["os"]` |
| nullable | `boolean` | `false` | 允许为空,如果子表单项里面配置验证器,且又是单条模式。可以允许用户选择清空(不填)。 |
| itemClassName | `string` | | 单组 CSS 类 |
| itemsWrapperClassName | `string` | | 组合区域 CSS 类 |

View File

@ -83,6 +83,7 @@ import AlertDanger from '../icons/alert-danger.svg';
import FunctionIcon from '../icons/function.svg';
import InputClearIcon from '../icons/input-clear.svg';
import SliderHandleIcon from '../icons/slider-handle-icon.svg';
import TrashIcon from '../icons/trash.svg';
// 兼容原来的用法,后续不直接试用。
@ -192,6 +193,7 @@ registerIcon('slider-handle', SliderHandleIcon);
registerIcon('cloud-upload', CloudUploadIcon);
registerIcon('image', ImageIcon);
registerIcon('refresh', RefreshIcon);
registerIcon('trash', TrashIcon);
export function Icon({
icon,

8
src/icons/trash.svg Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="16px" height="16px" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>4.图标元件/3.操作/删除</title>
<g id="4.图标元件/3.操作/删除" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<rect id="矩形" stroke="#979797" fill="#D8D8D8" opacity="0" x="0.5" y="0.5" width="15" height="15"></rect>
<path d="M14,3.499 L14,4.5 L12.497,4.5 L12.498,14.5 L3.498,14.5 L3.497,4.5 L2,4.5 L2,3.499 L14,3.499 Z M11.498,4.5 L4.497,4.5 L4.497,13.5 L11.498,13.5 L11.498,4.5 Z M6.998,7.499 L6.998,11.499 L5.998,11.499 L5.998,7.499 L6.998,7.499 Z M9.998,7.499 L9.998,11.499 L8.998,11.499 L8.998,7.499 L9.998,7.499 Z M9.999,1.5 L9.999,2.499 L5.998,2.499 L5.998,1.5 L9.999,1.5 Z" id="形状结合" fill="#151B26"></path>
</g>
</svg>

After

Width:  |  Height:  |  Size: 887 B

View File

@ -10,6 +10,7 @@ import {
import {Schema, Action, Api} from '../../types';
import {ComboStore, IComboStore} from '../../store/combo';
import {default as CTabs, Tab} from '../../components/Tabs';
import Button from '../../components/Button';
import {
guid,
@ -294,6 +295,8 @@ export default class ComboControl extends React.Component<ComboProps> {
| 'tabsMode'
| 'tabsStyle'
| 'placeholder'
| 'itemClassName'
| 'itemsWrapperClassName'
> = {
minLength: 0,
maxLength: 0,
@ -310,7 +313,9 @@ export default class ComboControl extends React.Component<ComboProps> {
deleteIcon: '',
tabsMode: false,
tabsStyle: '',
placeholder: 'placeholder.empty'
placeholder: 'placeholder.empty',
itemClassName: '',
itemsWrapperClassName: ''
};
static propsList: Array<string> = [
'minLength',
@ -337,7 +342,9 @@ export default class ComboControl extends React.Component<ComboProps> {
'items',
'conditions',
'messages',
'formStore'
'formStore',
'itemClassName',
'itemsWrapperClassName'
];
subForms: Array<any> = [];
@ -1186,7 +1193,9 @@ export default class ComboControl extends React.Component<ComboProps> {
lazyLoad,
changeImmediately,
placeholder,
translate: __
translate: __,
itemClassName,
itemsWrapperClassName
} = this.props;
let items = this.props.items;
@ -1213,7 +1222,7 @@ export default class ComboControl extends React.Component<ComboProps> {
: ''
)}
>
<div className={cx(`Combo-items`)}>
<div className={cx(`Combo-items`, itemsWrapperClassName)}>
{Array.isArray(value) && value.length ? (
value.map((value, index, thelist) => {
let delBtn: any = null;
@ -1224,21 +1233,20 @@ export default class ComboControl extends React.Component<ComboProps> {
evalExpression(itemRemovableOn, value) !== false)
) {
delBtn = (
<a
onClick={this.removeItem.bind(this, index)}
<Button
key="remove"
className={cx(
`Combo-delBtn ${!store.removable ? 'is-disabled' : ''}`
)}
data-tooltip={__('delete')}
data-position="bottom"
className={cx('Combo-delBtn')}
disabled={!store.removable}
tooltip={__('delete')}
tooltipPlacement="bottom"
onClick={this.removeItem.bind(this, index)}
>
{deleteIcon ? (
<i className={deleteIcon} />
) : (
<Icon icon="status-close" className="icon" />
)}
</a>
</Button>
);
}
@ -1262,7 +1270,7 @@ export default class ComboControl extends React.Component<ComboProps> {
return (
<div
className={cx(`Combo-item`)}
className={cx(`Combo-item`, itemClassName)}
key={this.keys[index] || (this.keys[index] = guid())}
>
{!disabled && draggable && thelist.length > 1 ? (
@ -1363,15 +1371,16 @@ export default class ComboControl extends React.Component<ComboProps> {
}
)
) : (
<button
type="button"
<Button
level="default"
className={cx(`Combo-addBtn`, addButtonClassName)}
block
tooltip={__('Combo.add')}
onClick={this.addItem}
className={cx(`Button Combo-addBtn`, addButtonClassName)}
data-tooltip={__('Combo.add')}
>
{addIcon ? <Icon icon="plus" className="icon" /> : null}
<span>{__(addButtonText || 'Combo.add')}</span>
</button>
</Button>
)
) : null}
{draggable ? (
@ -1400,7 +1409,8 @@ export default class ComboControl extends React.Component<ComboProps> {
disabled,
typeSwitchable,
nullable,
translate: __
translate: __,
itemClassName
} = this.props;
let items = this.props.items;
@ -1421,7 +1431,7 @@ export default class ComboControl extends React.Component<ComboProps> {
disabled ? 'is-disabled' : ''
)}
>
<div className={cx(`Combo-item`)}>
<div className={cx(`Combo-item`, itemClassName)}>
{condition && typeSwitchable !== false ? (
<div className={cx('Combo-itemTag')}>
<label>{__('Combo.type')}</label>