-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ front: moved copy link button to own file (#50)
- Loading branch information
1 parent
339d4d7
commit c4a9a6d
Showing
2 changed files
with
46 additions
and
28 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
tdrive/frontend/src/app/views/client/body/drive/modals/public-link/copy-link-button.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,42 @@ | ||
import { useState } from 'react'; | ||
|
||
import Languages from 'features/global/services/languages-service'; | ||
import { copyToClipboard } from '@features/global/utils/CopyClipboard'; | ||
|
||
import { Button } from '@atoms/button/button'; | ||
import { LinkIcon, CheckCircleIcon } from '@heroicons/react/outline'; | ||
|
||
export const CopyLinkButton = (props: { | ||
textToCopy?: string | false; | ||
}) => { | ||
const [didJustCompleteACopy, setDidJustCompleteACopy] = useState<boolean>(false); | ||
const haveTextToCopy = props.textToCopy && props.textToCopy.length > 0 || false; | ||
return ( | ||
<Button | ||
onClick={() => { | ||
if (!haveTextToCopy) return; | ||
copyToClipboard(props.textToCopy as string); | ||
if (!didJustCompleteACopy) { | ||
// No point enqueuing further ones, the first timeout will undo immediately anyway | ||
// so not bothering with useEffect either - tiny window of a tiny leak in improbable use case | ||
setDidJustCompleteACopy(true); | ||
setTimeout(() => setDidJustCompleteACopy(false), 1500); | ||
} | ||
}} | ||
disabled={!haveTextToCopy} | ||
theme={didJustCompleteACopy ? "green" : "primary"} | ||
className="justify-center" | ||
> | ||
{ didJustCompleteACopy | ||
? <CheckCircleIcon className="w-5 mr-2" /> | ||
: <LinkIcon className="w-5 mr-2" /> | ||
} | ||
{Languages.t( | ||
didJustCompleteACopy | ||
? 'components.public-link-copied-info' | ||
: (haveTextToCopy | ||
? "components.public-link-copy" | ||
: "components.public-link-get"))} | ||
</Button> | ||
); | ||
} |
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