Class: LightningUiKit::SeparatorComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/lightning_ui_kit/separator_component.rb

Constant Summary collapse

ORIENTATIONS =
%i[horizontal vertical].freeze

Instance Method Summary collapse

Constructor Details

#initialize(orientation: :horizontal, decorative: true, **options) ⇒ SeparatorComponent

Returns a new instance of SeparatorComponent.



4
5
6
7
8
# File 'app/components/lightning_ui_kit/separator_component.rb', line 4

def initialize(orientation: :horizontal, decorative: true, **options)
  @orientation = ORIENTATIONS.include?(orientation) ? orientation : :horizontal
  @decorative = decorative
  @options = options
end

Instance Method Details

#aria_attributesObject



25
26
27
28
29
30
31
# File 'app/components/lightning_ui_kit/separator_component.rb', line 25

def aria_attributes
  if @decorative
    {role: "none"}
  else
    {role: "separator", "aria-orientation": @orientation.to_s}
  end
end

#classesObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/components/lightning_ui_kit/separator_component.rb', line 10

def classes
  orientation_classes =
    if @orientation == :vertical
      "lui:h-full lui:w-px"
    else
      "lui:h-px lui:w-full"
    end

  merge_classes([
    "lui:shrink-0 lui:bg-border",
    orientation_classes,
    @options[:class]
  ].compact.join(" "))
end

#dataObject



33
34
35
# File 'app/components/lightning_ui_kit/separator_component.rb', line 33

def data
  @options[:data] || {}
end