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
- AS_TAGS =
as:is dispatched dynamically (send) — whitelist the documented elements so it can't reach arbitrary (including private) methods. %i[div hr].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.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/components/phlex_kit/separator/separator.rb', line 13 def initialize(as: :div, orientation: :horizontal, decorative: true, **attrs) @as = as.to_sym unless AS_TAGS.include?(@as) raise ArgumentError, "unknown Separator as: #{@as.inspect} (use one of #{AS_TAGS.join(", ")})" end @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
26 27 28 |
# File 'app/components/phlex_kit/separator/separator.rb', line 26 def view_template(&block) send(@as, **mix({ role: (@decorative ? "none" : "separator"), class: classes }, @attrs), &block) end |