import { CloseOutlined } from '@ant-design/icons'; import { useIntl } from '@umijs/max'; import { Button, Checkbox, Divider, Input, Tooltip } from 'antd'; import classNames from 'classnames'; import React, { useEffect, useState } from 'react'; import '../../style/sys-message.less'; interface SystemMessageProps { style?: React.CSSProperties; systemMessage: string; showApplyToAll?: boolean; applyToAll?: (e: any) => void; setSystemMessage: (value: string) => void; } const SystemMessage: React.FC = (props) => { const { systemMessage, showApplyToAll, setSystemMessage, style, applyToAll } = props; const intl = useIntl(); const [applyToAllModels, setApplyToAllModels] = useState(false); const systemMessageRef = React.useRef(null); const [autoSize, setAutoSize] = useState<{ minRows: number; maxRows: number; focus: boolean; }>({ minRows: 1, maxRows: 1, focus: false }); const handleFocus = () => { setAutoSize({ minRows: 4, maxRows: 4, focus: true }); setTimeout(() => { systemMessageRef.current?.focus?.({ cursor: 'end' }); }, 100); }; const handleBlur = (e: any) => { setAutoSize({ minRows: 1, maxRows: 1, focus: false }); }; const handleOnChange = (e: any) => { setSystemMessage(e.target.value); if (applyToAllModels) { applyToAll?.(e.target.value); } }; const handleClearSystemMessage = () => { setSystemMessage(''); }; const handleClickCheckbox = (e?: any) => { e.preventDefault(); setApplyToAllModels(!applyToAllModels); }; useEffect(() => { if (applyToAllModels) { applyToAll?.(systemMessage); } }, [applyToAllModels]); return (
{
{intl.formatMessage({ id: 'playground.systemMessage' })} {showApplyToAll && ( {intl.formatMessage({ id: 'playground.compare.applytoall' })} )}
} {!autoSize.focus && (
{intl.formatMessage({ id: 'playground.systemMessage' })} {systemMessage || ( {intl.formatMessage({ id: 'playground.system.tips' })} )}
{systemMessage && ( )}
)}
); }; export default SystemMessage;