Class: PhlexKit::Separator

Inherits:
BaseComponent show all
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

Methods inherited from BaseComponent

#on

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