Sha256: ecc89bd177756fc155bab2f1d6b22c8b598d25377146dc2d0a4bacdb357994e5

Contents?: true

Size: 1.91 KB

Versions: 23

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true

module Primer
  # Use `ButtonGroup` to render a series of buttons.
  class ButtonGroup < Primer::Component
    status :beta

    # Required list of buttons to be rendered.
    #
    # @param kwargs [Hash] The same arguments as <%= link_to_component(Primer::ButtonComponent) %> except for `size` and `group_item`.
    renders_many :buttons, lambda { |**kwargs|
      kwargs[:group_item] = true
      kwargs[:size] = @size

      Primer::ButtonComponent.new(**kwargs)
    }

    # @example Default
    #
    #   <%= render(Primer::ButtonGroup.new) do |component| %>
    #     <% component.button { "Default" } %>
    #     <% component.button(scheme: :primary) { "Primary" } %>
    #     <% component.button(scheme: :danger) { "Danger" } %>
    #     <% component.button(scheme: :outline) { "Outline" } %>
    #     <% component.button(classes: "custom-class") { "Custom class" } %>
    #   <% end %>
    #
    # @example Sizes
    #
    #   <%= render(Primer::ButtonGroup.new(size: :small)) do |component| %>
    #     <% component.button { "Default" } %>
    #     <% component.button(scheme: :primary) { "Primary" } %>
    #     <% component.button(scheme: :danger) { "Danger" } %>
    #     <% component.button(scheme: :outline) { "Outline" } %>
    #   <% end %>
    #
    # @param variant [Symbol] DEPRECATED. <%= one_of(Primer::ButtonComponent::SIZE_OPTIONS) %>
    # @param size [Symbol] <%= one_of(Primer::ButtonComponent::SIZE_OPTIONS) %>
    # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
    def initialize(variant: nil, size: Primer::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

    def render?
      buttons.any?
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
primer_view_components-0.0.87 app/components/primer/button_group.rb
primer_view_components-0.0.86 app/components/primer/button_group.rb
primer_view_components-0.0.85 app/components/primer/button_group.rb
primer_view_components-0.0.84 app/components/primer/button_group.rb
primer_view_components-0.0.83 app/components/primer/button_group.rb
primer_view_components-0.0.82 app/components/primer/button_group.rb
primer_view_components-0.0.81 app/components/primer/button_group.rb
primer_view_components-0.0.80 app/components/primer/button_group.rb
primer_view_components-0.0.79 app/components/primer/button_group.rb
primer_view_components-0.0.78 app/components/primer/button_group.rb
primer_view_components-0.0.77 app/components/primer/button_group.rb
primer_view_components-0.0.76 app/components/primer/button_group.rb
primer_view_components-0.0.75 app/components/primer/button_group.rb
primer_view_components-0.0.74 app/components/primer/button_group.rb
primer_view_components-0.0.73 app/components/primer/button_group.rb
primer_view_components-0.0.72 app/components/primer/button_group.rb
primer_view_components-0.0.71 app/components/primer/button_group.rb
primer_view_components-0.0.70 app/components/primer/button_group.rb
primer_view_components-0.0.69 app/components/primer/button_group.rb
primer_view_components-0.0.68 app/components/primer/button_group.rb