Module: Shadcn::Sidebar

Extended by:
Parts
Defined in:
app/components/shadcn/sidebar.rb,
app/components/shadcn/sidebar/preview.rb,
app/components/shadcn/sidebar/component.rb,
app/components/shadcn/sidebar/rail/component.rb,
app/components/shadcn/sidebar/input/component.rb,
app/components/shadcn/sidebar/trigger/component.rb,
app/components/shadcn/sidebar/provider/component.rb,
app/components/shadcn/sidebar/separator/component.rb,
app/components/shadcn/sidebar/menu_action/component.rb,
app/components/shadcn/sidebar/menu_button/component.rb,
app/components/shadcn/sidebar/menu_skeleton/component.rb,
app/components/shadcn/sidebar/menu_sub_button/component.rb

Overview

The parts of the Sidebar family that are an element with its two attributes and a fixed set of classes. Anything with variants, slots or markup of its own keeps its own component.rb.

This family needs a macro of its own because shadcn stamps a second attribute on every one of its 24 parts — data-sidebar="header" beside data-slot="sidebar-header" — and part declares a slot, classes and a tag and deliberately nothing else. Taken literally that meant 23 files of eleven lines each, which is precisely what part was written to remove.

sidebar_part is not part widened to take attributes; that was considered and rejected in decisions/01-architecture.md, on the grounds that it turns a lookup table into a configuration language. It adds exactly one attribute and derives it: measured across the whole vendored source, data-sidebar is data-slot without its sidebar- prefix in 21 of 21 cases, no exceptions. A rule, not a parameter. If upstream ever breaks it, one file changes.

Defined Under Namespace

Modules: Input, MenuAction, MenuButton, MenuSkeleton, MenuSubButton, Provider, Rail, Separator, Trigger Classes: Component, Preview

Class Method Summary collapse

Methods included from Parts

part

Class Method Details

Declares a part and stamps the derived data-sidebar on it. Caller attributes still win, as they do everywhere else here.



25
26
27
28
29
30
31
32
33
# File 'app/components/shadcn/sidebar.rb', line 25

def self.sidebar_part(name, slot:, **options)
  marker = slot.to_s.delete_prefix("sidebar-")

  part(name, slot:, **options).tap do |component|
    component.define_method(:element_attributes) do |**defaults|
      super(**{ "data-sidebar" => marker }.merge(defaults))
    end
  end
end