import React, { useEffect, useRef, useState } from 'react'; import { Alert, Flex, Input, Tag, Form, Switch, theme } from 'antd'; import Styles from './web.pc.module.less'; import { PlusOutlined } from '@ant-design/icons'; const tagInputStyle = { width: 64, height: 22, marginInlineEnd: 8, verticalAlign: 'top', }; export default function Offline(props) { const { config, update, t } = props; const { options = [], allowUser = false, tips } = config; const { token } = theme.useToken(); const tagPlusStyle = { height: 22, background: token.colorBgContainer, borderStyle: 'dashed', }; const [inputVisible, setInputVisible] = useState(false); const [option, setOption] = useState(''); const inputRef = useRef(null); useEffect(() => { if (inputVisible) { inputRef.current?.focus(); } }, [inputVisible]); const handleOptionCreated = () => { if (option) { options.push(option); update({ ...config, options, }); } setOption(''); setInputVisible(false); }; return (
{ update({ ...config, tips: currentTarget.value, }); }}/> {options.map((option, idx) => { options.splice(idx, 1); update({ ...config, options, }); }}> {option} )} {inputVisible ? ( setOption(currentTarget.value)} onBlur={handleOptionCreated} onPressEnter={handleOptionCreated}/>) : (} onClick={() => setInputVisible(true)}> {t('newOption')} )} { update({ ...config, allowUser: v, }); }}/>
); }