Class: Anchor::TextComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/anchor/text_component.rb

Constant Summary collapse

TAG_DEFAULT =
:div
VARIANT_DEFAULT =
:body_base
VARIANT_MAPPING =
{
  body_lg: "text-lg",
  body_base: "text-base",
  body_sm: "text-sm",
  heading_base: "text-base font-semibold",
  heading_lg: "text-lg font-semibold",
  heading_xl: "text-xl font-semibold",
  heading_2xl: "text-2xl font-semibold",
  heading_3xl: "text-3xl font-semibold",
  heading_4xl: "text-4xl font-semibold",
  subheading_sm: "text-sm font-bold leading-4 uppercase",
  subheading_xs: "text-xs font-bold leading-4 uppercase",
}.freeze
VARIANT_OPTIONS =
VARIANT_MAPPING.keys

Instance Method Summary collapse

Methods inherited from Component

generate_id

Methods included from ViewHelper

#text_prose

Methods included from FetchOrFallbackHelper

#fetch_or_fallback

Constructor Details

#initialize(variant: VARIANT_DEFAULT, tag: TAG_DEFAULT, id: nil, **kwargs) ⇒ TextComponent

Returns a new instance of TextComponent.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/components/anchor/text_component.rb', line 21

def initialize(
  variant: VARIANT_DEFAULT,
  tag: TAG_DEFAULT,
  id: nil,
  **kwargs
)
  @variant = VARIANT_MAPPING[
    fetch_or_fallback(VARIANT_OPTIONS, variant, VARIANT_DEFAULT)
  ]

  @tag = tag
  @id = id

  super
end