-
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add copy button for Device Identifier in Grower Details (#207)
* fix: add copy button to grower detail > device identifier * fix: move copyButton and copyNotification to common components folder
- Loading branch information
1 parent
9056e44
commit 7a0037d
Showing
5 changed files
with
117 additions
and
58 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
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,28 @@ | ||
import React from 'react'; | ||
import { IconButton } from '@material-ui/core'; | ||
import FileCopy from '@material-ui/icons/FileCopy'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
copyButton: { | ||
margin: theme.spacing(-2, 0), | ||
}, | ||
})); | ||
|
||
export function CopyButton(props) { | ||
const { value, label, confirmCopy } = props; | ||
const classes = useStyles(); | ||
|
||
return ( | ||
<IconButton | ||
className={classes.copyButton} | ||
title="Copy to clipboard" | ||
onClick={() => { | ||
navigator.clipboard.writeText(value); | ||
confirmCopy(label); | ||
}} | ||
> | ||
<FileCopy fontSize="small" /> | ||
</IconButton> | ||
); | ||
} |
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,45 @@ | ||
import React from 'react'; | ||
import { Snackbar } from '@material-ui/core'; | ||
import { IconButton } from '@material-ui/core'; | ||
import CloseIcon from '@material-ui/icons/Close'; | ||
|
||
const CopyNotification = (props) => { | ||
const { snackbarLabel, snackbarOpen, setSnackbarOpen } = props; | ||
|
||
function handleSnackbarClose(event, reason) { | ||
if (reason === 'clickaway') { | ||
return; | ||
} | ||
setSnackbarOpen(false); | ||
} | ||
|
||
return ( | ||
<> | ||
<Snackbar | ||
anchorOrigin={{ | ||
vertical: 'top', | ||
horizontal: 'right', | ||
}} | ||
key={snackbarLabel.length ? snackbarLabel : undefined} | ||
open={snackbarOpen} | ||
autoHideDuration={2000} | ||
onClose={handleSnackbarClose} | ||
message={`${snackbarLabel} copied to clipboard`} | ||
color="primary" | ||
action={ | ||
<> | ||
<IconButton | ||
size="small" | ||
aria-label="close" | ||
onClick={handleSnackbarClose} | ||
> | ||
<CloseIcon fontSize="small" /> | ||
</IconButton> | ||
</> | ||
} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default CopyNotification; |