Class: PhlexKit::DrawerContent
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::DrawerContent
- Defined in:
- app/components/phlex_kit/drawer/drawer_content.rb
Overview
holding the drawer overlay + panel (cloned into on open,
like SheetContent). side: picks the attached edge — :bottom (default),
:top, :left or :right, matching shadcn's direction prop. See drawer.rb.
Constant Summary collapse
- SIDES =
{ bottom: "bottom", top: "top", left: "left", right: "right" }.freeze
Instance Method Summary collapse
-
#initialize(side: :bottom, **attrs) ⇒ DrawerContent
constructor
A new instance of DrawerContent.
- #view_template(&block) ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(side: :bottom, **attrs) ⇒ DrawerContent
Returns a new instance of DrawerContent.
8 9 10 11 |
# File 'app/components/phlex_kit/drawer/drawer_content.rb', line 8 def initialize(side: :bottom, **attrs) @side = side.to_sym @attrs = attrs end |
Instance Method Details
#view_template(&block) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/components/phlex_kit/drawer/drawer_content.rb', line 13 def view_template(&block) template(data: { phlex_kit__sheet_target: "content" }) do div(data: { controller: "phlex-kit--sheet-content", action: "keydown->phlex-kit--sheet-content#keydown", pk_overlay_clone: "" }) do div(class: "pk-drawer-overlay", data: { action: "click->phlex-kit--sheet-content#close mousedown->phlex-kit--sheet-content#overlayMousedown" }) panel_attrs = { class: "pk-drawer #{fetch_option(SIDES, @side, :side)}", data: { phlex_kit__sheet_content_target: "panel" } } # Defaults only when the caller didn't supply their own — `mix` # would fuse role="dialog region" / aria-modal="true false" / # tabindex="-1 0" instead of overriding. panel_attrs[:role] = "dialog" unless @attrs.key?(:role) || @attrs.key?("role") panel_attrs[:aria] = { modal: "true" } unless aria_key_set?(:modal) panel_attrs[:tabindex] = "-1" unless @attrs.key?(:tabindex) || @attrs.key?("tabindex") div(**mix(panel_attrs, @attrs)) do div(class: "pk-drawer-handle", aria: { hidden: "true" }) yield if block end end end end |