forked from glitch-soc/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/glitch-soc/mastodon
- Loading branch information
Showing
15 changed files
with
293 additions
and
315 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
43 changes: 43 additions & 0 deletions
43
app/javascript/flavours/glitch/components/copy_icon_button.jsx
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,43 @@ | ||
import PropTypes from 'prop-types'; | ||
import { useState, useCallback } from 'react'; | ||
|
||
import { defineMessages } from 'react-intl'; | ||
|
||
import classNames from 'classnames'; | ||
|
||
import { useDispatch } from 'react-redux'; | ||
|
||
import ContentCopyIcon from '@/material-icons/400-24px/content_copy.svg?react'; | ||
import { showAlert } from 'flavours/glitch/actions/alerts'; | ||
import { IconButton } from 'flavours/glitch/components/icon_button'; | ||
|
||
const messages = defineMessages({ | ||
copied: { id: 'copy_icon_button.copied', defaultMessage: 'Copied to clipboard' }, | ||
}); | ||
|
||
export const CopyIconButton = ({ title, value, className }) => { | ||
const [copied, setCopied] = useState(false); | ||
const dispatch = useDispatch(); | ||
|
||
const handleClick = useCallback(() => { | ||
navigator.clipboard.writeText(value); | ||
setCopied(true); | ||
dispatch(showAlert({ message: messages.copied })); | ||
setTimeout(() => setCopied(false), 700); | ||
}, [setCopied, value, dispatch]); | ||
|
||
return ( | ||
<IconButton | ||
className={classNames(className, copied ? 'copied' : 'copyable')} | ||
title={title} | ||
onClick={handleClick} | ||
iconComponent={ContentCopyIcon} | ||
/> | ||
); | ||
}; | ||
|
||
CopyIconButton.propTypes = { | ||
title: PropTypes.string, | ||
value: PropTypes.string, | ||
className: PropTypes.string, | ||
}; |
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
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
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
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
Oops, something went wrong.