-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31849d6
commit b1303f1
Showing
15 changed files
with
392 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { ActionIcon, ChatInputArea, DraggablePanel, Icon, TokenTag } from '@lobehub/ui'; | ||
import { Button } from 'antd'; | ||
import { Archive, Eraser, Languages } from 'lucide-react'; | ||
import { useState } from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
const View = styled.div` | ||
position: relative; | ||
display: flex; | ||
flex-direction: column; | ||
height: 400px; | ||
`; | ||
|
||
export default () => { | ||
const [expand, setExpand] = useState<boolean>(false); | ||
return ( | ||
<View> | ||
<div style={{ flex: 1 }}></div> | ||
<DraggablePanel expandable={false} fullscreen={expand} minHeight={200} placement="bottom"> | ||
<ChatInputArea | ||
actions={ | ||
<> | ||
<ActionIcon icon={Languages} /> | ||
<ActionIcon icon={Eraser} /> | ||
<TokenTag maxValue={5000} value={1000} /> | ||
</> | ||
} | ||
expand={expand} | ||
footer={<Button icon={<Icon icon={Archive} />} />} | ||
minHeight={200} | ||
onExpandChange={setExpand} | ||
/> | ||
</DraggablePanel> | ||
</View> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
nav: Components | ||
group: Chat | ||
title: ChatInputArea | ||
--- | ||
|
||
## Default | ||
|
||
<code src="./demos/index.tsx" nopadding></code> | ||
|
||
## APIs | ||
|
||
<API></API> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { Button } from 'antd'; | ||
import { Maximize2, Minimize2 } from 'lucide-react'; | ||
import { ReactNode, memo, useCallback, useEffect, useRef, useState } from 'react'; | ||
|
||
import { ActionIcon, TextArea } from '@/index'; | ||
import type { DivProps } from '@/types'; | ||
|
||
import { useStyles } from './style'; | ||
|
||
export interface ChatInputAreaProps extends DivProps { | ||
actions?: ReactNode; | ||
defaultValue?: string; | ||
disabled?: boolean; | ||
expand?: boolean; | ||
footer?: ReactNode; | ||
loading?: boolean; | ||
minHeight?: number; | ||
onExpandChange?: (expand: boolean) => void; | ||
onInputChange?: (value: string) => void; | ||
onSend?: (value: string) => void; | ||
placeholder?: string; | ||
} | ||
|
||
const ChatInputArea = memo<ChatInputAreaProps>( | ||
({ | ||
minHeight = 200, | ||
className, | ||
actions, | ||
footer, | ||
expand, | ||
placeholder = 'Type something to chat...', | ||
onExpandChange, | ||
onSend, | ||
defaultValue = '', | ||
loading, | ||
style, | ||
disabled, | ||
onInputChange, | ||
...props | ||
}) => { | ||
const isChineseInput = useRef(false); | ||
const [value, setValue] = useState<string>(defaultValue); | ||
const { cx, styles } = useStyles(); | ||
|
||
const handleExpandClick = useCallback(() => { | ||
if (onExpandChange) onExpandChange(!expand); | ||
}, [expand]); | ||
|
||
const handleSend = useCallback(() => { | ||
if (disabled) return; | ||
if (onSend) onSend(value); | ||
setValue(''); | ||
}, [disabled, value]); | ||
|
||
useEffect(() => { | ||
if (onInputChange) onInputChange(value); | ||
}, [value]); | ||
|
||
return ( | ||
<section | ||
className={cx(styles.container, className)} | ||
style={{ minHeight, ...style }} | ||
{...props} | ||
> | ||
<div className={styles.actionsBar}> | ||
<div className={styles.actionLeft}>{actions}</div> | ||
<div className={styles.actionsRight}> | ||
<ActionIcon icon={expand ? Minimize2 : Maximize2} onClick={handleExpandClick} /> | ||
</div> | ||
</div> | ||
<TextArea | ||
className={styles.textarea} | ||
defaultValue={defaultValue} | ||
onBlur={(e) => setValue(e.target.value)} | ||
onChange={(e) => setValue(e.target.value)} | ||
onCompositionEnd={() => { | ||
isChineseInput.current = false; | ||
}} | ||
onCompositionStart={() => { | ||
isChineseInput.current = true; | ||
}} | ||
onPressEnter={(e) => { | ||
if (!loading && !e.shiftKey && !isChineseInput.current) { | ||
e.preventDefault(); | ||
handleSend(); | ||
} | ||
}} | ||
placeholder={placeholder} | ||
resize={false} | ||
type="pure" | ||
value={value} | ||
/> | ||
<div className={styles.footerBar}> | ||
{footer} | ||
<Button disabled={disabled} loading={loading} onClick={handleSend} type="primary"> | ||
Send | ||
</Button> | ||
</div> | ||
</section> | ||
); | ||
}, | ||
); | ||
|
||
export default ChatInputArea; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { createStyles } from 'antd-style'; | ||
|
||
export const useStyles = createStyles(({ css }) => { | ||
return { | ||
container: css` | ||
position: relative; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 8px; | ||
height: 100%; | ||
padding: 12px 0 16px; | ||
`, | ||
actionsBar: css` | ||
display: flex; | ||
flex: none; | ||
align-items: center; | ||
justify-content: space-between; | ||
padding: 0 16px; | ||
`, | ||
actionLeft: css` | ||
display: flex; | ||
flex: 1; | ||
gap: 4px; | ||
align-items: center; | ||
justify-content: flex-start; | ||
`, | ||
actionsRight: css` | ||
display: flex; | ||
flex: 0; | ||
gap: 4px; | ||
align-items: center; | ||
justify-content: flex-end; | ||
`, | ||
textarea: css` | ||
flex: 1; | ||
padding: 0 24px; | ||
`, | ||
footerBar: css` | ||
display: flex; | ||
flex: none; | ||
gap: 8px; | ||
align-items: center; | ||
justify-content: flex-end; | ||
padding: 0 24px; | ||
`, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
b1303f1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
lobe-ui – ./
lobe-ui-lobehub.vercel.app
lobe-ui.vercel.app
ui.lobehub.com
lobe-ui-git-master-lobehub.vercel.app