Skip to content

Commit

Permalink
✨ feat: add MessageModal component
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed May 23, 2023
1 parent 0986c72 commit 969867e
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/MessageModal/demos/index.tsx
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'} />
</>
);
};
14 changes: 14 additions & 0 deletions src/MessageModal/index.md
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>
84 changes: 84 additions & 0 deletions src/MessageModal/index.tsx
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;
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export { default as List } from './List';
export { default as Logo, type LogoProps } from './Logo';
export { default as Markdown, type MarkdownProps } from './Markdown';
export { default as MessageInput, type MessageInputProps } from './MessageInput';
export { default as MessageModal, type MessageModalProps } from './MessageModal';
export { default as SearchBar, type SearchBarProps } from './SearchBar';
export { default as SideNav, type SideNavProps } from './SideNav';
export { default as Snippet, type SnippetProps } from './Snippet';
Expand Down

1 comment on commit 969867e

@vercel
Copy link

@vercel vercel bot commented on 969867e May 23, 2023

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

Please sign in to comment.