forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

button.tsx47 lines, 2.1 KiBHistoryRawDownload
1import { Button as ButtonPrimitive } from "@kobalte/core/button";
2import { cva, type VariantProps } from "class-variance-authority";
3import { type ComponentProps, type ValidComponent, splitProps } from "solid-js";
4import { cn } from "@/lib/cn";
5
6export const buttonVariants = cva(
7 "inline-flex cursor-pointer items-center justify-center gap-1.5 whitespace-nowrap text-sm font-medium transition-all focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background active:scale-[0.98] disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",
8 {
9 variants: {
10 variant: {
11 // Flat (no shadows), neutral fills, subtle hairline outlines.
12 default: "bg-primary text-primary-foreground hover:bg-primary/90",
13 destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
14 outline:
15 "border border-border/70 bg-transparent hover:border-border hover:bg-muted/60 hover:text-foreground",
16 secondary: "border border-border/60 bg-secondary text-secondary-foreground hover:bg-secondary/80",
17 ghost: "text-foreground/75 hover:bg-accent hover:text-accent-foreground focus-visible:bg-accent",
18 link: "text-primary-text underline-offset-4 hover:underline active:scale-100",
19 },
20 size: {
21 default: "h-9 rounded-lg px-3 py-2",
22 sm: "h-[26px] gap-1 rounded-md px-2 text-xs",
23 lg: "h-10 rounded-md px-8",
24 icon: "h-9 w-9",
25 },
26 },
27 defaultVariants: {
28 variant: "default",
29 size: "default",
30 },
31 },
32);
33
34export type ButtonProps<T extends ValidComponent = "button"> = ComponentProps<
35 typeof ButtonPrimitive<T>
36> &
37 VariantProps<typeof buttonVariants>;
38
39export function Button<T extends ValidComponent = "button">(props: ButtonProps<T>) {
40 const [local, rest] = splitProps(props as ButtonProps, ["class", "variant", "size"]);
41 return (
42 <ButtonPrimitive
43 class={cn(buttonVariants({ variant: local.variant, size: local.size }), local.class)}
44 {...rest}
45 />
46 );
47}