feat: playground rerank

This commit is contained in:
jialin
2024-10-14 10:27:46 +08:00
parent ecc683a6bd
commit 4c3dddc486
31 changed files with 1579 additions and 140 deletions
+115
View File
@@ -0,0 +1,115 @@
import { CloseOutlined } from '@ant-design/icons';
import { useIntl } from '@umijs/max';
import { Button, Input, Tooltip } from 'antd';
import classNames from 'classnames';
import React, { useState } from 'react';
import './styles/row-textarea.less';
interface SystemMessageProps {
style?: React.CSSProperties;
value: string;
placeholder?: string;
label?: React.ReactNode;
onChange: (e: any) => void;
}
const RowTextarea: React.FC<SystemMessageProps> = (props) => {
const { value, onChange, style, label, placeholder } = props;
const intl = useIntl();
const rowTextAreaRef = React.useRef<any>(null);
const [autoSize, setAutoSize] = useState<{
minRows: number;
maxRows: number;
focus: boolean;
}>({ minRows: 1, maxRows: 1, focus: false });
const handleFocus = () => {
setAutoSize({
minRows: 3,
maxRows: 3,
focus: true
});
setTimeout(() => {
rowTextAreaRef.current?.focus?.({
cursor: 'end'
});
}, 50);
};
const handleBlur = (e: any) => {
setAutoSize({
minRows: 2,
maxRows: 2,
focus: false
});
};
const handleOnChange = (e: any) => {
onChange?.(e);
};
const handleClear = () => {
onChange?.({ target: { value: '' } });
};
return (
<div
className={classNames('row-textarea', {
focus: autoSize.focus
})}
style={{ ...style }}
>
{
<div
style={{ display: autoSize.focus ? 'block' : 'none' }}
className="textarea-wrapper"
>
<span className="textarea-label">{label}</span>
<Input.TextArea
className="custome-scrollbar"
ref={rowTextAreaRef}
placeholder={placeholder}
style={{
borderRadius: '0',
border: 'none'
}}
value={value}
autoSize={{
minRows: autoSize.minRows,
maxRows: autoSize.maxRows
}}
onFocus={handleFocus}
onBlur={handleBlur}
allowClear={false}
onChange={handleOnChange}
></Input.TextArea>
</div>
}
{!autoSize.focus && (
<div className="content-wrap" onClick={handleFocus}>
<div className="content">
<span className="title">{label}</span>
{value || (
<span style={{ color: 'var(--ant-color-text-tertiary)' }}>
{placeholder}
</span>
)}
</div>
{value && (
<Tooltip title={intl.formatMessage({ id: 'common.button.clear' })}>
<Button
className="clear-btn"
type="text"
icon={<CloseOutlined />}
size="small"
onClick={handleClear}
></Button>
</Tooltip>
)}
</div>
)}
</div>
);
};
export default React.memo(RowTextarea);
@@ -0,0 +1,60 @@
.row-textarea {
position: relative;
&.focus {
padding-top: 9px;
}
.content-wrap {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
padding-right: 20px;
cursor: pointer;
&:hover {
.clear-btn {
display: block;
}
}
}
textarea.ant-input {
background-color: transparent;
box-shadow: none;
}
.clear-btn {
display: none;
position: absolute;
right: 6px;
top: 6px;
}
.textarea-label {
position: relative;
top: 1px;
font-weight: var(--font-weight-bold);
padding-left: 14px;
}
.content {
flex: 1;
width: 100px;
height: 40px;
line-height: 24px;
padding: 8px 14px;
padding-right: 4px;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
color: var(--ant-color-text-secondary);
.title {
font-weight: var(--font-weight-normal);
padding-right: 10px;
color: var(--ant-color-text);
}
}
}