-
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.
- Loading branch information
Showing
10 changed files
with
162 additions
and
116 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,43 @@ | ||
"use client"; | ||
import { useState } from "react"; | ||
import { FaAudioDescription } from "react-icons/fa6"; | ||
|
||
import Textarea from "@/components/ui/form/Textarea"; | ||
|
||
export default function Index() { | ||
const [form, setForm] = useState({ | ||
description: "", | ||
logo: "", | ||
error: "", | ||
}); | ||
|
||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
const { name, value } = event.target; | ||
setForm({ ...form, [name]: value }); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div className="flex flex-col gap-4"> | ||
<Textarea | ||
name="description" | ||
value={form.description} | ||
onChange={(event) => setForm({ ...form, description: event.target.value })} | ||
onChange={handleChange} | ||
label="Description" | ||
/> | ||
<Textarea | ||
name="logo" | ||
logo={<FaAudioDescription />} | ||
value={form.logo} | ||
onChange={handleChange} | ||
label="Logo" | ||
/> | ||
<Textarea | ||
name="error" | ||
value={form.error} | ||
onChange={handleChange} | ||
label="Error" | ||
error="error" | ||
/> | ||
</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
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,72 +1,64 @@ | ||
"use client"; | ||
import { forwardRef } from "react"; | ||
import { cn } from "@/lib/utils"; | ||
import { cn, variantInput } from "@/lib/utils"; | ||
import styles from "@/styles/component/form.module.css"; | ||
|
||
const variantInput = { | ||
solid: styles.input, | ||
outline: styles.inputOutline, | ||
underline: styles.inputUnderline, | ||
none: styles.inputNone, | ||
}; | ||
|
||
const Input = forwardRef<any, IInput>( | ||
({ | ||
label, | ||
labelSide = "top", | ||
error, | ||
className, | ||
isLoading = false, | ||
isRequired = false, | ||
onChange, | ||
inputClassName, | ||
logo, | ||
disabled, | ||
variant = "solid", | ||
...props | ||
}) => { | ||
return ( | ||
<div className={`${className} relative`}> | ||
<label | ||
className={cn("flex ", { | ||
"items-center gap-2": labelSide === "left", | ||
"flex-col": labelSide === "top", | ||
})} | ||
> | ||
{label && ( | ||
<span | ||
className={cn(styles.inputLabel, { | ||
"!text-red-500": error, | ||
"w-[80px]": labelSide === "left", | ||
})} | ||
> | ||
{label} {isRequired && <span className="text-red-500">*</span>} | ||
</span> | ||
)} | ||
<span className="flex relative w-full"> | ||
<span className={cn(styles.inputLogo, { "!text-red-500": error })}> | ||
{logo && logo} | ||
</span> | ||
<textarea | ||
{...props} | ||
className={cn(`${variantInput[variant]} ${inputClassName}`, { | ||
"opacity-50 cursor-not-allowed": disabled, | ||
"!pl-8": logo, | ||
"border !border-red-500": error, | ||
})} | ||
disabled={disabled} | ||
/> | ||
</span> | ||
</label> | ||
{error && ( | ||
<span role="alert" className={styles.inputError}> | ||
{error} | ||
export default function Textarea({ | ||
value, | ||
label, | ||
labelSide = "top", | ||
error, | ||
className, | ||
isLoading = false, | ||
isRequired = false, | ||
onChange, | ||
inputClassName, | ||
logo, | ||
disabled, | ||
variant = "solid", | ||
...props | ||
}: IInput) { | ||
return ( | ||
<div className={`${className} relative`}> | ||
<label | ||
className={cn("flex ", { | ||
"items-center gap-2": labelSide === "left", | ||
"flex-col": labelSide === "top", | ||
})} | ||
> | ||
{label && ( | ||
<span | ||
className={cn(styles.inputLabel, { | ||
"!text-red-500": error, | ||
"w-[80px]": labelSide === "left", | ||
})} | ||
> | ||
{label} {isRequired && <span className="text-red-500">*</span>} | ||
</span> | ||
)} | ||
</div> | ||
); | ||
}, | ||
); | ||
|
||
Input.displayName = "Input"; | ||
export default Input; | ||
<span className="flex relative w-full"> | ||
<span className={cn(styles.inputLogoTextarea, { "!text-red-500": error })}> | ||
{logo && logo} | ||
</span> | ||
<textarea | ||
{...props} | ||
defaultValue={value} | ||
className={cn( | ||
`${variantInput[variant]} ${styles.inputDefault} ${inputClassName}`, | ||
{ | ||
"opacity-50 cursor-not-allowed": disabled, | ||
"!pl-8": logo, | ||
"border !border-red-500 !bg-red-500/10": error, | ||
}, | ||
)} | ||
disabled={disabled} | ||
/> | ||
</span> | ||
</label> | ||
{error && ( | ||
<span role="alert" className={styles.inputError}> | ||
{error} | ||
</span> | ||
)} | ||
</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
Oops, something went wrong.