Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update combobox docs #154

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ GIT

GIT
remote: /~https://github.com/ruby-ui/ruby_ui.git
revision: 6c79d377e1c550b606f28987c8e04587cb7221ac
revision: d29fac6edc255c352beb688c38e8365c1b277c4b
branch: main
specs:
ruby_ui (1.0.0.beta1)
Expand Down
14 changes: 8 additions & 6 deletions app/components/ruby_ui/combobox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

module RubyUI
class Combobox < Base
def initialize(term: "items", **)
@term = term
super(**)
end

def view_template(&)
div(**attrs, &)
end
Expand All @@ -10,14 +15,11 @@ def view_template(&)

def default_attrs
{
role: "combobox",
data: {
controller: "ruby-ui--combobox",
ruby_ui__combobox_open_value: "false",
action: "click@window->ruby-ui--combobox#onClickOutside",
ruby_ui__combobox_ruby_ui__combobox_content_outlet: ".combobox-content",
ruby_ui__combobox_ruby_ui__combobox_item_outlet: ".combobox-item"
},
class: "group/combobox w-full relative"
ruby_ui__combobox_term_value: @term.to_s
}
}
end
end
Expand Down
25 changes: 25 additions & 0 deletions app/components/ruby_ui/combobox/combobox_checkbox.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module RubyUI
class ComboboxCheckbox < Base
def view_template
input(type: "checkbox", **attrs)
end

private

def default_attrs
{
class: [
"peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background accent-primary",
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
"disabled:cursor-not-allowed disabled:opacity-50"
],
data: {
ruby_ui__combobox_target: "input",
action: "ruby-ui--combobox#inputChanged"
}
}
end
end
end
31 changes: 0 additions & 31 deletions app/components/ruby_ui/combobox/combobox_content.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module RubyUI
class ComboboxEmpty < Base
class ComboboxEmptyState < Base
def view_template(&)
div(**attrs, &)
end
Expand All @@ -13,7 +13,7 @@ def default_attrs
role: "presentation",
class: "hidden py-6 text-center text-sm",
data: {
ruby_ui__combobox_content_target: "empty"
ruby_ui__combobox_target: "emptyState"
}
}
end
Expand Down
38 changes: 0 additions & 38 deletions app/components/ruby_ui/combobox/combobox_group.rb

This file was deleted.

22 changes: 0 additions & 22 deletions app/components/ruby_ui/combobox/combobox_input.rb

This file was deleted.

46 changes: 9 additions & 37 deletions app/components/ruby_ui/combobox/combobox_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,23 @@

module RubyUI
class ComboboxItem < Base
def initialize(value: nil, **attrs)
@value = value
super(**attrs)
end

def view_template(&block)
div(**attrs) do
div(class: "invisible group-aria-selected:visible") { icon }
block.call
end
def view_template(&)
label(**attrs, &)
end

private

def icon
svg(
xmlns: "http://www.w3.org/2000/svg",
viewbox: "0 0 24 24",
fill: "none",
stroke: "currentColor",
class: "mr-2 h-4 w-4",
stroke_width: "2",
stroke_linecap: "round",
stroke_linejoin: "round"
) do |s|
s.path(
d: "M20 6 9 17l-5-5"
)
end
end

def default_attrs
{
class: [
"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",
"select-none has-[:checked]:bg-accent hover:bg-accent p-2",
"[&>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"
],
role: "option",
tabindex: "0",
class:
"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",
data: {
value: @value,
ruby_ui__combobox_target: "item",
ruby_ui__combobox_content_target: "item",
controller: "ruby-ui--combobox-item",
action: "click->ruby-ui--combobox#onItemSelected"
},
aria_selected: "false"
ruby_ui__combobox_target: "item"
}
}
end
end
Expand Down
13 changes: 2 additions & 11 deletions app/components/ruby_ui/combobox/combobox_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

module RubyUI
class ComboboxList < Base
def initialize(**attrs)
@id = "list#{SecureRandom.hex(4)}"
super
end

def view_template(&)
div(**attrs, &)
end
Expand All @@ -15,12 +10,8 @@ def view_template(&)

def default_attrs
{
id: @id,
data: {
ruby_ui__combobox_target: "list"
},
role: "listbox",
tabindex: "-1"
class: "flex flex-col gap-1 p-1 max-h-72 overflow-y-auto text-foreground",
role: "listbox"
}
end
end
Expand Down
20 changes: 20 additions & 0 deletions app/components/ruby_ui/combobox/combobox_list_group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module RubyUI
class ComboboxListGroup < Base
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"

def view_template(&)
div(**attrs, &)
end

private

def default_attrs
{
class: ["hidden has-[label:not(.hidden)]:flex flex-col py-1 gap-1 border-b", LABEL_CLASSES],
role: "group"
}
end
end
end
30 changes: 30 additions & 0 deletions app/components/ruby_ui/combobox/combobox_popover.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

module RubyUI
class ComboboxPopover < Base
def view_template(&)
div(**attrs, &)
end

private

def default_attrs
{
class: "inset-auto m-0 absolute border bg-background shadow-lg rounded-lg",
role: "popover",
autofocus: true,
popover: true,
data: {
ruby_ui__combobox_target: "popover",
action: %w[
keydown.down->ruby-ui--combobox#keyDownPressed
keydown.up->ruby-ui--combobox#keyUpPressed
keydown.enter->ruby-ui--combobox#keyEnterPressed
keydown.esc->ruby-ui--combobox#closeDialog:prevent
resize@window->ruby-ui--combobox#updatePopoverWidth
]
}
}
end
end
end
26 changes: 26 additions & 0 deletions app/components/ruby_ui/combobox/combobox_radio.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

module RubyUI
class ComboboxRadio < Base
def view_template
input(type: "radio", **attrs)
end

private

def default_attrs
{
class: "aspect-square h-4 w-4 rounded-full border border-primary accent-primary text-primary shadow focus:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
data: {
ruby_ui__combobox_target: "input",
ruby_ui__form_field_target: "input",
action: %w[
ruby-ui--combobox#inputChanged
input->ruby-ui--form-field#onInput
invalid->ruby-ui--form-field#onInvalid
]
}
}
end
end
end
Loading
Loading