Class: OkonomiUiKit::Components::Typography

Inherits:
OkonomiUiKit::Component show all
Defined in:
app/helpers/okonomi_ui_kit/components/typography.rb

Constant Summary collapse

TYPOGRAPHY_COMPONENTS =
{
  body1: "p",
  body2: "p",
  h1: "h1",
  h2: "h2",
  h3: "h3",
  h4: "h4",
  h5: "h5",
  h6: "h6"
}.freeze

Instance Attribute Summary

Attributes inherited from OkonomiUiKit::Component

#view

Instance Method Summary collapse

Methods inherited from OkonomiUiKit::Component

#combined_styles, config_class?, config_class_name, config_classes, config_namespace, #config_styles_registry, config_styles_registry, deep_merge, #initialize, #internal_styles_registry, internal_styles_registry, #name, parent_styles_registry, register_styles, resolve_config_classes, #style, #styles, #template_path, #theme_name, #tw_merge, #variant_style

Constructor Details

This class inherits a constructor from OkonomiUiKit::Component

Instance Method Details

#render(text = nil, options = {}, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/helpers/okonomi_ui_kit/components/typography.rb', line 15

def render(text = nil, options = {}, &block)
  options, text = text, nil if block_given?
  options ||= {}
  options = options.with_indifferent_access

  variant = (options.delete(:variant) || "body1").to_sym
  component = (TYPOGRAPHY_COMPONENTS[variant] || "span").to_s
  color = (options.delete(:color) || "default").to_sym

  classes = [
    style(:variants, variant) || "",
    style(:colors, color) || "",
    options.delete(:class) || ""
  ].reject(&:blank?).join(" ")

  view.render(
    template_path,
    text: text,
    options: options,
    variant: variant,
    component: component,
    classes: classes,
    &block
  )
end