feat: expand inputbar height
This commit is contained in:
parent
11427a980c
commit
e28b96b45e
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
::-webkit-scrollbar-thumb {
|
::-webkit-scrollbar-thumb {
|
||||||
background: var(--color-scrollbar-thumb);
|
background: var(--color-scrollbar-thumb);
|
||||||
|
border-radius: 5px;
|
||||||
&:hover {
|
&:hover {
|
||||||
background: var(--color-scrollbar-thumb-hover);
|
background: var(--color-scrollbar-thumb-hover);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,6 +69,8 @@ const resources = {
|
|||||||
'input.new_topic': 'New Topic',
|
'input.new_topic': 'New Topic',
|
||||||
'input.topics': ' Topics ',
|
'input.topics': ' Topics ',
|
||||||
'input.clear': 'Clear',
|
'input.clear': 'Clear',
|
||||||
|
'input.expand': 'Expand',
|
||||||
|
'input.collapse': 'Collapse',
|
||||||
'input.clear.title': 'Clear all messages?',
|
'input.clear.title': 'Clear all messages?',
|
||||||
'input.clear.content': 'Are you sure to clear all messages?',
|
'input.clear.content': 'Are you sure to clear all messages?',
|
||||||
'input.placeholder': 'Type your message here...',
|
'input.placeholder': 'Type your message here...',
|
||||||
@ -305,6 +307,8 @@ const resources = {
|
|||||||
'input.new_topic': '新话题',
|
'input.new_topic': '新话题',
|
||||||
'input.topics': ' 话题 ',
|
'input.topics': ' 话题 ',
|
||||||
'input.clear': '清除',
|
'input.clear': '清除',
|
||||||
|
'input.expand': '展开',
|
||||||
|
'input.collapse': '收起',
|
||||||
'input.clear.title': '清除所有消息?',
|
'input.clear.title': '清除所有消息?',
|
||||||
'input.clear.content': '确定要清除所有消息吗?',
|
'input.clear.content': '确定要清除所有消息吗?',
|
||||||
'input.placeholder': '在这里输入消息...',
|
'input.placeholder': '在这里输入消息...',
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
import {
|
import {
|
||||||
ClearOutlined,
|
ClearOutlined,
|
||||||
ControlOutlined,
|
ControlOutlined,
|
||||||
|
FullscreenExitOutlined,
|
||||||
|
FullscreenOutlined,
|
||||||
HistoryOutlined,
|
HistoryOutlined,
|
||||||
PauseCircleOutlined,
|
PauseCircleOutlined,
|
||||||
PlusCircleOutlined,
|
PlusCircleOutlined,
|
||||||
@ -20,7 +22,7 @@ import { Button, Divider, Popconfirm, Tag, Tooltip } from 'antd'
|
|||||||
import TextArea, { TextAreaRef } from 'antd/es/input/TextArea'
|
import TextArea, { TextAreaRef } from 'antd/es/input/TextArea'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import { debounce, isEmpty } from 'lodash'
|
import { debounce, isEmpty } from 'lodash'
|
||||||
import { FC, useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
import { CSSProperties, FC, useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
|
|
||||||
@ -123,6 +125,32 @@ const Inputbar: FC<Props> = ({ assistant, setActiveTopic }) => {
|
|||||||
store.dispatch(setGenerating(false))
|
store.dispatch(setGenerating(false))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const resizeTextArea = () => {
|
||||||
|
const textArea = textareaRef.current?.resizableTextArea?.textArea
|
||||||
|
if (textArea) {
|
||||||
|
textArea.style.height = 'auto'
|
||||||
|
textArea.style.height = textArea?.scrollHeight > 400 ? '400px' : `${textArea?.scrollHeight}px`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const onToggleExpended = () => {
|
||||||
|
const isExpended = !expended
|
||||||
|
setExpend(isExpended)
|
||||||
|
const textArea = textareaRef.current?.resizableTextArea?.textArea
|
||||||
|
|
||||||
|
if (textArea) {
|
||||||
|
if (isExpended) {
|
||||||
|
textArea.style.height = '70vh'
|
||||||
|
} else {
|
||||||
|
resizeTextArea()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
textareaRef.current?.focus()
|
||||||
|
}
|
||||||
|
|
||||||
|
const onInput = () => !expended && resizeTextArea()
|
||||||
|
|
||||||
// Command or Ctrl + N create new topic
|
// Command or Ctrl + N create new topic
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const onKeydown = (e) => {
|
const onKeydown = (e) => {
|
||||||
@ -166,17 +194,10 @@ const Inputbar: FC<Props> = ({ assistant, setActiveTopic }) => {
|
|||||||
variant="borderless"
|
variant="borderless"
|
||||||
rows={1}
|
rows={1}
|
||||||
ref={textareaRef}
|
ref={textareaRef}
|
||||||
style={{ fontSize }}
|
styles={{ textarea: TextareaStyle }}
|
||||||
styles={{ textarea: { paddingLeft: 0, boxSizing: 'border-box', padding: '10px 15px 5px' } }}
|
|
||||||
onFocus={() => setInputFocus(true)}
|
onFocus={() => setInputFocus(true)}
|
||||||
onBlur={() => setInputFocus(false)}
|
onBlur={() => setInputFocus(false)}
|
||||||
onInput={() => {
|
onInput={onInput}
|
||||||
const textArea = textareaRef.current?.resizableTextArea?.textArea
|
|
||||||
if (textArea) {
|
|
||||||
textArea.style.height = 'auto'
|
|
||||||
textArea.style.height = textArea?.scrollHeight > 400 ? '400px' : `${textArea?.scrollHeight}px`
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
<ToolbarMenu>
|
<ToolbarMenu>
|
||||||
@ -209,24 +230,21 @@ const Inputbar: FC<Props> = ({ assistant, setActiveTopic }) => {
|
|||||||
</ToolbarButton>
|
</ToolbarButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<AttachmentButton images={images} setImages={setImages} ToolbarButton={ToolbarButton} />
|
<AttachmentButton images={images} setImages={setImages} ToolbarButton={ToolbarButton} />
|
||||||
|
<Tooltip placement="top" title={expended ? t('chat.input.collapse') : t('chat.input.expand')} arrow>
|
||||||
|
<ToolbarButton type="text" onClick={onToggleExpended}>
|
||||||
|
{expended ? <FullscreenExitOutlined /> : <FullscreenOutlined />}
|
||||||
|
</ToolbarButton>
|
||||||
|
</Tooltip>
|
||||||
{showInputEstimatedTokens && (
|
{showInputEstimatedTokens && (
|
||||||
<TextCount>
|
<TextCount>
|
||||||
<Tooltip title={t('chat.input.context_count.tip') + ' | ' + t('chat.input.estimated_tokens.tip')}>
|
<Tooltip title={t('chat.input.context_count.tip') + ' | ' + t('chat.input.estimated_tokens.tip')}>
|
||||||
<Tag
|
<StyledTag>
|
||||||
style={{
|
|
||||||
cursor: 'pointer',
|
|
||||||
borderRadius: '6px',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
padding: '2px 8px',
|
|
||||||
borderWidth: 0.5
|
|
||||||
}}>
|
|
||||||
<i className="iconfont icon-history" style={{ marginRight: '3px' }} />
|
<i className="iconfont icon-history" style={{ marginRight: '3px' }} />
|
||||||
{assistant?.settings?.contextCount ?? DEFAULT_CONEXTCOUNT}
|
{assistant?.settings?.contextCount ?? DEFAULT_CONEXTCOUNT}
|
||||||
<Divider type="vertical" style={{ marginTop: 2, marginLeft: 5, marginRight: 5 }} />↑{inputTokenCount}
|
<Divider type="vertical" style={{ marginTop: 2, marginLeft: 5, marginRight: 5 }} />↑{inputTokenCount}
|
||||||
<span style={{ margin: '0 2px' }}>/</span>
|
<span style={{ margin: '0 2px' }}>/</span>
|
||||||
{estimateTokenCount}
|
{estimateTokenCount}
|
||||||
</Tag>
|
</StyledTag>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</TextCount>
|
</TextCount>
|
||||||
)}
|
)}
|
||||||
@ -246,6 +264,12 @@ const Inputbar: FC<Props> = ({ assistant, setActiveTopic }) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TextareaStyle: CSSProperties = {
|
||||||
|
paddingLeft: 0,
|
||||||
|
padding: '10px 15px 8px',
|
||||||
|
transition: 'all 0.3s ease'
|
||||||
|
}
|
||||||
|
|
||||||
const Container = styled.div`
|
const Container = styled.div`
|
||||||
border: 1px solid var(--color-border-soft);
|
border: 1px solid var(--color-border-soft);
|
||||||
transition: all 0.3s ease;
|
transition: all 0.3s ease;
|
||||||
@ -285,12 +309,17 @@ const ToolbarMenu = styled.div`
|
|||||||
`
|
`
|
||||||
|
|
||||||
const ToolbarButton = styled(Button)`
|
const ToolbarButton = styled(Button)`
|
||||||
width: 32px;
|
width: 30px;
|
||||||
height: 32px;
|
height: 30px;
|
||||||
font-size: 18px;
|
font-size: 17px;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
transition: all 0.3s ease;
|
transition: all 0.3s ease;
|
||||||
color: var(--color-icon);
|
color: var(--color-icon);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0;
|
||||||
&.anticon {
|
&.anticon {
|
||||||
transition: all 0.3s ease;
|
transition: all 0.3s ease;
|
||||||
color: var(--color-icon);
|
color: var(--color-icon);
|
||||||
@ -313,4 +342,13 @@ const TextCount = styled.div`
|
|||||||
user-select: none;
|
user-select: none;
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const StyledTag = styled(Tag)`
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: 6px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-width: 0.5;
|
||||||
|
`
|
||||||
|
|
||||||
export default Inputbar
|
export default Inputbar
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user