| // Licensed to the Apache Software Foundation (ASF) under one |
| // or more contributor license agreements. See the NOTICE file |
| // distributed with this work for additional information |
| // regarding copyright ownership. The ASF licenses this file |
| // to you under the Apache License, Version 2.0 (the |
| // "License"); you may not use this file except in compliance |
| // with the License. You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, |
| // software distributed under the License is distributed on an |
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| // KIND, either express or implied. See the License for the |
| // specific language governing permissions and limitations |
| // under the License. |
| |
| import { Button as ButtonPrimitive } from "@base-ui/react/button"; |
| import { type VariantProps, cva } from "class-variance-authority"; |
| |
| import { cn } from "@/lib/utils"; |
| |
| // Spec §7.5 button system: |
| // - default → near-black primary (matches Figma "Add user") |
| // - outline → white card with border |
| // - ghost → text-only, hover tinted |
| // - destructive → soft red tint (not a fill) |
| // - brand → blue CTA for wizard "Continue" / proposal "Submit" |
| // - link → inline text link |
| const buttonVariants = cva( |
| "group/button inline-flex shrink-0 items-center justify-center rounded-md border border-transparent bg-clip-padding text-sm font-semibold whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", |
| { |
| variants: { |
| variant: { |
| default: "bg-primary text-primary-foreground hover:bg-primary/90", |
| outline: |
| "border-border bg-background text-foreground hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50", |
| secondary: |
| "bg-secondary text-secondary-foreground hover:bg-secondary/80 aria-expanded:bg-secondary aria-expanded:text-secondary-foreground", |
| ghost: |
| "text-foreground hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50", |
| destructive: |
| "bg-[color:var(--custos-red-50)] text-[color:var(--custos-red-700)] hover:bg-[color:var(--custos-red-100)] focus-visible:border-destructive/40 focus-visible:ring-destructive/20", |
| brand: "bg-brand text-brand-foreground hover:bg-brand/90", |
| link: "text-brand underline-offset-4 hover:underline", |
| }, |
| size: { |
| default: |
| "h-9 gap-1.5 px-4 has-data-[icon=inline-end]:pr-3 has-data-[icon=inline-start]:pl-3", |
| xs: "h-7 gap-1 rounded-[min(var(--radius-md),8px)] px-2 text-xs in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3", |
| sm: "h-8 gap-1 rounded-[min(var(--radius-md),8px)] px-3 text-[0.8rem] in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2 [&_svg:not([class*='size-'])]:size-3.5", |
| lg: "h-10 gap-1.5 px-5 has-data-[icon=inline-end]:pr-4 has-data-[icon=inline-start]:pl-4", |
| icon: "size-9", |
| "icon-xs": |
| "size-7 rounded-[min(var(--radius-md),8px)] in-data-[slot=button-group]:rounded-md [&_svg:not([class*='size-'])]:size-3", |
| "icon-sm": |
| "size-8 rounded-[min(var(--radius-md),8px)] in-data-[slot=button-group]:rounded-md", |
| "icon-lg": "size-10", |
| }, |
| }, |
| defaultVariants: { |
| variant: "default", |
| size: "default", |
| }, |
| }, |
| ); |
| |
| function Button({ |
| className, |
| variant = "default", |
| size = "default", |
| ...props |
| }: ButtonPrimitive.Props & VariantProps<typeof buttonVariants>) { |
| return ( |
| <ButtonPrimitive |
| data-slot="button" |
| className={cn(buttonVariants({ variant, size, className }))} |
| {...props} |
| /> |
| ); |
| } |
| |
| export { Button, buttonVariants }; |