Skip to content

Commit 5232f11

Browse files
authored
Add the radio button component to the doc (#155)
1 parent c8291b1 commit 5232f11

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
module RubyUI
4+
class RadioButton < Base
5+
def view_template
6+
input(**attrs)
7+
end
8+
9+
private
10+
11+
def default_attrs
12+
{
13+
type: "radio",
14+
data: {
15+
ruby_ui__form_field_target: "input",
16+
action: "change->ruby-ui--form-field#onInput invalid->ruby-ui--form-field#onInvalid"
17+
},
18+
class: "h-4 w-4 p-0 border-primary rounded-full flex-none"
19+
}
20+
end
21+
end
22+
end

app/controllers/docs_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ def popover
150150
render Docs::PopoverView.new
151151
end
152152

153+
def radio_button
154+
render Docs::RadioButtonView.new
155+
end
156+
153157
def select
154158
render Docs::SelectView.new
155159
end

app/views/components/shared/menu.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def components
9090
{name: "Masked Input", path: helpers.masked_input_path},
9191
{name: "Pagination", path: helpers.docs_pagination_path, badge: "New"},
9292
{name: "Popover", path: helpers.docs_popover_path},
93+
{name: "Radio Button", path: helpers.docs_radio_button_path, badge: "New"},
9394
{name: "Select", path: helpers.docs_select_path, badge: "New"},
9495
{name: "Sheet", path: helpers.docs_sheet_path},
9596
{name: "Shortcut Key", path: helpers.docs_shortcut_key_path},

app/views/docs/radio_button_view.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# frozen_string_literal: true
2+
3+
class Docs::RadioButtonView < ApplicationView
4+
def view_template
5+
component = "RadioButton"
6+
7+
div(class: "max-w-2xl mx-auto w-full py-10 space-y-10") do
8+
render Docs::Header.new(title: "Radio Button", description: "A control that allows users to make a single selection from a list of options.")
9+
10+
Heading(level: 2) { "Usage" }
11+
12+
render Docs::VisualCodeExample.new(title: "Example", context: self) do
13+
<<~RUBY
14+
div(class: "flex items-center space-x-2") do
15+
RadioButton(id: "default")
16+
FormFieldLabel(for: "default") { "Default" }
17+
end
18+
RUBY
19+
end
20+
21+
render Docs::VisualCodeExample.new(title: "Checked", context: self) do
22+
<<~RUBY
23+
div(class: "flex items-center space-x-2") do
24+
RadioButton(id: "checked", checked: true)
25+
FormFieldLabel(for: "checked") { "Checked" }
26+
end
27+
RUBY
28+
end
29+
30+
render Components::ComponentSetup::Tabs.new(component_name: component)
31+
32+
render Docs::ComponentsTable.new(component_files(component))
33+
end
34+
end
35+
end

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
get "masked_input", to: "docs#masked_input", as: :masked_input
4444
get "pagination", to: "docs#pagination", as: :docs_pagination
4545
get "popover", to: "docs#popover", as: :docs_popover
46+
get "radio_button", to: "docs#radio_button", as: :docs_radio_button
4647
get "select", to: "docs#select", as: :docs_select
4748
get "sheet", to: "docs#sheet", as: :docs_sheet
4849
get "shortcut_key", to: "docs#shortcut_key", as: :docs_shortcut_key

0 commit comments

Comments
 (0)