Class: Primer::FlexComponent

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

Overview

:nodoc

Constant Summary collapse

JUSTIFY_CONTENT_DEFAULT =
nil
JUSTIFY_CONTENT_MAPPINGS =
{
  flex_start: "flex-justify-start",
  flex_end: "flex-justify-end",
  center: "flex-justify-center",
  space_between: "flex-justify-between",
  space_around: "flex-justify-around"
}.freeze
JUSTIFY_CONTENT_OPTIONS =
[JUSTIFY_CONTENT_DEFAULT, *JUSTIFY_CONTENT_MAPPINGS.keys].freeze
ALIGN_ITEMS_DEFAULT =
nil
ALIGN_ITEMS_MAPPINGS =
{
  start: "flex-items-start",
  end: "flex-items-end",
  center: "flex-items-center",
  baseline: "flex-items-baseline",
  stretch: "flex-items-stretch"
}.freeze
ALIGN_ITEMS_OPTIONS =
[ALIGN_ITEMS_DEFAULT, *ALIGN_ITEMS_MAPPINGS.keys].freeze
INLINE_DEFAULT =
false
INLINE_OPTIONS =
[INLINE_DEFAULT, true].freeze
FLEX_WRAP_DEFAULT =
nil
FLEX_WRAP_OPTIONS =
[FLEX_WRAP_DEFAULT, true, false].freeze
DEFAULT_DIRECTION =
nil
ALLOWED_DIRECTIONS =
[DEFAULT_DIRECTION, :column, :column_reverse, :row, :row_reverse].freeze

Constants inherited from Component

Component::STATUSES

Constants included from FetchOrFallbackHelper

Primer::FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods inherited from Component

status

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(justify_content: JUSTIFY_CONTENT_DEFAULT, inline: INLINE_DEFAULT, flex_wrap: FLEX_WRAP_DEFAULT, align_items: ALIGN_ITEMS_DEFAULT, direction: nil, **system_arguments) ⇒ FlexComponent

Returns a new instance of FlexComponent.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/components/primer/flex_component.rb', line 35

def initialize(
  justify_content: JUSTIFY_CONTENT_DEFAULT,
  inline: INLINE_DEFAULT,
  flex_wrap: FLEX_WRAP_DEFAULT,
  align_items: ALIGN_ITEMS_DEFAULT,
  direction: nil,
  **system_arguments
)
  @align_items = fetch_or_fallback(ALIGN_ITEMS_OPTIONS, align_items, ALIGN_ITEMS_DEFAULT)
  @justify_content = fetch_or_fallback(JUSTIFY_CONTENT_OPTIONS, justify_content, JUSTIFY_CONTENT_DEFAULT)
  @flex_wrap = fetch_or_fallback(FLEX_WRAP_OPTIONS, flex_wrap, FLEX_WRAP_DEFAULT)

  # Support direction argument that is an array
  @direction =
    if (Array(direction) - ALLOWED_DIRECTIONS).empty?
      direction
    else
      DEFAULT_DIRECTION
    end

  @system_arguments = system_arguments.merge({ direction: @direction }.compact)
  @system_arguments[:classes] = class_names(@system_arguments[:classes], component_class_names)
  @system_arguments[:display] = fetch_or_fallback(INLINE_OPTIONS, inline, INLINE_DEFAULT) ? :inline_flex : :flex
end

Instance Method Details

#callObject



60
61
62
# File 'app/components/primer/flex_component.rb', line 60

def call
  render(Primer::BoxComponent.new(**@system_arguments)) { content }
end