Class: PhlexKit::Heading
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::Heading
- Defined in:
- app/components/phlex_kit/typography/heading.rb
Overview
Heading, ported from ruby_ui's RubyUI::Heading. level: (1–6) picks the
element AND a default size; as: overrides the element; size: (1–9)
overrides the size on ruby_ui's scale (text-xs … text-5xl). Presentational;
attrs pass through via mix. Tailwind → vanilla .pk-heading* (typography.css).
Constant Summary collapse
- SIZES =
%w[1 2 3 4 5 6 7 8 9].freeze
- LEVEL_SIZE =
ruby_ui's level → default size mapping (h1 is big, h4 smaller); 5/6 extend the scale downward — HTML has h1–h6, so all six must map.
{ "1" => "7", "2" => "6", "3" => "5", "4" => "4", "5" => "3", "6" => "2" }.freeze
Instance Method Summary collapse
-
#initialize(level: nil, as: nil, size: nil, **attrs) ⇒ Heading
constructor
A new instance of Heading.
- #view_template(&block) ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(level: nil, as: nil, size: nil, **attrs) ⇒ Heading
Returns a new instance of Heading.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/components/phlex_kit/typography/heading.rb', line 12 def initialize(level: nil, as: nil, size: nil, **attrs) # Fail loud at construction: level 7 previously exploded at render time # with NoMethodError (no h7 element), and 5/6 fell through the size map. unless level.nil? || LEVEL_SIZE.key?(level.to_s) raise ArgumentError, "Invalid heading level: #{level.inspect} — valid: 1–6" end @level = level @as = as @size = size @attrs = attrs end |
Instance Method Details
#view_template(&block) ⇒ Object
24 25 26 |
# File 'app/components/phlex_kit/typography/heading.rb', line 24 def view_template(&block) send(element, **mix({ class: classes }, @attrs), &block) end |