bulma-phlex-rails 0.3.0 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8534c00b03a3ae8dad07d870b62ff94369802828940f05f6e8e9389b916c3dc9
4
- data.tar.gz: 8a1284dc1ec5c8dd3a8bb60fdba5e69303fb6f3ae6a18bf6b3f58e70baf1840a
3
+ metadata.gz: 44794453fc2f23bad30359fbe4c2334a3f01f492e883d149752eb7855d22926e
4
+ data.tar.gz: 63fafad11cdb41bb3c26e768bb9042faea483befb1802c0741b9c054cd9262a9
5
5
  SHA512:
6
- metadata.gz: ed9272374b031aba4d8a685b011a5bd9f86989302da74cf8de070295e5457ce4b3502d1a6469ce94fdd536f6bca7bf5df0d501e2d4f29cd5c6f11e43a371ad98
7
- data.tar.gz: ee41ceed1abc0e13778f74dce863579396740d19854f465fb1d12d086d3ca8480a6abb34c6959a8885dd9cff237fc9618632d3b2c7e3a154dca4439929eeed80
6
+ metadata.gz: 88e3734a644ae73ccde892ddbae655a6e3f5e18ae1d3ec5ed951822d4ec3a1c4bd903f0f315e8811860929d4e473894e4dfd536da4c39b12bad59230459036d4
7
+ data.tar.gz: f36bcded467eacbc374f08b75a8033aa0e9089de882f2363c9d51f547803b7b9586478ddbdb2377ec4bb2f3091b967a6bd901f18a184b85cdeae3d170268b0d4
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BulmaPhlex
4
+ module Rails
5
+ # # Checkbox Component
6
+ #
7
+ # This component renders a Bulma-styled checkbox within a form. It integrates with Rails' form builder
8
+ # to ensure proper labeling and value handling.
9
+ #
10
+ # The label can be generated automatically based on the attribute name or customized using a block.
11
+ #
12
+ # Example usage:
13
+ #
14
+ # ```ruby
15
+ # form_with model: @user do |f|
16
+ # f.checkbox :subscribe_newsletter
17
+ # f.checkbox :terms_of_service do
18
+ # span { "I agree to " }
19
+ # a(href: "/terms") { "the terms and conditions" }
20
+ # end
21
+ # end
22
+ # ```
23
+ class Checkbox < BulmaPhlex::Base
24
+ def initialize(form_builder, method, options, delivered, label_block)
25
+ @form_builder = form_builder
26
+ @method = method
27
+ @options = options.dup
28
+ @delivered = delivered
29
+ @label_block = label_block
30
+
31
+ @options[:class] = Array.wrap(@options[:class]) << "mr-2"
32
+ @form_field_options = @options.extract!(:column, :grid)
33
+ .with_defaults(column: @form_builder.columns_flag,
34
+ grid: @form_builder.grid_flag)
35
+ end
36
+
37
+ def view_template
38
+ render FormField.new(**@form_field_options) do |f|
39
+ f.control do
40
+ @form_builder.label(@method, nil, class: "checkbox", skip_label_class: true) do |label_builder|
41
+ raw @delivered.call(@options)
42
+ render_label(label_builder)
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def render_label(label_builder)
51
+ output = @label_block ? @label_block.call(label_builder) : label_builder.to_s
52
+
53
+ # ActiveSupport::SafeBuffer is html safe, strings are not
54
+ if output.html_safe?
55
+ raw output
56
+ else
57
+ plain output
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -13,22 +13,68 @@ module BulmaPhlex
13
13
  # - `column`: If true, the input will be wrapped in a Bulma column (only within a `columns` block).
14
14
  # - `grid`: If true, the input will be wrapped in a Bulma grid cell (only within a `grid` block).
15
15
  class FormBuilder < ActionView::Helpers::FormBuilder
16
- def text_field(method, **options) = wrap_field(method, options) { |m, opts| super(m, opts) }
17
- def password_field(method, **options) = wrap_field(method, options) { |m, opts| super(m, opts) }
18
- def color_field(method, **options) = wrap_field(method, options) { |m, opts| super(m, opts) }
19
- def search_field(method, **options) = wrap_field(method, options) { |m, opts| super(m, opts) }
20
- def telephone_field(method, **options) = wrap_field(method, options) { |m, opts| super(m, opts) }
21
- def phone_field(method, **options) = wrap_field(method, options) { |m, opts| super(m, opts) }
22
- def date_field(method, **options) = wrap_field(method, options) { |m, opts| super(m, opts) }
23
- def time_field(method, **options) = wrap_field(method, options) { |m, opts| super(m, opts) }
24
- def datetime_field(method, **options) = wrap_field(method, options) { |m, opts| super(m, opts) }
25
- def datetime_local_field(method, **options) = wrap_field(method, options) { |m, opts| super(m, opts) }
26
- def month_field(method, **options) = wrap_field(method, options) { |m, opts| super(m, opts) }
27
- def week_field(method, **options) = wrap_field(method, options) { |m, opts| super(m, opts) }
28
- def url_field(method, **options) = wrap_field(method, options) { |m, opts| super(m, opts) }
29
- def email_field(method, **options) = wrap_field(method, options) { |m, opts| super(m, opts) }
30
- def number_field(method, **options) = wrap_field(method, options) { |m, opts| super(m, opts) }
31
- def range_field(method, **options) = wrap_field(method, options) { |m, opts| super(m, opts) }
16
+ attr_reader :columns_flag, :grid_flag
17
+
18
+ def text_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
19
+ def password_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
20
+ def color_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
21
+ def search_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
22
+ def telephone_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
23
+ def phone_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
24
+ def date_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
25
+ def time_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
26
+ def datetime_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
27
+ def datetime_local_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
28
+ def month_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
29
+ def week_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
30
+ def url_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
31
+ def email_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
32
+ def number_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
33
+ def range_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
34
+
35
+ def textarea(method, options = {})
36
+ wrap_field(method, options, add_class: "textarea") do |m, opts|
37
+ super(m, opts)
38
+ end
39
+ end
40
+ alias text_area textarea
41
+
42
+ def checkbox(method, options = {}, checked_value = "1", unchecked_value = "0", &label_block)
43
+ delivered = ->(opts) { super(method, opts, checked_value, unchecked_value) }
44
+ Checkbox.new(self, method, options, delivered, label_block).render_in(@template)
45
+ end
46
+ alias check_box checkbox
47
+
48
+ # Override label to add Bulma's `label` class by default. Add `:skip_label_class` option
49
+ # to skip adding the class.
50
+ def label(method, text = nil, options = {}, &)
51
+ skip_label_class = options.delete(:skip_label_class)
52
+ options[:class] = Array.wrap(options[:class]) << :label unless skip_label_class
53
+ super
54
+ end
55
+
56
+ def select(method, choices = nil, options = {}, html_options = {}, &)
57
+ wrap_select_field(method, html_options) do |m, html_opts|
58
+ super(m, choices, options, html_opts, &)
59
+ end
60
+ end
61
+
62
+ # rubocop:disable Metrics/ParameterLists
63
+ def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
64
+ wrap_select_field(method, html_options) do |m, html_opts|
65
+ super(m, collection, value_method, text_method, options, html_opts)
66
+ end
67
+ end
68
+ # rubocop:enable Metrics/ParameterLists
69
+
70
+ def submit(value = nil, options = {})
71
+ options = options.dup
72
+ options[:class] = Array.wrap(options[:class]) << :button
73
+
74
+ FormField.new do |field|
75
+ field.control { super(value, options) }
76
+ end.render_in(@template)
77
+ end
32
78
 
33
79
  # Fields declared in a column block will be wrapped in a Bulma column and carry
34
80
  # the `column` class by default (fields can use the `column` option to set sizes).
@@ -66,20 +112,28 @@ module BulmaPhlex
66
112
 
67
113
  private
68
114
 
69
- def wrap_field(method, options, &delivered)
115
+ def wrap_field(method, options, add_class: "input", &delivered)
70
116
  options = options.dup
71
- options[:class] = "input #{options[:class]}".rstrip
117
+ options[:class] = Array.wrap(options[:class]) << add_class if add_class
72
118
 
73
- form_field_options = options.extract!(:icon_left, :icon_right, :column, :grid)
119
+ form_field_options = options.extract!(:help, :icon_left, :icon_right, :column, :grid)
74
120
  .with_defaults(column: @columns_flag, grid: @grid_flag)
75
121
 
76
122
  form_field = FormField.new(**form_field_options) do |f|
77
- f.label { label(method, class: "label").html_safe } unless options.delete(:suppress_label)
123
+ f.label { label(method).html_safe } unless options.delete(:suppress_label)
78
124
  f.control { delivered.call(method, options) }
79
125
  end
80
126
 
81
127
  form_field.render_in(@template)
82
128
  end
129
+
130
+ def wrap_select_field(method, html_options, &delivered)
131
+ wrap_field(method, html_options, add_class: false) do |m, html_opts|
132
+ @template.content_tag(:div, class: "select") do
133
+ delivered.call(m, html_opts)
134
+ end
135
+ end
136
+ end
83
137
  end
84
138
  end
85
139
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module BulmaPhlex
4
4
  module Rails
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bulma-phlex-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Kummer
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-01-24 00:00:00.000000000 Z
10
+ date: 2026-01-31 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: actionpack
@@ -80,6 +80,7 @@ files:
80
80
  - config/importmap.rb
81
81
  - lib/bulma-phlex-rails.rb
82
82
  - lib/bulma_phlex/rails.rb
83
+ - lib/bulma_phlex/rails/components/checkbox.rb
83
84
  - lib/bulma_phlex/rails/engine.rb
84
85
  - lib/bulma_phlex/rails/form_builder.rb
85
86
  - lib/bulma_phlex/rails/helpers/card_helper.rb