-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathcombobox_trigger.rb
More file actions
63 lines (58 loc) · 1.67 KB
/
Copy pathcombobox_trigger.rb
File metadata and controls
63 lines (58 loc) · 1.67 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# frozen_string_literal: true
module RubyUI
class ComboboxTrigger < Base
def initialize(placeholder: "", **)
@placeholder = placeholder
super(**)
end
def view_template
button(**attrs) do
span(class: "truncate", data: {ruby_ui__combobox_target: "triggerContent"}) do
@placeholder
end
icon
end
end
private
def default_attrs
{
type: "button",
class: [
"flex h-full w-full items-center whitespace-nowrap rounded-md text-sm ring-offset-background transition-colors border border-input bg-background h-10 px-4 py-2 justify-between",
"hover:bg-accent hover:text-accent-foreground",
"disabled:pointer-events-none disabled:opacity-50",
"aria-disabled:pointer-events-none aria-disabled:opacity-50 aria-disabled:cursor-not-allowed",
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
],
data: {
placeholder: @placeholder,
ruby_ui__combobox_target: "trigger",
action: "ruby-ui--combobox#togglePopover"
},
aria: {
haspopup: "listbox",
expanded: "false"
}
}
end
def icon
svg(
xmlns: "http://www.w3.org/2000/svg",
viewbox: "0 0 24 24",
fill: "none",
stroke: "currentColor",
class: "ml-2 h-4 w-4 shrink-0 opacity-50",
stroke_width: "2",
stroke_linecap: "round",
stroke_linejoin: "round"
) do |s|
s.path(
d: "m7 15 5 5 5-5"
)
s.path(
d: "m7 9 5-5 5 5"
)
end
end
end
end