package webui import "kjol/wasmruntime/vdom" // Port of web/kit/Buttons.tsx. const ( ButtonNeutral = "neutral" ButtonWhite = "white" ButtonLightNeutral = "light-neutral" ButtonBlue = "blue" ButtonDarkBlue = "dark-blue" ButtonGreen = "green" ButtonDarkGreen = "dark-green" ButtonRed = "red" ButtonDarkRed = "dark-red" ButtonYellow = "yellow" ButtonOrange = "orange" ButtonPrimary = "primary" ButtonSecondary = "secondary" ButtonGhost = "ghost" ) const btnBase = "inline-flex items-center justify-center gap-2 cursor-pointer text-sm font-normal rounded-default transition disabled:opacity-50 disabled:cursor-not-allowed focus-visible:outline-2 focus-visible:outline-current focus-visible:outline-offset-2" var btnColors = map[string]string{ "neutral": "shadow-xs bg-neutral-700 text-white hover:bg-neutral-800", "white": "shadow-xs bg-surface text-ink border border-line-strong hover:bg-surface-muted", "light-neutral": "shadow-xs bg-surface-muted text-ink border border-line-strong hover:bg-surface-raised", "blue": "shadow-xs bg-sky-700 text-white hover:bg-sky-800", "dark-blue": "shadow-xs bg-sky-900 text-white hover:bg-sky-950", "green": "shadow-xs bg-green-700 text-white hover:bg-green-800", "dark-green": "shadow-xs bg-green-900 text-white hover:bg-green-950", "red": "shadow-xs bg-red-700 text-white hover:bg-red-800", "dark-red": "shadow-xs bg-red-900 text-white hover:bg-red-950", "yellow": "shadow-xs bg-yellow-700 text-white hover:bg-yellow-800", "orange": "shadow-xs bg-orange-600 text-white hover:bg-orange-700", "primary": "shadow-xs bg-primary text-white hover:bg-primary-hover", "secondary": "shadow-none bg-surface-raised text-ink-soft border border-line-strong hover:bg-surface-strong", "ghost": "shadow-none bg-transparent text-ink-soft border-none hover:bg-surface-raised", } var btnOutlineColors = map[string]string{ "neutral": "text-ink-soft", "white": "text-ink-faint", "light-neutral": "text-ink-faint", "blue": "text-sky-700 dark:text-sky-400", "dark-blue": "text-sky-900", "green": "text-green-700 dark:text-green-400", "dark-green": "text-green-900", "red": "text-red-700", "dark-red": "text-red-900", "yellow": "text-yellow-700", "orange": "text-orange-600", "primary": "text-accent", } const btnOutlineBase = "bg-transparent shadow-[inset_0_0_0_1px_currentColor] hover:shadow-[inset_0_0_0_2px_currentColor]" // ButtonProps configures Button. Icon is an icon name (see webui.Icon); Text is // the label. If neither Text nor children are given the button is icon-only. type ButtonProps struct { Color string Outline bool Small bool Icon string Text string Type string Disabled bool Title string Class string OnClick func() } func buttonClass(p ButtonProps) string { c := btnBase if p.Outline { oc := btnOutlineColors[p.Color] if oc == "" { oc = btnOutlineColors["neutral"] } c = cx(c, btnOutlineBase, oc) } else { cc := btnColors[p.Color] if cc == "" { cc = btnColors["neutral"] } c = cx(c, cc) } hasText := p.Text != "" switch { case p.Small && p.Icon != "": c = cx(c, "py-1 px-3") case p.Small: c = cx(c, "py-1 px-4") case p.Icon != "" && !hasText: c = cx(c, "py-2 px-3") case p.Icon != "": c = cx(c, "py-2 px-5") default: c = cx(c, "py-2 px-8") } return cx(c, p.Class) } // Button renders a styled