# frozen_string_literal: true module Ariadne # Layout component to control the widths of 1-3 columns class LayoutComponent < Ariadne::Component DEFAULT_TAG = :div DEFAULT_SIDECAR_TAG = :div DEFAULT_ASIDE_TAG = :div DEFAULT_MAIN_TAG = :div DEFAULT_CLASSES = { wrapper: "ariadne-group ariadne-flex ariadne-gap-2 ariadne-flex-col md:ariadne-flex-row", sidecar: "ariadne-w-full md:ariadne-w-1/6", main: "ariadne-grow", aside: "ariadne-w-full md:ariadne-w-1/6", } DEFAULT_ATTRIBUTES = { wrapper: {}, sidecar: {}, main: {}, aside: {}, } renders_many :sidecars renders_many :mains renders_many :asides # @example Default # # <%= render(Ariadne::LayoutComponent.new) { "Example" } %> # # @param tag [Symbol, String] The rendered tag name. # @param classes [String] <%= link_to_classes_docs %> # @param attributes [Hash] <%= link_to_attributes_docs %> def initialize( tag: DEFAULT_TAG, classes: "", attributes: {}, main_tag: DEFAULT_MAIN_TAG, main_classes: "", main_attributes: {}, sidecar_tag: DEFAULT_SIDECAR_TAG, sidecar_classes: "", sidecar_attributes: {}, aside_tag: DEFAULT_ASIDE_TAG, aside_classes: "", aside_attributes: {} ) @tag = check_incoming_tag(DEFAULT_TAG, tag) @classes = merge_class_names(DEFAULT_CLASSES[:wrapper], classes) @attributes = DEFAULT_ATTRIBUTES[:wrapper].merge(attributes) @sidecar_tag = check_incoming_tag(DEFAULT_SIDECAR_TAG, tag) @sidecar_attributes = DEFAULT_ATTRIBUTES[:sidecar].merge(sidecar_attributes) @sidecar_classes = merge_class_names(DEFAULT_CLASSES[:sidecar], sidecar_classes) @main_tag = check_incoming_tag(DEFAULT_MAIN_TAG, tag) @main_attributes = DEFAULT_ATTRIBUTES[:main].merge(main_attributes) @main_classes = merge_class_names(DEFAULT_CLASSES[:main], main_classes) @aside_tag = check_incoming_tag(DEFAULT_ASIDE_TAG, tag) @aside_attributes = DEFAULT_ATTRIBUTES[:aside].merge(aside_attributes) @aside_classes = merge_class_names(DEFAULT_CLASSES[:aside], aside_classes) end end end