Class: Polaris::TextStyleComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/polaris/text_style_component.rb

Constant Summary collapse

VARIATION_OPTIONS =
%i[positive negative strong subdued code]
SIZE_DEFAULT =
:default
SIZE_MAPPINGS =
{
  SIZE_DEFAULT => :bodyMd,
  :small => :bodySm
}
SIZE_OPTIONS =
SIZE_MAPPINGS.keys

Constants included from ViewHelper

ViewHelper::POLARIS_HELPERS, ViewHelper::POLARIS_TEXT_STYLES

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods included from ViewHelper

#polaris_body_styles, #polaris_html_classes, #polaris_html_styles, #polaris_icon_source

Methods included from StylesListHelper

#styles_list

Methods included from OptionHelper

#append_option, #prepend_option

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #fetch_or_fallback_nested

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(variation: nil, size: SIZE_DEFAULT, **system_arguments) ⇒ TextStyleComponent

Returns a new instance of TextStyleComponent.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/components/polaris/text_style_component.rb', line 14

def initialize(
  variation: nil,
  size: SIZE_DEFAULT,
  **system_arguments
)
  @variation = variation
  @system_arguments = system_arguments.tap do |opts|
    opts[:as] = :span
    opts[:color] = case variation
    when :subdued then :subdued
    when :positive then :success
    when :negative then :critical
    when :warning then :warning
    end
    opts[:font_weight] = case variation
    when :strong then :semibold
    end
    opts[:variant] = SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)]
  end
end

Instance Method Details

#callObject



35
36
37
38
39
40
41
42
43
# File 'app/components/polaris/text_style_component.rb', line 35

def call
  render(Polaris::TextComponent.new(**@system_arguments)) do
    if @variation == :code
      render(Polaris::InlineCodeComponent.new) { content }
    else
      content
    end
  end
end