Skip to content
This repository was archived by the owner on May 11, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions app/components/ruby_ui/switch/switch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,22 @@ def initialize(include_hidden: true, checked_value: "1", unchecked_value: "0", *
def view_template
label(
role: "switch",
class: "peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background has-[:disabled]:cursor-not-allowed has-[:disabled]:opacity-50 bg-input has-[:checked]:bg-primary"
class: [
"peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors bg-input",
"has-checked:bg-primary",
"has-disabled:cursor-not-allowed has-disabled:opacity-50",
"has-aria-disabled:cursor-not-allowed has-aria-disabled:opacity-50 has-aria-disabled:pointer-events-none",
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
]
) do
input(type: "hidden", name: attrs[:name], value: @unchecked_value) if @include_hidden

input(**attrs.merge(type: "checkbox", class: "hidden peer", value: @checked_value))

span(class: "pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform translate-x-0 peer-checked:translate-x-5 ")
span(class: [
"pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform translate-x-0",
"peer-checked:translate-x-5"
])
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions app/views/docs/switch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def view_template
RUBY
end

render Docs::VisualCodeExample.new(title: "Aria Disabled", context: self) do
<<~RUBY
Switch(name: "switch", aria: {disabled: "true"})
RUBY
end

render Docs::VisualCodeExample.new(title: "With flag include_hidden false", context: self) do
<<~RUBY
# Supports the creation of a hidden input to be used in forms inspired by the Ruby on Rails implementation of check_box. Default is true.
Expand Down