forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits

button.tsx54 lines, 2.6 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 // Filled variants carry a transparent 1px border and clip their fill
13 // to the padding box: the box matches an outline button's height, and
14 // the visible fill sits 1px inside it like an outline's hairline, so a
15 // filled pill never reads bigger than the bordered pill next to it.
16 // A filled button never gets a border in its own fill colour.
17 default: "border border-transparent bg-primary bg-clip-padding text-primary-foreground hover:bg-primary/90",
18 destructive:
19 "border border-transparent bg-destructive bg-clip-padding text-destructive-foreground hover:bg-destructive/90",
20 outline:
21 "border border-border/70 bg-transparent hover:border-border hover:bg-muted/60 hover:text-foreground",
22 secondary:
23 "border border-transparent bg-secondary bg-clip-padding text-secondary-foreground hover:bg-secondary/80",
24 ghost: "text-foreground/75 hover:bg-accent hover:text-accent-foreground focus-visible:bg-accent",
25 link: "text-primary-text underline-offset-4 hover:underline active:scale-100",
26 },
27 size: {
28 default: "h-9 rounded-lg px-3 py-2",
29 sm: "h-[26px] gap-1 rounded-md px-2 text-xs",
30 lg: "h-10 rounded-md px-8",
31 icon: "h-9 w-9",
32 },
33 },
34 defaultVariants: {
35 variant: "default",
36 size: "default",
37 },
38 },
39);
40
41export type ButtonProps<T extends ValidComponent = "button"> = ComponentProps<
42 typeof ButtonPrimitive<T>
43> &
44 VariantProps<typeof buttonVariants>;
45
46export function Button<T extends ValidComponent = "button">(props: ButtonProps<T>) {
47 const [local, rest] = splitProps(props as ButtonProps, ["class", "variant", "size"]);
48 return (
49 <ButtonPrimitive
50 class={cn(buttonVariants({ variant: local.variant, size: local.size }), local.class)}
51 {...rest}
52 />
53 );
54}