Class: PhlexKit::Separator
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::Separator
- Defined in:
- app/components/phlex_kit/separator/separator.rb
Overview
Visual/semantic divider, ported from ruby_ui's RubyUI::Separator. as: picks
the element (div/hr), orientation: is horizontal (default) or vertical, and
decorative: toggles the a11y role (none vs separator). Presentational; attrs
pass through via mix. A bad orientation fails loud (ArgumentError), mirroring
the kit's fail-loud selectors.
Constant Summary collapse
- ORIENTATIONS =
%i[horizontal vertical].freeze
Instance Method Summary collapse
-
#initialize(as: :div, orientation: :horizontal, decorative: true, **attrs) ⇒ Separator
constructor
A new instance of Separator.
- #view_template(&block) ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(as: :div, orientation: :horizontal, decorative: true, **attrs) ⇒ Separator
Returns a new instance of Separator.
10 11 12 13 14 15 16 17 18 |
# File 'app/components/phlex_kit/separator/separator.rb', line 10 def initialize(as: :div, orientation: :horizontal, decorative: true, **attrs) @as = as @orientation = orientation.to_sym unless ORIENTATIONS.include?(@orientation) raise ArgumentError, "Invalid orientation: #{orientation.inspect}" end @decorative = decorative @attrs = attrs end |
Instance Method Details
#view_template(&block) ⇒ Object
20 21 22 |
# File 'app/components/phlex_kit/separator/separator.rb', line 20 def view_template(&block) send(@as, **mix({ role: (@decorative ? "none" : "separator"), class: classes }, @attrs), &block) end |