ruby_ui 1.0.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +4 -0
  4. data/lib/generators/ruby_ui/component_generator.rb +5 -1
  5. data/lib/generators/ruby_ui/dependencies.yml +10 -0
  6. data/lib/generators/ruby_ui/install/docs_generator.rb +33 -0
  7. data/lib/generators/ruby_ui/install/install_generator.rb +1 -1
  8. data/lib/generators/ruby_ui/javascript_utils.rb +4 -0
  9. data/lib/ruby_ui/accordion/accordion_docs.rb +53 -0
  10. data/lib/ruby_ui/alert/alert_docs.rb +135 -0
  11. data/lib/ruby_ui/alert_dialog/alert_dialog_docs.rb +35 -0
  12. data/lib/ruby_ui/aspect_ratio/aspect_ratio_docs.rb +64 -0
  13. data/lib/ruby_ui/avatar/avatar_docs.rb +92 -0
  14. data/lib/ruby_ui/badge/badge_docs.rb +80 -0
  15. data/lib/ruby_ui/breadcrumb/breadcrumb_docs.rb +116 -0
  16. data/lib/ruby_ui/button/button_docs.rb +143 -0
  17. data/lib/ruby_ui/calendar/calendar_docs.rb +34 -0
  18. data/lib/ruby_ui/card/card_docs.rb +114 -0
  19. data/lib/ruby_ui/carousel/carousel_docs.rb +104 -0
  20. data/lib/ruby_ui/chart/chart_docs.rb +115 -0
  21. data/lib/ruby_ui/checkbox/checkbox.rb +2 -2
  22. data/lib/ruby_ui/checkbox/checkbox_docs.rb +41 -0
  23. data/lib/ruby_ui/clipboard/clipboard_docs.rb +30 -0
  24. data/lib/ruby_ui/codeblock/codeblock_docs.rb +55 -0
  25. data/lib/ruby_ui/collapsible/collapsible_docs.rb +96 -0
  26. data/lib/ruby_ui/combobox/combobox.rb +7 -1
  27. data/lib/ruby_ui/combobox/combobox_badge.rb +17 -0
  28. data/lib/ruby_ui/combobox/combobox_badge_trigger.rb +47 -0
  29. data/lib/ruby_ui/combobox/combobox_checkbox.rb +1 -7
  30. data/lib/ruby_ui/combobox/combobox_clear_button.rb +40 -0
  31. data/lib/ruby_ui/combobox/combobox_controller.js +252 -47
  32. data/lib/ruby_ui/combobox/combobox_docs.rb +286 -0
  33. data/lib/ruby_ui/combobox/combobox_input_trigger.rb +64 -0
  34. data/lib/ruby_ui/combobox/combobox_item.rb +5 -7
  35. data/lib/ruby_ui/combobox/combobox_item_indicator.rb +30 -0
  36. data/lib/ruby_ui/combobox/combobox_list_group.rb +1 -1
  37. data/lib/ruby_ui/combobox/combobox_popover.rb +1 -5
  38. data/lib/ruby_ui/combobox/combobox_radio.rb +1 -8
  39. data/lib/ruby_ui/combobox/combobox_toggle_all_checkbox.rb +1 -6
  40. data/lib/ruby_ui/combobox/combobox_trigger.rb +19 -19
  41. data/lib/ruby_ui/command/command_docs.rb +154 -0
  42. data/lib/ruby_ui/context_menu/context_menu.rb +1 -1
  43. data/lib/ruby_ui/context_menu/context_menu_docs.rb +85 -0
  44. data/lib/ruby_ui/data_table/data_table.rb +29 -0
  45. data/lib/ruby_ui/data_table/data_table_bulk_actions.rb +18 -0
  46. data/lib/ruby_ui/data_table/data_table_column_toggle.rb +62 -0
  47. data/lib/ruby_ui/data_table/data_table_column_visibility_controller.js +14 -0
  48. data/lib/ruby_ui/data_table/data_table_controller.js +57 -0
  49. data/lib/ruby_ui/data_table/data_table_docs.rb +180 -0
  50. data/lib/ruby_ui/data_table/data_table_expand_toggle.rb +53 -0
  51. data/lib/ruby_ui/data_table/data_table_form.rb +39 -0
  52. data/lib/ruby_ui/data_table/data_table_kaminari_adapter.rb +17 -0
  53. data/lib/ruby_ui/data_table/data_table_manual_adapter.rb +17 -0
  54. data/lib/ruby_ui/data_table/data_table_pagination.rb +100 -0
  55. data/lib/ruby_ui/data_table/data_table_pagination_bar.rb +15 -0
  56. data/lib/ruby_ui/data_table/data_table_pagy_adapter.rb +17 -0
  57. data/lib/ruby_ui/data_table/data_table_per_page_select.rb +35 -0
  58. data/lib/ruby_ui/data_table/data_table_row_checkbox.rb +30 -0
  59. data/lib/ruby_ui/data_table/data_table_search.rb +57 -0
  60. data/lib/ruby_ui/data_table/data_table_search_controller.js +62 -0
  61. data/lib/ruby_ui/data_table/data_table_select_all_checkbox.rb +21 -0
  62. data/lib/ruby_ui/data_table/data_table_selection_summary.rb +25 -0
  63. data/lib/ruby_ui/data_table/data_table_sort_head.rb +112 -0
  64. data/lib/ruby_ui/data_table/data_table_toolbar.rb +15 -0
  65. data/lib/ruby_ui/dialog/dialog_docs.rb +102 -0
  66. data/lib/ruby_ui/docs/base.rb +90 -0
  67. data/lib/ruby_ui/docs/component_setup_tabs.rb +15 -0
  68. data/lib/ruby_ui/docs/components_table.rb +13 -0
  69. data/lib/ruby_ui/docs/header.rb +17 -0
  70. data/lib/ruby_ui/docs/sidebar_examples.rb +22 -0
  71. data/lib/ruby_ui/docs/visual_code_example.rb +22 -0
  72. data/lib/ruby_ui/dropdown_menu/dropdown_menu_docs.rb +212 -0
  73. data/lib/ruby_ui/form/form_docs.rb +178 -0
  74. data/lib/ruby_ui/form/form_field.rb +1 -1
  75. data/lib/ruby_ui/form/form_field_error.rb +1 -1
  76. data/lib/ruby_ui/form/form_field_hint.rb +1 -1
  77. data/lib/ruby_ui/form/form_field_label.rb +1 -1
  78. data/lib/ruby_ui/hover_card/hover_card_docs.rb +71 -0
  79. data/lib/ruby_ui/input/input.rb +4 -3
  80. data/lib/ruby_ui/input/input_docs.rb +68 -0
  81. data/lib/ruby_ui/link/link_docs.rb +106 -0
  82. data/lib/ruby_ui/masked_input/masked_input.rb +11 -1
  83. data/lib/ruby_ui/masked_input/masked_input_controller.js +13 -0
  84. data/lib/ruby_ui/masked_input/masked_input_docs.rb +47 -0
  85. data/lib/ruby_ui/native_select/native_select.rb +39 -0
  86. data/lib/ruby_ui/native_select/native_select_docs.rb +83 -0
  87. data/lib/ruby_ui/native_select/native_select_group.rb +15 -0
  88. data/lib/ruby_ui/native_select/native_select_icon.rb +39 -0
  89. data/lib/ruby_ui/native_select/native_select_option.rb +15 -0
  90. data/lib/ruby_ui/pagination/pagination_docs.rb +127 -0
  91. data/lib/ruby_ui/popover/popover_docs.rb +971 -0
  92. data/lib/ruby_ui/progress/progress_docs.rb +27 -0
  93. data/lib/ruby_ui/radio_button/radio_button.rb +1 -1
  94. data/lib/ruby_ui/radio_button/radio_button_docs.rb +53 -0
  95. data/lib/ruby_ui/select/select_docs.rb +129 -0
  96. data/lib/ruby_ui/separator/separator_docs.rb +36 -0
  97. data/lib/ruby_ui/sheet/sheet_content.rb +1 -1
  98. data/lib/ruby_ui/sheet/sheet_docs.rb +76 -0
  99. data/lib/ruby_ui/shortcut_key/shortcut_key_docs.rb +29 -0
  100. data/lib/ruby_ui/sidebar/sidebar_docs.rb +176 -0
  101. data/lib/ruby_ui/skeleton/skeleton_docs.rb +29 -0
  102. data/lib/ruby_ui/switch/switch_docs.rb +46 -0
  103. data/lib/ruby_ui/table/table_docs.rb +102 -0
  104. data/lib/ruby_ui/tabs/tabs_docs.rb +211 -0
  105. data/lib/ruby_ui/textarea/textarea_docs.rb +54 -0
  106. data/lib/ruby_ui/theme_toggle/theme_toggle_docs.rb +71 -0
  107. data/lib/ruby_ui/tooltip/tooltip_docs.rb +52 -0
  108. data/lib/ruby_ui/typography/typography_docs.rb +107 -0
  109. data/lib/ruby_ui.rb +1 -1
  110. metadata +90 -3
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Views::Docs::Clipboard < Views::Base
4
+ def view_template
5
+ component = "Clipboard"
6
+ div(class: "max-w-2xl mx-auto w-full py-10 space-y-10") do
7
+ render Docs::Header.new(title: "Clipboard", description: "A control to allow you to copy content to the clipboard.")
8
+
9
+ Heading(level: 2) { "Usage" }
10
+
11
+ render Docs::VisualCodeExample.new(title: "Example", context: self) do
12
+ <<~RUBY
13
+ Clipboard(success: "Copied!", error: "Copy failed!", class: "relative", options: {placement: "top"}) do
14
+ ClipboardSource(class: "hidden") { span { "Born rich!!!" } }
15
+
16
+ ClipboardTrigger do
17
+ Link(href: "#", class: "gap-1") do
18
+ Text(size: :small, class: "text-primary") { "Copy the secret of success!!!" }
19
+ end
20
+ end
21
+ end
22
+ RUBY
23
+ end
24
+
25
+ render Components::ComponentSetup::Tabs.new(component_name: component)
26
+
27
+ render Docs::ComponentsTable.new(component_files(component))
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Views::Docs::Codeblock < Views::Base
4
+ def view_template
5
+ component = "Codeblock"
6
+ div(class: "max-w-2xl mx-auto w-full py-10 space-y-10") do
7
+ render Docs::Header.new(title: "Codeblock", description: "A component for displaying highlighted code.")
8
+
9
+ Heading(level: 2) { "Usage" }
10
+
11
+ render Docs::VisualCodeExample.new(title: "With clipboard", context: self) do
12
+ <<~RUBY
13
+ code = <<~CODE
14
+ def hello_world
15
+ puts "Hello, world!"
16
+ end
17
+ CODE
18
+ div(class: 'w-full') do
19
+ Codeblock(code, syntax: :ruby)
20
+ end
21
+ RUBY
22
+ end
23
+
24
+ render Docs::VisualCodeExample.new(title: "Without clipboard", context: self) do
25
+ <<~RUBY
26
+ code = <<~CODE
27
+ def hello_world
28
+ puts "Hello, world!"
29
+ end
30
+ CODE
31
+ div(class: 'w-full') do
32
+ Codeblock(code, syntax: :ruby, clipboard: false)
33
+ end
34
+ RUBY
35
+ end
36
+
37
+ render Docs::VisualCodeExample.new(title: "Custom message", description: "Copy the code to see the message", context: self) do
38
+ <<~RUBY
39
+ code = <<~CODE
40
+ def hello_world
41
+ puts "Hello, world!"
42
+ end
43
+ CODE
44
+ div(class: 'w-full') do
45
+ Codeblock(code, syntax: :ruby, clipboard_success: "Nice one!")
46
+ end
47
+ RUBY
48
+ end
49
+
50
+ render Components::ComponentSetup::Tabs.new(component_name: component)
51
+
52
+ render Docs::ComponentsTable.new(component_files(component))
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Views::Docs::Collapsible < Views::Base
4
+ def view_template
5
+ component = "Collapsible"
6
+ div(class: "max-w-2xl mx-auto w-full py-10 space-y-10") do
7
+ render Docs::Header.new(title: "Collapsible", description: "An interactive component which expands/collapses a panel.")
8
+
9
+ Heading(level: 2) { "Usage" }
10
+
11
+ render Docs::VisualCodeExample.new(title: "Example", context: self) do
12
+ <<~RUBY
13
+ Collapsible do
14
+ div(class: "flex items-center justify-between space-x-4 px-4 py-2") do
15
+ h4(class: "text-sm font-semibold") { " @joeldrapper starred 3 repositories" }
16
+ CollapsibleTrigger do
17
+ Button(variant: :ghost, icon: true) do
18
+ chevron_icon
19
+ span(class: "sr-only") { "Toggle" }
20
+ end
21
+ end
22
+ end
23
+
24
+ div(class: "rounded-md border px-4 py-2 font-mono text-sm shadow-sm") do
25
+ "phlex-ruby/phlex"
26
+ end
27
+
28
+ CollapsibleContent do
29
+ div(class: 'space-y-2 mt-2') do
30
+ div(class: "rounded-md border px-4 py-2 font-mono text-sm shadow-sm") do
31
+ "phlex-ruby/phlex-rails"
32
+ end
33
+ div(class: "rounded-md border px-4 py-2 font-mono text-sm shadow-sm") do
34
+ "ruby-ui/ruby_ui"
35
+ end
36
+ end
37
+ end
38
+ end
39
+ RUBY
40
+ end
41
+
42
+ render Docs::VisualCodeExample.new(title: "Open", context: self) do
43
+ <<~RUBY
44
+ Collapsible(open: true) do
45
+ div(class: "flex items-center justify-between space-x-4 px-4 py-2") do
46
+ h4(class: "text-sm font-semibold") { " @joeldrapper starred 3 repositories" }
47
+ CollapsibleTrigger do
48
+ Button(variant: :ghost, icon: true) do
49
+ chevron_icon
50
+ span(class: "sr-only") { "Toggle" }
51
+ end
52
+ end
53
+ end
54
+
55
+ div(class: "rounded-md border px-4 py-2 font-mono text-sm shadow-sm") do
56
+ "phlex-ruby/phlex"
57
+ end
58
+
59
+ CollapsibleContent do
60
+ div(class: 'space-y-2 mt-2') do
61
+ div(class: "rounded-md border px-4 py-2 font-mono text-sm shadow-sm") do
62
+ "phlex-ruby/phlex-rails"
63
+ end
64
+ div(class: "rounded-md border px-4 py-2 font-mono text-sm shadow-sm") do
65
+ "ruby-ui/ruby_ui"
66
+ end
67
+ end
68
+ end
69
+ end
70
+ RUBY
71
+ end
72
+
73
+ render Components::ComponentSetup::Tabs.new(component_name: component)
74
+
75
+ render Docs::ComponentsTable.new(component_files(component))
76
+ end
77
+ end
78
+
79
+ private
80
+
81
+ def chevron_icon
82
+ svg(
83
+ xmlns: "http://www.w3.org/2000/svg",
84
+ viewbox: "0 0 20 20",
85
+ fill: "currentColor",
86
+ class: "w-4 h-4"
87
+ ) do |s|
88
+ s.path(
89
+ fill_rule: "evenodd",
90
+ d:
91
+ "M10 3a.75.75 0 01.55.24l3.25 3.5a.75.75 0 11-1.1 1.02L10 4.852 7.3 7.76a.75.75 0 01-1.1-1.02l3.25-3.5A.75.75 0 0110 3zm-3.76 9.2a.75.75 0 011.06.04l2.7 2.908 2.7-2.908a.75.75 0 111.1 1.02l-3.25 3.5a.75.75 0 01-1.1 0l-3.25-3.5a.75.75 0 01.04-1.06z",
92
+ clip_rule: "evenodd"
93
+ )
94
+ end
95
+ end
96
+ end
@@ -19,7 +19,13 @@ module RubyUI
19
19
  data: {
20
20
  controller: "ruby-ui--combobox",
21
21
  ruby_ui__combobox_term_value: @term,
22
- action: "turbo:morph@window->ruby-ui--combobox#updateTriggerContent"
22
+ action: %w[
23
+ turbo:morph@window->ruby-ui--combobox#updateTriggerContent
24
+ keydown.down->ruby-ui--combobox#keyDownPressed
25
+ keydown.up->ruby-ui--combobox#keyUpPressed
26
+ keydown.enter->ruby-ui--combobox#keyEnterPressed
27
+ keydown.esc->ruby-ui--combobox#closePopover:prevent
28
+ ]
23
29
  }
24
30
  }
25
31
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyUI
4
+ class ComboboxBadge < Base
5
+ def view_template(&)
6
+ span(**attrs, &)
7
+ end
8
+
9
+ private
10
+
11
+ def default_attrs
12
+ {
13
+ class: "inline-flex items-center gap-1 rounded-md border bg-secondary px-1.5 py-0.5 text-xs font-medium text-secondary-foreground"
14
+ }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyUI
4
+ class ComboboxBadgeTrigger < Base
5
+ def initialize(placeholder: "", clear_button: false, **)
6
+ @placeholder = placeholder
7
+ @clear_button = clear_button
8
+ super(**)
9
+ end
10
+
11
+ def view_template(&)
12
+ div(**attrs) do
13
+ div(data: {ruby_ui__combobox_target: "badgeContainer"}, class: "hidden")
14
+ input(
15
+ type: "text",
16
+ class: "flex-1 min-w-8 bg-transparent border-0 px-0 outline-none focus:ring-0 placeholder:text-muted-foreground text-sm",
17
+ autocomplete: "off",
18
+ autocorrect: "off",
19
+ spellcheck: "false",
20
+ placeholder: @placeholder,
21
+ data: {
22
+ ruby_ui__combobox_target: "badgeInput",
23
+ action: "keyup->ruby-ui--combobox#filterItems input->ruby-ui--combobox#filterItems keydown.backspace->ruby-ui--combobox#handleBadgeInputBackspace"
24
+ }
25
+ )
26
+ render ComboboxClearButton.new if @clear_button
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ # JS-toggled classes (referenced here so Tailwind compiles them): h-auto min-h-9 pt-1.5
33
+ def default_attrs
34
+ {
35
+ class: "flex h-9 w-full flex-wrap items-center gap-1 rounded-md border border-input bg-background px-3 text-sm ring-offset-background focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 cursor-text",
36
+ data: {
37
+ ruby_ui__combobox_target: "trigger",
38
+ action: "click->ruby-ui--combobox#openPopover focusin->ruby-ui--combobox#openPopover"
39
+ },
40
+ aria: {
41
+ haspopup: "listbox",
42
+ expanded: "false"
43
+ }
44
+ }
45
+ end
46
+ end
47
+ end
@@ -10,13 +10,7 @@ module RubyUI
10
10
 
11
11
  def default_attrs
12
12
  {
13
- class: [
14
- "peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background accent-primary",
15
- "disabled:cursor-not-allowed disabled:opacity-50",
16
- "checked:bg-primary checked:text-primary-foreground",
17
- "aria-disabled:cursor-not-allowed aria-disabled:opacity-50 aria-disabled:pointer-events-none",
18
- "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
19
- ],
13
+ class: "peer sr-only",
20
14
  data: {
21
15
  ruby_ui__combobox_target: "input",
22
16
  action: "ruby-ui--combobox#inputChanged"
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyUI
4
+ class ComboboxClearButton < Base
5
+ def view_template
6
+ button(**attrs) do
7
+ svg(
8
+ xmlns: "http://www.w3.org/2000/svg",
9
+ width: "24",
10
+ height: "24",
11
+ viewbox: "0 0 24 24",
12
+ fill: "none",
13
+ stroke: "currentColor",
14
+ stroke_width: "2",
15
+ stroke_linecap: "round",
16
+ stroke_linejoin: "round",
17
+ class: "size-3.5"
18
+ ) do |s|
19
+ s.path(d: "M18 6 6 18")
20
+ s.path(d: "m6 6 12 12")
21
+ end
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def default_attrs
28
+ {
29
+ type: "button",
30
+ class: "ml-auto shrink-0 rounded-sm text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring hidden",
31
+ aria: {label: "Clear selection"},
32
+ data: {
33
+ ruby_ui__combobox_target: "clearButton",
34
+ # JS implementation in combobox_controller.js
35
+ action: "ruby-ui--combobox#clearAll"
36
+ }
37
+ }
38
+ end
39
+ end
40
+ end