Class: PhlexKit::Button

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/button/button.rb

Overview

Button, ported from ruby_ui's RubyUI::Button and matched to shadcn/ui's current button. Renders a

Constant Summary collapse

VARIANTS =

variant => modifier class. Default is :primary (the filled brand button).

{
  primary: "primary",
  secondary: "secondary",
  destructive: "destructive",
  outline: "outline",
  ghost: "ghost",
  link: "link"
}.freeze
SIZES =
{
  xs: "xs",
  sm: "sm",
  md: nil,
  lg: "lg",
  xl: "xl"
}.freeze

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(variant: :primary, size: :md, type: :button, icon: false, href: nil, **attrs) ⇒ Button

Returns a new instance of Button.



35
36
37
38
39
40
41
42
# File 'app/components/phlex_kit/button/button.rb', line 35

def initialize(variant: :primary, size: :md, type: :button, icon: false, href: nil, **attrs)
  @variant = variant.to_sym
  @size = size.to_sym
  @type = type
  @icon = icon
  @href = href
  @attrs = attrs
end

Instance Method Details

#view_template(&block) ⇒ Object



44
45
46
47
48
49
50
# File 'app/components/phlex_kit/button/button.rb', line 44

def view_template(&block)
  if @href
    a(**mix({ href: @href, class: classes }, @attrs), &block)
  else
    button(**mix({ type: @type, class: classes }, @attrs), &block)
  end
end