Skip to content

Commit 33fedb2

Browse files
committed
Update controls styling
1 parent d0a8d42 commit 33fedb2

File tree

6 files changed

+104
-8
lines changed

6 files changed

+104
-8
lines changed

src/components/controls/Button.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { twMerge } from "tailwind-merge";
44

55
import { RequiredKeys } from "@/types/utility";
66

7-
export const style = cva("flex items-center justify-center transition-colors shadow-sm px-3 py-2 gap-2 rounded-md", {
7+
export const style = cva("flex items-center justify-center transition-colors shadow-sm px-3 py-2 gap-2 rounded-full", {
88
variants: {
99
color: {
10-
secondary: "bg-secondary hover:bg-secondary-dark text-secondary-contrast"
10+
secondary: "bg-secondary hover:bg-secondary-light text-secondary-contrast"
1111
}
1212
}
1313
});

src/components/controls/Input.tsx

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { ForwardedRef, forwardRef, InputHTMLAttributes, useMemo } from "react";
2+
import { cva, VariantProps as GetVariantProps } from "class-variance-authority";
3+
import { twMerge } from "tailwind-merge";
4+
5+
import { RequiredKeys } from "@/types/utility";
6+
7+
export const style = cva("rounded-full py-2 px-3", {
8+
variants: {
9+
variant: {
10+
outlined: "border-2"
11+
},
12+
color: {
13+
primary: ""
14+
},
15+
},
16+
compoundVariants: [
17+
{
18+
className: "border-primary bg-white",
19+
color: "primary",
20+
variant: "outlined"
21+
}
22+
],
23+
defaultVariants: {
24+
color: "primary",
25+
variant: "outlined"
26+
}
27+
});
28+
29+
export type TagProps = Omit<InputHTMLAttributes<HTMLInputElement>, "color">;
30+
export type VariantProps = GetVariantProps<typeof style>;
31+
export type InputProps = TagProps & RequiredKeys<VariantProps, "color" | "variant">;
32+
33+
const Input = forwardRef((
34+
{
35+
className,
36+
color,
37+
variant,
38+
...props
39+
}: InputProps,
40+
ref: ForwardedRef<HTMLInputElement>
41+
) => {
42+
43+
const computedClassName = useMemo(
44+
() => twMerge(style({ color, variant }), className),
45+
[className, color, variant]
46+
);
47+
48+
return (
49+
<input
50+
ref={ref}
51+
className={computedClassName}
52+
{...props}
53+
/>
54+
);
55+
});
56+
57+
export default Input;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { DetailedHTMLProps, ForwardedRef, forwardRef, TextareaHTMLAttributes, useMemo } from "react";
2+
import { twMerge } from "tailwind-merge";
3+
4+
import { RequiredKeys } from "@/types/utility";
5+
6+
import { style, VariantProps as InputVariantProps } from "./Input";
7+
8+
export type TagProps = DetailedHTMLProps<TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>;
9+
export type VariantProps = InputVariantProps;
10+
export type TextAreaProps = TagProps & RequiredKeys<VariantProps, "color" | "variant">;
11+
12+
const TextArea = forwardRef((
13+
{
14+
className,
15+
color,
16+
variant,
17+
...props
18+
}: TextAreaProps,
19+
ref: ForwardedRef<HTMLTextAreaElement>
20+
) => {
21+
22+
const computedClassName = useMemo(
23+
() => twMerge(style({ color, variant }), className),
24+
[className, color, variant]
25+
);
26+
27+
return (
28+
<textarea
29+
ref={ref}
30+
className={computedClassName}
31+
{...props}
32+
/>
33+
);
34+
});
35+
36+
export default TextArea;

src/components/navigation/NavLink.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const NavLink = ({ href, currentHref, children }: NavLinkProps) => {
1111
const active = currentHref === href;
1212
return (
1313
<Link
14-
className="text-lg font-bold py-2 border-y border-primary hover:border-primary-light aria-[current='page']:text-primary-dark aria-[current='page']:border-primary first-of-type:border-t-2 last-of-type:border-b-2 md:border-0 md:first-of-type:border-t-0 md:last-of-type:border-b-0"
14+
className="text-lg font-bold py-2 border-y border-primary hover:border-primary-dark aria-[current='page']:text-primary-light aria-[current='page']:border-primary first-of-type:border-t-2 last-of-type:border-b-2 md:border-0 md:first-of-type:border-t-0 md:last-of-type:border-b-0"
1515
aria-current={active ? "page" : undefined}
1616
color="primary"
1717
href={href}

src/components/pages/front/FeedbackSection.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Button from "@/components/controls/Button";
1212
import Error from "@/components/controls/Error";
1313
import Link from "@/components/navigation/Link";
1414
import { backend } from "@/utils/wretch";
15+
import TextArea from "@/components/controls/TextArea";
1516

1617
const feedbackSchema = z.object({
1718
text: z.string()
@@ -80,11 +81,12 @@ const FeedbackSection = () => {
8081
<form aria-label="feedback-inbox" className="flex flex-col items-center gap-4" onSubmit={submit}>
8182
<AnimatePresence mode="wait">
8283
{(!response || response.success === false) && <motion.div className="flex flex-col items-center w-full gap-4">
83-
<textarea
84-
className="w-full p-4 text-lg bg-white border-2 rounded-md md:text-xl border-primary h-fit"
84+
<TextArea
85+
86+
className="w-full p-4 text-lg rounded-lg md:text-xl h-fit"
8587
placeholder="I would like this feature!"
86-
{...register("text")}
8788
rows={5}
89+
{...register("text")}
8890
/>
8991
<Error className="w-full px-2 text-start" state={formState} name="text" />
9092
<Button type="submit" color="secondary" className="px-5 py-3 text-lg md:text-xl w-fit">

src/components/pages/front/SignupSection.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Button from "@/components/controls/Button";
1313
import Error from "@/components/controls/Error";
1414
import Link from "@/components/navigation/Link";
1515
import { backend } from "@/utils/wretch";
16+
import Input from "@/components/controls/Input";
1617

1718

1819
const signupSchema = z.object({
@@ -105,8 +106,8 @@ const SignupSection = () => {
105106
exit="exit"
106107
>
107108
<div className="w-full">
108-
<input
109-
className="w-full p-4 text-lg bg-white border-2 rounded-md md:text-xl border-primary"
109+
<Input
110+
className="w-full p-4 text-lg md:text-xl"
110111
placeholder="your@email.com"
111112
{...register("email")}
112113
/>

0 commit comments

Comments
 (0)