bulma-phlex 0.14.0 → 0.15.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 +4 -4
- data/README.md +15 -2
- data/lib/bulma_phlex/form_field.rb +5 -2
- data/lib/bulma_phlex/table.rb +73 -44
- data/lib/bulma_phlex/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8a1d3209d836363da07529fa00c9374618623280e70f3167c409e320b77dd4c4
|
|
4
|
+
data.tar.gz: e078ae57978d967610194b989078d484ad2297d4cdd71b0ae2d65b07d80dc105
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c7c0d1e8bbfb69e58e78af757f14b4dde6ab532f085e7ea970cb1addd511f2c5c33ba964df7b80dcfdac878f4475108858ceace18f3e5b52356d3b9b3d7df521
|
|
7
|
+
data.tar.gz: c41d7a84d0a5e5c2c03aafd7ff74764af2e94221c051aa67766815d46805cd153829deb87173b7d73285fcfaf9752433412070effb7755fced7d3e45df388912
|
data/README.md
CHANGED
|
@@ -59,7 +59,7 @@ gem install bulma-phlex
|
|
|
59
59
|
|
|
60
60
|
This gem requires:
|
|
61
61
|
|
|
62
|
-
- Ruby 3.
|
|
62
|
+
- Ruby 3.3 or higher
|
|
63
63
|
- Phlex 2.4.1 or higher
|
|
64
64
|
- Bulma CSS (which you'll need to include in your application)
|
|
65
65
|
|
|
@@ -162,7 +162,7 @@ Renders a [Bulma form field](https://bulma.io/documentation/form/general/#form-f
|
|
|
162
162
|
|
|
163
163
|
```ruby
|
|
164
164
|
render BulmaPhlex::FormField.new(help: "We'll never share your email.") do |field|
|
|
165
|
-
field.label("Email Address")
|
|
165
|
+
field.label("Email Address", for: "user_email_address")
|
|
166
166
|
field.control { input(name: "user[email_address]", type: "email") }
|
|
167
167
|
end
|
|
168
168
|
```
|
|
@@ -338,6 +338,19 @@ To add pagination to the table, call `paginate` with a block that returns a path
|
|
|
338
338
|
table.paginate { |page| products_path(page: page) }
|
|
339
339
|
```
|
|
340
340
|
|
|
341
|
+
Pass HTML attributes to the `tr` elements via the `row` method, using either keyword arguments or a block
|
|
342
|
+
that receives the record for the row:
|
|
343
|
+
|
|
344
|
+
```ruby
|
|
345
|
+
table.row(class: "custom-row-class") { |row| { id: "row-id-#{row.id}" } }
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
Hide columns on smaller screens with the column `hidden` option:
|
|
349
|
+
|
|
350
|
+
```ruby
|
|
351
|
+
table.column("Email", hidden: { mobile: true }) { |user| user.email }
|
|
352
|
+
```
|
|
353
|
+
|
|
341
354
|
|
|
342
355
|
### Tabs
|
|
343
356
|
|
|
@@ -9,6 +9,8 @@ module BulmaPhlex
|
|
|
9
9
|
# integrating with Bulma's column and grid systems. The form control content is set via the
|
|
10
10
|
# `control` method (or a block passed directly to the component).
|
|
11
11
|
#
|
|
12
|
+
# If the label is passes as a string argument, the any additional html attributes can also be included as arguments.
|
|
13
|
+
#
|
|
12
14
|
# ## References
|
|
13
15
|
#
|
|
14
16
|
# - [Bulma Form Field](https://bulma.io/documentation/form/general/#form-field)
|
|
@@ -46,8 +48,9 @@ module BulmaPhlex
|
|
|
46
48
|
#
|
|
47
49
|
# Optionally expects a block that renders a custom label (e.g. with a link or icon inside).
|
|
48
50
|
# Only one of `label_string` or a block should be provided.
|
|
49
|
-
def label(label_string = nil, &block)
|
|
51
|
+
def label(label_string = nil, **html_attributes, &block)
|
|
50
52
|
@label_string = label_string
|
|
53
|
+
@label_attributes = html_attributes
|
|
51
54
|
@label_builder = block
|
|
52
55
|
end
|
|
53
56
|
|
|
@@ -103,7 +106,7 @@ module BulmaPhlex
|
|
|
103
106
|
|
|
104
107
|
def render_label
|
|
105
108
|
if @label_string
|
|
106
|
-
html_label(class: "label") { @label_string }
|
|
109
|
+
html_label(**mix({ class: "label" }, **@label_attributes)) { @label_string }
|
|
107
110
|
elsif @label_builder
|
|
108
111
|
raw @label_builder&.call
|
|
109
112
|
end
|
data/lib/bulma_phlex/table.rb
CHANGED
|
@@ -8,24 +8,42 @@ module BulmaPhlex
|
|
|
8
8
|
# (bordered, striped, hoverable) and **layout** options (narrow, fullwidth). An optional
|
|
9
9
|
# **pagination** control can be added to the table footer via the `paginate` method.
|
|
10
10
|
#
|
|
11
|
+
# The `tr` elements can be customized with the `row` method, which accepts static HTML attributes
|
|
12
|
+
# and/or a block that generates dynamic attributes based on the row data.
|
|
13
|
+
#
|
|
14
|
+
# To make the table responsive, use the `hidden` argument to hide certain columns on smaller
|
|
15
|
+
# screens. See the [Bulma documentation](https://bulma.io/documentation/helpers/visibility-helpers/#hide)
|
|
16
|
+
# for the full list, but the most common options are `hidden: "mobile"` and `hidden: "touch"`.
|
|
17
|
+
#
|
|
18
|
+
# The table supports any additional HTML attributes on the `<table>` element, such as `id` or `data-*`
|
|
19
|
+
# attributes, via the `**html_attributes` argument in the constructor.
|
|
20
|
+
#
|
|
11
21
|
# ## Example
|
|
12
22
|
#
|
|
13
23
|
# users = User.all
|
|
14
24
|
#
|
|
15
25
|
# render BulmaPhlex::Table.new(users) do |table|
|
|
16
|
-
# table.
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
# table.
|
|
21
|
-
# user.email
|
|
22
|
-
# end
|
|
23
|
-
#
|
|
26
|
+
# table.row(class: "has-background-light") { |user| { id: "user-row-#{user.id}" } }
|
|
27
|
+
# table.column("Name", &:full_name)
|
|
28
|
+
# table.column("Email", hidden: "touch", &:email)
|
|
29
|
+
# table.date_column("Joined", hidden: "mobile", &:created_at, format: "%B %d, %Y")
|
|
30
|
+
# table.conditional_icon("Admin?", &:admin?)
|
|
24
31
|
# table.column "Actions" do |user|
|
|
25
32
|
# link_to "Edit", edit_user_path(user), class: "button is-small"
|
|
26
33
|
# end
|
|
27
34
|
# end
|
|
28
|
-
class Table < BulmaPhlex::Base
|
|
35
|
+
class Table < BulmaPhlex::Base # rubocop:disable Metrics/ClassLength
|
|
36
|
+
# Returns an array of CSS classes for the table based on the provided options.
|
|
37
|
+
def self.classes_for(bordered: false, striped: false, narrow: false, hoverable: false, fullwidth: false)
|
|
38
|
+
classes = ["table"]
|
|
39
|
+
classes << "is-bordered" if bordered
|
|
40
|
+
classes << "is-striped" if striped
|
|
41
|
+
classes << "is-narrow" if narrow
|
|
42
|
+
classes << "is-hoverable" if hoverable
|
|
43
|
+
classes << "is-fullwidth" if fullwidth
|
|
44
|
+
classes
|
|
45
|
+
end
|
|
46
|
+
|
|
29
47
|
# **Parameters**
|
|
30
48
|
#
|
|
31
49
|
# - `rows` — The collection of records to display in the table
|
|
@@ -53,11 +71,7 @@ module BulmaPhlex
|
|
|
53
71
|
fullwidth: false,
|
|
54
72
|
**html_attributes)
|
|
55
73
|
@rows = rows
|
|
56
|
-
@
|
|
57
|
-
@striped = striped
|
|
58
|
-
@narrow = narrow
|
|
59
|
-
@hoverable = hoverable
|
|
60
|
-
@fullwidth = fullwidth
|
|
74
|
+
@table_classes = self.class.classes_for(bordered:, striped:, narrow:, hoverable:, fullwidth:)
|
|
61
75
|
@html_attributes = html_attributes
|
|
62
76
|
@columns = []
|
|
63
77
|
end
|
|
@@ -65,19 +79,15 @@ module BulmaPhlex
|
|
|
65
79
|
def view_template(&)
|
|
66
80
|
vanish(&)
|
|
67
81
|
|
|
68
|
-
table(**mix({ class: table_classes }, @html_attributes)) do
|
|
82
|
+
table(**mix({ class: @table_classes }, @html_attributes)) do
|
|
69
83
|
thead do
|
|
70
|
-
@columns.each
|
|
71
|
-
table_header(column)
|
|
72
|
-
end
|
|
84
|
+
@columns.each { |column| table_header(column) }
|
|
73
85
|
end
|
|
74
86
|
|
|
75
87
|
tbody do
|
|
76
88
|
@rows.each do |row|
|
|
77
|
-
tr do
|
|
78
|
-
@columns.each
|
|
79
|
-
td(**column[:html_attributes]) { column[:content].call(row) }
|
|
80
|
-
end
|
|
89
|
+
tr(**table_row_html_attributes(row)) do
|
|
90
|
+
@columns.each { |column| table_data_cell(column, row) }
|
|
81
91
|
end
|
|
82
92
|
end
|
|
83
93
|
end
|
|
@@ -86,14 +96,19 @@ module BulmaPhlex
|
|
|
86
96
|
end
|
|
87
97
|
end
|
|
88
98
|
|
|
99
|
+
def row(**html_attributes, &attribute_builder)
|
|
100
|
+
@row_attributes = html_attributes
|
|
101
|
+
@row_attribute_builder = attribute_builder
|
|
102
|
+
end
|
|
103
|
+
|
|
89
104
|
# Adds a column to the table. Can be called multiple times to define all columns.
|
|
90
105
|
#
|
|
91
106
|
# - `header` — The column header text
|
|
92
107
|
# - `**html_attributes` — Additional HTML attributes for each `<td>` cell in this column
|
|
93
108
|
#
|
|
94
109
|
# Expects a block that receives each `row` object and returns the cell content.
|
|
95
|
-
def column(header, **html_attributes, &content)
|
|
96
|
-
@columns << { header:, html_attributes:, content: }
|
|
110
|
+
def column(header, hidden: false, **html_attributes, &content)
|
|
111
|
+
@columns << { header:, hidden:, html_attributes:, content: }
|
|
97
112
|
end
|
|
98
113
|
|
|
99
114
|
# Adds a date-formatted column to the table. Can be called multiple times.
|
|
@@ -103,8 +118,8 @@ module BulmaPhlex
|
|
|
103
118
|
# - `**html_attributes` — Additional HTML attributes for each `<td>` cell in this column
|
|
104
119
|
#
|
|
105
120
|
# Expects a block that receives each `row` object and returns a `Date` or `Time` value.
|
|
106
|
-
def date_column(header, format: "%Y-%m-%d", **html_attributes, &content)
|
|
107
|
-
column(header, **html_attributes) do |row|
|
|
121
|
+
def date_column(header, hidden: false, format: "%Y-%m-%d", **html_attributes, &content)
|
|
122
|
+
column(header, hidden:, **html_attributes) do |row|
|
|
108
123
|
content.call(row)&.strftime(format)
|
|
109
124
|
end
|
|
110
125
|
end
|
|
@@ -116,10 +131,10 @@ module BulmaPhlex
|
|
|
116
131
|
# - `**html_attributes` — Additional HTML attributes for each `<td>` cell in this column
|
|
117
132
|
#
|
|
118
133
|
# Expects a block that receives each `row` object and returns a truthy or falsy value.
|
|
119
|
-
def conditional_icon(header, icon_class: "fas fa-check", **html_attributes, &content)
|
|
134
|
+
def conditional_icon(header, hidden: false, icon_class: "fas fa-check", **html_attributes, &content)
|
|
120
135
|
html_attributes[:class] = [html_attributes[:class], "has-text-centered"].compact.join(" ")
|
|
121
136
|
|
|
122
|
-
column(header, **html_attributes) do |row|
|
|
137
|
+
column(header, hidden:, **html_attributes) do |row|
|
|
123
138
|
Icon(icon_class) if content.call(row)
|
|
124
139
|
end
|
|
125
140
|
end
|
|
@@ -134,35 +149,49 @@ module BulmaPhlex
|
|
|
134
149
|
|
|
135
150
|
private
|
|
136
151
|
|
|
137
|
-
def
|
|
138
|
-
|
|
139
|
-
classes << "is-bordered" if @bordered
|
|
140
|
-
classes << "is-striped" if @striped
|
|
141
|
-
classes << "is-narrow" if @narrow
|
|
142
|
-
classes << "is-hoverable" if @hoverable
|
|
143
|
-
classes << "is-fullwidth" if @fullwidth
|
|
144
|
-
classes
|
|
152
|
+
def table_header(column)
|
|
153
|
+
th(class: header_classes(column)) { column[:header] }
|
|
145
154
|
end
|
|
146
155
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
th(**attributes) { column[:header] }
|
|
156
|
+
def header_classes(column)
|
|
157
|
+
classes = []
|
|
158
|
+
classes << "is-hidden-#{column[:hidden]}" if column[:hidden]
|
|
159
|
+
classes << header_alignment(column[:html_attributes])
|
|
160
|
+
classes.compact
|
|
153
161
|
end
|
|
154
162
|
|
|
155
163
|
def header_alignment(html_attributes)
|
|
156
164
|
classes = html_attributes[:class]
|
|
157
165
|
return if classes.nil?
|
|
158
166
|
|
|
159
|
-
if classes
|
|
167
|
+
if classes.include?("has-text-right") || classes.include?("amount-display")
|
|
160
168
|
"has-text-right"
|
|
161
|
-
elsif classes
|
|
169
|
+
elsif classes.include?("has-text-centered")
|
|
162
170
|
"has-text-centered"
|
|
163
171
|
end
|
|
164
172
|
end
|
|
165
173
|
|
|
174
|
+
def table_row_html_attributes(row)
|
|
175
|
+
attributes = @row_attributes || {}
|
|
176
|
+
if @row_attribute_builder
|
|
177
|
+
dynamic_attributes = @row_attribute_builder.call(row) || {}
|
|
178
|
+
attributes = attributes.merge(dynamic_attributes)
|
|
179
|
+
end
|
|
180
|
+
attributes
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def table_data_cell(column, row)
|
|
184
|
+
td(**mix({ class: cell_classes(column) }, column[:html_attributes])) do
|
|
185
|
+
column[:content].call(row)
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def cell_classes(column)
|
|
190
|
+
return unless column[:hidden]
|
|
191
|
+
|
|
192
|
+
"is-hidden-#{column[:hidden]}"
|
|
193
|
+
end
|
|
194
|
+
|
|
166
195
|
def pagination
|
|
167
196
|
return unless @path_builder
|
|
168
197
|
|
data/lib/bulma_phlex/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bulma-phlex
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.15.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Todd Kummer
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-
|
|
10
|
+
date: 2026-04-16 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: phlex
|
|
@@ -103,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
103
103
|
requirements:
|
|
104
104
|
- - ">="
|
|
105
105
|
- !ruby/object:Gem::Version
|
|
106
|
-
version: 3.
|
|
106
|
+
version: '3.3'
|
|
107
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
requirements:
|
|
109
109
|
- - ">="
|