Class: Railsboot::DividerComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/railsboot/divider_component.rb

Overview

ViewComponent: renders the divider block.

Constant Summary collapse

DEFAULT_COLOR =

Default color.

"secondary-subtle".freeze
SIZES =

Sizes.

[1, 2, 3, 4, 5, 6].freeze
DEFAULT_SIZE =

Default size.

1

Instance Method Summary collapse

Constructor Details

#initialize(color: DEFAULT_COLOR, size: DEFAULT_SIZE, **html_attributes) ⇒ DividerComponent

Returns a new instance of DividerComponent.

Parameters:

  • color (String) (defaults to: DEFAULT_COLOR)

    the color option

  • size (String) (defaults to: DEFAULT_SIZE)

    the size option

  • html_attributes (Hash)

    additional HTML attributes applied to the rendered element

Options Hash (**html_attributes):

  • :class (String)

    additional CSS classes, merged with the component's own classes



16
17
18
19
20
21
22
23
24
25
26
# File 'app/components/railsboot/divider_component.rb', line 16

def initialize(color: DEFAULT_COLOR, size: DEFAULT_SIZE, **html_attributes)
  @color = color
  @size = size - 1
  @html_attributes = html_attributes

  @html_attributes[:class] = class_names(
    "w-100",
    "position-relative",
    html_attributes[:class]
  ).presence
end

Instance Method Details

#hr_classString

Builds the CSS class string for the horizontal rule element.

Returns:

  • (String)

    the space-separated CSS classes



30
31
32
33
34
# File 'app/components/railsboot/divider_component.rb', line 30

def hr_class
  classes = ["opacity-100", "text-#{@color}"]
  classes << "border border-#{@size} border-#{@color}" if @size > 0
  class_names(*classes)
end