-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #294 from Chainlit/at/CHA-229
refactor: Collapse long message
- Loading branch information
Showing
3 changed files
with
116 additions
and
39 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,52 @@ | ||
import React from 'react'; | ||
import { useToggle } from 'usehooks-ts'; | ||
|
||
import { DownloadRounded, ExpandLess, ExpandMore } from '@mui/icons-material'; | ||
import { | ||
Box, | ||
IconButton, | ||
Collapse as MCollapse, | ||
Stack, | ||
Theme | ||
} from '@mui/material'; | ||
|
||
interface CollapseProps { | ||
children: React.ReactNode; | ||
onDownload: () => void; | ||
} | ||
|
||
const Collapse = ({ children, onDownload }: CollapseProps): JSX.Element => { | ||
const [expandAll, toggleExpandAll] = useToggle(false); | ||
|
||
return ( | ||
<Box> | ||
<MCollapse | ||
sx={{ | ||
border: (theme: Theme) => `3px solid ${theme.palette.divider}`, | ||
borderRadius: 1, | ||
padding: 1 | ||
}} | ||
in={expandAll} | ||
collapsedSize={30} | ||
> | ||
{children} | ||
</MCollapse> | ||
<Stack | ||
sx={{ | ||
position: 'absolute', | ||
right: 0 | ||
}} | ||
direction="row" | ||
> | ||
<IconButton onClick={toggleExpandAll}> | ||
{expandAll ? <ExpandLess /> : <ExpandMore />} | ||
</IconButton> | ||
<IconButton onClick={onDownload}> | ||
<DownloadRounded /> | ||
</IconButton> | ||
</Stack> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default Collapse; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export function exportToFile(data: string, filename: string) { | ||
const blob = new Blob([data], { type: 'text/plain' }); | ||
const url = URL.createObjectURL(blob); | ||
const link = document.createElement('a'); | ||
|
||
link.setAttribute('href', url); | ||
link.setAttribute('download', filename); | ||
link.click(); | ||
|
||
URL.revokeObjectURL(url); | ||
} |