Sha256: 32d932bb6f603bee1b273d85cfc1af821c0cc45b8d34f75383873c8e79b231bf

Contents?: true

Size: 1.34 KB

Versions: 141

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

module Ariadne
  # Adds a flex container to the page.
  class FlexComponent < Ariadne::Component
    DEFAULT_TAG = :div
    TAG_OPTIONS = [DEFAULT_TAG].freeze

    DEFAULT_CLASSES = "ariadne-flex"

    VALID_TYPES = [:row, :column, :row_reverse, :column_reverse].freeze

    # @example Default
    #
    #   <%= render(Ariadne::FlexComponent.new(type: :column)) { "Example" } %>
    #
    # @param tag [Symbol, String] The rendered tag name.
    # @param type [Symbol] <%= one_of(Ariadne::FlexComponent::VALID_TYPES) %>
    # @param classes [String] <%= link_to_classes_docs %>
    # @param attributes [Hash] <%= link_to_attributes_docs %>
    def initialize(tag: DEFAULT_TAG, type:, classes: "", attributes: {})
      @tag = check_incoming_tag(DEFAULT_TAG, tag)
      @type = fetch_or_raise(VALID_TYPES, type)

      flex_class = case @type
      when :row
        "ariadne-flex-row"
      when :column
        "ariadne-flex-col"
      when :row_reverse
        "ariadne-flex-row-reverse"
      when :column_reverse
        "ariadne-flex-col-reverse"
      end

      @classes = class_names(
        DEFAULT_CLASSES,
        classes,
        flex_class,
      )

      @attributes = attributes
    end

    def call
      render(Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes)) { content }
    end
  end
end

Version data entries

141 entries across 141 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.34 app/components/ariadne/flex_component.rb
ariadne_view_components-0.0.34-x86_64-linux app/components/ariadne/flex_component.rb
ariadne_view_components-0.0.34-x86_64-darwin app/components/ariadne/flex_component.rb
ariadne_view_components-0.0.34-x64-mingw32 app/components/ariadne/flex_component.rb
ariadne_view_components-0.0.34-x64-mingw-ucrt app/components/ariadne/flex_component.rb
ariadne_view_components-0.0.34-arm64-darwin app/components/ariadne/flex_component.rb
ariadne_view_components-0.0.34-aarch64-linux app/components/ariadne/flex_component.rb
ariadne_view_components-0.0.33 app/components/ariadne/flex_component.rb
ariadne_view_components-0.0.33-x86_64-linux app/components/ariadne/flex_component.rb
ariadne_view_components-0.0.33-x86_64-darwin app/components/ariadne/flex_component.rb
ariadne_view_components-0.0.33-x64-mingw32 app/components/ariadne/flex_component.rb
ariadne_view_components-0.0.33-x64-mingw-ucrt app/components/ariadne/flex_component.rb
ariadne_view_components-0.0.33-arm64-darwin app/components/ariadne/flex_component.rb
ariadne_view_components-0.0.33-aarch64-linux app/components/ariadne/flex_component.rb
ariadne_view_components-0.0.32 app/components/ariadne/flex_component.rb
ariadne_view_components-0.0.32-x86_64-linux app/components/ariadne/flex_component.rb
ariadne_view_components-0.0.32-x86_64-darwin app/components/ariadne/flex_component.rb
ariadne_view_components-0.0.32-x64-mingw32 app/components/ariadne/flex_component.rb
ariadne_view_components-0.0.32-x64-mingw-ucrt app/components/ariadne/flex_component.rb
ariadne_view_components-0.0.32-arm64-darwin app/components/ariadne/flex_component.rb