11'use client'
22
33import { useState } from 'react'
4- import { Box , Button , Snackbar , TextField , Tooltip } from '@mui/material'
4+ import { Box , Button , Snackbar , TextField , Tooltip , InputAdornment } from '@mui/material'
5+ import { styled } from '@mui/material/styles'
6+ import AccountCircle from '@mui/icons-material/AccountCircle' ;
57import { encrypt } from "./encryptAction"
8+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
9+ import { faClipboard } from "@fortawesome/free-regular-svg-icons"
610
711export const EncryptionForm = ( ) => {
812 const [ inputText , setInputText ] = useState ( '' )
@@ -11,18 +15,30 @@ export const EncryptionForm = () => {
1115
1216 const handleSubmit = async ( event : React . FormEvent ) => {
1317 event . preventDefault ( )
14- const encrypted = await encrypt ( inputText )
15- setEncryptedText ( encrypted )
18+ if ( inputText . length > 0 ) {
19+ const encrypted = await encrypt ( inputText )
20+ setEncryptedText ( encrypted )
21+ } else {
22+ setEncryptedText ( "" )
23+ }
1624 }
1725
1826 const handleCopy = ( ) => {
19- navigator . clipboard . writeText ( encryptedText )
20- setOpenSnackbar ( true )
27+ if ( encryptedText . length > 0 ) {
28+ navigator . clipboard . writeText ( encryptedText )
29+ setOpenSnackbar ( true )
30+ }
2131 }
2232
2333 const handleCloseSnackbar = ( ) => {
2434 setOpenSnackbar ( false )
2535 }
36+
37+ const EncryptedValueTextField = styled ( TextField ) ( {
38+ '& .MuiInputBase-root' : {
39+ backgroundColor : '#F8F8F8'
40+ }
41+ } )
2642
2743 return < Box
2844 component = "form"
@@ -51,13 +67,28 @@ export const EncryptionForm = () => {
5167 > Encrypt</ Button >
5268
5369 < Tooltip title = "Click to copy to clipboard" >
54- < TextField
70+ < EncryptedValueTextField
5571 value = { encryptedText }
5672 onClick = { handleCopy }
57- sx = { { input : { cursor : 'pointer' } , width : "300px" } }
58- slotProps = { { input : { readOnly : true } } }
59- placeholder = "Encrypted text will appear here"
60- />
73+ sx = { {
74+ width : "300px" ,
75+ input : {
76+ cursor : "pointer" ,
77+ color : "#727272"
78+ }
79+ } }
80+ slotProps = { {
81+ input : {
82+ readOnly : true ,
83+ startAdornment : (
84+ < InputAdornment position = "start" >
85+ < FontAwesomeIcon icon = { faClipboard } size = "lg" />
86+ </ InputAdornment >
87+ )
88+ }
89+ } }
90+ placeholder = "Encrypted text appears here"
91+ />
6192 </ Tooltip >
6293
6394 < Snackbar
0 commit comments