Class: Shadcn::Resizable::Handle::Component

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

Overview

The bar between two panels: a role="separator" that can be dragged and driven from the keyboard.

Its own orientation is the opposite of the group's — a row of panels is divided by a vertical line — and role="separator" defaults to horizontal, so the attribute is always written rather than left out.

Constant Summary collapse

GRIP_CLASSES =
"z-10 flex h-4 w-3 items-center justify-center rounded-xs border bg-border"

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

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

Constructor Details

#initialize(with_handle: false, orientation: :horizontal, disabled: false, **attributes) ⇒ Component

with_handle: is upstream's withHandle: the grip a pointer can see, which is off by default there too.



35
36
37
38
39
40
# File 'app/components/shadcn/resizable/handle/component.rb', line 35

def initialize(with_handle: false, orientation: :horizontal, disabled: false, **attributes)
  @with_handle = with_handle
  @orientation = orientation&.to_sym == :vertical ? :vertical : :horizontal
  @disabled = disabled
  super(**attributes)
end

Instance Attribute Details

#disabledObject (readonly)

Returns the value of attribute disabled.



31
32
33
# File 'app/components/shadcn/resizable/handle/component.rb', line 31

def disabled
  @disabled
end

#orientationObject (readonly)

Returns the value of attribute orientation.



31
32
33
# File 'app/components/shadcn/resizable/handle/component.rb', line 31

def orientation
  @orientation
end

#with_handleObject (readonly)

Returns the value of attribute with_handle.



31
32
33
# File 'app/components/shadcn/resizable/handle/component.rb', line 31

def with_handle
  @with_handle
end

Instance Method Details

#callObject



56
57
58
# File 'app/components/shadcn/resizable/handle/component.rb', line 56

def call
  render_element(body: grip)
end

#element_attributes(**defaults) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/components/shadcn/resizable/handle/component.rb', line 42

def element_attributes(**defaults)
  super(**{
    role: "separator",
    # The group's orientation decides the separator's, inverted.
    "aria-orientation" => orientation == :vertical ? "horizontal" : "vertical",
    "aria-disabled" => (disabled.presence && "true"),
    tabindex: (disabled ? "-1" : "0"),
    "data-separator" => "inactive",
    "data-shadcn--resizable-target" => "handle",
    "data-action" => "pointerdown->shadcn--resizable#press keydown->shadcn--resizable#keydown",
    style: merged_style("flex-basis:auto;flex-grow:0;flex-shrink:0")
  }.compact.merge(defaults))
end