Class: Primer::FlexComponent Deprecated
- Defined in:
- app/components/primer/flex_component.rb
Overview
Use <%= link_to_component(Primer::BoxComponent) %> instead.
Before:
“‘erb <%%= render Primer::FlexComponent.new(justify_content: :center) %> <%%= render Primer::FlexComponent.new(inline: true) %> <%%= render Primer::FlexComponent.new(flex_wrap: true) %> <%%= render Primer::FlexComponent.new(align_items: :start) %> <%%= render Primer::FlexComponent.new(direction: :column) %> “`
After:
“‘erb <%%= render Primer::BoxComponent.new(display: :flex, justify_content: :center) %> <%%= render Primer::BoxComponent.new(display: :inline_flex) %> <%%= render Primer::BoxComponent.new(display: :flex, flex_wrap: :wrap) %> <%%= render Primer::BoxComponent.new(display: :flex, align_items: :start) %> <%%= render Primer::BoxComponent.new(display: :flex, direction: :column) %> “`
Use ‘Flex` to make an element lay out its content using the flexbox model. Before using these utilities, you should be familiar with CSS3 Flexible Box spec. If you are not, check out MDN’s guide [Using CSS Flexible Boxes](developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox).
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::INVALID_ARIA_LABEL_TAGS
Constants included from Status::Dsl
Constants included from ViewHelper
Constants included from TestSelectorHelper
TestSelectorHelper::TEST_SELECTOR_TAG
Constants included from FetchOrFallbackHelper
Primer::FetchOrFallbackHelper::InvalidValueError
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(justify_content: JUSTIFY_CONTENT_DEFAULT, inline: INLINE_DEFAULT, flex_wrap: FLEX_WRAP_DEFAULT, align_items: ALIGN_ITEMS_DEFAULT, direction: nil, **system_arguments) ⇒ FlexComponent
constructor
A new instance of FlexComponent.
Methods included from JoinStyleArgumentsHelper
Methods included from TestSelectorHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?
Methods included from ClassNameHelper
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.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/components/primer/flex_component.rb', line 97 def initialize( justify_content: JUSTIFY_CONTENT_DEFAULT, inline: INLINE_DEFAULT, flex_wrap: FLEX_WRAP_DEFAULT, align_items: ALIGN_ITEMS_DEFAULT, direction: nil, **system_arguments ) deprecated_component_warning(new_class: Primer::BoxComponent, version: "0.0.40") @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
#call ⇒ Object
124 125 126 |
# File 'app/components/primer/flex_component.rb', line 124 def call render(Primer::BoxComponent.new(**@system_arguments)) { content } end |