Class: Shadcn::Separator::Component

Inherits:
ApplicationViewComponent show all
Defined in:
app/components/shadcn/separator/component.rb

Overview

Port of registry/new-york-v4/ui/separator.tsx

Reproduces Radix's semantics: a decorative separator is role="none", a meaningful one is role="separator" and only advertises aria-orientation when vertical.

Constant Summary

Constants inherited from ApplicationViewComponent

ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS

Instance Attribute Summary collapse

Attributes inherited from ApplicationViewComponent

#attributes

Instance Method Summary collapse

Methods inherited from ApplicationViewComponent

#call, #css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name

Constructor Details

#initialize(orientation: :horizontal, decorative: true, **attributes) ⇒ Component

Returns a new instance of Component.



23
24
25
26
27
# File 'app/components/shadcn/separator/component.rb', line 23

def initialize(orientation: :horizontal, decorative: true, **attributes)
  @orientation = orientation.to_sym
  @decorative = decorative
  super(**attributes)
end

Instance Attribute Details

#decorativeObject (readonly)

Returns the value of attribute decorative.



21
22
23
# File 'app/components/shadcn/separator/component.rb', line 21

def decorative
  @decorative
end

#orientationObject (readonly)

Returns the value of attribute orientation.



21
22
23
# File 'app/components/shadcn/separator/component.rb', line 21

def orientation
  @orientation
end

Instance Method Details

#element_attributes(**defaults) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'app/components/shadcn/separator/component.rb', line 29

def element_attributes(**defaults)
  semantics =
    if decorative
      { role: "none" }
    else
      { role: "separator", "aria-orientation" => (orientation.to_s if orientation == :vertical) }
    end

  super(**{ "data-orientation" => orientation }.merge(semantics).merge(defaults))
end