-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
137 additions
and
0 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,125 @@ | ||
import React from 'react' | ||
import Head from 'next/head' | ||
import { motion } from 'framer-motion' | ||
import { | ||
Button, | ||
HStack, | ||
Textarea, | ||
useColorModeValue, | ||
VStack, | ||
} from '@chakra-ui/react' | ||
|
||
const Base64EncodeDecode = () => { | ||
const [text, setText] = React.useState('') | ||
const [base64, setBase64] = React.useState('') | ||
const [isInvalid, setIsInvalid] = React.useState(false) | ||
|
||
const bg = useColorModeValue('blackAlpha.50', 'whiteAlpha.50') | ||
|
||
const handleTextChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => { | ||
if (e.target.value === '') { | ||
setIsInvalid(false) | ||
} | ||
|
||
setText(e.target.value) | ||
} | ||
|
||
const handleBase64 = (type: string) => { | ||
try { | ||
let base64 = '' | ||
|
||
if (type === 'encode') { | ||
const buffer = Buffer.from(text) | ||
base64 = buffer.toString('base64') | ||
} else { | ||
const buffer = Buffer.from(text, 'base64') | ||
base64 = buffer.toString() | ||
} | ||
|
||
setBase64(base64) | ||
} catch (e) { | ||
setIsInvalid(true) | ||
} | ||
} | ||
|
||
const handleBack = () => { | ||
setBase64('') | ||
setIsInvalid(false) | ||
} | ||
|
||
const handleNew = () => { | ||
setText('') | ||
setBase64('') | ||
setIsInvalid(false) | ||
} | ||
|
||
return ( | ||
<> | ||
<Head> | ||
<title>Gerador | Base64 Encode/Decode</title> | ||
<meta | ||
name="description" | ||
content="Base64 Encode e Decode, para facilitar a visualização de base64." | ||
/> | ||
</Head> | ||
|
||
<VStack flex="1" justifyContent="center" spacing="5"> | ||
{base64.length > 0 ? ( | ||
<> | ||
<HStack spacing="5"> | ||
<Button onClick={handleBack}>Editar</Button> | ||
<Button onClick={handleNew}>Novo</Button> | ||
</HStack> | ||
|
||
<Textarea | ||
as={motion.textarea} | ||
key={'base64'} | ||
initial={{ x: 100, opacity: 0 }} | ||
animate={{ x: 0, opacity: 1 }} | ||
transition="0.2s linear" | ||
maxWidth="container.sm" | ||
height="31.25rem" | ||
resize="none" | ||
bg={bg} | ||
value={base64} | ||
/> | ||
</> | ||
) : ( | ||
<> | ||
<HStack spacing="5"> | ||
<Button | ||
disabled={text.length === 0} | ||
onClick={() => handleBase64('encode')} | ||
> | ||
Encode | ||
</Button> | ||
<Button | ||
disabled={text.length === 0} | ||
onClick={() => handleBase64('decode')} | ||
> | ||
Decode | ||
</Button> | ||
</HStack> | ||
|
||
<Textarea | ||
as={motion.textarea} | ||
key={'text'} | ||
initial={{ x: -100, opacity: 0 }} | ||
animate={{ x: 0, opacity: 1 }} | ||
transition="0.2s linear" | ||
maxWidth="container.sm" | ||
height="31.25rem" | ||
resize="none" | ||
bg={bg} | ||
value={text} | ||
onChange={handleTextChange} | ||
isInvalid={isInvalid} | ||
/> | ||
</> | ||
)} | ||
</VStack> | ||
</> | ||
) | ||
} | ||
|
||
export default Base64EncodeDecode |
b9dcb37
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
gerador – ./
gerador.vercel.app
gerador-git-main-avuenja.vercel.app
gerador.progmar.dev
gerador-avuenja.vercel.app
gerador.dev.br
b9dcb37
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gyb