Class: Primer::Alpha::Stack

Inherits:
Component
  • Object
show all
Defined in:
app/components/primer/alpha/stack.rb

Overview

Stack is a layout component that creates responsive horizontal and vertical flows.

Defined Under Namespace

Classes: AlignArg, DirectionArg, GapArg, JustifyArg, PaddingArg, WrapArg

Constant Summary collapse

DEFAULT_TAG =
:div
ARG_CLASSES =
[
  JustifyArg,
  DirectionArg,
  AlignArg,
  WrapArg,
  PaddingArg,
  GapArg
].freeze

Constants inherited from Component

Component::INVALID_ARIA_LABEL_TAGS

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Constants included from Primer::AttributesHelper

Primer::AttributesHelper::PLURAL_ARIA_ATTRIBUTES, Primer::AttributesHelper::PLURAL_DATA_ATTRIBUTES

Instance Method Summary collapse

Methods inherited from Component

deprecated?, generate_id

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from TestSelectorHelper

#add_test_selector

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Methods included from Primer::AttributesHelper

#aria, #data, #extract_data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes

Methods included from ExperimentalSlotHelpers

included

Methods included from ExperimentalRenderHelpers

included

Constructor Details

#initialize(tag: DEFAULT_TAG, justify: JustifyArg::DEFAULT, gap: GapArg::DEFAULT, direction: DirectionArg::DEFAULT, align: AlignArg::DEFAULT, wrap: WrapArg::DEFAULT, padding: PaddingArg::DEFAULT, **system_arguments) ⇒ Stack

Returns a new instance of Stack.

Parameters:

  • tag (Symbol) (defaults to: DEFAULT_TAG)

    Customize the element type of the rendered container.

  • gap (Symbol) (defaults to: GapArg::DEFAULT)

    Specify the gap between children elements in the stack. <%= one_of(Primer::Alpha::Stack::GapArg::OPTIONS) %>

  • direction (Symbol) (defaults to: DirectionArg::DEFAULT)

    Specify the direction for the stack container. <%= one_of(Primer::Alpha::Stack::DirectionArg::OPTIONS) %>

  • align (Symbol) (defaults to: AlignArg::DEFAULT)

    Specify the alignment between items in the cross-axis of the direction. <%= one_of(Primer::Alpha::Stack::AlignArg::OPTIONS) %>

  • wrap (Symbol) (defaults to: WrapArg::DEFAULT)

    Specify whether items are forced onto one line or can wrap onto multiple lines. <%= one_of(Primer::Alpha::Stack::WrapArg::OPTIONS) %>

  • justify (Symbol) (defaults to: JustifyArg::DEFAULT)

    Specify how items will be distributed in the stacking direction. <%= one_of(Primer::Alpha::Stack::JustifyArg::OPTIONS) %>

  • padding (Symbol) (defaults to: PaddingArg::DEFAULT)

    Specify the padding of the stack container. <%= one_of(Primer::Alpha::Stack::PaddingArg::OPTIONS) %>

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'app/components/primer/alpha/stack.rb', line 152

def initialize(
  tag: DEFAULT_TAG,
  justify: JustifyArg::DEFAULT,
  gap: GapArg::DEFAULT,
  direction: DirectionArg::DEFAULT,
  align: AlignArg::DEFAULT,
  wrap: WrapArg::DEFAULT,
  padding: PaddingArg::DEFAULT,
  **system_arguments
)
  @system_arguments = system_arguments

  @system_arguments[:tag] = tag
  @system_arguments[:classes] = class_names(
    @system_arguments.delete(:classes),
    "Stack"
  )

  @system_arguments[:data] = merge_data(
    @system_arguments, {
      data: {
        **JustifyArg.for(justify).to_data_attributes,
        **GapArg.for(gap).to_data_attributes,
        **DirectionArg.for(direction).to_data_attributes,
        **AlignArg.for(align).to_data_attributes,
        **WrapArg.for(wrap).to_data_attributes,
        **PaddingArg.for(padding).to_data_attributes,
      }
    }
  )
end