forked from p96170835/amis
Merge remote-tracking branch 'baidu/master'
This commit is contained in:
commit
79817f11ce
|
@ -41,6 +41,26 @@
|
||||||
background: $Form-select-onHover-bg;
|
background: $Form-select-onHover-bg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&--multi {
|
||||||
|
.#{$ns}Select-value {
|
||||||
|
position: static;
|
||||||
|
user-select: none;
|
||||||
|
line-height: $Form-input-lineHeight * $Form-input-fontSize - px2rem(2px);
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: middle;
|
||||||
|
font-size: $Form-selectValue-fontSize;
|
||||||
|
color: $Form-selectValue-color;
|
||||||
|
background: $Form-selectValue-bg;
|
||||||
|
border: px2rem(1px) solid $Form-selectValue-borderColor;
|
||||||
|
border-radius: px2rem(2px);
|
||||||
|
margin-right: $gap-xs;
|
||||||
|
margin-bottom: $gap-xs;
|
||||||
|
}
|
||||||
|
.#{$ns}Select-valueLabel {
|
||||||
|
padding: 0 $gap-xs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&-placeholder {
|
&-placeholder {
|
||||||
color: $Form-select-placeholderColor;
|
color: $Form-select-placeholderColor;
|
||||||
line-height: $Form-input-lineHeight;
|
line-height: $Form-input-lineHeight;
|
||||||
|
@ -52,12 +72,6 @@
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.#{$ns}Select-arrow {
|
|
||||||
position: absolute;
|
|
||||||
right: 0;
|
|
||||||
top: px2rem(10px);
|
|
||||||
}
|
|
||||||
|
|
||||||
&-clear {
|
&-clear {
|
||||||
padding: px2rem(3px);
|
padding: px2rem(3px);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
@ -80,8 +94,7 @@
|
||||||
|
|
||||||
&-optionArrowRight {
|
&-optionArrowRight {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
position: absolute;
|
padding-right: px2rem(10px);
|
||||||
right: px2rem(10px);
|
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
width: px2rem(12px);
|
width: px2rem(12px);
|
||||||
|
@ -95,7 +108,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
&-menu {
|
&-menu {
|
||||||
min-width: px2rem(160px);
|
width: px2rem(160px);
|
||||||
max-height: px2rem(300px);
|
max-height: px2rem(300px);
|
||||||
background: $Form-select-menu-bg;
|
background: $Form-select-menu-bg;
|
||||||
color: $Form-select-menu-color;
|
color: $Form-select-menu-color;
|
||||||
|
@ -120,6 +133,10 @@
|
||||||
> label {
|
> label {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
span {
|
||||||
|
display: inline-flex;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.is-active {
|
&.is-active {
|
||||||
|
@ -147,3 +164,13 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 需要能撑开
|
||||||
|
@include media-breakpoint-up(sm) {
|
||||||
|
.#{$ns}Form-control--sizeXs > .#{$ns}NestedSelect,
|
||||||
|
.#{$ns}Form-control--sizeSm > .#{$ns}NestedSelect,
|
||||||
|
.#{$ns}Form-control--sizeMd > .#{$ns}NestedSelect,
|
||||||
|
.#{$ns}Form-control--sizeLg > .#{$ns}NestedSelect {
|
||||||
|
display: inline-flex !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -752,7 +752,8 @@ export default class Cards extends React.Component<GridProps, object> {
|
||||||
checkOnItemClick,
|
checkOnItemClick,
|
||||||
masonryLayout,
|
masonryLayout,
|
||||||
itemsClassName,
|
itemsClassName,
|
||||||
classnames: cx
|
classnames: cx,
|
||||||
|
data
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
this.renderedToolbars = []; // 用来记录哪些 toolbar 已经渲染了,已经渲染了就不重复渲染了。
|
this.renderedToolbars = []; // 用来记录哪些 toolbar 已经渲染了,已经渲染了就不重复渲染了。
|
||||||
|
@ -838,7 +839,9 @@ export default class Cards extends React.Component<GridProps, object> {
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className={cx('Cards-placeholder')}>{placeholder}</div>
|
<div className={cx('Cards-placeholder')}>
|
||||||
|
{filter(placeholder, data)}
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{footer}
|
{footer}
|
||||||
|
|
|
@ -67,19 +67,75 @@ export default class NestedSelectControl extends React.Component<
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeItem(index: number, e?: React.MouseEvent<HTMLElement>) {
|
||||||
|
let {
|
||||||
|
onChange,
|
||||||
|
selectedOptions,
|
||||||
|
disabled,
|
||||||
|
joinValues,
|
||||||
|
valueField,
|
||||||
|
extractValue,
|
||||||
|
delimiter,
|
||||||
|
value
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
if (disabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
e && e.stopPropagation();
|
||||||
|
|
||||||
|
selectedOptions.splice(index, 1);
|
||||||
|
|
||||||
|
if (joinValues) {
|
||||||
|
value = (selectedOptions as Options)
|
||||||
|
.map(item => item[valueField || 'value'])
|
||||||
|
.join(delimiter || ',');
|
||||||
|
} else if (extractValue) {
|
||||||
|
value = (selectedOptions as Options).map(
|
||||||
|
item => item[valueField || 'value']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
onChange(value);
|
||||||
|
}
|
||||||
|
|
||||||
renderValue() {
|
renderValue() {
|
||||||
const {multiple, classnames: cx, selectedOptions, labelField} = this.props;
|
const {
|
||||||
const len = Array.isArray(selectedOptions) ? selectedOptions.length : 0;
|
multiple,
|
||||||
return (
|
classnames: cx,
|
||||||
<div className={cx('NestedSelect-valueWrap')} onClick={this.open}>
|
selectedOptions,
|
||||||
{len > 0 ? (
|
labelField,
|
||||||
<div className={cx('NestedSelect-value')}>
|
placeholder,
|
||||||
{multiple
|
disabled
|
||||||
? `已选择 ${len} 项`
|
} = this.props;
|
||||||
: selectedOptions[0][labelField || 'label']}
|
|
||||||
</div>
|
if (!(selectedOptions && selectedOptions.length > 0)) {
|
||||||
) : null}
|
return (
|
||||||
</div>
|
<div className={cx('NestedSelect-placeholder')}>{placeholder}</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return selectedOptions.map((item, index) =>
|
||||||
|
multiple ? (
|
||||||
|
<div className={cx('Select-value')} key={index}>
|
||||||
|
<span
|
||||||
|
className={cx('Select-valueIcon', {
|
||||||
|
'is-disabled': disabled || item.disabled
|
||||||
|
})}
|
||||||
|
onClick={this.removeItem.bind(this, index)}
|
||||||
|
>
|
||||||
|
×
|
||||||
|
</span>
|
||||||
|
<span className={cx('Select-valueLabel')}>
|
||||||
|
{item[labelField || 'label']}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className={cx('Select-value')} key={index}>
|
||||||
|
{item[labelField || 'label']}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,14 +417,13 @@ export default class NestedSelectControl extends React.Component<
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{stack.map((options, index) => (
|
{stack.map((options, index) => (
|
||||||
<div
|
<div key={index} className={cx('NestedSelect-menu')}>
|
||||||
key={index}
|
|
||||||
className={cx('NestedSelect-menu')}
|
|
||||||
style={{minWidth: this.target.offsetWidth}}
|
|
||||||
>
|
|
||||||
{index === 0 ? searchInput : null}
|
{index === 0 ? searchInput : null}
|
||||||
{multiple && index === 0 ? (
|
{multiple && index === 0 ? (
|
||||||
<div className={cx('NestedSelect-option', 'checkall')}>
|
<div
|
||||||
|
className={cx('NestedSelect-option', 'checkall')}
|
||||||
|
onMouseEnter={this.onMouseEnterAll}
|
||||||
|
>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
onChange={this.handleCheck.bind(this, options)}
|
onChange={this.handleCheck.bind(this, options)}
|
||||||
checked={partialChecked}
|
checked={partialChecked}
|
||||||
|
@ -422,6 +477,13 @@ export default class NestedSelectControl extends React.Component<
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@autobind
|
||||||
|
onMouseEnterAll() {
|
||||||
|
this.setState({
|
||||||
|
stack: [this.props.options]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
onMouseEnter(option: Option, index: number, e: MouseEvent) {
|
onMouseEnter(option: Option, index: number, e: MouseEvent) {
|
||||||
let {stack} = this.state;
|
let {stack} = this.state;
|
||||||
let {cascade, multiple, selectedOptions} = this.props;
|
let {cascade, multiple, selectedOptions} = this.props;
|
||||||
|
@ -442,7 +504,7 @@ export default class NestedSelectControl extends React.Component<
|
||||||
stack[index] && stack.splice(index, 1);
|
stack[index] && stack.splice(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({stack});
|
this.setState({stack: stack.slice(0, index + 1)});
|
||||||
}
|
}
|
||||||
|
|
||||||
renderOuter() {
|
renderOuter() {
|
||||||
|
@ -453,10 +515,7 @@ export default class NestedSelectControl extends React.Component<
|
||||||
disabled={!this.state.isOpened}
|
disabled={!this.state.isOpened}
|
||||||
onRootClose={this.close}
|
onRootClose={this.close}
|
||||||
>
|
>
|
||||||
<div
|
<div className={cx('NestedSelect-menuOuter')}>
|
||||||
className={cx('NestedSelect-menuOuter')}
|
|
||||||
style={{minWidth: this.target.offsetWidth}}
|
|
||||||
>
|
|
||||||
{this.renderOptions()}
|
{this.renderOptions()}
|
||||||
</div>
|
</div>
|
||||||
</RootCloseWrapper>
|
</RootCloseWrapper>
|
||||||
|
@ -468,44 +527,29 @@ export default class NestedSelectControl extends React.Component<
|
||||||
target={this.getTarget}
|
target={this.getTarget}
|
||||||
show
|
show
|
||||||
>
|
>
|
||||||
<PopOver
|
<PopOver className={cx('NestedSelect-popover')}>{body}</PopOver>
|
||||||
className={cx('NestedSelect-popover')}
|
|
||||||
style={{minWidth: this.target.offsetWidth}}
|
|
||||||
>
|
|
||||||
{body}
|
|
||||||
</PopOver>
|
|
||||||
</Overlay>
|
</Overlay>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {className, disabled, classnames: cx, multiple} = this.props;
|
||||||
className,
|
|
||||||
disabled,
|
|
||||||
placeholder,
|
|
||||||
selectedOptions,
|
|
||||||
classnames: cx
|
|
||||||
} = this.props;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cx('NestedSelectControl')}>
|
<div className={cx('NestedSelectControl', className)}>
|
||||||
<div
|
<div
|
||||||
className={cx(
|
className={cx('NestedSelect', {
|
||||||
'NestedSelect',
|
[`NestedSelect--multi`]: multiple,
|
||||||
{
|
'is-opened': this.state.isOpened,
|
||||||
'is-opened': this.state.isOpened,
|
'is-disabled': disabled
|
||||||
'is-disabled': disabled
|
})}
|
||||||
},
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
onClick={this.open}
|
onClick={this.open}
|
||||||
ref={this.domRef}
|
ref={this.domRef}
|
||||||
>
|
>
|
||||||
{!(selectedOptions && selectedOptions.length > 0) ? (
|
<div className={cx('NestedSelect-valueWrap')} onClick={this.open}>
|
||||||
<div className={cx('NestedSelect-placeholder')}>{placeholder}</div>
|
{this.renderValue()}
|
||||||
) : null}
|
</div>
|
||||||
|
|
||||||
{this.renderValue()}
|
|
||||||
{this.renderClear()}
|
{this.renderClear()}
|
||||||
|
|
||||||
<span className={cx('Select-arrow')} />
|
<span className={cx('Select-arrow')} />
|
||||||
|
|
Loading…
Reference in New Issue