-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added button to copy current path to clipboard (#607)
Co-authored-by: Axel Bocciarelli <[email protected]>
- Loading branch information
Showing
3 changed files
with
56 additions
and
40 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useState } from 'react'; | ||
import { FiCheck, FiClipboard } from 'react-icons/fi'; | ||
import styles from './BreadcrumbsBar.module.css'; | ||
|
||
interface Props { | ||
name: string; | ||
path: string; | ||
} | ||
|
||
function CopyableCrumb(props: Props) { | ||
const { name, path } = props; | ||
|
||
const [isPathCopied, setPathCopied] = useState(false); | ||
const CopyIcon = isPathCopied ? FiCheck : FiClipboard; | ||
|
||
return ( | ||
<button | ||
className={styles.crumbButton} | ||
type="button" | ||
title="Copy path to clipboard" | ||
onClick={() => { | ||
navigator.clipboard.writeText(path); | ||
setPathCopied(true); | ||
}} | ||
onPointerOut={() => setPathCopied(false)} | ||
data-current | ||
> | ||
<span className={styles.crumb}>{name}</span> | ||
<CopyIcon className={styles.copyIcon} /> | ||
</button> | ||
); | ||
} | ||
|
||
export default CopyableCrumb; |