use topcoat::{ Result, view::{Attributes, Child, Class, StaticClass, View, class, component, view}, }; /// The visual style of a [`button`]. /// /// [`Default`] is `ButtonVariant::Primary`, used when no variant is given. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[allow(dead_code)] pub enum ButtonVariant { /// The highlighter-filled button for the main action. #[default] Primary, /// A muted tinted fill for secondary actions. Secondary, /// A neutral hairline button on the card surface. The everyday button. Outline, /// No fill until hovered, for toolbars and inline actions. Ghost, /// A red hairline button for actions that delete data. Destructive, } impl ButtonVariant { /// Classes for the button variant and its interaction states. /// /// Each variant sets its own border color. Keep border colors out of the shared /// base to avoid conflicting classes. fn classes(self) -> StaticClass { match self { Self::Primary => class!( "border-transparent bg-primary text-primary-foreground", "hover:bg-primary/90 active:bg-primary/80", ), Self::Secondary => class!( "border-transparent bg-foreground/5 text-foreground", "hover:bg-foreground/10 active:bg-foreground/15", ), Self::Outline => class!( "border-border bg-card text-foreground", "hover:bg-foreground/5 active:bg-foreground/10", ), Self::Ghost => class!( "border-transparent text-foreground hover:bg-foreground/5 active:bg-foreground/10", ), Self::Destructive => class!( "border-destructive bg-card text-destructive", "hover:bg-destructive/5 active:bg-destructive/10", ), } } } /// The size of a [`button`]. /// /// [`Default`] is `ButtonSize::Md`, used when no size is given. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[allow(dead_code)] pub enum ButtonSize { /// A compact 28px button. Sm, /// The standard 32px button. #[default] Md, /// A prominent 40px button. Lg, /// A square 32px button sized for a single icon. Icon, } impl ButtonSize { /// Classes for the button dimensions. Text size stays the same across sizes. fn classes(self) -> StaticClass { match self { Self::Sm => class!("h-7 gap-1.5 px-2.5"), Self::Md => class!("h-8 gap-2 px-3"), Self::Lg => class!("h-10 gap-2 px-4"), Self::Icon => class!("size-8"), } } } /// Classes shared by button variants and sizes. A border reserves the same space in /// every variant. Focus uses the global `:focus-visible` outline from `styles.css`. const BASE: StaticClass = class!( "inline-flex shrink-0 items-center justify-center rounded-control border", "text-sm font-medium whitespace-nowrap select-none transition-colors duration-150 ease-out", "cursor-pointer disabled:cursor-not-allowed disabled:opacity-50", ); /// Builds the full class list for a button of the given `variant` and `size`. /// /// Use it to give button styling to an element that is not a ` }) }