Class: NitroKit::CommandPalette
- Defined in:
- app/components/nitro_kit/command_palette.rb
Defined Under Namespace
Classes: Results
Constant Summary
Constants inherited from Component
NitroKit::Component::ADDITIVE_DATA_ATTRIBUTES, NitroKit::Component::COMPONENT_OWNED_DATA_ATTRIBUTES, NitroKit::Component::FORBIDDEN_ATTRIBUTES, NitroKit::Component::RESERVED_DATA_ATTRIBUTES
Instance Attribute Summary collapse
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
Instance Method Summary collapse
- #destination(label, href:, description: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ Object
-
#initialize(id:, label: I18n.t("nitro_kit.command_palette.label"), placeholder: I18n.t("nitro_kit.command_palette.placeholder"), empty_text: I18n.t("nitro_kit.command_palette.empty"), close_label: I18n.t("nitro_kit.command_palette.close"), shortcut: true, shortcut_label: I18n.t("nitro_kit.command_palette.shortcut"), search_url: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ CommandPalette
constructor
A new instance of CommandPalette.
- #view_template(&block) ⇒ Object
Constructor Details
#initialize(id:, label: I18n.t("nitro_kit.command_palette.label"), placeholder: I18n.t("nitro_kit.command_palette.placeholder"), empty_text: I18n.t("nitro_kit.command_palette.empty"), close_label: I18n.t("nitro_kit.command_palette.close"), shortcut: true, shortcut_label: I18n.t("nitro_kit.command_palette.shortcut"), search_url: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ CommandPalette
Returns a new instance of CommandPalette.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'app/components/nitro_kit/command_palette.rb', line 152 def initialize( id:, label: I18n.t("nitro_kit.command_palette.label"), placeholder: I18n.t("nitro_kit.command_palette.placeholder"), empty_text: I18n.t("nitro_kit.command_palette.empty"), close_label: I18n.t("nitro_kit.command_palette.close"), shortcut: true, shortcut_label: I18n.t("nitro_kit.command_palette.shortcut"), search_url: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil ) @identifier = component_id(id) @label = required_text(:label, label) @placeholder = required_text(:placeholder, placeholder) @empty_text = required_text(:empty_text, empty_text) @close_label = required_text(:close_label, close_label) @shortcut = validate_boolean!(:shortcut, shortcut) @shortcut_label = required_text(:shortcut_label, shortcut_label) @search_url = validate_optional_text!(:search_url, search_url) @destinations = [] super( component: :command_palette, attributes: { id: @identifier, data: { controller: "nk--dialog nk--command-palette", action: root_actions, nk__dialog_dismissible_value: true, nk__command_palette_empty_value: @empty_text, nk__command_palette_results_one_value: I18n.t("nitro_kit.command_palette.results.one"), nk__command_palette_results_other_value: I18n.t("nitro_kit.command_palette.results.other") } }, html:, aria:, data:, desperately_need_a_class: ) end |
Instance Attribute Details
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
196 197 198 |
# File 'app/components/nitro_kit/command_palette.rb', line 196 def identifier @identifier end |
Instance Method Details
#destination(label, href:, description: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'app/components/nitro_kit/command_palette.rb', line 207 def destination( label, href:, description: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil ) ensure_collecting! @destinations << Destination.new( label: required_text(:label, label), href: required_text(:href, href), description: validate_optional_text!(:description, description), html:, aria:, data:, css_class: desperately_need_a_class ) nil end |
#view_template(&block) ⇒ Object
198 199 200 201 202 203 204 205 |
# File 'app/components/nitro_kit/command_palette.rb', line 198 def view_template(&block) collect_destinations(&block) div(**root_attributes) do render_trigger render_panel end end |