bulma-phlex 0.8.2 → 0.9.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 +43 -14
- data/lib/bulma_phlex/form_control.rb +20 -0
- data/lib/bulma_phlex/form_field.rb +145 -0
- data/lib/bulma_phlex/icon.rb +70 -0
- data/lib/bulma_phlex/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3136a7a0dd22a5d85922b80419ece937d391f6cbd385ba668079eb65d4387a61
|
|
4
|
+
data.tar.gz: 7553361a230fff3ecd6f121f6ec985348e4fc767a5f3927b27178676dea4de98
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d500797827a0ef15b9ad2f5ef334d63440cce5f8501ad90b8a9e93e0bb2a3ff0edf71eadf9a47aa47e7ef2ba570418a50250a3c586e106f631a45763c8bfe096
|
|
7
|
+
data.tar.gz: f62d2ae5b7c9dbba1fc3d73a775859ede75491d78faf2b6134aa34ed0101aad3991c3e1ee3555a41fa9fd7def98e18dcd026cd8e8c6909b3e7d0a44cda94dbf0
|
data/README.md
CHANGED
|
@@ -26,11 +26,13 @@ Finally, the optional Rails extensions for the Card and Table components have be
|
|
|
26
26
|
- [Usage](#usage)
|
|
27
27
|
- [Card](#card)
|
|
28
28
|
- [Dropdown](#dropdown)
|
|
29
|
+
- [Form Field](#form-field)
|
|
29
30
|
- [Level](#level)
|
|
30
31
|
- [NavigationBar](#navigationbar)
|
|
31
32
|
- [Pagination](#pagination)
|
|
32
33
|
- [Table](#table)
|
|
33
34
|
- [Tabs](#tabs)
|
|
35
|
+
- [Tag](#tag)
|
|
34
36
|
- [Title and Subtitle](#title-and-subtitle)
|
|
35
37
|
- [Development](#development)
|
|
36
38
|
- [Contributing](#contributing)
|
|
@@ -137,6 +139,36 @@ end
|
|
|
137
139
|
- `item(content = nil, &block)`: Adds a custom item (string or block).
|
|
138
140
|
- `divider`: Adds a divider line.
|
|
139
141
|
|
|
142
|
+
|
|
143
|
+
### Form Field
|
|
144
|
+
|
|
145
|
+
The [Form Field](https://bulma.io/documentation/form/general/) component provides a way to create form fields with labels, inputs, and help text, following Bulma's form styling conventions. It also supports adding icons to the input, as well as tagging the field as a column or grid cell.
|
|
146
|
+
|
|
147
|
+
```ruby
|
|
148
|
+
BulmaPhlex::FormField(help: "We'll never share your email.") do |field|
|
|
149
|
+
field.label("Email Address")
|
|
150
|
+
field.control { input(name: "user[email_address]", type: "email") }
|
|
151
|
+
end
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
The label can be passed in as a string or created with a block:
|
|
155
|
+
|
|
156
|
+
```ruby
|
|
157
|
+
field.label do
|
|
158
|
+
span { "Email Address" }
|
|
159
|
+
span(class: "has-text-danger") { "*" }
|
|
160
|
+
end
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**Constructor Keyword Arguments:**
|
|
164
|
+
|
|
165
|
+
- `icon_left`: Icon class to display on the left side of the input (such as `fas fa-user`).
|
|
166
|
+
- `icon_right`: Icon class to display on the right side of the input.
|
|
167
|
+
- `help`: Help text to display below the field.
|
|
168
|
+
- `column`: When true, adds the `column` class to the container. Can also be a string specifying the column size (such as `two-thirds`) or a hash with sizes by breakpoint (such as `{ mobile: "full", desktop: "half" }`).
|
|
169
|
+
- `grid`: When true, adds the `cell` class to the container. Can also be a string specifying the heighth or width of the cell (such as `col-span-3`).
|
|
170
|
+
|
|
171
|
+
|
|
140
172
|
### Level
|
|
141
173
|
|
|
142
174
|
The [Level](https://bulma.io/documentation/layout/level/) component provides a flexible horizontal layout system with left and right alignment.
|
|
@@ -195,13 +227,19 @@ end
|
|
|
195
227
|
The [Pagination](https://bulma.io/documentation/components/pagination/) component provides navigation controls for paginated content, including previous/next links, page number links, and a summary of items being displayed.
|
|
196
228
|
|
|
197
229
|
```ruby
|
|
198
|
-
# In a controller action:
|
|
199
|
-
@products = Product.page(params[:page]).per(20)
|
|
200
|
-
|
|
201
|
-
# In the view:
|
|
202
230
|
BulmaPhlex::Pagination(@products, ->(page) { products_path(page: page) })
|
|
203
231
|
```
|
|
204
232
|
|
|
233
|
+
In order to support pagination, the argument passed into the constructor must repond with integers to the following:
|
|
234
|
+
|
|
235
|
+
- current_page
|
|
236
|
+
- total_pages
|
|
237
|
+
- per_page
|
|
238
|
+
- total_count
|
|
239
|
+
- previous_page (can be nil)
|
|
240
|
+
- next_page (can be nil)
|
|
241
|
+
|
|
242
|
+
|
|
205
243
|
### Table
|
|
206
244
|
|
|
207
245
|
The [Table](https://bulma.io/documentation/elements/table/) component provides a way to display data in rows and columns with customizable headers and formatting options.
|
|
@@ -272,16 +310,7 @@ If the table should be paginated, invoke method `paginate` with a block that wil
|
|
|
272
310
|
end
|
|
273
311
|
```
|
|
274
312
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
- current_page
|
|
278
|
-
- total_pages
|
|
279
|
-
- per_page
|
|
280
|
-
- total_count
|
|
281
|
-
- previous_page (can be nil)
|
|
282
|
-
- next_page (can be nil)
|
|
283
|
-
|
|
284
|
-
This generates the [Bulma pagination](https://bulma.io/documentation/components/pagination/) component, providing navigation controls for paginated content.
|
|
313
|
+
This generates the [Bulma pagination](https://bulma.io/documentation/components/pagination/) component, providing navigation controls for paginated content. The rows argument is passed into the Pagination component to determine the current page, total pages, and other pagination details.
|
|
285
314
|
|
|
286
315
|
|
|
287
316
|
### Tabs
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module BulmaPhlex
|
|
4
|
+
# # Form Control
|
|
5
|
+
#
|
|
6
|
+
# The Bulma Form Control is used to wrap form elements like inputs, selects, and textareas. Additional classes can
|
|
7
|
+
# be added via the `classes` argument.
|
|
8
|
+
#
|
|
9
|
+
# ## References
|
|
10
|
+
# - [Bulma Form Control](https://bulma.io/documentation/form/general/#form-control)
|
|
11
|
+
class FormControl < Phlex::HTML
|
|
12
|
+
def initialize(**attributes)
|
|
13
|
+
@attributes = attributes.compact
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def view_template(&)
|
|
17
|
+
div(**mix({ class: "control" }, @attributes), &)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module BulmaPhlex
|
|
4
|
+
# # Form Field Component
|
|
5
|
+
#
|
|
6
|
+
# The Bulma Form Field is a `field` container that groups a label with yielded content
|
|
7
|
+
# (usually an input). It can optionally include a help text.
|
|
8
|
+
#
|
|
9
|
+
# The label can be provided either as a string argument to the `label` method or as a
|
|
10
|
+
# block. If a string is provided, it will be rendered inside a `<label>` tag with the
|
|
11
|
+
# `label` class. The label can also be omitted entirely if not needed.
|
|
12
|
+
#
|
|
13
|
+
# ## Icons
|
|
14
|
+
#
|
|
15
|
+
# The component supports optional left and right icons within the input control. Specify
|
|
16
|
+
# icons with the `icon_left` and `icon_right` keyword arguments.
|
|
17
|
+
#
|
|
18
|
+
# ```ruby
|
|
19
|
+
# FormField(icon_left: "fas fa-user", icon_right: "fas fa-check")
|
|
20
|
+
# ```
|
|
21
|
+
#
|
|
22
|
+
# ## Column Layout
|
|
23
|
+
#
|
|
24
|
+
# If the form field is to be used within a Bulma column layout, you can specify the `column`
|
|
25
|
+
# keyword. There are three ways to use this:
|
|
26
|
+
# - `true`: makes the field a column without specific sizing.
|
|
27
|
+
# - a size string (e.g., `"half"`): makes the field a column with that size for all breakpoints.
|
|
28
|
+
# - a hash mapping breakpoints to sizes (e.g., `{ mobile: "full", desktop: "half" }`): makes the
|
|
29
|
+
# field a column with sizes specific to breakpoints
|
|
30
|
+
#
|
|
31
|
+
# ## Example Usage
|
|
32
|
+
#
|
|
33
|
+
# Here is the label provided as a block:
|
|
34
|
+
#
|
|
35
|
+
# ```ruby
|
|
36
|
+
# FormField(help: "Enter the project name.") do |field|
|
|
37
|
+
# field.label { label "Project Name" }
|
|
38
|
+
# field.input { input id: "project_name", name: "project[name]", type: "text" }
|
|
39
|
+
# end
|
|
40
|
+
# ```
|
|
41
|
+
#
|
|
42
|
+
# Here is the label provided as a string:
|
|
43
|
+
#
|
|
44
|
+
# ```ruby
|
|
45
|
+
# FormField(help: "Enter the project name.") do |field|
|
|
46
|
+
# field.label "Project Name"
|
|
47
|
+
# field.input { input id: "project_name", name: "project[name]", type: "text" }
|
|
48
|
+
# end
|
|
49
|
+
# ```
|
|
50
|
+
#
|
|
51
|
+
# Here is no label provided:
|
|
52
|
+
#
|
|
53
|
+
# ```ruby
|
|
54
|
+
# FormField(help: "Enter the project name.") do |field|
|
|
55
|
+
# field.input { input id: "project_name", name: "project[name]", type: "text" }
|
|
56
|
+
# end
|
|
57
|
+
# ```
|
|
58
|
+
#
|
|
59
|
+
# ## References
|
|
60
|
+
#
|
|
61
|
+
# - [Bulma Form Field](https://bulma.io/documentation/form/general/#form-field)
|
|
62
|
+
# - [With Icons](https://bulma.io/documentation/form/general/#with-icons)
|
|
63
|
+
# - [Columns](https://bulma.io/documentation/columns/basics/)
|
|
64
|
+
# - [Grid Cells](https://bulma.io/documentation/grid/grid-cells/)
|
|
65
|
+
class FormField < Phlex::HTML
|
|
66
|
+
def initialize(help: nil, icon_left: nil, icon_right: nil, column: nil, grid: nil)
|
|
67
|
+
@help = help
|
|
68
|
+
@icon_left = icon_left
|
|
69
|
+
@icon_right = icon_right
|
|
70
|
+
@column = column
|
|
71
|
+
@grid = grid
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# in order to use the method name `label`, we need to grab a reference to the method on the base class
|
|
75
|
+
# so it is stil available to us
|
|
76
|
+
alias html_label label
|
|
77
|
+
|
|
78
|
+
def label(label_string = nil, &block)
|
|
79
|
+
@label_string = label_string
|
|
80
|
+
@label_builder = block
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def control(&block)
|
|
84
|
+
@control_builder = block
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def view_template(&)
|
|
88
|
+
vanish(&)
|
|
89
|
+
|
|
90
|
+
div(class: field_classes) do
|
|
91
|
+
render_label
|
|
92
|
+
render FormControl.new(class: control_classes) do
|
|
93
|
+
render raw @control_builder.call
|
|
94
|
+
Icon(@icon_left, size: :small, left: true) if @icon_left
|
|
95
|
+
Icon(@icon_right, size: :small, right: true) if @icon_right
|
|
96
|
+
end
|
|
97
|
+
p(class: "help") { @help } if @help
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
private
|
|
102
|
+
|
|
103
|
+
def field_classes
|
|
104
|
+
[:field].tap do |classes|
|
|
105
|
+
classes.append(column_classes) if @column
|
|
106
|
+
classes.append(grid_classes) if @grid
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def column_classes
|
|
111
|
+
[:column].tap do |classes|
|
|
112
|
+
if @column.is_a?(String) || @column.is_a?(Integer)
|
|
113
|
+
classes << "is-#{@column}"
|
|
114
|
+
elsif @column.is_a?(Hash)
|
|
115
|
+
@column.each do |breakpoint, size|
|
|
116
|
+
classes << "is-#{size}-#{breakpoint}"
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def grid_classes
|
|
123
|
+
if @grid.is_a?(String)
|
|
124
|
+
[:cell, "is-#{@grid}"]
|
|
125
|
+
else
|
|
126
|
+
[:cell]
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def render_label
|
|
131
|
+
if @label_string
|
|
132
|
+
html_label(class: "label") { @label_string }
|
|
133
|
+
elsif @label_builder
|
|
134
|
+
render raw @label_builder&.call
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def control_classes
|
|
139
|
+
[].tap do |classes|
|
|
140
|
+
classes << "has-icons-left" if @icon_left
|
|
141
|
+
classes << "has-icons-right" if @icon_right
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module BulmaPhlex
|
|
4
|
+
# # Icon
|
|
5
|
+
#
|
|
6
|
+
# This component implements the
|
|
7
|
+
# [Bulma icon element](https://bulma.io/documentation/elements/icon/).
|
|
8
|
+
#
|
|
9
|
+
# ## Options
|
|
10
|
+
#
|
|
11
|
+
# - `color`: Sets the [color of the icon](https://bulma.io/documentation/elements/icon/#colors)
|
|
12
|
+
# - `size`: Sets the [size of the icon](https://bulma.io/documentation/elements/icon/#sizes)
|
|
13
|
+
# - `text_right`: Text to display to the right of the icon
|
|
14
|
+
# - `text_left`: Text to display to the left of the icon
|
|
15
|
+
# - `left`: If true, adds the `is-left` class for use in form controls
|
|
16
|
+
# - `right`: If true, adds the `is-right` class for use in form controls
|
|
17
|
+
#
|
|
18
|
+
# ## Example
|
|
19
|
+
#
|
|
20
|
+
# ```ruby
|
|
21
|
+
# BulmaPhlex::Icon.new("fas fa-home")
|
|
22
|
+
# BulmaPhlex::Icon.new("fas fa-home", color: :primary, size: :large, text_right: "Home")
|
|
23
|
+
# ```
|
|
24
|
+
class Icon < BulmaPhlex::Base
|
|
25
|
+
def initialize(icon, # rubocop:disable Metrics/ParameterLists
|
|
26
|
+
text_right: nil,
|
|
27
|
+
text_left: nil,
|
|
28
|
+
size: nil,
|
|
29
|
+
color: nil,
|
|
30
|
+
left: false,
|
|
31
|
+
right: false)
|
|
32
|
+
@icon = icon
|
|
33
|
+
@text_right = text_right
|
|
34
|
+
@text_left = text_left
|
|
35
|
+
@size = size
|
|
36
|
+
@color = color
|
|
37
|
+
@left = left
|
|
38
|
+
@right = right
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def view_template
|
|
42
|
+
optional_text_wrapper do
|
|
43
|
+
span { @text_left } if @text_left
|
|
44
|
+
span(class: icon_classes) do
|
|
45
|
+
i(class: @icon)
|
|
46
|
+
end
|
|
47
|
+
span { @text_right } if @text_right
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
def optional_text_wrapper(&)
|
|
54
|
+
if @text_right || @text_left
|
|
55
|
+
span(class: "icon-text", &)
|
|
56
|
+
else
|
|
57
|
+
yield
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def icon_classes
|
|
62
|
+
classes = ["icon"]
|
|
63
|
+
classes << "is-#{@size}" if @size
|
|
64
|
+
classes << "has-text-#{@color}" if @color
|
|
65
|
+
classes << "is-left" if @left
|
|
66
|
+
classes << "is-right" if @right
|
|
67
|
+
classes.join(" ")
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
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.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Todd Kummer
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-01-
|
|
10
|
+
date: 2026-01-24 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: phlex
|
|
@@ -67,6 +67,9 @@ files:
|
|
|
67
67
|
- lib/bulma_phlex/base.rb
|
|
68
68
|
- lib/bulma_phlex/card.rb
|
|
69
69
|
- lib/bulma_phlex/dropdown.rb
|
|
70
|
+
- lib/bulma_phlex/form_control.rb
|
|
71
|
+
- lib/bulma_phlex/form_field.rb
|
|
72
|
+
- lib/bulma_phlex/icon.rb
|
|
70
73
|
- lib/bulma_phlex/level.rb
|
|
71
74
|
- lib/bulma_phlex/navigation_bar.rb
|
|
72
75
|
- lib/bulma_phlex/navigation_bar_dropdown.rb
|