({value, style}: IProps)
| 12 | } |
| 13 | |
| 14 | const CopyableSecret = ({value, style}: IProps) => { |
| 15 | const [visible, setVisible] = React.useState(false); |
| 16 | const text = visible ? value : '•••••••••••••••'; |
| 17 | const {snackManager} = useStores(); |
| 18 | const toggleVisibility = () => setVisible((b) => !b); |
| 19 | const copyToClipboard = async () => { |
| 20 | try { |
| 21 | await navigator.clipboard.writeText(value); |
| 22 | snackManager.snack('Copied to clipboard'); |
| 23 | } catch (error) { |
| 24 | console.error('Failed to copy to clipboard:', error); |
| 25 | snackManager.snack('Failed to copy to clipboard'); |
| 26 | } |
| 27 | }; |
| 28 | return ( |
| 29 | <div style={style}> |
| 30 | <IconButton onClick={copyToClipboard} title="Copy to clipboard" size="large"> |
| 31 | <Copy /> |
| 32 | </IconButton> |
| 33 | <IconButton onClick={toggleVisibility} className="toggle-visibility" size="large"> |
| 34 | {visible ? <VisibilityOff /> : <Visibility />} |
| 35 | </IconButton> |
| 36 | <Typography style={{fontFamily: 'monospace', fontSize: 16}}>{text}</Typography> |
| 37 | </div> |
| 38 | ); |
| 39 | }; |
| 40 | |
| 41 | export default CopyableSecret; |
nothing calls this directly
no test coverage detected
searching dependent graphs…