forked from ruby-ui/web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch.rb
More file actions
34 lines (30 loc) · 1.3 KB
/
switch.rb
File metadata and controls
34 lines (30 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true
module RubyUI
class Switch < Base
def initialize(include_hidden: true, checked_value: "1", unchecked_value: "0", **attrs)
@include_hidden = include_hidden
@checked_value = checked_value
@unchecked_value = unchecked_value
super(**attrs)
end
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 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"
])
end
end
end
end