Class: BetterUi::DividerComponent

Inherits:
ApplicationComponent show all
Defined in:
app/components/better_ui/divider_component.rb

Overview

A divider component for visually separating content sections.

Renders a horizontal or vertical divider line with optional centered label text. Supports multiple border styles, color variants, sizes, and spacing options.

Examples:

Basic horizontal divider

<%= render BetterUi::DividerComponent.new %>

Dashed divider with primary color

<%= render BetterUi::DividerComponent.new(style: :dashed, variant: :primary) %>

Divider with centered label

<%= render BetterUi::DividerComponent.new(label: "OR") %>

Divider with left-aligned label

<%= render BetterUi::DividerComponent.new(label: "Section", label_position: :left) %>

Vertical divider

<%= render BetterUi::DividerComponent.new(orientation: :vertical) %>

Thick divider with large spacing

<%= render BetterUi::DividerComponent.new(size: :md, spacing: :xl) %>

Constant Summary collapse

ORIENTATIONS =
%i[horizontal vertical].freeze
STYLES =
%i[solid dashed dotted].freeze
SIZES =
%i[xs sm md].freeze
LABEL_POSITIONS =
%i[left center right].freeze
SPACINGS =
%i[xs sm md lg xl].freeze

Constants inherited from ApplicationComponent

ApplicationComponent::SHADOWS, ApplicationComponent::VARIANTS, ApplicationComponent::VARIANT_BODY_DIVIDE, ApplicationComponent::VARIANT_DIVIDE, ApplicationComponent::VARIANT_HEADER_BG, ApplicationComponent::VARIANT_HEADER_TEXT, ApplicationComponent::VARIANT_HIGHLIGHTED, ApplicationComponent::VARIANT_HOVERABLE, ApplicationComponent::VARIANT_RING, ApplicationComponent::VARIANT_SORT_ICON, ApplicationComponent::VARIANT_STRIPED

Instance Method Summary collapse

Constructor Details

#initialize(orientation: :horizontal, style: :solid, variant: nil, size: :md, label: nil, label_position: :center, spacing: :md, container_classes: nil, **options) ⇒ DividerComponent

Initializes a new divider component.

Parameters:

  • orientation (Symbol) (defaults to: :horizontal) —

    the divider direction (:horizontal, :vertical)

  • style (Symbol) (defaults to: :solid) —

    the border style (:solid, :dashed, :dotted)

  • variant (Symbol, nil) (defaults to: nil) —

    the color variant (nil for default gray)

  • size (Symbol) (defaults to: :md) —

    the border thickness (:xs, :sm, :md)

  • label (String, nil) (defaults to: nil) —

    centered text label for horizontal dividers

  • label_position (Symbol) (defaults to: :center) —

    label alignment (:left, :center, :right)

  • spacing (Symbol) (defaults to: :md) —

    outer margins (:xs, :sm, :md, :lg, :xl)

  • container_classes (String, nil) (defaults to: nil) —

    additional CSS classes

  • options (Hash) —

    additional HTML attributes

Raises:

  • (ArgumentError) —

    if any parameter value is invalid



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/components/better_ui/divider_component.rb', line 46

def initialize(
  orientation: :horizontal,
  style: :solid,
  variant: nil,
  size: :md,
  label: nil,
  label_position: :center,
  spacing: :md,
  container_classes: nil,
  **options
)
  @orientation = validate_orientation(orientation)
  @style = validate_style(style)
  @variant = validate_variant(variant) if variant
  @size = validate_size(size)
  @label = label
  @label_position = validate_label_position(label_position)
  @spacing = validate_spacing(spacing)
  @container_classes = container_classes
  @options = options
end