Sha256: 99da70a067197c7c3af544ea26ac4f1fa6c96175d748681b3bf04c8ad8dce749

Contents?: true

Size: 1.51 KB

Versions: 24

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

module Ariadne
  # Represents a sequence of tabs which, when clicked, swap between panel contents.
  class TabComponent < Ariadne::Component
    DEFAULT_TAG = :button
    TAG_OPTIONS = [DEFAULT_TAG].freeze

    # The Tab's text.
    #
    # @param kwargs [Hash] The same arguments as <%= link_to_component(Ariadne::Text) %>.
    renders_one :text, Ariadne::Text

    attr_reader :selected

    DEFAULT_CLASSES = "ariadne-border-gray-300 ariadne-border ariadne-shadow ariadne-py-5 ariadne-px-5 ariadne-rounded-md"

    BASE_TAB_CLASSES = "ariadne-whitespace-nowrap ariadne-py-4 ariadne-px-1 ariadne-border-b-2 ariadne-font-medium ariadne-text-sm"

    # @example Default
    #
    #   <%= render(Ariadne::TabComponent.new) { "Example" } %>
    #
    # @param tag [Symbol, String] The rendered tag name.
    # @param selected [Boolean] Whether the tab is selected or not.
    # @param classes [String] <%= link_to_classes_docs %>
    # @param attributes [Hash] <%= link_to_attributes_docs %>
    def initialize(tag: DEFAULT_TAG, selected: false, classes: "", attributes: {})
      @tag = check_incoming_tag(DEFAULT_TAG, tag)
      @classes = class_names(
        DEFAULT_CLASSES,
        classes
      )

      @attributes = attributes
      @attributes[:id] ||= "tabs-tab-#{@tab_idx}"
      @attributes[:"aria-controls"] = "tabs-panel-#{@tab_idx}"
      @attributes[:"aria-current"] = "page" if selected
      @attributes[:selected] = selected
      @classes = class_names(BASE_TAB_CLASSES, classes)
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.10-aarch64-linux app/components/ariadne/tab_component.rb
ariadne_view_components-0.0.9 app/components/ariadne/tab_component.rb
ariadne_view_components-0.0.8 app/components/ariadne/tab_component.rb
ariadne_view_components-0.0.7 app/components/ariadne/tab_component.rb