generated from ainunns/laravel-react-ts-inertia-starter
-
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
6 changed files
with
286 additions
and
30 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import { LucideIcon } from "lucide-react"; | ||
import * as React from "react"; | ||
|
||
import UnstyledLink, { UnstyledLinkProps } from "@/Components/UnstyledLink"; | ||
import { cn } from "@/Lib/utils"; | ||
|
||
const ButtonLinkVariant = [ | ||
"primary", | ||
"secondary", | ||
"outline", | ||
"ghost", | ||
"warning", | ||
] as const; | ||
const ButtonLinkSize = ["sm", "base", "lg"] as const; | ||
|
||
type ButtonLinkProps = { | ||
variant?: (typeof ButtonLinkVariant)[number]; | ||
size?: (typeof ButtonLinkSize)[number]; | ||
leftIcon?: LucideIcon; | ||
rightIcon?: LucideIcon; | ||
leftIconClassName?: string; | ||
rightIconClassName?: string; | ||
} & UnstyledLinkProps; | ||
|
||
const ButtonLink = React.forwardRef<HTMLAnchorElement, ButtonLinkProps>( | ||
( | ||
{ | ||
children, | ||
className, | ||
variant = "primary", | ||
size = "base", | ||
leftIcon: LeftIcon, | ||
rightIcon: RightIcon, | ||
leftIconClassName, | ||
rightIconClassName, | ||
...rest | ||
}, | ||
ref, | ||
) => { | ||
return ( | ||
<UnstyledLink | ||
ref={ref} | ||
{...rest} | ||
className={cn( | ||
"inline-flex items-center justify-center rounded-lg font-medium", | ||
"focus:outline-none focus-visible:ring", | ||
"shadow-sm", | ||
"transition-colors duration-75", | ||
//#region //*=========== Size =========== | ||
[ | ||
size === "lg" && [ | ||
"min-h-[3rem] px-3.5 md:min-h-[2.75rem]", | ||
"text-base", | ||
], | ||
size === "base" && [ | ||
"min-h-[2.25rem] px-3 md:min-h-[2.5rem]", | ||
"text-sm md:text-base", | ||
], | ||
size === "sm" && [ | ||
"min-h-[1.75rem] px-2 md:min-h-[2rem]", | ||
"text-xs md:text-sm", | ||
], | ||
], | ||
//#endregion //*======== Size =========== | ||
//#region //*=========== Variants =========== | ||
[ | ||
variant === "primary" && [ | ||
"bg-primary-500 text-white", | ||
"border border-primary-600", | ||
"hover:bg-primary-600 hover:text-white", | ||
"active:bg-primary-700", | ||
"disabled:bg-primary-700", | ||
"focus-visible:ring-primary-400", | ||
], | ||
variant === "secondary" && [ | ||
"bg-secondary-500 text-white", | ||
"border border-secondary-600", | ||
"hover:bg-secondary-600 hover:text-white", | ||
"active:bg-secondary-700", | ||
"disabled:bg-secondary-700", | ||
"focus-visible:ring-secondary-400", | ||
], | ||
variant === "warning" && [ | ||
"bg-amber-500 text-white", | ||
"border border-amber-500", | ||
"hover:bg-amber-600 hover:text-white", | ||
"active:bg-amber-700", | ||
"disabled:bg-amber-700", | ||
"focus-visible:ring-amber-400", | ||
], | ||
variant === "outline" && [ | ||
"text-typo", | ||
"border border-gray-300", | ||
"hover:bg-light focus-visible:ring-primary-400 active:bg-typo-divider disabled:bg-typo-divider", | ||
], | ||
variant === "ghost" && [ | ||
"text-primary-500", | ||
"shadow-none", | ||
"hover:bg-primary-50 focus-visible:ring-primary-400 active:bg-primary-100 disabled:bg-primary-100", | ||
], | ||
], | ||
//#endregion //*======== Variants =========== | ||
"disabled:cursor-not-allowed", | ||
className, | ||
)} | ||
> | ||
{LeftIcon && ( | ||
<div | ||
className={cn([ | ||
size === "lg" && "mr-3", | ||
size === "base" && "mr-2", | ||
size === "sm" && "mr-1", | ||
])} | ||
> | ||
<LeftIcon | ||
size="1em" | ||
className={cn("text-base", leftIconClassName)} | ||
/> | ||
</div> | ||
)} | ||
{children} | ||
{RightIcon && ( | ||
<div | ||
className={cn([ | ||
size === "lg" && "ml-3", | ||
size === "base" && "ml-2", | ||
size === "sm" && "ml-1", | ||
])} | ||
> | ||
<RightIcon | ||
size="1em" | ||
className={cn("text-base", rightIconClassName)} | ||
/> | ||
</div> | ||
)} | ||
</UnstyledLink> | ||
); | ||
}, | ||
); | ||
|
||
export default ButtonLink; |
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 { cn } from "@/Lib/utils"; | ||
import { InertiaLinkProps, Link } from "@inertiajs/react"; | ||
import * as React from "react"; | ||
|
||
export type UnstyledLinkProps = { | ||
href: string; | ||
children: React.ReactNode; | ||
openNewTab?: boolean; | ||
className?: string; | ||
inertiaLinkProps?: Omit<InertiaLinkProps, "href">; | ||
} & React.ComponentPropsWithRef<"a">; | ||
|
||
const UnstyledLink = React.forwardRef<HTMLAnchorElement, UnstyledLinkProps>( | ||
( | ||
{ children, href, openNewTab, className, inertiaLinkProps, ...rest }, | ||
ref, | ||
) => { | ||
const isNewTab = | ||
openNewTab !== undefined | ||
? openNewTab | ||
: href && !href.startsWith("/") && !href.startsWith("#"); | ||
|
||
if (!isNewTab) { | ||
return ( | ||
<Link href={href} ref={ref} className={className} {...inertiaLinkProps}> | ||
{children} | ||
</Link> | ||
); | ||
} | ||
|
||
return ( | ||
<a | ||
ref={ref} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
href={href} | ||
{...rest} | ||
className={cn(className)} | ||
> | ||
{children} | ||
</a> | ||
); | ||
}, | ||
); | ||
|
||
export default UnstyledLink; |
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,6 @@ | ||
import { type ClassValue, clsx } from "clsx"; | ||
import { twMerge } from "tailwind-merge"; | ||
|
||
export function cn(...inputs: ClassValue[]) { | ||
return twMerge(clsx(inputs)); | ||
} |