From bac51af992874ecb8bac1f1bfce98f3277bafb4c Mon Sep 17 00:00:00 2001 From: Djalma Araujo Date: Thu, 7 May 2026 00:43:44 -0300 Subject: [PATCH] fix(docs): restore header theme and command search --- .../stylesheets/application.tailwind.css | 2 ++ docs/app/components/shared/logo.rb | 8 +++++++- .../controllers/ruby_ui/command_controller.js | 18 +++++++++++++++--- gem/lib/ruby_ui/command/command_controller.js | 18 +++++++++++++++--- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/docs/app/assets/stylesheets/application.tailwind.css b/docs/app/assets/stylesheets/application.tailwind.css index 67fc2752a..36096405a 100644 --- a/docs/app/assets/stylesheets/application.tailwind.css +++ b/docs/app/assets/stylesheets/application.tailwind.css @@ -3,6 +3,8 @@ @plugin "@tailwindcss/forms"; @plugin "@tailwindcss/typography"; +/* Safelist classes from RubyUI gem components rendered by the docs app. */ +@source inline("dark:inline-block"); @import "tw-animate-css"; diff --git a/docs/app/components/shared/logo.rb b/docs/app/components/shared/logo.rb index 4d06f7b04..afa2cbde1 100644 --- a/docs/app/components/shared/logo.rb +++ b/docs/app/components/shared/logo.rb @@ -9,10 +9,16 @@ def view_template img(src: image_url("logo.svg"), class: "h-4 block dark:hidden") img(src: image_url("logo_dark.svg"), class: "h-4 hidden dark:block") span(class: "sr-only") { "RubyUI" } - Badge(class: "ml-2 whitespace-nowrap bg-black text-white hover:bg-black/90 px-1.5 py-0.5 rounded-full text-xs font-semibold") { "1.0" } + Badge(class: "ml-2 whitespace-nowrap bg-black text-white hover:bg-black/90 px-1.5 py-0.5 rounded-full text-xs font-semibold") { ruby_ui_version } } end end + + private + + def ruby_ui_version + RubyUI::VERSION.split(".").first(2).join(".") + end end end end diff --git a/docs/app/javascript/controllers/ruby_ui/command_controller.js b/docs/app/javascript/controllers/ruby_ui/command_controller.js index 85c098eff..2ef0c47e9 100644 --- a/docs/app/javascript/controllers/ruby_ui/command_controller.js +++ b/docs/app/javascript/controllers/ruby_ui/command_controller.js @@ -13,18 +13,30 @@ export default class extends Controller { }; connect() { + this.selectedIndex = -1; + + if (!this.hasInputTarget) { + return; + } + this.inputTarget.focus(); this.searchIndex = this.buildSearchIndex(); this.toggleVisibility(this.emptyTargets, false); - this.selectedIndex = -1; - if (this.openValue) { + if (this.openValue && this.hasContentTarget) { this.open(); } } open(e) { - e.preventDefault(); + if (e) { + e.preventDefault(); + } + + if (!this.hasContentTarget) { + return; + } + document.body.insertAdjacentHTML("beforeend", this.contentTarget.innerHTML); // prevent scroll on body document.body.classList.add("overflow-hidden"); diff --git a/gem/lib/ruby_ui/command/command_controller.js b/gem/lib/ruby_ui/command/command_controller.js index 85c098eff..2ef0c47e9 100644 --- a/gem/lib/ruby_ui/command/command_controller.js +++ b/gem/lib/ruby_ui/command/command_controller.js @@ -13,18 +13,30 @@ export default class extends Controller { }; connect() { + this.selectedIndex = -1; + + if (!this.hasInputTarget) { + return; + } + this.inputTarget.focus(); this.searchIndex = this.buildSearchIndex(); this.toggleVisibility(this.emptyTargets, false); - this.selectedIndex = -1; - if (this.openValue) { + if (this.openValue && this.hasContentTarget) { this.open(); } } open(e) { - e.preventDefault(); + if (e) { + e.preventDefault(); + } + + if (!this.hasContentTarget) { + return; + } + document.body.insertAdjacentHTML("beforeend", this.contentTarget.innerHTML); // prevent scroll on body document.body.classList.add("overflow-hidden");