-
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
- Loading branch information
1 parent
d35fed0
commit ef5a2cc
Showing
6 changed files
with
99 additions
and
23 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; |
18 changes: 12 additions & 6 deletions
18
packages/react/src/components/Attachments/AudioAttachment.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
24 changes: 15 additions & 9 deletions
24
packages/react/src/components/Attachments/ImageAttachment.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
25 changes: 17 additions & 8 deletions
25
packages/react/src/components/Attachments/VideoAttachment.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
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