mhsf-dev/src/components/ui/button.tsx

99 lines
4.2 KiB
TypeScript
Raw Normal View History

2024-10-05 09:07:26 -05:00
/*
* MHSF, Minehut Server List
* All external content is rather licensed under the ECA Agreement
* located here: https://list.mlnehut.com/docs/legal/external-content-agreement
*
* All code under MHSF is licensed under the MIT License
* by open source contributors
*
* Copyright (c) 2024 dvelo
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
2024-08-07 16:37:54 -05:00
import * as React from "react";
import { Slot } from "@radix-ui/react-slot";
import { cva, type VariantProps } from "class-variance-authority";
2024-07-23 18:49:21 -05:00
2024-08-07 16:37:54 -05:00
import { cn } from "@/lib/utils";
2024-07-23 18:49:21 -05:00
const buttonVariants = cva(
2024-08-24 12:37:08 -05:00
"inline-flex items-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
2024-07-23 18:49:21 -05:00
{
variants: {
variant: {
2024-08-07 16:37:54 -05:00
default:
"bg-primary text-primary-foreground hover:bg-primary/90 focus:ring-4 focus:ring-neutral-300 focus:ring-offset-current dark:focus:ring-neutral-500 duration-150 ease-in-out transition-all",
2024-07-23 18:49:21 -05:00
destructive:
2024-08-07 16:37:54 -05:00
"bg-destructive text-destructive-foreground hover:bg-destructive/90 focus:ring-4 focus:ring-red-300 focus:ring-offset-current dark:focus:ring-red-950 duration-150 ease-in-out transition-all",
2024-07-23 18:49:21 -05:00
outline:
2024-08-07 16:37:54 -05:00
"border border-input bg-background hover:bg-accent hover:text-accent-foreground focus:ring-4 focus:ring-neutral-100 focus:ring-offset-current dark:focus:ring-neutral-900 duration-150 ease-in-out transition-all",
2024-07-23 18:49:21 -05:00
secondary:
2024-08-07 16:37:54 -05:00
"bg-secondary text-secondary-foreground hover:bg-secondary/80 focus:ring-4 focus:ring-neutral-300 focus:ring-offset-current dark:focus:ring-neutral-500 duration-150 ease-in-out transition-all",
ghost:
"hover:bg-accent hover:text-accent-foreground focus:ring-4 focus:ring-neutral-100 focus:ring-offset-current dark:focus:ring-neutral-900 duration-150 ease-in-out transition-all",
2024-07-23 18:49:21 -05:00
link: "text-primary underline-offset-4 hover:underline",
2024-11-17 21:10:02 -06:00
favorite:
"text-black rounded-lg hover:bg-primary/90 focus:ring-4 focus:ring-yellow-400/60 focus:ring-offset-current dark:focus:ring-yellow-400/60 duration-150 ease-in-out transition-all bg-gradient-to-bl from-yellow-300 via-yellow-500 to-yellow-100",
2024-07-23 18:49:21 -05:00
},
size: {
default: "h-10 px-4 py-2",
sm: "h-9 rounded-md px-3",
lg: "h-11 rounded-md px-8",
icon: "h-10 w-10",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
2024-08-07 16:37:54 -05:00
);
2024-07-23 18:49:21 -05:00
export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
2024-08-07 16:37:54 -05:00
asChild?: boolean;
2024-08-24 12:37:08 -05:00
noJustify?: boolean;
2024-07-23 18:49:21 -05:00
}
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
2024-08-24 12:37:08 -05:00
(
{ className, variant, size, asChild = false, noJustify = false, ...props },
ref
) => {
2024-08-07 16:37:54 -05:00
const Comp = asChild ? Slot : "button";
2024-07-23 18:49:21 -05:00
return (
<Comp
2024-08-24 12:37:08 -05:00
className={cn(
buttonVariants({ variant, size, className }) +
" " +
(noJustify ? "" : "justify-center")
)}
2024-07-23 18:49:21 -05:00
ref={ref}
{...props}
/>
2024-08-07 16:37:54 -05:00
);
2024-07-23 18:49:21 -05:00
}
2024-08-07 16:37:54 -05:00
);
Button.displayName = "Button";
2024-07-23 18:49:21 -05:00
2024-08-07 16:37:54 -05:00
export { Button, buttonVariants };