From bd68d2ab21bfcc434812d7a208f8474716388a50 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 12 Sep 2024 14:54:16 +0200 Subject: [PATCH] [Glitch] Change design of embed modal in web UI Port 24ef8255b3f9b44cb54f49bc78fe3382a7070b1a to glitch-soc Signed-off-by: Claire --- .../glitch/components/copy_paste_text.tsx | 90 ++++++++++++++ .../glitch/components/status_action_bar.jsx | 2 +- .../glitch/containers/status_container.js | 7 +- .../glitch/features/onboarding/share.jsx | 63 +--------- .../features/status/components/action_bar.jsx | 2 +- .../features/ui/components/embed_modal.jsx | 101 --------------- .../features/ui/components/embed_modal.tsx | 116 ++++++++++++++++++ .../flavours/glitch/styles/components.scss | 107 +++++++--------- 8 files changed, 254 insertions(+), 234 deletions(-) create mode 100644 app/javascript/flavours/glitch/components/copy_paste_text.tsx delete mode 100644 app/javascript/flavours/glitch/features/ui/components/embed_modal.jsx create mode 100644 app/javascript/flavours/glitch/features/ui/components/embed_modal.tsx diff --git a/app/javascript/flavours/glitch/components/copy_paste_text.tsx b/app/javascript/flavours/glitch/components/copy_paste_text.tsx new file mode 100644 index 00000000000000..053654b6e0f561 --- /dev/null +++ b/app/javascript/flavours/glitch/components/copy_paste_text.tsx @@ -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(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 ( +
+