-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add download function and file name to messages attachments (#489)
* Add download function and file name to messages attachments * Fix linting errors
- Loading branch information
1 parent
da8b930
commit a6cd592
Showing
6 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
packages/react/src/components/Attachments/AttachmentMetadata.js
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,39 @@ | ||
import React from 'react'; | ||
import { ActionButton } from '../ActionButton'; | ||
import { Box } from '../Box'; | ||
|
||
const AttachmentMetadata = ({ attachment, url }) => { | ||
const handleDownload = () => { | ||
const anchor = document.createElement('a'); | ||
anchor.href = url; | ||
anchor.download = attachment.title; | ||
|
||
document.body.appendChild(anchor); | ||
anchor.click(); | ||
document.body.removeChild(anchor); | ||
}; | ||
|
||
return ( | ||
<> | ||
<p style={{ margin: 0 }}>{attachment.description}</p> | ||
<Box | ||
style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }} | ||
> | ||
<p style={{ margin: 0, color: 'grey' }}>{attachment.title}</p> | ||
<ActionButton | ||
ghost | ||
icon="download" | ||
size="small" | ||
onClick={handleDownload} | ||
style={{ | ||
marginLeft: '10px', | ||
marginTop: '5px', | ||
color: 'grey', | ||
}} | ||
/> | ||
</Box> | ||
</> | ||
); | ||
}; | ||
|
||
export default AttachmentMetadata; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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