Skip to content
Merged
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 lib/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",
Comment on lines +17 to +18
Copy link
Contributor Author

@pierry01 pierry01 May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephannv @cirdes

the old syntax is (Tailwind v3)

has-[:disabled]:cursor-not-allowed has-[:disabled]:opacity-50 bg-input has-[:checked]:bg-primary

the new syntax is (Tailwind v4)

has-disabled:cursor-not-allowed has-disabled:opacity-50 bg-input has-checked:bg-primary

should I use the old or the new syntax?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pierry01 , we should be using the new syntax.

"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