Class: Shadcn::Resizable::Panel::Component

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

Overview

One panel. Upstream carries no classes at all — the package writes an inline style — so what is reproduced here is that style, minus the part of it that resets borders and padding the package cannot know a caller wants.

A size is a share, not a pixel: flex-grow against flex-basis: 0 is exactly the proportional layout the package computes, which is why the browser does the resizing and the controller only writes two numbers.

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(default_size: nil, min_size: nil, max_size: nil, **attributes) ⇒ Component

Sizes are percentages, as upstream's are. Give every panel one or give none: with a mix, the ones without would each take a single share against another's twenty-five, which is not what anybody means.



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

def initialize(default_size: nil, min_size: nil, max_size: nil, **attributes)
  @default_size = default_size
  @min_size = min_size
  @max_size = max_size
  super(**attributes)
end

Instance Attribute Details

#default_sizeObject (readonly)

Returns the value of attribute default_size.



18
19
20
# File 'app/components/shadcn/resizable/panel/component.rb', line 18

def default_size
  @default_size
end

#max_sizeObject (readonly)

Returns the value of attribute max_size.



18
19
20
# File 'app/components/shadcn/resizable/panel/component.rb', line 18

def max_size
  @max_size
end

#min_sizeObject (readonly)

Returns the value of attribute min_size.



18
19
20
# File 'app/components/shadcn/resizable/panel/component.rb', line 18

def min_size
  @min_size
end

Instance Method Details

#element_attributes(**defaults) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/components/shadcn/resizable/panel/component.rb', line 30

def element_attributes(**defaults)
  super(**{
    id: panel_id,
    "data-shadcn--resizable-target" => "panel",
    "data-min-size" => min_size,
    "data-max-size" => max_size,
    style: merged_style(
      "flex-basis:0;flex-shrink:1;flex-grow:#{default_size || 1};overflow:hidden;" \
      "display:flex;min-width:0;min-height:0"
    )
  }.compact.merge(defaults))
end