Shortcut Key
A component for displaying keyboard shortcuts.
Usage
Example
⌘K
Note this does not trigger anything, it is purely a visual prompt
div(class: "flex flex-col items-center gap-y-4") do ShortcutKey do span(class: "text-xs") { "⌘" } plain "K" end p(class: "text-muted-foreground text-sm text-center") { "Note this does not trigger anything, it is purely a visual prompt" } end
Copied!
Copy failed!
Installation
Using RubyUI CLI
Run the install command
rails g ruby_ui:component ShortcutKey
Copied!
Copy failed!
Manual installation
1
Add RubyUI::ShortcutKey to app/components/ruby_ui/shortcut_key/shortcut_key.rb
# frozen_string_literal: true module RubyUI class ShortcutKey < Base def view_template(&) kbd(**attrs, &) end private def default_attrs { class: "pointer-events-none inline-flex h-5 select-none items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium text-muted-foreground opacity-100" } end end end
Copied!
Copy failed!
2
Add RubyUI::ShortcutKeyDocs to app/components/ruby_ui/shortcut_key/shortcut_key_docs.rb
# frozen_string_literal: true class Views::Docs::ShortcutKey < Views::Base def view_template component = "ShortcutKey" div(class: "max-w-2xl mx-auto w-full py-10 space-y-10") do render Docs::Header.new(title: "Shortcut Key", description: "A component for displaying keyboard shortcuts.") Heading(level: 2) { "Usage" } render Docs::VisualCodeExample.new(title: "Example", context: self) do <<~RUBY div(class: "flex flex-col items-center gap-y-4") do ShortcutKey do span(class: "text-xs") { "⌘" } plain "K" end p(class: "text-muted-foreground text-sm text-center") { "Note this does not trigger anything, it is purely a visual prompt" } end RUBY end render Components::ComponentSetup::Tabs.new(component_name: component) render Docs::ComponentsTable.new(component_files(component)) end end end
Copied!
Copy failed!
Components
| Component | Built using | Source |
|---|---|---|
ShortcutKey | Phlex | |
ShortcutKeyDocs | Phlex |