Class: Yattho::Beta::ButtonGroup

Inherits:
Component
  • Object
show all
Defined in:
app/components/yattho/beta/button_group.rb

Overview

Use ‘ButtonGroup` to render a series of buttons.

Constant Summary

Constants inherited from Component

Component::INVALID_ARIA_LABEL_TAGS

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods inherited from Component

deprecated?, generate_id

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from TestSelectorHelper

#add_test_selector

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(variant: nil, size: Yattho::ButtonComponent::DEFAULT_SIZE, **system_arguments) ⇒ ButtonGroup

Returns a new instance of ButtonGroup.

Examples:

Default


<%= render(Yattho::Beta::ButtonGroup.new) do |component| %>
  <% component.with_button { "Default" } %>
  <% component.with_button(scheme: :primary) { "Primary" } %>
  <% component.with_button(scheme: :danger) { "Danger" } %>
  <% component.with_button(scheme: :outline) { "Outline" } %>
  <% component.with_button(classes: "custom-class") { "Custom class" } %>
<% end %>

Sizes


<%= render(Yattho::Beta::ButtonGroup.new(size: :small)) do |component| %>
  <% component.with_button { "Default" } %>
  <% component.with_button(scheme: :primary) { "Primary" } %>
  <% component.with_button(scheme: :danger) { "Danger" } %>
  <% component.with_button(scheme: :outline) { "Outline" } %>
<% end %>

Parameters:

  • variant (Symbol) (defaults to: nil)

    DEPRECATED. <%= one_of(Yattho::ButtonComponent::SIZE_OPTIONS) %>

  • size (Symbol) (defaults to: Yattho::ButtonComponent::DEFAULT_SIZE)

    <%= one_of(Yattho::ButtonComponent::SIZE_OPTIONS) %>

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



43
44
45
46
47
48
49
50
51
52
# File 'app/components/yattho/beta/button_group.rb', line 43

def initialize(variant: nil, size: Yattho::ButtonComponent::DEFAULT_SIZE, **system_arguments)
  @size = variant || size
  @system_arguments = deny_tag_argument(**system_arguments)
  @system_arguments[:tag] = :div

  @system_arguments[:classes] = class_names(
    "BtnGroup",
    system_arguments[:classes]
  )
end

Instance Method Details

#render?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'app/components/yattho/beta/button_group.rb', line 54

def render?
  buttons.any?
end