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 (https://ruby-ui.com) to full variant/size parity. Renders a

Constant Summary collapse

VARIANTS =

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

{
  primary: "primary",
  secondary: "secondary",
  destructive: "destructive",
  outline: "outline",
  ghost: "ghost",
  link: "link"
}.freeze
SIZES =
{
  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, **attrs) ⇒ Button

Returns a new instance of Button.



33
34
35
36
37
38
39
# File 'app/components/phlex_kit/button/button.rb', line 33

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

Instance Method Details

#view_template(&block) ⇒ Object



41
42
43
# File 'app/components/phlex_kit/button/button.rb', line 41

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