Skip to content

Commit

Permalink
refactor(textarea, sidebar)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeddnyx committed Jul 7, 2024
1 parent e8e9374 commit 90f607b
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 116 deletions.
27 changes: 25 additions & 2 deletions components/form/textarea/index.tsx
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>
);
}
7 changes: 6 additions & 1 deletion components/ui/MobileNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default function MobileNav() {
return (
<Link
key={child.href}
href={child.href}
href={child.isMaintenance ? "#" : child.href}
onClick={() => setIsOpen(false)}
className={cn(
"hover:bg-primary rounded-md p-3 text-light-200 text-sm",
Expand All @@ -91,6 +91,11 @@ export default function MobileNav() {
>
<p className="capitalize text-start ">
{child.title}
{child.isMaintenance && (
<span className="text-red-500 text-xs">
(under maintenance)
</span>
)}
</p>
</Link>
);
Expand Down
12 changes: 10 additions & 2 deletions components/ui/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,23 @@ export default function Sidebar() {
item.children.length > 0 &&
item.children.map((child) => {
const isChildActive = path === child.href;

return (
<Link
key={child.href}
href={child.href}
href={child.isMaintenance ? "#" : child.href}
className={cn("", {
"bg-primary": isChildActive,
})}
>
<p className="capitalize">{child.title}</p>
<p className="capitalize">
{child.title}
{child.isMaintenance && (
<span className="text-red-500 text-xs">
(under maintenance)
</span>
)}
</p>
</Link>
);
})}
Expand Down
2 changes: 1 addition & 1 deletion components/ui/component/AcordionImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function AcordionImage({
</div>
<div
className={cn(
"group-hover:max-h-fit group-hover:py-5 group-hover:md:max-w-fit ",
"group-hover:max-h-fit group-hover:py-10 group-hover:md:max-w-fit ",
{
"max-h-fit py-5 md:max-w-fit": isOpen,
"max-h-0 md:max-w-0": !isOpen,
Expand Down
126 changes: 59 additions & 67 deletions components/ui/form/Textarea.tsx
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>
);
}
42 changes: 34 additions & 8 deletions constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,112 +9,138 @@ export const SIDEBAR_ITEMS: ISidebar[] = [
icon: AiOutlineForm,
title: "Form",
href: "/form",
isMaintenance: false,
children: [
{
title: "Input",
href: ROUTES.formUrl("input"),
isMaintenance: false,
},
{
title: "Input Suggestion",
href: ROUTES.formUrl("input-suggest"),
isMaintenance: false,
},
{
title: "Input Tag",
href: ROUTES.formUrl("input-tag"),
isMaintenance: false,
},
{
title: "Input Dynamic",
href: ROUTES.formUrl("input-dynamic"),
isMaintenance: false,
},
{
title: "Input File",
href: ROUTES.formUrl("input-file"),
isMaintenance: false,
},
{
title: "Textarea",
href: ROUTES.formUrl("textarea"),
isMaintenance: false,
},
{
title: "Dropdown",
href: ROUTES.formUrl("dropdown"),
isMaintenance: false,
},
{
title: "Date Picker",
href: ROUTES.formUrl("date-picker"),
isMaintenance: true,
},
{
title: "Time Picker",
href: ROUTES.formUrl("time-picker"),
isMaintenance: true,
},
// {
// title: "Date Picker",
// href: ROUTES.formUrl("date-picker"),
// },
// {
// title: "Time Picker",
// href: ROUTES.formUrl("time-picker"),
// },
{
title: "Checkbox",
href: ROUTES.formUrl("checkbox"),
isMaintenance: false,
},
{
title: "Otp",
href: ROUTES.formUrl("otp"),
isMaintenance: false,
},
],
},
{
icon: BiSolidComponent,
title: "Component",
href: "/component",
isMaintenance: false,
children: [
{
title: "acordion",
href: ROUTES.componentUrl("acordion"),
isMaintenance: false,
},
{
title: "button",
href: ROUTES.componentUrl("button"),
isMaintenance: false,
},
{
title: "table",
href: ROUTES.componentUrl("table"),
isMaintenance: false,
},
{
title: "modal",
href: ROUTES.componentUrl("modal"),
isMaintenance: false,
},
{
title: "paralax",
href: ROUTES.componentUrl("paralax"),
isMaintenance: false,
},
{
title: "gallery",
href: ROUTES.componentUrl("gallery"),
isMaintenance: false,
},
{
title: "carousel",
href: ROUTES.componentUrl("carousel"),
isMaintenance: true,
},
{
title: "canban",
href: ROUTES.componentUrl("canban"),
isMaintenance: false,
},
],
},
{
icon: MdOutlineAnimation,
title: "Animation",
href: "/animation",
isMaintenance: false,
children: [
{
title: "Scroll Reveal",
href: ROUTES.animationUrl("scroll-reveal"),
isMaintenance: false,
},
{
title: "Scroll Based",
href: ROUTES.animationUrl("scroll-based"),
isMaintenance: false,
},
{
title: "Scroll Opacity",
href: ROUTES.animationUrl("scroll-opacity"),
isMaintenance: true,
},
{
title: "Directionally Aware",
href: ROUTES.animationUrl("directionally-aware"),
isMaintenance: false,
},
],
},
Expand Down
Loading

0 comments on commit 90f607b

Please sign in to comment.