-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom hooks and validation schemas; refactor button components
- Loading branch information
1 parent
e4f2b03
commit cc57ed5
Showing
14 changed files
with
214 additions
and
316 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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import { ButtonSecondary } from "@/components/Button"; | ||
import { Button } from "@/components/Button"; | ||
|
||
export default function NotFound() { | ||
return ( | ||
<div className="mb-16 mt-20"> | ||
<h1 className="mx-0 mt-0 bg-gradient-to-r from-[#ff7170] to-[#ffe57f] box-decoration-clone bg-clip-text text-4xl font-black tracking-[-0.03em] text-fill-transparent">404 - Page not found</h1> | ||
<p className="mb-4 mt-2 text-lg text-neutral-700 dark:text-neutral-400">We're sorry — we can't find the page you're looking for.</p> | ||
<ButtonSecondary href="/">Go home</ButtonSecondary> | ||
<Button variant="secondary" href="/"> | ||
Go home | ||
</Button> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,42 @@ | ||
import { cva, VariantProps } from "class-variance-authority"; | ||
import Link from "next/link"; | ||
import React from "react"; | ||
import { Icons } from "@/components/Icons"; | ||
import { cn } from "@/lib/utils"; | ||
|
||
export interface ButtonProps extends React.HTMLAttributes<HTMLButtonElement | HTMLAnchorElement> { | ||
export const buttonVariants = cva("group flex w-fit items-center rounded-md px-4 py-2 font-medium duration-200 disabled:cursor-not-allowed disabled:opacity-50 motion-reduce:transition-none", { | ||
variants: { | ||
variant: { | ||
primary: "bg-blue-500 text-white hover:bg-blue-600", | ||
secondary: "bg-neutral-200 text-neutral-700 hover:bg-neutral-300 dark:bg-white/10 dark:text-white dark:hover:bg-white/15", | ||
tertiary: "border text-neutral-700 hover:bg-[#f2f3f5] dark:border-neutral-800 dark:bg-[#161617] dark:text-white dark:hover:border-neutral-700 dark:hover:bg-[#202021]", | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: "primary", | ||
}, | ||
}); | ||
|
||
export interface ButtonProps extends React.HTMLAttributes<HTMLButtonElement | HTMLAnchorElement>, VariantProps<typeof buttonVariants> { | ||
href?: string; | ||
children: React.ReactNode; | ||
icon?: boolean; | ||
type?: "button" | "submit" | "reset"; | ||
disabled?: boolean; | ||
} | ||
|
||
export const buttonPrimaryStyles = "group flex w-fit items-center rounded-md bg-blue-500 px-4 py-2 font-medium text-white duration-200 hover:bg-blue-600 disabled:cursor-not-allowed disabled:opacity-50 motion-reduce:transition-none"; | ||
|
||
export function ButtonPrimary({ href, children, icon = true, ...props }: ButtonProps) { | ||
if (href) { | ||
return ( | ||
<Link href={href} {...props} className={cn(buttonPrimaryStyles, props.className || "")}> | ||
{children} | ||
{icon && ( | ||
<svg className="ml-2 size-4 duration-200 group-hover:translate-x-1 motion-reduce:transition-none motion-reduce:group-hover:translate-x-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}> | ||
<path strokeLinecap="round" strokeLinejoin="round" d="M13 7l5 5m0 0l-5 5m5-5H6" /> | ||
</svg> | ||
)} | ||
</Link> | ||
); | ||
} | ||
return ( | ||
<button {...props} className={cn(buttonPrimaryStyles, props.className || "")} type="button"> | ||
{children} | ||
{icon && ( | ||
<svg className="ml-2 size-4 duration-200 group-hover:translate-x-1 motion-reduce:transition-none motion-reduce:group-hover:translate-x-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}> | ||
<path strokeLinecap="round" strokeLinejoin="round" d="M13 7l5 5m0 0l-5 5m5-5H6" /> | ||
</svg> | ||
)} | ||
</button> | ||
); | ||
type?: HTMLButtonElement["type"]; | ||
disabled?: HTMLButtonElement["disabled"]; | ||
} | ||
|
||
export const buttonSecondaryStyles = "group flex w-fit items-center rounded-md bg-neutral-200 px-4 py-2 font-medium text-neutral-700 duration-200 hover:bg-neutral-300 disabled:cursor-not-allowed disabled:opacity-50 motion-reduce:transition-none dark:bg-white/10 dark:text-white dark:hover:bg-white/15"; | ||
|
||
export function ButtonSecondary({ href, children, icon = true, ...props }: ButtonProps) { | ||
if (href) { | ||
return ( | ||
<Link href={href} {...props} className={cn(buttonSecondaryStyles, props.className || "")}> | ||
{children} | ||
{icon && ( | ||
<svg className="ml-2 size-4 duration-200 group-hover:translate-x-1 motion-reduce:transition-none motion-reduce:group-hover:translate-x-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}> | ||
<path strokeLinecap="round" strokeLinejoin="round" d="M13 7l5 5m0 0l-5 5m5-5H6" /> | ||
</svg> | ||
)} | ||
</Link> | ||
); | ||
} else { | ||
return ( | ||
<button {...props} className={cn(buttonSecondaryStyles, props.className || "")} type="button"> | ||
{children} | ||
{icon && ( | ||
<svg className="ml-2 size-4 duration-200 group-hover:translate-x-1 motion-reduce:transition-none motion-reduce:group-hover:translate-x-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}> | ||
<path strokeLinecap="round" strokeLinejoin="round" d="M13 7l5 5m0 0l-5 5m5-5H6" /> | ||
</svg> | ||
)} | ||
</button> | ||
); | ||
} | ||
} | ||
|
||
export const buttonTertiaryStyles = "group flex w-fit items-center rounded-md border px-4 py-2 font-medium text-neutral-700 duration-200 hover:bg-[#f2f3f5] disabled:cursor-not-allowed disabled:opacity-50 motion-reduce:transition-none dark:border-neutral-800 dark:bg-[#161617] dark:text-white dark:hover:border-neutral-700 dark:hover:bg-[#202021]"; | ||
|
||
export function ButtonTertiary({ href, children, icon = true, ...props }: ButtonProps) { | ||
export const Button = React.forwardRef<HTMLButtonElement | HTMLAnchorElement, ButtonProps>(({ href, children, icon = true, variant, ...props }, ref) => { | ||
if (href) { | ||
return ( | ||
<Link href={href} {...props} className={cn(buttonTertiaryStyles, props.className || "")}> | ||
<Link href={href} {...props} ref={ref as React.Ref<HTMLAnchorElement>} className={cn(buttonVariants({ variant }), props.className || "")}> | ||
{children} | ||
{icon && ( | ||
<svg className="ml-2 size-4 duration-200 group-hover:translate-x-1 motion-reduce:transition-none motion-reduce:group-hover:translate-x-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}> | ||
<path strokeLinecap="round" strokeLinejoin="round" d="M13 7l5 5m0 0l-5 5m5-5H6" /> | ||
</svg> | ||
)} | ||
{icon && <Icons.ArrowRight className="ml-2 size-4 duration-200 group-hover:translate-x-1 motion-reduce:transition-none motion-reduce:group-hover:translate-x-0" />} | ||
</Link> | ||
); | ||
} | ||
return ( | ||
<button {...props} className={cn(buttonTertiaryStyles, props.className || "")} type="button"> | ||
<button {...props} ref={ref as React.Ref<HTMLButtonElement>} className={cn(buttonVariants({ variant }), props.className || "")}> | ||
{children} | ||
{icon && ( | ||
<svg className="ml-2 size-4 duration-200 group-hover:translate-x-1 motion-reduce:transition-none motion-reduce:group-hover:translate-x-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}> | ||
<path strokeLinecap="round" strokeLinejoin="round" d="M13 7l5 5m0 0l-5 5m5-5H6" /> | ||
</svg> | ||
)} | ||
{icon && <Icons.ArrowRight className="ml-2 size-4 duration-200 group-hover:translate-x-1 motion-reduce:transition-none motion-reduce:group-hover:translate-x-0" />} | ||
</button> | ||
); | ||
} | ||
}); |
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.