Module: Shadcn::Concerns::ModalRoot
- Included in:
- AlertDialog::Component, Dialog::Component, Drawer::Component, Sheet::Component
- Defined in:
- app/components/shadcn/concerns/modal_root.rb
Overview
Shared behaviour of the three components shadcn builds on Radix's Dialog primitive: Dialog, Sheet and AlertDialog.
It is a module rather than a superclass because ViewComponent refuses to
let a subclass redeclare an inherited slot, and each of the three needs
its own trigger / content slot types.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#dismissable? ⇒ Boolean
Radix keeps alert dialogs open on an outside click; AlertDialog says so by overriding this.
- #element_attributes(**defaults) ⇒ Object
- #initialize(open: false, modal: true, **attributes) ⇒ Object
Class Method Details
.included(base) ⇒ Object
12 13 14 15 16 |
# File 'app/components/shadcn/concerns/modal_root.rb', line 12 def self.included(base) base.class_eval do attr_reader :open, :modal end end |
Instance Method Details
#call ⇒ Object
38 39 40 |
# File 'app/components/shadcn/concerns/modal_root.rb', line 38 def call render_element(body: safe_join([ trigger, dialog_content, content ].compact)) end |
#dismissable? ⇒ Boolean
Radix keeps alert dialogs open on an outside click; AlertDialog says so by overriding this.
20 |
# File 'app/components/shadcn/concerns/modal_root.rb', line 20 def dismissable? = true |
#element_attributes(**defaults) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'app/components/shadcn/concerns/modal_root.rb', line 28 def element_attributes(**defaults) super(**{ style: merged_style(ApplicationViewComponent::CONTENTS_STYLE), "data-controller" => "shadcn--dialog", "data-shadcn--dialog-open-value" => open, "data-shadcn--dialog-modal-value" => modal, "data-shadcn--dialog-dismissable-value" => dismissable? }.merge(defaults)) end |
#initialize(open: false, modal: true, **attributes) ⇒ Object
22 23 24 25 26 |
# File 'app/components/shadcn/concerns/modal_root.rb', line 22 def initialize(open: false, modal: true, **attributes) @open = open @modal = modal super(**attributes) end |