fix: show clear button

This commit is contained in:
chenos 2021-05-10 15:47:03 +08:00
parent 6b7e26fb90
commit 797da5bdb0

View File

@ -1,42 +1,48 @@
import React, { useState } from 'react';
import { connect } from '@formily/react-schema-renderer';
import { Popover, Button } from 'antd';
import { Popover, Button, Input } from 'antd';
import { acceptEnum, mapStyledProps, mapTextComponent } from '../shared';
import { icons, hasIcon, Icon as IconComponent } from '@/components/icons';
import { CloseOutlined } from '@ant-design/icons';
function IconField(props: any) {
const { value, onChange } = props;
const [visible, setVisible] = useState(false);
return (
<div>
<Popover
placement={'bottom'}
visible={visible}
onVisibleChange={val => {
setVisible(val);
}}
content={
<div>
{[...icons.keys()].map(key => (
<span
style={{ fontSize: 18, marginRight: 10, cursor: 'pointer' }}
onClick={() => {
onChange(key);
setVisible(false);
}}
>
<IconComponent type={key} />
</span>
))}
</div>
}
title="图标"
trigger="click"
>
<Button>
{hasIcon(value) ? <IconComponent type={value} /> : '选择图标'}
</Button>
</Popover>
<Input.Group compact>
<Popover
placement={'bottom'}
visible={visible}
onVisibleChange={val => {
setVisible(val);
}}
content={
<div>
{[...icons.keys()].map(key => (
<span
style={{ fontSize: 18, marginRight: 10, cursor: 'pointer' }}
onClick={() => {
onChange(key);
setVisible(false);
}}
>
<IconComponent type={key} />
</span>
))}
</div>
}
title="图标"
trigger="click"
>
<Button>
{hasIcon(value) ? <IconComponent type={value} /> : '选择图标'}
</Button>
</Popover>
{value && <Button icon={<CloseOutlined/>} onClick={e => {
onChange(null);
}}></Button>}
</Input.Group>
</div>
);
}