Class: NitroKit::Dialog
- Defined in:
- app/components/nitro_kit/dialog.rb
Constant Summary
Constants inherited from Component
Component::ADDITIVE_DATA_ATTRIBUTES, Component::COMPONENT_OWNED_DATA_ATTRIBUTES, Component::FORBIDDEN_ATTRIBUTES, Component::RESERVED_DATA_ATTRIBUTES
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #close_button(label: default_close_label, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ Object
-
#initialize(id:, dismissible: true, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ Dialog
constructor
A new instance of Dialog.
- #panel(title:, description: nil, nonmodal: false, html: {}, aria: {}, data: {}, desperately_need_a_class: nil, &content) ⇒ Object
- #trigger(text = nil, variant: :default, size: :md, icon: nil, icon_end: nil, label: nil, disabled: false, html: {}, aria: {}, data: {}, desperately_need_a_class: nil, &content) ⇒ Object
- #view_template(&block) ⇒ Object
Constructor Details
#initialize(id:, dismissible: true, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ Dialog
Returns a new instance of Dialog.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/components/nitro_kit/dialog.rb', line 14 def initialize( id:, dismissible: true, html: {}, aria: {}, data: {}, desperately_need_a_class: nil ) unless id.is_a?(String) && id.present? && !id.match?(/\s/) raise ArgumentError, "Dialog id: must be a non-blank String without whitespace" end @id = id @dismissible = validate_boolean!(:dismissible, dismissible) super( component: :dialog, attributes: { id:, data: { controller: "nk--dialog", action: [ "click->nk--dialog#invoke", "turbo:before-cache@document->nk--dialog#closeForCache" ].join(" "), nk__dialog_dismissible_value: @dismissible } }, html:, aria:, data:, desperately_need_a_class: ) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
49 50 51 |
# File 'app/components/nitro_kit/dialog.rb', line 49 def id @id end |
Instance Method Details
#close_button(label: default_close_label, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'app/components/nitro_kit/dialog.rb', line 127 def ( label: default_close_label, html: {}, aria: {}, data: {}, desperately_need_a_class: nil ) ensure_rendering_panel! raise ArgumentError, "Dialog accepts at most one close button" if @close_button unless @dismissible raise ArgumentError, "Dialog dismissible: false renders no close button" end @close_button = CloseButton.new( label:, html:, aria:, data:, css_class: desperately_need_a_class ) nil end |
#panel(title:, description: nil, nonmodal: false, html: {}, aria: {}, data: {}, desperately_need_a_class: nil, &content) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'app/components/nitro_kit/dialog.rb', line 94 def panel( title:, description: nil, nonmodal: false, html: {}, aria: {}, data: {}, desperately_need_a_class: nil, &content ) ensure_collecting! raise ArgumentError, "Dialog accepts exactly one panel" if @panel unless title.is_a?(String) && title.present? raise ArgumentError, "Dialog title: must be a non-blank String" end unless description.nil? || (description.is_a?(String) && description.present?) raise ArgumentError, "Dialog description: must be nil or a non-blank String" end @panel = Panel.new( title:, description:, nonmodal: validate_boolean!(:nonmodal, nonmodal), html:, aria:, data:, css_class: desperately_need_a_class, content: ) nil end |
#trigger(text = nil, variant: :default, size: :md, icon: nil, icon_end: nil, label: nil, disabled: false, html: {}, aria: {}, data: {}, desperately_need_a_class: nil, &content) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/components/nitro_kit/dialog.rb', line 60 def trigger( text = nil, variant: :default, size: :md, icon: nil, icon_end: nil, label: nil, disabled: false, html: {}, aria: {}, data: {}, desperately_need_a_class: nil, &content ) ensure_collecting! raise ArgumentError, "Dialog accepts at most one trigger" if @trigger @trigger = Trigger.new( text:, variant:, size:, icon:, icon_end:, label:, disabled: validate_boolean!(:disabled, disabled), html:, aria:, data:, css_class: desperately_need_a_class, content: ) nil end |
#view_template(&block) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'app/components/nitro_kit/dialog.rb', line 51 def view_template(&block) collect_declarations(&block) div(**root_attributes) do render_trigger if @trigger render_panel end end |