fluxbit_view_components 0.2.0 → 0.3.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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/app/components/fluxbit/form/check_box_component.rb +56 -0
  3. data/app/components/fluxbit/form/component.rb +18 -24
  4. data/app/components/fluxbit/form/dropzone_component.html.erb +39 -0
  5. data/app/components/fluxbit/form/dropzone_component.rb +39 -0
  6. data/app/components/fluxbit/form/field_component.rb +26 -0
  7. data/app/components/fluxbit/form/form_builder_component.rb +1 -1
  8. data/app/components/fluxbit/form/{helper_text_component.rb → help_text_component.rb} +8 -3
  9. data/app/components/fluxbit/form/label_component.rb +32 -29
  10. data/app/components/fluxbit/form/range_component.rb +52 -0
  11. data/app/components/fluxbit/form/select_component.rb +88 -0
  12. data/app/components/fluxbit/form/text_field_component.rb +168 -0
  13. data/app/components/fluxbit/form/toggle_component.html.erb +23 -0
  14. data/app/components/fluxbit/form/toggle_component.rb +81 -0
  15. data/app/components/fluxbit/form/upload_image_component.html.erb +50 -0
  16. data/app/components/fluxbit/form/upload_image_component.rb +50 -0
  17. data/app/helpers/fluxbit/components_helper.rb +23 -51
  18. data/app/helpers/fluxbit/form_builder.rb +87 -0
  19. data/lib/fluxbit/config/form/check_box_component.rb +19 -0
  20. data/lib/fluxbit/config/form/dropzone_component.rb +20 -0
  21. data/lib/fluxbit/config/form/{helper_text_component.rb → help_text_component.rb} +1 -1
  22. data/lib/fluxbit/config/form/label_component.rb +30 -0
  23. data/lib/fluxbit/config/form/range_component.rb +15 -0
  24. data/lib/fluxbit/config/form/text_field_component.rb +76 -0
  25. data/{app/components/fluxbit/form/toggle_input_component.rb → lib/fluxbit/config/form/toggle_component.rb} +28 -115
  26. data/lib/fluxbit/view_components/version.rb +1 -1
  27. data/lib/fluxbit/view_components.rb +7 -1
  28. data/lib/install/install.rb +3 -3
  29. metadata +21 -18
  30. data/LICENSE.txt +0 -20
  31. data/app/components/fluxbit/form/checkbox_input_component.rb +0 -61
  32. data/app/components/fluxbit/form/datepicker_component.rb +0 -7
  33. data/app/components/fluxbit/form/radio_input_component.rb +0 -21
  34. data/app/components/fluxbit/form/range_input_component.rb +0 -51
  35. data/app/components/fluxbit/form/select_free_input_component.rb +0 -77
  36. data/app/components/fluxbit/form/select_input_component.rb +0 -21
  37. data/app/components/fluxbit/form/spacer_input_component.rb +0 -12
  38. data/app/components/fluxbit/form/text_input_component.rb +0 -225
  39. data/app/components/fluxbit/form/textarea_input_component.rb +0 -57
  40. data/app/components/fluxbit/form/upload_image_input_component.html.erb +0 -48
  41. data/app/components/fluxbit/form/upload_image_input_component.rb +0 -61
  42. data/app/components/fluxbit/form/upload_input_component.html.erb +0 -12
  43. data/app/components/fluxbit/form/upload_input_component.rb +0 -47
@@ -1,22 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Fluxbit::Form::ToggleInputComponent < Fluxbit::Form::Component
3
+ module Fluxbit::Config::Form::ToggleComponent
4
+ mattr_accessor :color, default: :default
5
+ mattr_accessor :unchecked_color, default: :default
6
+ mattr_accessor :button_color, default: :default
7
+ mattr_accessor :invert_label, default: false
8
+ mattr_accessor :sizing, default: 1
9
+
4
10
  # rubocop: disable Layout/LineLength, Metrics/BlockLength
5
- cattr_accessor :styles do
11
+ mattr_accessor :styles do
6
12
  {
7
- root: {
8
- base: "relative inline-flex items-center mr-2",
9
- base2: "relative inline-flex items-center",
10
- no_helper_text: "mb-5",
11
- active: {
12
- on: "cursor-pointer",
13
- off: "cursor-not-allowed opacity-50"
14
- },
15
- label: "ml-3 text-sm font-medium text-slate-900 dark:text-slate-300",
16
- input: "sr-only peer"
17
- },
13
+ label: "text-sm rtl:text-right font-medium text-gray-700 dark:text-gray-200 flex items-center",
14
+ input: "w-4 h-4 bg-gray-100 border-gray-300 dark:ring-offset-gray-800 focus:ring-2 rounded-sm dark:bg-gray-700 dark:border-gray-600 sr-only peer",
18
15
  toggle: {
19
- base: "toggle-bg rounded-full after:rounded-full peer peer-focus:ring-4 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:bg-white after:border after:transition-all",
16
+ base: "me-3 shrink-0 rounded-full peer-focus:ring-4 peer-checked:after:translate-x-full peer-checked:rtl:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:border after:rounded-full after:transition-all relative",
20
17
  checked: {
21
18
  default: "peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 peer-checked:bg-blue-600",
22
19
  success: "peer-focus:ring-green-300 dark:peer-focus:ring-green-800 peer-checked:bg-green-600",
@@ -58,109 +55,25 @@ class Fluxbit::Form::ToggleInputComponent < Fluxbit::Form::Component
58
55
  light_indigo: "bg-indigo-200 dark:bg-indigo-700 dark:border-indigo-600 after:border-indigo-300",
59
56
  light_pink: "bg-pink-200 dark:bg-pink-700 dark:border-pink-600 after:border-pink-300"
60
57
  },
61
- sizes: {
62
- sm: "w-9 h-5 after:top-[2px] after:left-[2px] after:h-4 after:w-4",
63
- md: "w-11 h-6 after:top-[2px] after:left-[2px] after:h-5 after:w-5",
64
- lg: "w-14 h-7 after:top-0.5 after:left-[4px] after:h-6 after:w-6"
65
- }
66
- },
67
- right_sided: {
68
- top: "flex items-center justify-between py-4",
69
- inside: "flex flex-col"
58
+ button: {
59
+ default: "after:bg-white",
60
+ success: "after:bg-green-500",
61
+ failure: "after:bg-red-500",
62
+ info: "after:bg-cyan-500"
63
+
64
+ },
65
+ sizes: [
66
+ "w-9 h-5 after:top-[2px] after:start-[2px] after:h-4 after:w-4",
67
+ "w-11 h-6 after:top-0.5 after:start-[2px] after:h-5 after:w-5",
68
+ "w-14 h-7 after:top-0.5 after:start-[4px] after:h-6 after:w-6"
69
+ ],
70
+ active: {
71
+ on: "cursor-pointer",
72
+ off: "cursor-not-allowed opacity-50"
73
+ },
74
+ invert_label: "ms-3"
70
75
  }
71
76
  }
72
77
  end
73
78
  # rubocop: enable Layout/LineLength, Metrics/BlockLength
74
-
75
- renders_one :helper, "Fluxbit::Form::HelperTextComponent"
76
-
77
- def initialize(form: nil, field: nil, color: nil, unchecked_color: :default, sizing: :md,
78
- right_sided: false, label: nil, helper_text: nil, helper_popover: nil,
79
- helper_popover_placement: "right", **props)
80
- super
81
- @form = form
82
- @field = field
83
- @object = form&.object
84
- @right_sided = right_sided
85
- @sizing = sizing.in?(styles[:toggle][:sizes].keys) ? sizing : :md
86
- @color = valid_color(color)
87
- @unchecked_color = unchecked_color.in?(styles[:toggle][:unchecked].keys) ? unchecked_color : :default
88
- @props = props
89
- @label = label_value(label, @object, field, id)
90
- @helper_text = define_helper_text(helper_text, @object, field)
91
- @helper_popover = define_helper_popover(helper_popover, @object, field)
92
- @helper_popover_placement = helper_popover_placement
93
- @label_class = "ml-2" unless right_sided
94
-
95
- # Input
96
- @props[:type] = "checkbox"
97
- declare_classes
98
- end
99
-
100
- def valid_color(color)
101
- return color if styles[:toggle][:checked].key?(color)
102
- return :failure if errors.present?
103
-
104
- :default
105
- end
106
-
107
- def declare_classes
108
- add(class: styles[:root][:input], to: @props)
109
-
110
- # Root
111
- @root_element = { class: "#{styles[:root][:base]} #{styles[:root][:active][(@props[:disabled] ? :off : :on)]}" }
112
-
113
- # Toggle
114
- @toggle_element = {
115
- class:
116
- [
117
- styles[:toggle][:base],
118
- styles[:toggle][:unchecked][@unchecked_color],
119
- styles[:toggle][:checked][@color],
120
- styles[:toggle][:sizes][@sizing]
121
- ].join(" ")
122
- }
123
- end
124
-
125
- def input
126
- if @form.nil?
127
- content_tag :input, content, @props
128
- else
129
- @form.check_box(@field, **@props)
130
- end
131
- end
132
-
133
- def toggle
134
- content_tag :div, "", @toggle_element
135
- end
136
-
137
- def toggle_input
138
- content_tag :div, safe_join(input, toggle), class: styles[:root][:base2]
139
- end
140
-
141
- def label_container
142
- content_tag(:label, safe_join(toggle_input, label), @root_element)
143
- end
144
-
145
- def left_sided
146
- safe_join label_container, (helper? ? helper : helper_text)
147
- end
148
-
149
- def right_sided
150
- content_tag :label, class: styles[:right_sided][:top] do
151
- safe_join(
152
- content_tag(
153
- :div,
154
- safe_join(label, (helper? ? helper : helper_text)),
155
- class: styles[:right_sided][:inside]
156
- ),
157
- toggle_input
158
- )
159
- end
160
- end
161
-
162
- def call
163
- add(class: styles[:root][:no_helper_text], to: @root_element) if @helper_text.nil? && !helper?
164
- @right_sided ? right_sided : left_sided
165
- end
166
79
  end
@@ -1,5 +1,5 @@
1
1
  module Fluxbit
2
2
  module ViewComponents
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -9,7 +9,13 @@ module Fluxbit
9
9
 
10
10
  module Config
11
11
  module Form
12
- require "fluxbit/config/form/helper_text_component"
12
+ require "fluxbit/config/form/help_text_component"
13
+ require "fluxbit/config/form/check_box_component"
14
+ require "fluxbit/config/form/dropzone_component"
15
+ require "fluxbit/config/form/label_component"
16
+ require "fluxbit/config/form/range_component"
17
+ require "fluxbit/config/form/text_field_component"
18
+ require "fluxbit/config/form/toggle_component"
13
19
  end
14
20
 
15
21
  require "fluxbit/config/alert_component"
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- gem_path = Gem.loaded_specs['fluxbit_view_components'].full_gem_path
3
+ gem_path = Gem.loaded_specs["fluxbit_view_components"].full_gem_path
4
4
  template_path = File.join(gem_path, "lib/fluxbit/templates/tailwind.config.js.template")
5
5
  darkmode_path = File.join(gem_path, "lib/fluxbit/templates/darkmode.js.template")
6
6
  layout_path = Rails.root.join("app/views/layouts/application.html.erb")
@@ -37,7 +37,7 @@ if stylesheets_path.exist?
37
37
  say.call "- Updating CSS with Flowbite imports..."
38
38
  content = File.read(stylesheets_path)
39
39
  content.prepend("@import \"flowbite/src/themes/default\";\n")
40
- content << "\n@plugin \"flowbite/plugin\";\n@source \"../../../node_modules/flowbite\";\n@config \"../../../tailwind.config.js\";\n"
40
+ content << "\n@plugin \"flowbite/plugin\";\n@source \"../../../node_modules/flowbite\";\n@config \"../../../tailwind.config.js\";\n@custom-variant dark (&:where(.dark, .dark *));\n\n"
41
41
  File.write(stylesheets_path, content)
42
42
  else
43
43
  say.call "⚠️ Couldn't find application.tailwind.css, skipping CSS modifications", :red
@@ -59,7 +59,7 @@ if layout_path.exist?
59
59
 
60
60
 
61
61
  if layout_content.include?("<body")
62
- # gsub_file layout_path.to_s, "<html", "<html class=\"<%= fluxbit_html_classes %>\""
62
+ # gsub_file layout_path.to_s, "<html", "<html class=\"<%= fx_html_class %>\""
63
63
  gsub_file layout_path.to_s, "<body>", "<body class=\"<%= fx_body_class %>\">"
64
64
  else
65
65
  say.call "<body> tag is not found in application layout.", :red
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluxbit_view_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur Molina
@@ -147,7 +147,6 @@ executables: []
147
147
  extensions: []
148
148
  extra_rdoc_files: []
149
149
  files:
150
- - LICENSE.txt
151
150
  - README.md
152
151
  - app/components/fluxbit/alert_component.rb
153
152
  - app/components/fluxbit/avatar_component.rb
@@ -158,24 +157,21 @@ files:
158
157
  - app/components/fluxbit/card_component.rb
159
158
  - app/components/fluxbit/component.rb
160
159
  - app/components/fluxbit/flex_component.rb
161
- - app/components/fluxbit/form/checkbox_input_component.rb
160
+ - app/components/fluxbit/form/check_box_component.rb
162
161
  - app/components/fluxbit/form/component.rb
163
- - app/components/fluxbit/form/datepicker_component.rb
162
+ - app/components/fluxbit/form/dropzone_component.html.erb
163
+ - app/components/fluxbit/form/dropzone_component.rb
164
+ - app/components/fluxbit/form/field_component.rb
164
165
  - app/components/fluxbit/form/form_builder_component.rb
165
- - app/components/fluxbit/form/helper_text_component.rb
166
+ - app/components/fluxbit/form/help_text_component.rb
166
167
  - app/components/fluxbit/form/label_component.rb
167
- - app/components/fluxbit/form/radio_input_component.rb
168
- - app/components/fluxbit/form/range_input_component.rb
169
- - app/components/fluxbit/form/select_free_input_component.rb
170
- - app/components/fluxbit/form/select_input_component.rb
171
- - app/components/fluxbit/form/spacer_input_component.rb
172
- - app/components/fluxbit/form/text_input_component.rb
173
- - app/components/fluxbit/form/textarea_input_component.rb
174
- - app/components/fluxbit/form/toggle_input_component.rb
175
- - app/components/fluxbit/form/upload_image_input_component.html.erb
176
- - app/components/fluxbit/form/upload_image_input_component.rb
177
- - app/components/fluxbit/form/upload_input_component.html.erb
178
- - app/components/fluxbit/form/upload_input_component.rb
168
+ - app/components/fluxbit/form/range_component.rb
169
+ - app/components/fluxbit/form/select_component.rb
170
+ - app/components/fluxbit/form/text_field_component.rb
171
+ - app/components/fluxbit/form/toggle_component.html.erb
172
+ - app/components/fluxbit/form/toggle_component.rb
173
+ - app/components/fluxbit/form/upload_image_component.html.erb
174
+ - app/components/fluxbit/form/upload_image_component.rb
179
175
  - app/components/fluxbit/gravatar_component.rb
180
176
  - app/components/fluxbit/heading_component.rb
181
177
  - app/components/fluxbit/modal_component.rb
@@ -185,6 +181,7 @@ files:
185
181
  - app/components/fluxbit/tooltip_component.rb
186
182
  - app/helpers/fluxbit/classes_helper.rb
187
183
  - app/helpers/fluxbit/components_helper.rb
184
+ - app/helpers/fluxbit/form_builder.rb
188
185
  - config/deploy.yml
189
186
  - config/locales/en.yml
190
187
  - lib/fluxbit/config/alert_component.rb
@@ -193,7 +190,13 @@ files:
193
190
  - lib/fluxbit/config/button_component.rb
194
191
  - lib/fluxbit/config/card_component.rb
195
192
  - lib/fluxbit/config/flex_component.rb
196
- - lib/fluxbit/config/form/helper_text_component.rb
193
+ - lib/fluxbit/config/form/check_box_component.rb
194
+ - lib/fluxbit/config/form/dropzone_component.rb
195
+ - lib/fluxbit/config/form/help_text_component.rb
196
+ - lib/fluxbit/config/form/label_component.rb
197
+ - lib/fluxbit/config/form/range_component.rb
198
+ - lib/fluxbit/config/form/text_field_component.rb
199
+ - lib/fluxbit/config/form/toggle_component.rb
197
200
  - lib/fluxbit/config/gravatar_component.rb
198
201
  - lib/fluxbit/config/heading_component.rb
199
202
  - lib/fluxbit/config/modal_component.rb
data/LICENSE.txt DELETED
@@ -1,20 +0,0 @@
1
- Copyright 2021 Dan Gamble
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Fluxbit::Form::CheckboxInputComponent < Fluxbit::Form::Component
4
- # rubocop: disable Layout/LineLength
5
- cattr_accessor :styles do
6
- {
7
- checkbox: "rounded-sm",
8
- base: "w-4 h-4 text-blue-600 bg-slate-100 border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-slate-700 dark:border-slate-600",
9
- label: {
10
- with_helper: "font-medium text-slate-900 dark:text-slate-300",
11
- base: "ml-2 text-sm font-medium text-slate-900 dark:text-slate-300"
12
- },
13
- input_div: "flex items-center h-5",
14
- helper_div: "ml-2 text-sm",
15
- no_helper_div: "flex items-center"
16
- }
17
- end
18
- # rubocop: enable Layout/LineLength
19
-
20
- def initialize(form: nil, field: nil, label: nil, helper_text: nil, helper_popover: nil,
21
- helper_popover_placement: "right", **props)
22
- super
23
- @form = form
24
- @field = field
25
- @object = form&.object
26
- @props = props
27
- @label = label_value(label, @object, field, id)
28
- @helper_text = define_helper_text(helper_text, @object, field)
29
- @helper_popover = define_helper_popover(helper_popover, @object, field)
30
- @helper_popover_placement = helper_popover_placement
31
-
32
- @props[:type] = @props[:type].to_s.in?(%w[checkbox radio]) ? @props[:type].to_s : "checkbox"
33
- add(class: styles[:checkbox], to: @props, first_element: true) if @props[:type] == "checkbox"
34
- add(class: styles[:base], to: @props, first_element: true)
35
- end
36
-
37
- def input
38
- if @form.nil?
39
- content_tag :input, content, @props
40
- else
41
- @form.text_field(@field, **@props)
42
- end
43
- end
44
-
45
- def call
46
- if @helper_text
47
- content_tag :div, { class: "flex" } do
48
- concat content_tag(:div, input, { class: styles[:input_div] })
49
- concat content_tag(:div, { class: styles[:helper_div] }) do
50
- concat label
51
- concat helper_text
52
- end
53
- end
54
- else
55
- content_tag :div, { class: styles[:no_helper_div] } do
56
- concat input
57
- concat label
58
- end
59
- end
60
- end
61
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Fluxbit::Form::DatepickerComponent < Fluxbit::Form::Component
4
- cattr_accessor :styles
5
-
6
- def call; end
7
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Fluxbit::Form::RadioInputComponent < Fluxbit::Form::Component
4
- def initialize(**kwargs, &block)
5
- super
6
- kwargs[:type] = :radio
7
-
8
- @component_klass = "Fluxbit::Form::CheckboxInputComponent".constantize
9
- @kwargs = kwargs
10
- @block = block
11
- end
12
-
13
- def call
14
- if @kwargs[:with_content]
15
- content = @kwargs.delete(:with_content)
16
- render(@component_klass.new(**@kwargs).with_content(content), &@block)
17
- else
18
- render(@component_klass.new(**@kwargs), &@block)
19
- end
20
- end
21
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Fluxbit::Form::RangeInputComponent < Fluxbit::Form::Component
4
- cattr_accessor :styles do
5
- {
6
- base: "w-full bg-slate-200 rounded-lg appearance-none cursor-pointer dark:bg-slate-700",
7
- sizes: {
8
- sm: "h-1 range-sm",
9
- md: "h-2",
10
- lg: "h-3 range-lg"
11
- }
12
- }
13
- end
14
-
15
- def initialize(form: nil, field: nil, sizing: :md, label: nil, helper_text: nil, helper_popover: nil,
16
- helper_popover_placement: "right", **props)
17
- super
18
- @form = form
19
- @field = field
20
- @object = form&.object
21
- @sizing = sizing.in?(styles[:sizes].keys) ? sizing : :md
22
- @props = props
23
- @label = label_value(label, @object, field, id)
24
- @helper_text = define_helper_text(helper_text, @object, field)
25
- @helper_popover = define_helper_popover(helper_popover, @object, field)
26
- @helper_popover_placement = helper_popover_placement
27
- @props[:type] = "range"
28
-
29
- add(class: styles[:sizes][@sizing], to: @props, first_element: true)
30
- add(class: styles[:base], to: @props, first_element: true)
31
- end
32
-
33
- def id
34
- return @id ||= (0...30).map { ("a".."z").to_a[rand(26)] }.join if @props[:id].nil? && @form.nil?
35
- return @props[:id] unless @props[:id].nil?
36
-
37
- "#{@form.object_name}_#{@field}"
38
- end
39
-
40
- def range
41
- if @form.nil?
42
- content_tag :input, content, @props
43
- else
44
- @form.text_field(@field, **@props)
45
- end
46
- end
47
-
48
- def call
49
- safe_join([ label, range, helper_text ])
50
- end
51
- end
@@ -1,77 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Fluxbit::Form::SelectFreeInputComponent < Fluxbit::Form::Component
4
- def initialize(free_option: "Specify...", **kwargs, &block)
5
- super
6
-
7
- @kwargs = kwargs
8
- @block = block
9
- @free_option = free_option
10
- end
11
-
12
- def call
13
- if @kwargs[:with_content]
14
- content = @kwargs.delete(:with_content)
15
- content_tag :div do
16
- concat render(Fluxbit::Form::SelectInputComponent.new(**select_params).with_content(content), &@block)
17
- concat render(Fluxbit::Form::TextInputComponent.new(**text_params).with_content(content), &@block)
18
- end
19
- else
20
- content_tag :div do
21
- concat render(Fluxbit::Form::SelectInputComponent.new(**select_params), &@block)
22
- concat render(Fluxbit::Form::TextInputComponent.new(**text_params), &@block)
23
- end
24
- end
25
- end
26
-
27
- private
28
-
29
- def select_params
30
- @kwargs[:options].push @free_option
31
- @kwargs.merge(
32
- {
33
- class: (corresponding_options? ? "" : "hidden").to_s,
34
- onchange: "
35
- const select = this.selectedOptions[0];
36
- const input = this.parentElement.querySelector('div > input');
37
- const input_div = this.parentElement.querySelector('div');
38
- if(select.value == '#{@free_option}') {
39
- input.value = ''
40
- this.classList.add('hidden');
41
- input_div.classList.remove('hidden');
42
- } else {
43
- input.value = select.value;
44
- }
45
- "
46
- }
47
- )
48
- end
49
-
50
- def text_params
51
- @kwargs.merge(
52
- {
53
- label: false,
54
- helper_popover: false,
55
- helper_text: false,
56
- right_icon: "heroicons_solid:x-mark:cursor-pointer",
57
- right_icon_props: {
58
- onclick: "
59
- this.parentElement.classList.add('hidden');
60
- this.parentElement.querySelector('input').value='';
61
- this.parentElement.parentElement.querySelector('select').classList.remove('hidden');
62
- this.parentElement.parentElement.querySelector('select').selectedIndex = null;
63
- "
64
- },
65
- div_props: { class: (corresponding_options? ? "hidden" : "").to_s }
66
- }
67
- )
68
- end
69
-
70
- def corresponding_options?
71
- value.blank? || @kwargs[:options].include?(value)
72
- end
73
-
74
- def value
75
- @kwargs[:value] || @kwargs[:form]&.object&[@kwargs[:field]]
76
- end
77
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Fluxbit::Form::SelectInputComponent < Fluxbit::Form::Component
4
- def initialize(**kwargs, &block)
5
- super
6
- kwargs[:type] = :select
7
-
8
- @component_klass = "Fluxbit::Form::TextInputComponent".constantize
9
- @kwargs = kwargs
10
- @block = block
11
- end
12
-
13
- def call
14
- if @kwargs[:with_content]
15
- content = @kwargs.delete(:with_content)
16
- render(@component_klass.new(**@kwargs).with_content(content), &@block)
17
- else
18
- render(@component_klass.new(**@kwargs), &@block)
19
- end
20
- end
21
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Fluxbit::Form::SpacerInputComponent < Fluxbit::Component
4
- def initialize(with_content: "", **_args)
5
- super
6
- @with_content = with_content
7
- end
8
-
9
- def call
10
- content || @with_content
11
- end
12
- end