better_ui 0.1.0 → 0.1.1

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 (118) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +225 -119
  4. data/app/assets/stylesheets/better_ui/application.css +0 -356
  5. data/app/components/better_ui/application/card/component.html.erb +20 -0
  6. data/app/components/better_ui/application/card/component.rb +214 -0
  7. data/app/components/better_ui/application/main/component.html.erb +9 -0
  8. data/app/components/better_ui/application/main/component.rb +123 -0
  9. data/app/components/better_ui/application/navbar/component.html.erb +92 -0
  10. data/app/components/better_ui/application/navbar/component.rb +136 -0
  11. data/app/components/better_ui/application/sidebar/component.html.erb +190 -0
  12. data/app/components/better_ui/application/sidebar/component.rb +129 -0
  13. data/app/components/better_ui/general/alert/component.html.erb +32 -0
  14. data/app/components/better_ui/general/alert/component.rb +242 -0
  15. data/app/components/better_ui/general/avatar/component.html.erb +20 -0
  16. data/app/components/better_ui/general/avatar/component.rb +301 -0
  17. data/app/components/better_ui/general/badge/component.html.erb +23 -0
  18. data/app/components/better_ui/general/badge/component.rb +248 -0
  19. data/app/components/better_ui/general/breadcrumb/component.html.erb +15 -0
  20. data/app/components/better_ui/general/breadcrumb/component.rb +187 -0
  21. data/app/components/better_ui/general/button/component.html.erb +34 -0
  22. data/app/components/better_ui/general/button/component.rb +214 -0
  23. data/app/components/better_ui/general/divider/component.html.erb +10 -0
  24. data/app/components/better_ui/general/divider/component.rb +226 -0
  25. data/app/components/better_ui/general/field/component.html.erb +27 -0
  26. data/app/components/better_ui/general/field/component.rb +37 -0
  27. data/app/components/better_ui/general/heading/component.html.erb +22 -0
  28. data/app/components/better_ui/general/heading/component.rb +257 -0
  29. data/app/components/better_ui/general/icon/component.html.erb +7 -0
  30. data/app/components/better_ui/general/icon/component.rb +239 -0
  31. data/app/components/better_ui/general/input/checkbox/component.html.erb +5 -0
  32. data/app/components/better_ui/general/input/checkbox/component.rb +238 -0
  33. data/app/components/better_ui/general/input/datetime/component.html.erb +5 -0
  34. data/app/components/better_ui/general/input/datetime/component.rb +223 -0
  35. data/app/components/better_ui/general/input/radio/component.html.erb +5 -0
  36. data/app/components/better_ui/general/input/radio/component.rb +230 -0
  37. data/app/components/better_ui/general/input/select/component.html.erb +16 -0
  38. data/app/components/better_ui/general/input/select/component.rb +184 -0
  39. data/app/components/better_ui/general/input/select/select_component.html.erb +5 -0
  40. data/app/components/better_ui/general/input/select/select_component.rb +37 -0
  41. data/app/components/better_ui/general/input/text/component.html.erb +5 -0
  42. data/app/components/better_ui/general/input/text/component.rb +171 -0
  43. data/app/components/better_ui/general/input/textarea/component.html.erb +5 -0
  44. data/app/components/better_ui/general/input/textarea/component.rb +166 -0
  45. data/app/components/better_ui/general/link/component.html.erb +18 -0
  46. data/app/components/better_ui/general/link/component.rb +258 -0
  47. data/app/components/better_ui/general/panel/component.html.erb +28 -0
  48. data/app/components/better_ui/general/panel/component.rb +249 -0
  49. data/app/components/better_ui/general/progress/component.html.erb +11 -0
  50. data/app/components/better_ui/general/progress/component.rb +160 -0
  51. data/app/components/better_ui/general/spinner/component.html.erb +35 -0
  52. data/app/components/better_ui/general/spinner/component.rb +93 -0
  53. data/app/components/better_ui/general/table/component.html.erb +5 -0
  54. data/app/components/better_ui/general/table/component.rb +217 -0
  55. data/app/components/better_ui/general/table/tbody_component.html.erb +3 -0
  56. data/app/components/better_ui/general/table/tbody_component.rb +30 -0
  57. data/app/components/better_ui/general/table/td_component.html.erb +3 -0
  58. data/app/components/better_ui/general/table/td_component.rb +44 -0
  59. data/app/components/better_ui/general/table/tfoot_component.html.erb +3 -0
  60. data/app/components/better_ui/general/table/tfoot_component.rb +28 -0
  61. data/app/components/better_ui/general/table/th_component.html.erb +6 -0
  62. data/app/components/better_ui/general/table/th_component.rb +51 -0
  63. data/app/components/better_ui/general/table/thead_component.html.erb +3 -0
  64. data/app/components/better_ui/general/table/thead_component.rb +28 -0
  65. data/app/components/better_ui/general/table/tr_component.html.erb +3 -0
  66. data/app/components/better_ui/general/table/tr_component.rb +30 -0
  67. data/app/components/better_ui/general/tag/component.html.erb +3 -0
  68. data/app/components/better_ui/general/tag/component.rb +104 -0
  69. data/app/components/better_ui/general/tooltip/component.html.erb +7 -0
  70. data/app/components/better_ui/general/tooltip/component.rb +239 -0
  71. data/app/helpers/better_ui/application/components/card/card_helper.rb +96 -0
  72. data/app/helpers/better_ui/application/components/card.rb +11 -0
  73. data/app/helpers/better_ui/application/components/main/main_helper.rb +64 -0
  74. data/app/helpers/better_ui/application/components/navbar/navbar_helper.rb +77 -0
  75. data/app/helpers/better_ui/application/components/sidebar/sidebar_helper.rb +51 -0
  76. data/app/helpers/better_ui/application_helper.rb +42 -179
  77. data/app/helpers/better_ui/general/components/alert/alert_helper.rb +57 -0
  78. data/app/helpers/better_ui/general/components/avatar/avatar_helper.rb +29 -0
  79. data/app/helpers/better_ui/general/components/badge/badge_helper.rb +53 -0
  80. data/app/helpers/better_ui/general/components/breadcrumb/breadcrumb_helper.rb +37 -0
  81. data/app/helpers/better_ui/general/components/button/button_helper.rb +65 -0
  82. data/app/helpers/better_ui/general/components/container/container_helper.rb +60 -0
  83. data/app/helpers/better_ui/general/components/divider/divider_helper.rb +63 -0
  84. data/app/helpers/better_ui/general/components/field/field_helper.rb +26 -0
  85. data/app/helpers/better_ui/general/components/heading/heading_helper.rb +72 -0
  86. data/app/helpers/better_ui/general/components/icon/icon_helper.rb +16 -0
  87. data/app/helpers/better_ui/general/components/input/checkbox/checkbox_helper.rb +81 -0
  88. data/app/helpers/better_ui/general/components/input/datetime/datetime_helper.rb +91 -0
  89. data/app/helpers/better_ui/general/components/input/radio/radio_helper.rb +79 -0
  90. data/app/helpers/better_ui/general/components/input/radio_group/radio_group_helper.rb +124 -0
  91. data/app/helpers/better_ui/general/components/input/select/select_helper.rb +70 -0
  92. data/app/helpers/better_ui/general/components/input/text/text_helper.rb +138 -0
  93. data/app/helpers/better_ui/general/components/input/textarea/textarea_helper.rb +73 -0
  94. data/app/helpers/better_ui/general/components/link/link_helper.rb +89 -0
  95. data/app/helpers/better_ui/general/components/panel/panel_helper.rb +83 -0
  96. data/app/helpers/better_ui/general/components/progress/progress_helper.rb +53 -0
  97. data/app/helpers/better_ui/general/components/spinner/spinner_helper.rb +19 -0
  98. data/app/helpers/better_ui/general/components/table/table_helper.rb +53 -0
  99. data/app/helpers/better_ui/general/components/table/tbody_helper.rb +13 -0
  100. data/app/helpers/better_ui/general/components/table/td_helper.rb +19 -0
  101. data/app/helpers/better_ui/general/components/table/tfoot_helper.rb +13 -0
  102. data/app/helpers/better_ui/general/components/table/th_helper.rb +19 -0
  103. data/app/helpers/better_ui/general/components/table/thead_helper.rb +13 -0
  104. data/app/helpers/better_ui/general/components/table/tr_helper.rb +13 -0
  105. data/app/helpers/better_ui/general/components/tag/tag_helper.rb +26 -0
  106. data/app/helpers/better_ui/general/components/tooltip/tooltip_helper.rb +60 -0
  107. data/app/views/layouts/better_ui/application.html.erb +6 -124
  108. data/config/initializers/lookbook.rb +23 -0
  109. data/config/routes.rb +0 -8
  110. data/lib/better_ui/engine.rb +5 -19
  111. data/lib/better_ui/railtie.rb +20 -0
  112. data/lib/better_ui/version.rb +1 -1
  113. data/lib/better_ui.rb +4 -20
  114. metadata +131 -28
  115. data/app/controllers/better_ui/docs_controller.rb +0 -41
  116. data/app/views/better_ui/docs/component.html.erb +0 -365
  117. data/app/views/better_ui/docs/index.html.erb +0 -100
  118. data/app/views/better_ui/docs/show.html.erb +0 -60
@@ -0,0 +1,72 @@
1
+ module BetterUi
2
+ module General
3
+ module Components
4
+ module Heading
5
+ module HeadingHelper
6
+ # Genera un heading usando BetterUi::General::Heading::Component
7
+ #
8
+ # @param text [String] testo del heading
9
+ # @param level [Integer] livello del heading (1-6)
10
+ # @param theme [Symbol] tema del colore (:default, :white, etc.)
11
+ # @param align [Symbol] allineamento (:left, :center, :right)
12
+ # @param size [Symbol] dimensione (:small, :medium, :large)
13
+ # @param style [Symbol] stile (:normal, :bold, :italic, :underline)
14
+ # @param icon [String] icona opzionale
15
+ # @param subtitle [String] sottotitolo opzionale
16
+ # @param with_divider [Boolean] mostra linea divisoria
17
+ # @param html_options [Hash] opzioni HTML per il container
18
+ # @return [String] HTML del heading renderizzato
19
+ #
20
+ # @example Uso base
21
+ # bui_heading("Titolo principale")
22
+ # bui_heading("Sottotitolo", level: 3, theme: :blue)
23
+ #
24
+ # @example Con icona e sottotitolo
25
+ # bui_heading("Dashboard", icon: "home", subtitle: "Panoramica generale")
26
+ #
27
+ # @example Con divider
28
+ # bui_heading("Sezione", level: 2, with_divider: true, theme: :green)
29
+ #
30
+ # @example Con opzioni avanzate
31
+ # bui_heading(
32
+ # "Titolo personalizzato",
33
+ # level: 1,
34
+ # theme: :violet,
35
+ # align: :center,
36
+ # size: :large,
37
+ # style: :bold,
38
+ # icon: "star",
39
+ # subtitle: "Con tutte le opzioni",
40
+ # with_divider: true,
41
+ # id: "main-title",
42
+ # class: "custom-heading"
43
+ # )
44
+ def bui_heading(
45
+ text,
46
+ level: 2,
47
+ theme: :white,
48
+ align: :left,
49
+ size: :medium,
50
+ style: :normal,
51
+ icon: nil,
52
+ subtitle: nil,
53
+ with_divider: false,
54
+ **html_options
55
+ )
56
+ render BetterUi::General::Heading::Component.new(
57
+ level: level,
58
+ theme: theme,
59
+ align: align,
60
+ size: size,
61
+ style: style,
62
+ icon: icon,
63
+ subtitle: subtitle,
64
+ with_divider: with_divider,
65
+ **html_options
66
+ ).with_content(text)
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,16 @@
1
+ module BetterUi
2
+ module General
3
+ module Components
4
+ module Icon
5
+ module IconHelper
6
+ def bui_icon(name = nil, **options)
7
+ render BetterUi::General::Icon::Component.new(
8
+ name: name,
9
+ **options
10
+ )
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BetterUi
4
+ module General
5
+ module Components
6
+ module Input
7
+ module Checkbox
8
+ module CheckboxHelper
9
+ # Renderizza un componente Checkbox con tutti i parametri disponibili.
10
+ #
11
+ # @param name [String] Nome del campo checkbox (obbligatorio)
12
+ # @param value [String] Valore del checkbox (default: "1")
13
+ # @param checked [Boolean] Se il checkbox è selezionato
14
+ # @param required [Boolean] Se il campo è obbligatorio
15
+ # @param disabled [Boolean] Se il campo è disabilitato
16
+ # @param indeterminate [Boolean] Se il checkbox è in stato indeterminate
17
+ # @param label [String, nil] Testo della label associata al checkbox
18
+ # @param label_position [Symbol] Posizione della label (:left, :right)
19
+ # @param theme [Symbol] Tema del componente (:default, :white, :red, :rose, :orange, :green, :blue, :yellow, :violet)
20
+ # @param size [Symbol] Dimensione del componente (:small, :medium, :large)
21
+ # @param rounded [Symbol] Border radius (:none, :small, :medium, :large, :full)
22
+ # @param classes [String] Classi CSS aggiuntive
23
+ # @param form [ActionView::Helpers::FormBuilder, nil] Form builder Rails opzionale
24
+ # @param options [Hash] Opzioni aggiuntive per l'input (es. data attributes, aria attributes)
25
+ #
26
+ # @return [String] HTML del componente Checkbox renderizzato
27
+ #
28
+ # @example Uso base
29
+ # <%= bui_input_checkbox(name: 'accept_terms') %>
30
+ #
31
+ # @example Con label
32
+ # <%= bui_input_checkbox(name: 'newsletter', label: 'Iscriviti alla newsletter', checked: true) %>
33
+ #
34
+ # @example Con label a sinistra
35
+ # <%= bui_input_checkbox(name: 'terms', label: 'Accetto i termini e condizioni', label_position: :left, required: true) %>
36
+ #
37
+ # @example Con tema e dimensione personalizzati
38
+ # <%= bui_input_checkbox(name: 'important', label: 'Importante', theme: :green, size: :large) %>
39
+ #
40
+ # @example Con border radius personalizzato
41
+ # <%= bui_input_checkbox(name: 'rounded_option', label: 'Opzione arrotondata', rounded: :full) %>
42
+ #
43
+ # @example Con classi aggiuntive
44
+ # <%= bui_input_checkbox(name: 'custom', label: 'Campo personalizzato', classes: 'mb-4', checked: true) %>
45
+ #
46
+ # @example Con attributi HTML aggiuntivi
47
+ # <%= bui_input_checkbox(name: 'data-field', label: 'Campo obbligatorio', 'data-validation': 'required', 'aria-describedby': 'help-text') %>
48
+ #
49
+ # @example Con Rails form builder
50
+ # <%= form_with model: @user do |form| %>
51
+ # <%= bui_input_checkbox(name: :terms_accepted, label: 'Accetto i termini', form: form, theme: :green, required: true) %>
52
+ # <% end %>
53
+ #
54
+ # @example Stato indeterminate
55
+ # <%= bui_input_checkbox(name: 'partial_selection', label: 'Selezione parziale', indeterminate: true, theme: :blue) %>
56
+ def bui_input_checkbox(name:, value: '1', checked: false, required: false, disabled: false,
57
+ indeterminate: false, label: nil, label_position: :right, theme: :default,
58
+ size: :medium, rounded: :medium, classes: '', form: nil, **options)
59
+ render BetterUi::General::Input::Checkbox::Component.new(
60
+ name: name,
61
+ value: value,
62
+ checked: checked,
63
+ required: required,
64
+ disabled: disabled,
65
+ indeterminate: indeterminate,
66
+ label: label,
67
+ label_position: label_position,
68
+ theme: theme,
69
+ size: size,
70
+ rounded: rounded,
71
+ classes: classes,
72
+ form: form,
73
+ **options
74
+ )
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BetterUi
4
+ module General
5
+ module Components
6
+ module Input
7
+ module Datetime
8
+ module DatetimeHelper
9
+ # Crea un campo input datetime unificato
10
+ #
11
+ # @param name [String] Nome del campo input (obbligatorio)
12
+ # @param type [Symbol] Tipo del campo datetime (default: :date)
13
+ # Valori disponibili: :date, :month, :week, :time
14
+ # @param value [String] Valore del campo nel formato appropriato per il tipo
15
+ # @param required [Boolean] Se il campo è obbligatorio (default: false)
16
+ # @param disabled [Boolean] Se il campo è disabilitato (default: false)
17
+ # @param min [String] Valore minimo selezionabile nel formato appropriato
18
+ # @param max [String] Valore massimo selezionabile nel formato appropriato
19
+ # @param theme [Symbol] Tema del componente (default: :default)
20
+ # Valori disponibili: :default, :white, :red, :rose, :orange, :green, :blue, :yellow, :violet
21
+ # @param size [Symbol] Dimensione del componente (default: :medium)
22
+ # Valori disponibili: :small, :medium, :large
23
+ # @param rounded [Symbol] Border radius (default: :medium)
24
+ # Valori disponibili: :none, :small, :medium, :large, :full
25
+ # @param classes [String] Classi CSS aggiuntive
26
+ # @param form [ActionView::Helpers::FormBuilder] Form builder Rails opzionale per integrazione con form
27
+ # @param options [Hash] Attributi HTML aggiuntivi da passare all'elemento input
28
+ # @return [String] HTML del componente datetime input renderizzato
29
+ #
30
+ # @example Uso base per date
31
+ # <%= bui_input_datetime(name: 'birthdate', type: :date) %>
32
+ #
33
+ # @example Input per mese con validazione
34
+ # <%= bui_input_datetime(name: 'report_month', type: :month, required: true, min: '2024-01', max: '2024-12') %>
35
+ #
36
+ # @example Input per settimana con tema
37
+ # <%= bui_input_datetime(name: 'work_week', type: :week, theme: :blue, size: :large) %>
38
+ #
39
+ # @example Input per time con stili personalizzati
40
+ # <%= bui_input_datetime(name: 'meeting_time', type: :time, theme: :green, rounded: :full) %>
41
+ #
42
+ # @example Con Rails form builder
43
+ # <%= form_with model: @event do |form| %>
44
+ # <%= bui_input_datetime(name: :start_date, type: :date, form: form, theme: :blue, required: true) %>
45
+ # <%= bui_input_datetime(name: :start_time, type: :time, form: form, theme: :green) %>
46
+ # <% end %>
47
+ def bui_input_datetime(name:, type: :date, value: nil, required: false, disabled: false,
48
+ min: nil, max: nil, theme: :default, size: :medium, rounded: :medium,
49
+ classes: '', form: nil, **options)
50
+ render BetterUi::General::Input::Datetime::Component.new(
51
+ name: name,
52
+ type: type,
53
+ value: value,
54
+ required: required,
55
+ disabled: disabled,
56
+ min: min,
57
+ max: max,
58
+ theme: theme,
59
+ size: size,
60
+ rounded: rounded,
61
+ classes: classes,
62
+ form: form,
63
+ **options
64
+ )
65
+ end
66
+
67
+ # Helper convenienza per input date
68
+ def bui_input_date(name:, **options)
69
+ bui_input_datetime(name: name, type: :date, **options)
70
+ end
71
+
72
+ # Helper convenienza per input month
73
+ def bui_input_month(name:, **options)
74
+ bui_input_datetime(name: name, type: :month, **options)
75
+ end
76
+
77
+ # Helper convenienza per input week
78
+ def bui_input_week(name:, **options)
79
+ bui_input_datetime(name: name, type: :week, **options)
80
+ end
81
+
82
+ # Helper convenienza per input time
83
+ def bui_input_time(name:, **options)
84
+ bui_input_datetime(name: name, type: :time, **options)
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BetterUi
4
+ module General
5
+ module Components
6
+ module Input
7
+ module Radio
8
+ # Helper specifico per radio button Better UI
9
+ module RadioHelper
10
+ # Genera un radio button con stili Better UI
11
+ #
12
+ # @param name [String] Nome del campo radio (obbligatorio)
13
+ # @param value [String] Valore del radio button (obbligatorio)
14
+ # @param checked [Boolean] Se il radio è selezionato
15
+ # @param required [Boolean] Se il campo è obbligatorio
16
+ # @param disabled [Boolean] Se il campo è disabilitato
17
+ # @param label [String, nil] Testo della label associata al radio
18
+ # @param label_position [Symbol] Posizione della label (:left, :right)
19
+ # @param theme [Symbol] Tema del componente (:default, :white, :red, :rose, :orange, :green, :blue, :yellow, :violet)
20
+ # @param size [Symbol] Dimensione del componente (:small, :medium, :large)
21
+ # @param rounded [Symbol] Border radius (:none, :small, :medium, :large, :full)
22
+ # @param classes [String] Classi CSS aggiuntive
23
+ # @param form [ActionView::Helpers::FormBuilder, nil] Form builder Rails opzionale
24
+ # @param options [Hash] Opzioni aggiuntive per l'input
25
+ # @return [String] HTML del radio button renderizzato
26
+ #
27
+ # @example Gruppo radio base - Selezione genere (STESSO name, value DIVERSI)
28
+ # bui_input_radio(name: "gender", value: "male", label: "Maschio")
29
+ # bui_input_radio(name: "gender", value: "female", label: "Femmina")
30
+ # bui_input_radio(name: "gender", value: "other", label: "Altro")
31
+ #
32
+ # @example Gruppo radio con temi diversi - Priorità task
33
+ # bui_input_radio(name: "priority", value: "low", label: "Bassa", theme: :green)
34
+ # bui_input_radio(name: "priority", value: "medium", label: "Media", theme: :yellow)
35
+ # bui_input_radio(name: "priority", value: "high", label: "Alta", theme: :red, size: :large)
36
+ #
37
+ # @example Gruppo radio con Rails form builder
38
+ # <%= form_with model: @user do |form| %>
39
+ # <%= bui_input_radio(name: :role, value: "admin", label: "Amministratore", form: form) %>
40
+ # <%= bui_input_radio(name: :role, value: "user", label: "Utente", form: form) %>
41
+ # <%= bui_input_radio(name: :role, value: "guest", label: "Ospite", form: form) %>
42
+ # <% end %>
43
+ #
44
+ # @example Gruppo radio con selezione dinamica e validazione
45
+ # current_method = @user&.payment_method
46
+ # bui_input_radio(name: "payment", value: "card", label: "Carta", checked: current_method == "card", required: true)
47
+ # bui_input_radio(name: "payment", value: "bank", label: "Bonifico", checked: current_method == "bank", required: true)
48
+ # bui_input_radio(name: "payment", value: "cash", label: "Contrassegno", checked: current_method == "cash", required: true)
49
+ #
50
+ # @example Gruppo radio con attributi HTML personalizzati
51
+ # bui_input_radio(name: "notification", value: "email", label: "Email", theme: :blue, data: { action: "change->form#updateNotification" })
52
+ # bui_input_radio(name: "notification", value: "sms", label: "SMS", theme: :blue, data: { action: "change->form#updateNotification" })
53
+ # bui_input_radio(name: "notification", value: "push", label: "Push", theme: :blue, data: { action: "change->form#updateNotification" })
54
+ #
55
+ def bui_input_radio(name:, value:, checked: false, required: false, disabled: false,
56
+ label: nil, label_position: :right, theme: :default,
57
+ size: :medium, rounded: :full, classes: '', form: nil, **options)
58
+ render BetterUi::General::Input::Radio::Component.new(
59
+ name: name,
60
+ value: value,
61
+ checked: checked,
62
+ required: required,
63
+ disabled: disabled,
64
+ label: label,
65
+ label_position: label_position,
66
+ theme: theme,
67
+ size: size,
68
+ rounded: rounded,
69
+ classes: classes,
70
+ form: form,
71
+ **options
72
+ )
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BetterUi
4
+ module General
5
+ module Components
6
+ module Input
7
+ module RadioGroup
8
+ # Helper per creare gruppi di radio button Better UI
9
+ module RadioGroupHelper
10
+ # Genera un gruppo completo di radio button con stili Better UI
11
+ #
12
+ # @param name [String] Nome del campo radio (comune a tutto il gruppo)
13
+ # @param options [Array<Hash>] Array di opzioni per ogni radio button
14
+ # @param selected [String, nil] Valore dell'opzione selezionata
15
+ # @param theme [Symbol] Tema del componente (:default, :white, :red, :rose, :orange, :green, :blue, :yellow, :violet)
16
+ # @param size [Symbol] Dimensione del componente (:small, :medium, :large)
17
+ # @param rounded [Symbol] Border radius (:none, :small, :medium, :large, :full)
18
+ # @param direction [Symbol] Direzione del gruppo (:vertical, :horizontal)
19
+ # @param required [Boolean] Se il gruppo è obbligatorio
20
+ # @param disabled [Boolean] Se il gruppo è disabilitato
21
+ # @param classes [String] Classi CSS aggiuntive per il contenitore
22
+ # @param form [ActionView::Helpers::FormBuilder, nil] Form builder Rails opzionale
23
+ # @param html_options [Hash] Opzioni HTML aggiuntive per ogni radio
24
+ # @return [String] HTML del gruppo radio renderizzato
25
+ #
26
+ # @example Gruppo radio base - Selezione genere
27
+ # bui_input_radio_group(
28
+ # name: "gender",
29
+ # options: [
30
+ # { value: "male", label: "Maschio" },
31
+ # { value: "female", label: "Femmina" },
32
+ # { value: "other", label: "Altro" }
33
+ # ]
34
+ # )
35
+ #
36
+ # @example Gruppo radio con tema e selezione
37
+ # bui_input_radio_group(
38
+ # name: "priority",
39
+ # options: [
40
+ # { value: "low", label: "Bassa", theme: :green },
41
+ # { value: "medium", label: "Media", theme: :yellow },
42
+ # { value: "high", label: "Alta", theme: :red }
43
+ # ],
44
+ # selected: "medium",
45
+ # size: :large
46
+ # )
47
+ #
48
+ # @example Gruppo radio orizzontale con Rails form
49
+ # <%= form_with model: @user do |form| %>
50
+ # <%= bui_input_radio_group(
51
+ # name: :role,
52
+ # options: [
53
+ # { value: "admin", label: "Amministratore" },
54
+ # { value: "user", label: "Utente" },
55
+ # { value: "guest", label: "Ospite" }
56
+ # ],
57
+ # selected: @user.role,
58
+ # direction: :horizontal,
59
+ # form: form
60
+ # ) %>
61
+ # <% end %>
62
+ #
63
+ # @example Gruppo radio con validazione e attributi HTML
64
+ # bui_input_radio_group(
65
+ # name: "notification_type",
66
+ # options: [
67
+ # { value: "email", label: "Email" },
68
+ # { value: "sms", label: "SMS" },
69
+ # { value: "push", label: "Push Notification" }
70
+ # ],
71
+ # required: true,
72
+ # theme: :blue,
73
+ # html_options: { data: { action: "change->form#validateNotification" } }
74
+ # )
75
+ #
76
+ # @example Gruppo radio con temi personalizzati per opzione
77
+ # bui_input_radio_group(
78
+ # name: "status",
79
+ # options: [
80
+ # { value: "active", label: "Attivo", theme: :green },
81
+ # { value: "pending", label: "In Sospeso", theme: :yellow },
82
+ # { value: "inactive", label: "Inattivo", theme: :red }
83
+ # ],
84
+ # selected: "active",
85
+ # direction: :horizontal
86
+ # )
87
+ #
88
+ def bui_input_radio_group(name:, options:, selected: nil, theme: :default, size: :medium,
89
+ rounded: :full, direction: :vertical, required: false, disabled: false,
90
+ classes: '', form: nil, **html_options)
91
+ container_classes = [
92
+ 'space-y-2',
93
+ direction == :horizontal ? 'flex flex-wrap gap-6' : 'space-y-2',
94
+ classes
95
+ ].compact.join(' ')
96
+
97
+ content_tag(:div, class: container_classes) do
98
+ options.map do |option|
99
+ option_theme = option[:theme] || theme
100
+ option_classes = option[:classes] || ''
101
+
102
+ render BetterUi::General::Input::Radio::Component.new(
103
+ name: name,
104
+ value: option[:value],
105
+ label: option[:label],
106
+ checked: selected.to_s == option[:value].to_s,
107
+ theme: option_theme,
108
+ size: size,
109
+ rounded: rounded,
110
+ required: required,
111
+ disabled: disabled || option[:disabled],
112
+ classes: option_classes,
113
+ form: form,
114
+ **html_options
115
+ )
116
+ end.join.html_safe
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BetterUi
4
+ module General
5
+ module Components
6
+ module Input
7
+ module Select
8
+ module SelectHelper
9
+ # Renders a Select component for selection fields from option lists.
10
+ #
11
+ # @param name [String] Name of the select field
12
+ # @param options [Array<Hash>] Array of select options in format [{value: 'value', label: 'label'}, ...]
13
+ # @param selected [String, Array, nil] Selected value or values
14
+ # @param required [Boolean] Whether the field is required
15
+ # @param disabled [Boolean] Whether the field is disabled
16
+ # @param multiple [Boolean] Whether multiple options can be selected
17
+ # @param theme [Symbol] Component theme (:default, :white, :red, :rose, :orange, :green, :blue, :yellow, :violet)
18
+ # @param size [Symbol] Component size (:small, :medium, :large)
19
+ # @param rounded [Symbol] Border radius (:none, :small, :medium, :large, :full)
20
+ # @param placeholder [String, nil] Placeholder text for the field (creates an initial disabled option)
21
+ # @param classes [String] Additional CSS classes
22
+ # @param form [ActionView::Helpers::FormBuilder, nil] Optional Rails form builder
23
+ # @param options_html [Hash] Additional HTML attributes for option tags
24
+ # @param html_options [Hash] Additional HTML attributes for the select tag
25
+ #
26
+ # @return [String] Rendered HTML of the Select component
27
+ #
28
+ # @example Basic select
29
+ # <%= bui_input_select(name: 'country', options: [{value: 'it', label: 'Italy'}, {value: 'fr', label: 'France'}]) %>
30
+ #
31
+ # @example Select with selected option
32
+ # <%= bui_input_select(name: 'role', options: roles_array, selected: 'admin') %>
33
+ #
34
+ # @example Multiple select
35
+ # <%= bui_input_select(name: 'languages[]', options: languages_array, multiple: true, selected: ['en', 'fr']) %>
36
+ #
37
+ # @example Select with custom theme and size
38
+ # <%= bui_input_select(name: 'category', options: categories_array, theme: :blue, size: :large) %>
39
+ #
40
+ # @example With Rails form builder
41
+ # <%= form_with model: @user do |form| %>
42
+ # <%= bui_input_select(name: :country_id, options: countries_array, form: form, required: true) %>
43
+ # <% end %>
44
+ def bui_input_select(name:, options:, selected: nil, required: false, disabled: false,
45
+ multiple: false, theme: :default, size: :medium, rounded: :medium,
46
+ placeholder: nil, classes: '', form: nil, options_html: {}, **html_options)
47
+
48
+ render BetterUi::General::Input::Select::Component.new(
49
+ name: name,
50
+ options: options,
51
+ selected: selected,
52
+ required: required,
53
+ disabled: disabled,
54
+ multiple: multiple,
55
+ theme: theme,
56
+ size: size,
57
+ rounded: rounded,
58
+ placeholder: placeholder,
59
+ classes: classes,
60
+ form: form,
61
+ options_html: options_html,
62
+ **html_options
63
+ )
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end