Class: KozenetUi::ButtonComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/kozenet_ui/button_component.rb

Overview

Apple-inspired button component with smooth interactions Supports multiple variants, sizes, and states

rubocop:disable Metrics/ClassLength

Examples:

Basic usage

<%= render KozenetUi::ButtonComponent.new(variant: :primary) do %>
  Click me
<% end %>

With helper

<%= kz_button(variant: :primary, size: :lg) { "Sign up" } %>

With icon slot

<%= kz_button(variant: :secondary) do |button| %>
  <% button.with_icon do %>
    <svg>...</svg>
  <% end %>
  Save changes
<% end %>

As link

<%= kz_button(variant: :ghost, href: "/path") { "Learn more" } %>

Loading state

<%= kz_button(variant: :primary, loading: true) { "Processing..." } %>

Constant Summary

Constants inherited from BaseComponent

KozenetUi::BaseComponent::UNSET

Instance Attribute Summary

Attributes inherited from BaseComponent

#html_options, #size, #variant

Instance Method Summary collapse

Constructor Details

#initialize(variant: :primary, size: :md, type: :button, href: nil, disabled: false, loading: false, full_width: false, html_options: {}) ⇒ ButtonComponent

rubocop:disable Metrics/ParameterLists



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/components/kozenet_ui/button_component.rb', line 33

def initialize(
  variant: :primary,
  size: :md,
  type: :button,
  href: nil,
  disabled: false,
  loading: false,
  full_width: false,
  html_options: {}
)
  super(variant: variant, size: size, **html_options)
  @type = type
  @href = href
  @disabled = disabled
  @loading = loading
  @full_width = full_width
end

Instance Method Details

#callObject

rubocop:enable Metrics/ParameterLists



52
53
54
55
56
57
58
# File 'app/components/kozenet_ui/button_component.rb', line 52

def call
  if link?
    link_tag
  else
    button_tag
  end
end