-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: validações, react-hook-form e toast
- Loading branch information
Showing
13 changed files
with
260 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import { ToastContainer } from 'react-toastify' | ||
import { Router } from './router' | ||
|
||
export const App = () => ( | ||
<Router /> | ||
<> | ||
<Router /> | ||
<ToastContainer position="bottom-right" theme="colored" /> | ||
</> | ||
) |
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 |
---|---|---|
@@ -1,46 +1,2 @@ | ||
import { ReactNode, useEffect, useState } from 'react' | ||
import { InputField, InputFieldProps } from './input-field' | ||
import { Typography } from '../../Typography' | ||
import { Adapters } from './adapter' | ||
import { Label } from './label' | ||
|
||
export type Option = { | ||
value: any | ||
label: string | ||
} | ||
|
||
export type InputProps = InputFieldProps & { | ||
name: string | ||
label?: string | ||
helpText?: ReactNode | ||
options?: Option[] | ||
rows?: number | ||
isMulti?: boolean | ||
} | ||
|
||
export const Input = ({ label, helpText, type = 'text', options, onChange, ...props }: InputProps) => { | ||
const [hasAdapter, setHasAdapter] = useState<boolean>(false) | ||
|
||
useEffect(() => { | ||
setHasAdapter(!!Adapters[type]) | ||
}, [type]) | ||
|
||
let localHelpTextClassName = 'mt-2 !mb-0 text-sm text-gray-500 dark:text-gray-400' | ||
|
||
if (props?.error) { | ||
localHelpTextClassName += ' !text-red-500' | ||
} | ||
|
||
return ( | ||
<div> | ||
{label && <Label name={props.name} label={label} />} | ||
<InputField type={hasAdapter ? 'hidden' : type} id={props.name} onChange={onChange} {...props} /> | ||
{ | ||
hasAdapter && Adapters[type]({ label, helpText, type, options, onChange, ...props }) | ||
} | ||
{helpText && | ||
<Typography id="helper-text-explanation" className={localHelpTextClassName}>{helpText}</Typography> | ||
} | ||
</div> | ||
) | ||
} | ||
export * from './input-controller' | ||
export * from './input' |
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 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
||
import { | ||
Control, Controller, FieldErrors, | ||
} from 'react-hook-form' | ||
import { Input, InputProps } from './input' | ||
|
||
type InputControllerProps = { | ||
control: Control<any> | ||
name: keyof FieldErrors | ||
errors: FieldErrors<any> | ||
size?: number | ||
} & InputProps | ||
|
||
export const InputController = ({ | ||
name, control, errors, size, ...props | ||
}: InputControllerProps) => ( | ||
<Controller | ||
name={name ?? ''} | ||
control={control} | ||
render={({ field: { value, onChange } }) => ( | ||
<Input | ||
name={name} | ||
value={value as unknown as string || ''} | ||
error={!!errors?.[name]} | ||
helpText={<>{errors?.[name]?.message}</>} | ||
onChange={onChange} | ||
width={size ? '100%' : props.width} | ||
{...props} | ||
/> | ||
)} | ||
/> | ||
) | ||
|
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,46 @@ | ||
import { ReactNode, useEffect, useState } from 'react' | ||
import { InputField, InputFieldProps } from './input-field' | ||
import { Typography } from '../../Typography' | ||
import { Adapters } from './adapter' | ||
import { Label } from './label' | ||
|
||
export type Option = { | ||
value: any | ||
label: string | ||
} | ||
|
||
export type InputProps = InputFieldProps & { | ||
name: string | ||
label?: string | ||
helpText?: ReactNode | ||
options?: Option[] | ||
rows?: number | ||
isMulti?: boolean | ||
} | ||
|
||
export const Input = ({ label, helpText, type = 'text', options, onChange, ...props }: InputProps) => { | ||
const [hasAdapter, setHasAdapter] = useState<boolean>(false) | ||
|
||
useEffect(() => { | ||
setHasAdapter(!!Adapters[type]) | ||
}, [type]) | ||
|
||
let localHelpTextClassName = 'mt-2 !mb-0 text-sm text-gray-500 dark:text-gray-400' | ||
|
||
if (props?.error) { | ||
localHelpTextClassName += ' !text-red-500' | ||
} | ||
|
||
return ( | ||
<div> | ||
{label && <Label name={props.name} label={label} />} | ||
<InputField type={hasAdapter ? 'hidden' : type} id={props.name} onChange={onChange} {...props} /> | ||
{ | ||
hasAdapter && Adapters[type]({ label, helpText, type, options, onChange, ...props }) | ||
} | ||
{helpText && | ||
<Typography id="helper-text-explanation" className={localHelpTextClassName}>{helpText}</Typography> | ||
} | ||
</div> | ||
) | ||
} |
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 @@ | ||
export * from 'react-toastify' |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,300;1,400;1,500;1,600;1,700;1,800&family=Space+Grotesk:[email protected]&display=swap'); | ||
@import url('https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0'); | ||
@import 'react-toastify/dist/ReactToastify.css'; | ||
|
||
@tailwind base; | ||
@tailwind components; | ||
|
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
Oops, something went wrong.