Skip to content

Commit c8291b1

Browse files
authored
Update combobox docs (#154)
1 parent 81e90a3 commit c8291b1

24 files changed

+395
-483
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ GIT
1414

1515
GIT
1616
remote: https://github.com/ruby-ui/ruby_ui.git
17-
revision: 6c79d377e1c550b606f28987c8e04587cb7221ac
17+
revision: d29fac6edc255c352beb688c38e8365c1b277c4b
1818
branch: main
1919
specs:
2020
ruby_ui (1.0.0.beta1)

app/components/ruby_ui/combobox.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
module RubyUI
44
class Combobox < Base
5+
def initialize(term: "items", **)
6+
@term = term
7+
super(**)
8+
end
9+
510
def view_template(&)
611
div(**attrs, &)
712
end
@@ -10,14 +15,11 @@ def view_template(&)
1015

1116
def default_attrs
1217
{
18+
role: "combobox",
1319
data: {
1420
controller: "ruby-ui--combobox",
15-
ruby_ui__combobox_open_value: "false",
16-
action: "click@window->ruby-ui--combobox#onClickOutside",
17-
ruby_ui__combobox_ruby_ui__combobox_content_outlet: ".combobox-content",
18-
ruby_ui__combobox_ruby_ui__combobox_item_outlet: ".combobox-item"
19-
},
20-
class: "group/combobox w-full relative"
21+
ruby_ui__combobox_term_value: @term.to_s
22+
}
2123
}
2224
end
2325
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
module RubyUI
4+
class ComboboxCheckbox < Base
5+
def view_template
6+
input(type: "checkbox", **attrs)
7+
end
8+
9+
private
10+
11+
def default_attrs
12+
{
13+
class: [
14+
"peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background accent-primary",
15+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
16+
"disabled:cursor-not-allowed disabled:opacity-50"
17+
],
18+
data: {
19+
ruby_ui__combobox_target: "input",
20+
action: "ruby-ui--combobox#inputChanged"
21+
}
22+
}
23+
end
24+
end
25+
end

app/components/ruby_ui/combobox/combobox_content.rb

Lines changed: 0 additions & 31 deletions
This file was deleted.

app/components/ruby_ui/combobox/combobox_empty.rb renamed to app/components/ruby_ui/combobox/combobox_empty_state.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
module RubyUI
4-
class ComboboxEmpty < Base
4+
class ComboboxEmptyState < Base
55
def view_template(&)
66
div(**attrs, &)
77
end
@@ -13,7 +13,7 @@ def default_attrs
1313
role: "presentation",
1414
class: "hidden py-6 text-center text-sm",
1515
data: {
16-
ruby_ui__combobox_content_target: "empty"
16+
ruby_ui__combobox_target: "emptyState"
1717
}
1818
}
1919
end

app/components/ruby_ui/combobox/combobox_group.rb

Lines changed: 0 additions & 38 deletions
This file was deleted.

app/components/ruby_ui/combobox/combobox_input.rb

Lines changed: 0 additions & 22 deletions
This file was deleted.

app/components/ruby_ui/combobox/combobox_item.rb

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,23 @@
22

33
module RubyUI
44
class ComboboxItem < Base
5-
def initialize(value: nil, **attrs)
6-
@value = value
7-
super(**attrs)
8-
end
9-
10-
def view_template(&block)
11-
div(**attrs) do
12-
div(class: "invisible group-aria-selected:visible") { icon }
13-
block.call
14-
end
5+
def view_template(&)
6+
label(**attrs, &)
157
end
168

179
private
1810

19-
def icon
20-
svg(
21-
xmlns: "http://www.w3.org/2000/svg",
22-
viewbox: "0 0 24 24",
23-
fill: "none",
24-
stroke: "currentColor",
25-
class: "mr-2 h-4 w-4",
26-
stroke_width: "2",
27-
stroke_linecap: "round",
28-
stroke_linejoin: "round"
29-
) do |s|
30-
s.path(
31-
d: "M20 6 9 17l-5-5"
32-
)
33-
end
34-
end
35-
3611
def default_attrs
3712
{
13+
class: [
14+
"flex flex-row w-full text-wrap truncate gap-2 items-center rounded-sm px-2 py-1.5 text-sm outline-none cursor-pointer",
15+
"select-none has-[:checked]:bg-accent hover:bg-accent p-2",
16+
"[&>svg]:pointer-events-none [&>svg]:size-4 [&>svg]:shrink-0 aria-[current=true]:bg-accent aria-[current=true]:ring aria-[current=true]:ring-offset-2"
17+
],
3818
role: "option",
39-
tabindex: "0",
40-
class:
41-
"combobox-item group relative flex cursor-pointer select-none items-center gap-x-2 rounded-sm px-2 py-1.5 text-sm outline-none hover:bg-accent hover:text-accent-foreground aria-[current]:bg-accent aria-[current]:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
4219
data: {
43-
value: @value,
44-
ruby_ui__combobox_target: "item",
45-
ruby_ui__combobox_content_target: "item",
46-
controller: "ruby-ui--combobox-item",
47-
action: "click->ruby-ui--combobox#onItemSelected"
48-
},
49-
aria_selected: "false"
20+
ruby_ui__combobox_target: "item"
21+
}
5022
}
5123
end
5224
end

app/components/ruby_ui/combobox/combobox_list.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
module RubyUI
44
class ComboboxList < Base
5-
def initialize(**attrs)
6-
@id = "list#{SecureRandom.hex(4)}"
7-
super
8-
end
9-
105
def view_template(&)
116
div(**attrs, &)
127
end
@@ -15,12 +10,8 @@ def view_template(&)
1510

1611
def default_attrs
1712
{
18-
id: @id,
19-
data: {
20-
ruby_ui__combobox_target: "list"
21-
},
22-
role: "listbox",
23-
tabindex: "-1"
13+
class: "flex flex-col gap-1 p-1 max-h-72 overflow-y-auto text-foreground",
14+
role: "listbox"
2415
}
2516
end
2617
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
module RubyUI
4+
class ComboboxListGroup < Base
5+
LABEL_CLASSES = "before:content-[attr(label)] before:px-2 before:py-1.5 before:text-xs before:font-medium before:text-muted-foreground before:not-italic"
6+
7+
def view_template(&)
8+
div(**attrs, &)
9+
end
10+
11+
private
12+
13+
def default_attrs
14+
{
15+
class: ["hidden has-[label:not(.hidden)]:flex flex-col py-1 gap-1 border-b", LABEL_CLASSES],
16+
role: "group"
17+
}
18+
end
19+
end
20+
end

0 commit comments

Comments
 (0)