Sha256: dcc5a61b2bad964396873ca382f27b7904c96fddf1ea968b2a892b227a7e19a2
Contents?: true
Size: 1.33 KB
Versions: 7
Compression:
Stored size: 1.33 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 = "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
7 entries across 7 versions & 1 rubygems