forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Glitch] Change design of embed modal in web UI
Port 24ef825 to glitch-soc Signed-off-by: Claire <[email protected]>
- Loading branch information
1 parent
5752c49
commit 73cb02b
Showing
8 changed files
with
258 additions
and
234 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
app/javascript/flavours/glitch/components/copy_paste_text.tsx
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,90 @@ | ||
import { useRef, useState, useCallback } from 'react'; | ||
|
||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import classNames from 'classnames'; | ||
|
||
import ContentCopyIcon from '@/material-icons/400-24px/content_copy.svg?react'; | ||
import { Icon } from 'flavours/glitch/components/icon'; | ||
import { useTimeout } from 'flavours/glitch/hooks/useTimeout'; | ||
|
||
export const CopyPasteText: React.FC<{ value: string }> = ({ value }) => { | ||
const inputRef = useRef<HTMLTextAreaElement>(null); | ||
const [copied, setCopied] = useState(false); | ||
const [focused, setFocused] = useState(false); | ||
const [setAnimationTimeout] = useTimeout(); | ||
|
||
const handleInputClick = useCallback(() => { | ||
setCopied(false); | ||
|
||
if (inputRef.current) { | ||
inputRef.current.focus(); | ||
inputRef.current.select(); | ||
inputRef.current.setSelectionRange(0, value.length); | ||
} | ||
}, [setCopied, value]); | ||
|
||
const handleButtonClick = useCallback( | ||
(e: React.MouseEvent) => { | ||
e.stopPropagation(); | ||
void navigator.clipboard.writeText(value); | ||
inputRef.current?.blur(); | ||
setCopied(true); | ||
setAnimationTimeout(() => { | ||
setCopied(false); | ||
}, 700); | ||
}, | ||
[setCopied, setAnimationTimeout, value], | ||
); | ||
|
||
const handleKeyUp = useCallback( | ||
(e: React.KeyboardEvent) => { | ||
if (e.key !== ' ') return; | ||
void navigator.clipboard.writeText(value); | ||
setCopied(true); | ||
setAnimationTimeout(() => { | ||
setCopied(false); | ||
}, 700); | ||
}, | ||
[setCopied, setAnimationTimeout, value], | ||
); | ||
|
||
const handleFocus = useCallback(() => { | ||
setFocused(true); | ||
}, [setFocused]); | ||
|
||
const handleBlur = useCallback(() => { | ||
setFocused(false); | ||
}, [setFocused]); | ||
|
||
return ( | ||
<div | ||
className={classNames('copy-paste-text', { copied, focused })} | ||
tabIndex={0} | ||
role='button' | ||
onClick={handleInputClick} | ||
onKeyUp={handleKeyUp} | ||
> | ||
<textarea | ||
readOnly | ||
value={value} | ||
ref={inputRef} | ||
onClick={handleInputClick} | ||
onFocus={handleFocus} | ||
onBlur={handleBlur} | ||
/> | ||
|
||
<button className='button' onClick={handleButtonClick}> | ||
<Icon id='copy' icon={ContentCopyIcon} />{' '} | ||
{copied ? ( | ||
<FormattedMessage id='copypaste.copied' defaultMessage='Copied' /> | ||
) : ( | ||
<FormattedMessage | ||
id='copypaste.copy_to_clipboard' | ||
defaultMessage='Copy to clipboard' | ||
/> | ||
)} | ||
</button> | ||
</div> | ||
); | ||
}; |
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
101 changes: 0 additions & 101 deletions
101
app/javascript/flavours/glitch/features/ui/components/embed_modal.jsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.