fluxbit_view_components 0.4.1 → 0.4.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60a235092c19fce1b3548ee037d23e4698e106230bcffc2c64e38eea922c3fe2
4
- data.tar.gz: 61ffaeca393020f18b18a6b1956bf568c5bcc99379f4b53c778da4512fe48b82
3
+ metadata.gz: 98187d5ac8174cfe0b38638e43b70e8076ec32068cab920e5829105e0e903f6a
4
+ data.tar.gz: 1e7c9b50861f506bb56407ecdd008988a96c9b8d3f79f75e43fbae7f2642c989
5
5
  SHA512:
6
- metadata.gz: '046998a7d114dc3e3734079b51a509665ae36c1ec585891d832c514f8bfca125d1ea991dce89f49b9758872c97a0c4ce9ca5738d6e49457401f2e2a37626e6e2'
7
- data.tar.gz: 78d051dc5b7b9dd7ef26bcdaf5f26d6c3a1e8c6352dc1fe70dd19f3bfb46e933378e9fff5e79411aae94e85218526c3318ab66b0b88382a1e3f3026d548115e3
6
+ metadata.gz: 426024fbf92e4dd34587a9f14057a541e5f00cb501578026c940ffcc98739398cded786b733c36aa0d1d4de2292ce56b7700e9b93d630c4b15a9e58f9098a1e6
7
+ data.tar.gz: 688a8bec19c6def98088f4e59dc8bd96f46c7fc7818612e799bb77f2f44ebced4dc2055d77b7afcad78b6bbd1b5e0d9c16859fcf4ba62866ff472a15955f4c63
@@ -6,11 +6,7 @@
6
6
  @other_label || (other_label if other_label?)
7
7
  end %>
8
8
 
9
- <% if @form.present? && @attribute.present? %>
10
- <%= @form.check_box(@attribute, **@props) %>
11
- <% else %>
12
- <%= check_box_tag(@name, **@props) %>
13
- <% end %>
9
+ <%= checkbox_without_wrapper %>
14
10
 
15
11
  <span class="<%= toggle_class %>"></span>
16
12
  <%= if @invert_label
@@ -50,6 +50,7 @@ class Fluxbit::Form::ToggleComponent < Fluxbit::Form::FieldComponent
50
50
  @invert_label = options(@props.delete(:invert_label), collection: [ true, false ], default: @@invert_label)
51
51
 
52
52
  add to: @props, first_element: true, class: styles[:input]
53
+ @props[:class] = remove_class(@props.delete(:remove_class) || "", @props[:class])
53
54
  end
54
55
 
55
56
  def valid_color(color)
@@ -78,4 +79,25 @@ class Fluxbit::Form::ToggleComponent < Fluxbit::Form::FieldComponent
78
79
  styles[:toggle][:active][(@props[:disabled] ? :off : :on)]
79
80
  ].compact.join(" ")
80
81
  end
82
+
83
+ # Renders the checkbox without Rails' field_with_errors wrapper
84
+ # We handle errors through help_text instead
85
+ def checkbox_without_wrapper
86
+ return check_box_tag(@name, **@props) unless @form.present? && @attribute.present?
87
+
88
+ # Temporarily remove errors to prevent field_with_errors wrapper
89
+ if @object&.errors&.any? && @object.errors.include?(@attribute)
90
+ # Store the errors for this attribute
91
+ attribute_errors = @object.errors.where(@attribute).to_a
92
+ # Delete them temporarily
93
+ @object.errors.delete(@attribute)
94
+ # Render checkbox without wrapper
95
+ checkbox_html = @form.check_box(@attribute, **@props)
96
+ # Restore the errors
97
+ attribute_errors.each { |error| @object.errors.add(@attribute, error.type, **error.options) }
98
+ checkbox_html
99
+ else
100
+ @form.check_box(@attribute, **@props)
101
+ end
102
+ end
81
103
  end
@@ -15,19 +15,23 @@ class Fluxbit::PaginationComponent < Fluxbit::Component
15
15
  @next = @props.delete(:next)
16
16
  @page = @props.delete(:page) || 1
17
17
  @previous = @props.delete(:previous)
18
- @size = @props.delete(:size) || :default
18
+ @size = @props.delete(:size) || 3
19
19
  @ends = @props.delete(:ends) || true
20
20
  @request_path = @props.delete(:request_path) || nil
21
21
 
22
22
  if @pagy
23
- @count = @pagy.count
24
- @last = @pagy.last
25
- @next = @pagy.next
26
- @page = @pagy.page
27
- @previous = @pagy.previous
28
- @size = @pagy.vars[:size]
29
- @ends = @pagy.vars[:ends]
30
- @request_path = @pagy.vars[:request_path]
23
+ @count = @pagy.count if @pagy.respond_to?(:count)
24
+ @last = @pagy.last if @pagy.respond_to?(:last)
25
+ @next = @pagy.next if @pagy.respond_to?(:next)
26
+ @page = @pagy.page if @pagy.respond_to?(:page)
27
+ @previous = @pagy.prev if @pagy.respond_to?(:prev)
28
+ @previous = @pagy.previous if @pagy.respond_to?(:previous)
29
+
30
+ if @pagy.respond_to?(:vars)
31
+ @size = @pagy.vars[:size]
32
+ @ends = @pagy.vars[:ends]
33
+ @request_path = @pagy.vars[:request_path]
34
+ end
31
35
  end
32
36
 
33
37
  unless @size.is_a?(Integer) && @size >= 0
@@ -186,13 +190,14 @@ class Fluxbit::PaginationComponent < Fluxbit::Component
186
190
  end
187
191
 
188
192
  def url_for(page)
189
- vars = @pagy&.vars || {}
193
+ vars = @pagy.respond_to?(:vars) ? @pagy&.vars : {}
190
194
  # Use current request parameters as base
191
195
  params = (respond_to?(:request) ? request.GET : controller.request.GET).dup
192
196
  params.merge!(vars[:params].transform_keys(&:to_s)) if vars[:params].is_a?(Hash)
193
197
  # Set page and possibly limit
194
- params[vars[:page_param].to_s] = page
195
- params[vars[:limit_param].to_s] = vars[:limit] if vars[:limit_extra]
198
+ page_param = vars[:page_param]&.to_s.presence || 'page'
199
+ params[page_param] = page
200
+ params[vars[:limit_param].to_s] = vars[:limit] if vars[:limit_extra] && vars[:limit_param]
196
201
  # Apply params proc if given
197
202
  params = vars[:params].call(params) if vars[:params].is_a?(Proc)
198
203
 
@@ -1,5 +1,5 @@
1
1
  module Fluxbit
2
2
  module ViewComponents
3
- VERSION = "0.4.1"
3
+ VERSION = "0.4.3"
4
4
  end
5
5
  end
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.4.1
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur Molina