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,14 +1,16 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { connect } from '@formily/react-schema-renderer'; 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 { acceptEnum, mapStyledProps, mapTextComponent } from '../shared';
import { icons, hasIcon, Icon as IconComponent } from '@/components/icons'; import { icons, hasIcon, Icon as IconComponent } from '@/components/icons';
import { CloseOutlined } from '@ant-design/icons';
function IconField(props: any) { function IconField(props: any) {
const { value, onChange } = props; const { value, onChange } = props;
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
return ( return (
<div> <div>
<Input.Group compact>
<Popover <Popover
placement={'bottom'} placement={'bottom'}
visible={visible} visible={visible}
@ -37,6 +39,10 @@ function IconField(props: any) {
{hasIcon(value) ? <IconComponent type={value} /> : '选择图标'} {hasIcon(value) ? <IconComponent type={value} /> : '选择图标'}
</Button> </Button>
</Popover> </Popover>
{value && <Button icon={<CloseOutlined/>} onClick={e => {
onChange(null);
}}></Button>}
</Input.Group>
</div> </div>
); );
} }