-
-
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
Showing
4 changed files
with
118 additions
and
0 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,19 @@ | ||
import { MessageModal } from '@lobehub/ui'; | ||
import { Button } from 'antd'; | ||
import { useState } from 'react'; | ||
|
||
export default () => { | ||
const [open, setOpen] = useState(false); | ||
return ( | ||
<> | ||
<Button | ||
onClick={() => { | ||
setOpen(true); | ||
}} | ||
> | ||
open | ||
</Button> | ||
<MessageModal open={open} onOpenChange={setOpen} value={'editable text'} /> | ||
</> | ||
); | ||
}; |
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,14 @@ | ||
--- | ||
nav: Components | ||
group: Chat | ||
title: MessageModal | ||
description: MessageModal | ||
--- | ||
|
||
## Default | ||
|
||
<code src="./demos/index.tsx" center></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,84 @@ | ||
import { AimOutlined } from '@ant-design/icons'; | ||
import { Modal } from 'antd'; | ||
import { createStyles } from 'antd-style'; | ||
import { memo } from 'react'; | ||
import { Flexbox } from 'react-layout-kit'; | ||
import useControlledState from 'use-merge-value'; | ||
|
||
import Markdown from '@/Markdown'; | ||
import MessageInput from '@/MessageInput'; | ||
|
||
const useStyles = createStyles(({ css, prefixCls }) => ({ | ||
modal: css` | ||
height: 70%; | ||
.${prefixCls}-modal-header { | ||
margin-bottom: 24px; | ||
} | ||
`, | ||
body: css` | ||
overflow-y: scroll; | ||
max-height: 70vh; | ||
`, | ||
})); | ||
|
||
export interface MessageModalProps { | ||
open?: boolean; | ||
onOpenChange?: (open: boolean) => void; | ||
editing?: boolean; | ||
onEditingChange?: (editing: boolean) => void; | ||
onChange?: (text: string) => void; | ||
value: string; | ||
} | ||
|
||
const MessageModal = memo<MessageModalProps>( | ||
({ editing, open, onOpenChange, onEditingChange, value, onChange }) => { | ||
const { styles } = useStyles(); | ||
|
||
const [isEdit, setTyping] = useControlledState(false, { | ||
value: editing, | ||
onChange: onEditingChange, | ||
}); | ||
|
||
const [expand, setExpand] = useControlledState(false, { | ||
value: open, | ||
onChange: onOpenChange, | ||
}); | ||
|
||
return ( | ||
<Modal | ||
open={expand} | ||
width={800} | ||
onCancel={() => setExpand(false)} | ||
okText={'编辑'} | ||
onOk={() => { | ||
setTyping(true); | ||
}} | ||
footer={isEdit ? null : undefined} | ||
cancelText={'关闭'} | ||
title={ | ||
<Flexbox horizontal align={'center'} gap={4}> | ||
<AimOutlined /> | ||
提示词 | ||
</Flexbox> | ||
} | ||
className={styles.modal} | ||
> | ||
{isEdit ? ( | ||
<MessageInput | ||
onConfirm={(text) => { | ||
setTyping(false); | ||
onChange?.(text); | ||
}} | ||
onCancel={() => setTyping(false)} | ||
defaultValue={value} | ||
height={400} | ||
/> | ||
) : ( | ||
<Markdown className={styles.body}>{value}</Markdown> | ||
)} | ||
</Modal> | ||
); | ||
}, | ||
); | ||
|
||
export default MessageModal; |
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
969867e
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-git-master-lobehub.vercel.app
lobe-ui-lobehub.vercel.app
ui.lobehub.com
lobe-ui.vercel.app