1. BoolSetter bug 修复;

2. IconSetter 体验优化(新增 defaultValue 和 hasClear 等能力);
3. Button、Icon 等组件使用 IconSetter;
This commit is contained in:
金禅 2020-08-10 23:26:19 +08:00
parent b79fc93d6c
commit 5a801781ce
4 changed files with 79 additions and 45 deletions

View File

@ -1581,12 +1581,12 @@
"override": [ "override": [
{ {
"name": "icon", "name": "icon",
"setter": "StringSetter", "setter": "IconSetter",
"extraProps": { "extraProps": {
"defaultValue": "success", "defaultValue": "success",
"onChange": { "onChange": {
"type": "JSFunction", "type": "JSFunction",
"value": "(val, field, editor) => {\n field.nodes[0].children.import({\"componentName\": \"Icon\", \"props\": {\"type\": val, \"style\": {\"marginRight\": 5}}}, true); //field.top.setPropValue('children', [{\"componentName\": \"Icon\", \"props\": {\"type\": val}}, (field.top.getPropValue('children') || []).slice(-1)]);\n}" "value": "(val, field, editor) => {\n field.nodes[0].children.import(val && {\"componentName\": \"Icon\", \"props\": {\"type\": val, \"style\": {\"marginRight\": 5}}}, true); //field.top.setPropValue('children', [{\"componentName\": \"Icon\", \"props\": {\"type\": val}}, (field.top.getPropValue('children') || []).slice(-1)]);\n}"
} }
} }
}, },
@ -5716,7 +5716,7 @@
"props": [ "props": [
{ {
"name": "type", "name": "type",
"propType": "string", "propType": "icon",
"description": "指定显示哪种图标" "description": "指定显示哪种图标"
}, },
{ {
@ -5741,7 +5741,7 @@
"number" "number"
] ]
}, },
"description": "指定图标大小\n<br/>**可选值**<br/> xxs, xs, small, medium, large, xl, xxl, xxxl, inherit", "description": "指定图标大小",
"defaultValue": "medium" "defaultValue": "medium"
}, },
{ {
@ -5752,7 +5752,23 @@
"name": "style", "name": "style",
"propType": "object" "propType": "object"
} }
],
"configure": {
"props": {
"isExtends": true,
"override": [
{
"name": "type",
"setter": {
"componentName": "IconSetter",
"props": {
"hasClear": false
}
}
}
] ]
}
}
}, },
{ {
"componentName": "Input", "componentName": "Input",

View File

@ -1,24 +1,16 @@
.lowcode-icon-box {
display: inline-block;
margin-right: -5px;
padding: 3px 0 3px 0;
width: 26px;
height: 26px;
text-align: center;
line-height: 20px;
background: #f2f2f2;
div {
width: 20px;
height: 20px;
border: 1px solid #ddd;
}
}
.lc-icon-setter{ .lc-icon-setter{
.next-input{ .next-input{
width: auto !important; width: auto !important;
} }
i {
min-width: 12px;
}
i:hover {
cursor: pointer;
}
input:hover {
cursor: pointer;
}
} }

View File

@ -64,31 +64,68 @@ const icons = [
]; ];
interface IconSetterProps { interface IconSetterProps {
value: string; value: string;
defaultValue: string;
placeholder: string;
hasClear: boolean;
onChange: (icon: string) => undefined; onChange: (icon: string) => undefined;
icons: string[]; icons: string[];
} }
export default class IconSetter extends PureComponent<IconSetterProps, {}> { export default class IconSetter extends PureComponent<IconSetterProps, {}> {
static defaultProps = { static defaultProps = {
value: '', value: undefined,
defaultValue: '',
hasClear: true,
icons: icons, icons: icons,
placeholder: '请点击选择 Icon',
onChange: (icon: string) => undefined, onChange: (icon: string) => undefined,
}; };
onInputChange() { state = {
console.log(this); firstLoad: true,
} };
onSelectIcon(icon: string) { onInputChange = (icon: string) => {
const { onChange } = this.props; const { onChange } = this.props;
onChange(icon); onChange(icon);
} };
onSelectIcon = (icon: string) => {
const { onChange } = this.props;
onChange(icon);
};
render() { render() {
const { icons, value } = this.props; const { icons, value, defaultValue, onChange, placeholder, hasClear } = this.props;
const { firstLoad } = this.state;
if (firstLoad && defaultValue && typeof value === 'undefined') onChange(defaultValue);
this.setState({
firstLoad: false,
});
const currentIcon = <Icon size="xs" type={value} />;
const clearIcon = hasClear && (
<Icon
size="xs"
id="icon-clear"
type="delete-filling"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
this.onSelectIcon('');
}}
/>
);
const triggerNode = ( const triggerNode = (
<div className="lowcode-icon-box"> <div>
<Icon type={value} /> <Input
placeholder={placeholder}
addonTextBefore={currentIcon}
onChange={this.onInputChange}
value={value}
defaultValue={defaultValue}
readOnly
addonTextAfter={clearIcon}
/>
</div> </div>
); );
const InnerBeforeNode = ( const InnerBeforeNode = (
@ -105,17 +142,13 @@ export default class IconSetter extends PureComponent<IconSetterProps, {}> {
<ul className="lowcode-icon-list"> <ul className="lowcode-icon-list">
{icons.map((icon) => ( {icons.map((icon) => (
<li onClick={() => this.onSelectIcon(icon)}> <li onClick={() => this.onSelectIcon(icon)}>
<Icon type={icon} size="large" /> <Icon type={icon} size="medium" />
</li> </li>
))} ))}
</ul> </ul>
</Balloon> </Balloon>
); );
return ( return <div className="lc-icon-setter">{InnerBeforeNode}</div>;
<div className="lc-icon-setter">
<Input innerBefore={InnerBeforeNode} onChange={this.onInputChange} value={value} />
</div>
);
} }
} }

View File

@ -19,14 +19,7 @@ export const NumberSetter = NumberPicker;
export class BoolSetter extends Component { export class BoolSetter extends Component {
render() { render() {
const { onChange, value, defaultValue } = this.props; const { onChange, value, defaultValue } = this.props;
return ( return <Switch checked={value} defaultChecked={defaultValue} onChange={onChange} />;
<Switch
checked={value || defaultValue}
onChange={(val) => {
onChange(val);
}}
/>
);
} }
} }
export const SelectSetter = Select; export const SelectSetter = Select;