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,225 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- #
4
- # @param
5
- # form: The form to create a input element
6
- # options: {
7
- # size: :large, :base, :small,
8
- # label: nil | 'Label',
9
- # placeholder: nil | 'placeholder',
10
- # validators: [:required]
11
- # required: true | false | message,
12
- # }
13
- #
14
- # Validators can be predefined or customized:
15
- # [:required, :min_length, :max_length, :min_value, :max_value,
16
- # { type: :regexp, regex: /dd/, success: '', failure: ''},
17
- # ]
18
- #
19
- class Fluxbit::Form::TextInputComponent < Fluxbit::Form::Component
20
- # rubocop: disable Layout/LineLength, Metrics/BlockLength
21
- cattr_accessor :styles do
22
- {
23
- default: "mt-1 block w-full border disabled:cursor-not-allowed disabled:opacity-50 disabled:text-slate-900 disabled:dark:text-slate-400 disabled:bg-slate-100 disabled:dark:bg-slate-700",
24
- text: {
25
- default: "text-slate-900 dark:text-white",
26
- success: "text-green-900",
27
- failure: "text-red-900",
28
- info: "text-cyan-900",
29
- warning: "text-yellow-900"
30
- },
31
- ring: {
32
- default: "focus:ring-blue-500 dark:focus:ring-blue-500",
33
- success: "focus:ring-green-500",
34
- failure: "focus:ring-red-500",
35
- info: "focus:ring-cyan-500",
36
- warning: "focus:ring-yellow-500"
37
- },
38
- bg: {
39
- default: "bg-slate-50 dark:bg-slate-700",
40
- success: "bg-green-50 dark:bg-green-100",
41
- failure: "bg-red-50 dark:bg-red-100",
42
- info: "bg-cyan-50 dark:bg-cyan-100",
43
- warning: "bg-yellow-50 dark:bg-yellow-100"
44
- },
45
- placeholder: {
46
- default: "dark:placeholder-slate-400",
47
- success: "placeholder-green-700",
48
- failure: "placeholder-red-700",
49
- info: "placeholder-cyan-700",
50
- warning: "placeholder-yellow-700"
51
- },
52
- border: {
53
- default: "border-slate-300 focus:border-blue-500 dark:border-slate-600 dark:focus:border-blue-500",
54
- success: "border-green-500 focus:border-green-500 dark:border-green-400",
55
- failure: "border-red-500 focus:border-red-500 dark:border-red-400",
56
- info: "border-cyan-500 focus:border-cyan-500 dark:border-cyan-400",
57
- warning: "border-yellow-500 focus:border-yellow-500 dark:border-yellow-400"
58
- },
59
- shadow: "shadow-xs dark:shadow-xs-light",
60
- icon: "pl-10",
61
- right_icon: "pr-10",
62
- sizing: {
63
- md: "p-2.5 text-sm rounded-lg",
64
- lg: "p-4 sm:text-md rounded-lg",
65
- sm: "p-2 rounded-lg sm:text-xs",
66
- md_addon: "p-2.5 rounded-none rounded-r-lg flex-1 min-w-0 text-sm"
67
- },
68
- additional_icons: {
69
- class: {
70
- default: "mt-1 w-4 h-4 text-slate-500 dark:text-slate-400",
71
- success: "mt-1 w-4 h-4 text-green-500 dark:text-green-400",
72
- failure: "mt-1 w-4 h-4 text-red-500 dark:text-red-400",
73
- info: "mt-1 w-4 h-4 text-cyan-500 dark:text-cyan-400",
74
- warning: "mt-1 w-4 h-4 text-yellow-500 dark:text-yellow-400"
75
- },
76
- icon: "absolute inset-y-0 left-0 flex items-center pl-3",
77
- right_icon: "absolute inset-y-0 right-0 flex items-center pr-3",
78
- addon: {
79
- default: "mt-1 inline-flex items-center px-3 text-sm text-slate-900 bg-slate-200 border border-r-0 border-slate-300 rounded-l-md dark:bg-slate-600 dark:text-slate-400 dark:border-slate-600",
80
- success: "mt-1 inline-flex items-center px-3 text-sm text-green-900 bg-green-200 border border-r-0 border-green-300 rounded-l-md dark:bg-green-600 dark:text-green-400 dark:border-green-600",
81
- failure: "mt-1 inline-flex items-center px-3 text-sm text-red-900 bg-red-200 border border-r-0 border-red-300 rounded-l-md dark:bg-red-600 dark:text-red-400 dark:border-red-600",
82
- info: "mt-1 inline-flex items-center px-3 text-sm text-cyan-900 bg-cyan-200 border border-r-0 border-cyan-300 rounded-l-md dark:bg-cyan-600 dark:text-cyan-400 dark:border-cyan-600",
83
- warning: "mt-1 inline-flex items-center px-3 text-sm text-yellow-900 bg-yellow-200 border border-r-0 border-yellow-300 rounded-l-md dark:bg-yellow-600 dark:text-yellow-400 dark:border-yellow-600"
84
- }
85
- }
86
- }
87
- end
88
- # rubocop: enable Layout/LineLength, Metrics/BlockLength
89
-
90
- def initialize(form: nil, field: nil, id: nil, shadow: false, type: "text", helper_text: nil,
91
- helper_popover: nil, helper_popover_placement: "right", icon: nil,
92
- right_icon: nil, addon: nil, color: nil, label: nil, sizing: :md, i18n: nil, options: [],
93
- validators: [], div_props: {}, icon_props: {}, right_icon_props: {}, addon_props: {}, **props)
94
- super
95
- @form = form
96
- @object = form&.object
97
- @field = field
98
- @id = id
99
- @shadow = shadow
100
- @type = valid_input_type(type)
101
- @helper_text = define_helper_text(helper_text, @object, field)
102
- @helper_popover = define_helper_popover(helper_popover, @object, field)
103
- @helper_popover_placement = helper_popover_placement
104
- @icon = icon
105
- @right_icon = right_icon
106
- @addon = addon
107
- @color = valid_color(color)
108
- @label = label_value(label, @object, field, id)
109
- @sizing = sizing_with_addon(sizing, addon)
110
- @validators = validators
111
- @props = props.merge(type: @type)
112
- @options = options
113
- @sizing = :md_addon if addon
114
- @div_props = div_props
115
- @icon_props = icon_props
116
- @right_icon_props = right_icon_props
117
- @addon_props = addon_props
118
-
119
- declare_classes
120
- end
121
-
122
- def call
123
- safe_join [ label, icon_container, helper_text ]
124
- end
125
-
126
- private
127
-
128
- def valid_input_type(type)
129
- %w[email password number search time date datetime-local select].include?(type.to_s) ? type.to_s : "text"
130
- end
131
-
132
- def valid_color(color)
133
- return color if styles[:bg].key?(color)
134
- return :failure if errors.present?
135
-
136
- :default
137
- end
138
-
139
- def sizing_with_addon(sizing, addon)
140
- return :md_addon if addon
141
-
142
- sizing.in?(%i[md sm lg]) ? sizing : :md
143
- end
144
-
145
- def declare_classes
146
- add to: @props,
147
- first_element: true,
148
- class: [
149
- styles[:default],
150
- (@props.key?(:readonly) || @props.key?(:disabled) ? styles[:text][@color] : ""),
151
- styles[:ring][@color],
152
- styles[:bg][@color],
153
- styles[:placeholder][@color],
154
- styles[:border][@color],
155
- styles[:sizing][@sizing],
156
- (@shadow ? styles[:shadow] : ""),
157
- (@right_icon ? styles[:right_icon] : ""),
158
- (@icon ? styles[:icon] : "")
159
- ].join(" ")
160
- end
161
-
162
- def icon(icon_v, tag: :div, props: nil)
163
- return "" if icon_v.blank?
164
-
165
- content_tag(
166
- tag,
167
- anyicon(
168
- icon: icon_v,
169
- class: styles[:additional_icons][:class][@color]
170
- ),
171
- **props
172
- )
173
- end
174
-
175
- def create_icon
176
- add class: styles[:additional_icons][:icon], to: @icon_props
177
- add(class: "pointer-events-none", to: @icon_props) unless events?(@icon_props)
178
- icon(@icon, props: @icon_props)
179
- end
180
-
181
- def create_addon
182
- add class: styles[:additional_icons][:addon][@color], to: @addon_props
183
- icon(@addon, tag: :span, props: @addon_props)
184
- end
185
-
186
- def create_right_icon
187
- add class: styles[:additional_icons][:right_icon], to: @right_icon_props
188
- add(class: "pointer-events-none", to: @right_icon_props) unless events?(@right_icon_props)
189
- icon(@right_icon, props: @right_icon_props)
190
- end
191
-
192
- def events?(props)
193
- props.keys.intersection(
194
- %i[onclick onsubmit onchange onkeydown onkeyup onkeypress href]
195
- ).present?
196
- end
197
-
198
- def input
199
- return content_tag :input, content, @props if @form.nil?
200
-
201
- if @type == "select"
202
- @props[:prompt] = @props[:placeholder] if @props[:placeholder]
203
- return @form.select(@field, @options || [], {}, @props)
204
- end
205
-
206
- @form.text_field(@field, **@props)
207
- end
208
-
209
- def icon_container_with_addon
210
- add class: "flex", to: @div_props
211
- content_tag :div, safe_join([ create_addon, create_right_icon, input ]), @div_props
212
- end
213
-
214
- def icon_container_without_addon
215
- add class: "relative w-full", to: @div_props
216
- content_tag :div, safe_join([ create_icon, create_right_icon, input ]), @div_props
217
- end
218
-
219
- def icon_container
220
- return input if @icon.nil? && @right_icon.nil? && @addon.nil?
221
- return icon_container_with_addon unless @addon.nil?
222
-
223
- icon_container_without_addon
224
- end
225
- end
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Fluxbit::Form::TextareaInputComponent < Fluxbit::Form::Component
4
- # rubocop: disable Layout/LineLength
5
- cattr_accessor :styles do
6
- {
7
- base: "mt-1 block w-full rounded-lg border disabled:cursor-not-allowed disabled:opacity-50 text-sm",
8
- bg: {
9
- default: "bg-slate-50 border-slate-300 text-slate-900 focus:border-blue-500 focus:ring-blue-500 dark:border-slate-600 dark:bg-slate-700 dark:text-white dark:placeholder-slate-400 dark:focus:border-blue-500 dark:focus:ring-blue-500",
10
- success: "border-green-500 bg-green-50 text-green-900 placeholder-green-700 focus:border-green-500 focus:ring-green-500 dark:border-green-400 dark:bg-green-100 dark:focus:border-green-500 dark:focus:ring-green-500",
11
- failure: "border-red-500 bg-red-50 text-red-900 placeholder-red-700 focus:border-red-500 focus:ring-red-500 dark:border-red-400 dark:bg-red-100 dark:focus:border-red-500 dark:focus:ring-red-500",
12
- info: "border-cyan-500 bg-cyan-50 text-cyan-900 placeholder-cyan-700 focus:border-cyan-500 focus:ring-cyan-500 dark:border-cyan-400 dark:bg-cyan-100 dark:focus:border-cyan-500 dark:focus:ring-cyan-500",
13
- warning: "border-yellow-500 bg-yellow-50 text-yellow-900 placeholder-yellow-700 focus:border-yellow-500 focus:ring-yellow-500 dark:border-yellow-400 dark:bg-yellow-100 dark:focus:border-yellow-500 dark:focus:ring-yellow-500"
14
- },
15
- shadow: "shadow-xs dark:shadow-xs-light"
16
- }
17
- end
18
- # rubocop: enable Layout/LineLength
19
-
20
- def initialize(form: nil, field: nil, color: nil, label: nil, helper_text: nil, helper_popover: nil,
21
- helper_popover_placement: "right", shadow: false, **props)
22
- super
23
- @form = form
24
- @object = form&.object
25
- @field = field
26
- @shadow = shadow
27
- @color = valid_color(color)
28
- @props = props
29
- @label = label_value(label, @object, field, id)
30
- @helper_text = define_helper_text(helper_text, @object, field)
31
- @helper_popover = define_helper_popover(helper_popover, @object, field)
32
- @helper_popover_placement = helper_popover_placement
33
-
34
- add(class: styles[:shadow], to: @props, first_element: true) if shadow
35
- add(class: styles[:bg][@color], to: @props, first_element: true)
36
- add(class: styles[:base], to: @props, first_element: true)
37
- end
38
-
39
- def valid_color(color)
40
- return color if styles[:bg].key?(color)
41
- return :failure if errors.present?
42
-
43
- :default
44
- end
45
-
46
- def textarea
47
- if @form.nil?
48
- content_tag :textarea, content, @props
49
- else
50
- @form.text_area(@field, **@props)
51
- end
52
- end
53
-
54
- def call
55
- safe_join([ label, textarea, helper_text ])
56
- end
57
- end
@@ -1,48 +0,0 @@
1
- <div id="<%= id %>" class="mt-6 grow lg:mt-0 lg:ml-6 lg:shrink-0 lg:grow-0">
2
- <%= label %>
3
- <div class="mt-1 lg:hidden">
4
- <div class="flex items-center">
5
- <div class="inline-block h-12 w-12 shrink-0 overflow-hidden rounded-full relative" aria-hidden="true">
6
- <%= image_element %>
7
- </div>
8
- <div class="ml-5 rounded-md shadow-xs">
9
- <div class="group relative flex items-center justify-center rounded-md border border-slate-300 py-2 px-3 focus-within:ring-2 focus-within:ring-sky-500 focus-within:ring-offset-2 hover:bg-slate-50">
10
- <label for="mobile-<%= id %>" class="pointer-events-none relative text-sm font-medium leading-4 text-slate-700">
11
- <span>Change</span>
12
- <span class="sr-only"><%= @label %></span>
13
- </label>
14
- <%= input_element(input_id: "mobile-#{id}") %>
15
- </div>
16
- </div>
17
- </div>
18
- </div>
19
-
20
-
21
- <div class="relative hidden overflow-hidden rounded-full lg:block w-40">
22
-
23
- <div class="inline-block h-40 w-40 shrink-0 overflow-hidden rounded-full relative" aria-hidden="true">
24
- <%= image_element %>
25
- </div>
26
-
27
- <label for="desktop-<%= id %>" class="absolute inset-0 flex flex-col h-full w-full items-center justify-center bg-blue-800/75 text-sm font-medium text-white opacity-0 hover:opacity-100">
28
- <svg xmlns="http://www.w3.org/2000/svg" class="h-12 w-12 text-white mb-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
29
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"></path>
30
- </svg>
31
- <span>Change</span>
32
- <span class="sr-only"><%= @label %></span>
33
- <%= input_element(input_id: "desktop-#{id}") %>
34
- </label>
35
- </div>
36
- <%= helper_text %>
37
- </div>
38
-
39
- <script>
40
- var loadFile = function(event, id) {
41
- const elements = document.getElementById('business_logo_image').querySelectorAll('.img_photo');
42
-
43
- elements.forEach(element => {
44
- element.src = URL.createObjectURL(event.target.files[0]);
45
- element.onload = function() { URL.revokeObjectURL(element.src) }
46
- });
47
- };
48
- </script>
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Fluxbit::Form::UploadImageInputComponent < Fluxbit::Form::Component
4
- cattr_accessor :styles do
5
- {
6
- height: {
7
- no: "",
8
- sm: "h-32",
9
- md: "h-64",
10
- lg: "h-96"
11
- }
12
- }
13
- end
14
-
15
- def initialize(form: nil, field: nil, id: nil, height: :md, label: nil, helper_text: nil, helper_popover: nil,
16
- helper_popover_placement: "right", type: nil, image_path: nil, image_placeholder: nil,
17
- title: true, subtitle: true, **props)
18
- super
19
- @form = form
20
- @object = form&.object
21
- @field = field
22
- @id = id
23
- @title = title
24
- @subtitle = subtitle
25
- @props = props
26
- # @height = height.in?(styles[:height].keys) ? height : :md
27
- @label = label_value(label, @object, field, id)
28
- @helper_text = helper_text.present? ? 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
- @image_path = image_path || (if @object&.send(@field)&.send("attached?")
32
- @object&.send(@field)&.variant(resize_to_fit: [ 160, 160 ])
33
- end) || image_placeholder || ""
34
- @props["class"] = "absolute inset-0 h-full w-full cursor-pointer rounded-md border-gray-300 opacity-0"
35
- end
36
-
37
- def input_element(input_id: nil)
38
- @props["onchange"] = "loadFile(event, '#{id}')"
39
- return content_tag :input, nil, @props.merge(id: input_id || id) if @form.nil?
40
-
41
- @form.file_field(@field, **@props, id: input_id || id)
42
- end
43
-
44
- def image_element
45
- image_tag @image_path,
46
- class: "img_photo absolute inset-0 w-full h-full object-cover rounded-full",
47
- alt: @field&.to_s&.humanize
48
- end
49
-
50
- def title
51
- return safe_join(content_tag(:span, "Click to upload", class: "font-semibold"), " or drag and drop") if @title == true
52
-
53
- @title
54
- end
55
-
56
- def subtitle
57
- return "SVG, PNG, JPG or GIF (MAX. 800x400px)" if @subtitle == true
58
-
59
- @subtitle
60
- end
61
- end
@@ -1,12 +0,0 @@
1
- <div class="<%= self.styles[:bae] %>">
2
- <label for="<%= id %>" class="<%= self.styles[:label] %> <%= self.styles[:height][@height] %>">
3
- <div class="<%= self.styles[:inner_div] %>">
4
- <svg class="w-8 h-8 mb-4 text-slate-500 dark:text-slate-400" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 16">
5
- <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 13h3a3 3 0 0 0 0-6h-.025A5.56 5.56 0 0 0 16 6.5 5.5 5.5 0 0 0 5.207 5.021C5.137 5.017 5.071 5 5 5a4 4 0 0 0 0 8h2.167M10 15V6m0 0L8 8m2-2 2 2"/>
6
- </svg>
7
- <p class="<%= self.styles[:title] %>"><%= title %></p>
8
- <p class="<%= self.styles[:subtitle] %>"><%= subtitle %></p>
9
- </div>
10
- <input id="<%= id %>" name="<%= @name %>" type="file" class="hidden" />
11
- </label>
12
- </div>
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Fluxbit::Form::UploadInputComponent < Fluxbit::Form::Component
4
- # rubocop: disable Layout/LineLength
5
- cattr_accessor :styles do
6
- {
7
- base: "flex items-center justify-center w-full",
8
- label: "flex flex-col items-center justify-center w-full border-2 border-slate-300 border-dashed rounded-lg cursor-pointer bg-slate-50 dark:hover:bg-bray-800 dark:bg-slate-700 hover:bg-slate-100 dark:border-slate-600 dark:hover:border-slate-500 dark:hover:bg-slate-600",
9
- inner_div: "flex flex-col items-center justify-center pt-5 pb-6",
10
- title: "mb-2 text-sm text-slate-500 dark:text-slate-400",
11
- subtitle: "text-xs text-slate-500 dark:text-slate-400",
12
- height: {
13
- no: "",
14
- sm: "h-32",
15
- md: "h-64",
16
- lg: "h-96"
17
- }
18
- }
19
- end
20
- # rubocop: enable Layout/LineLength
21
-
22
- def initialize(form: nil, field: nil, id: nil, height: :md,
23
- title: true, subtitle: true, **props)
24
- super
25
- @form = form
26
- @object = form&.object
27
- @field = field
28
- @id = id
29
- @title = title
30
- @subtitle = subtitle
31
- @props = props
32
- @height = height.in?(styles[:height].keys) ? height : :md
33
- end
34
-
35
- def title
36
- return safe_join(content_tag(:span, "Click to upload", class: "font-semibold"),
37
- " or drag and drop") if @title == true
38
-
39
- @title
40
- end
41
-
42
- def subtitle
43
- return "SVG, PNG, JPG or GIF (MAX. 800x400px)" if @subtitle == true
44
-
45
- @subtitle
46
- end
47
- end