bulma-phlex-rails 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.
- checksums.yaml +4 -4
- data/app/javascript/controllers/bulma_phlex/dropdown_controller.js +38 -0
- data/app/javascript/controllers/bulma_phlex/file_input_display_controller.js +82 -0
- data/app/javascript/controllers/bulma_phlex/navigation_bar_controller.js +10 -0
- data/app/javascript/controllers/bulma_phlex/tabs_controller.js +37 -0
- data/config/importmap.rb +3 -0
- data/lib/bulma_phlex/rails/form_builder.rb +85 -0
- data/lib/bulma_phlex/rails/version.rb +1 -1
- data/lib/bulma_phlex/rails.rb +1 -0
- metadata +10 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8534c00b03a3ae8dad07d870b62ff94369802828940f05f6e8e9389b916c3dc9
|
|
4
|
+
data.tar.gz: 8a1284dc1ec5c8dd3a8bb60fdba5e69303fb6f3ae6a18bf6b3f58e70baf1840a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ed9272374b031aba4d8a685b011a5bd9f86989302da74cf8de070295e5457ce4b3502d1a6469ce94fdd536f6bca7bf5df0d501e2d4f29cd5c6f11e43a371ad98
|
|
7
|
+
data.tar.gz: ee41ceed1abc0e13778f74dce863579396740d19854f465fb1d12d086d3ca8480a6abb34c6959a8885dd9cff237fc9618632d3b2c7e3a154dca4439929eeed80
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
To use this Stimulus controller, add the controller to your dropdown container
|
|
5
|
+
and the action to your dropdown button:
|
|
6
|
+
|
|
7
|
+
<div class="dropdown" data-controller="bulma_phlex--dropdown">
|
|
8
|
+
<button data-action="bulma_phlex--dropdown#toggle">
|
|
9
|
+
Dropdown
|
|
10
|
+
</button>
|
|
11
|
+
<div class="dropdown-menu">...</div>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
This will toggle the dropdown menu when the button is clicked.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export default class extends Controller {
|
|
18
|
+
connect() {
|
|
19
|
+
this.closeHandler = this.close.bind(this);
|
|
20
|
+
document.addEventListener("click", this.closeHandler);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
disconnect() {
|
|
24
|
+
if (this.closeHandler) {
|
|
25
|
+
document.removeEventListener("click", this.closeHandler);
|
|
26
|
+
this.closeHandler = null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
toggle(event) {
|
|
31
|
+
event.stopPropagation();
|
|
32
|
+
this.element.classList.toggle("is-active");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
close(_event) {
|
|
36
|
+
this.element.classList.remove("is-active");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
|
2
|
+
|
|
3
|
+
export default class extends Controller {
|
|
4
|
+
static targets = ["fileInput", "fileList"]
|
|
5
|
+
|
|
6
|
+
acceptValues = []
|
|
7
|
+
|
|
8
|
+
connect() {
|
|
9
|
+
this.show()
|
|
10
|
+
this.#parseAcceptAttribute()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
show() {
|
|
14
|
+
const preview = this.fileListTarget;
|
|
15
|
+
this.#clear(preview)
|
|
16
|
+
|
|
17
|
+
const curFiles = this.fileInputTarget.files;
|
|
18
|
+
if (curFiles.length === 0) {
|
|
19
|
+
const para = document.createElement("p")
|
|
20
|
+
para.textContent = "No files currently selected for upload"
|
|
21
|
+
preview.appendChild(para)
|
|
22
|
+
} else {
|
|
23
|
+
const list = document.createElement("ul")
|
|
24
|
+
preview.appendChild(list)
|
|
25
|
+
|
|
26
|
+
for (const file of curFiles) {
|
|
27
|
+
const listItem = document.createElement("li")
|
|
28
|
+
listItem.textContent = this.#fileTextContent(file)
|
|
29
|
+
list.appendChild(listItem);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
#clear(preview) {
|
|
35
|
+
while (preview.firstChild) {
|
|
36
|
+
preview.removeChild(preview.firstChild);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
#fileTextContent(file) {
|
|
41
|
+
if (this.#validFileType(file)) {
|
|
42
|
+
return this.#fileInfo(file);
|
|
43
|
+
} else {
|
|
44
|
+
return `File name ${file.name}: Not a valid file type. Update your selection.`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
#validFileType(file) {
|
|
49
|
+
// If no accept attribute is specified, accept all files
|
|
50
|
+
if (this.acceptValues.length === 0) {
|
|
51
|
+
return true
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const fileExtension = `.${file.name.split('.').pop().toLowerCase()}`
|
|
55
|
+
const fileMimeType = file.type.toLowerCase()
|
|
56
|
+
|
|
57
|
+
// Check if the file matches any of the accept criteria
|
|
58
|
+
return this.acceptValues.some(acceptValue => {
|
|
59
|
+
if (acceptValue.startsWith('.')) {
|
|
60
|
+
// Check file extension (e.g. ".jpg")
|
|
61
|
+
return acceptValue.toLowerCase() === fileExtension
|
|
62
|
+
} else if (acceptValue.includes('/*')) {
|
|
63
|
+
// Check MIME type with wildcard (e.g. "image/*")
|
|
64
|
+
const acceptGroup = acceptValue.split('/')[0]
|
|
65
|
+
return fileMimeType.startsWith(`${acceptGroup}/`)
|
|
66
|
+
} else {
|
|
67
|
+
// Check specific MIME type (e.g. "image/jpeg")
|
|
68
|
+
return acceptValue === fileMimeType
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
#fileInfo(file) {
|
|
74
|
+
return `${file.name} (${file.size} bytes)`
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
#parseAcceptAttribute() {
|
|
78
|
+
if (this.fileInputTarget.accept) {
|
|
79
|
+
this.acceptValues = this.fileInputTarget.accept.split(',').map(type => type.trim())
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
|
2
|
+
|
|
3
|
+
export default class extends Controller {
|
|
4
|
+
static targets = [ "burger", "menu" ]
|
|
5
|
+
|
|
6
|
+
toggle(_event) {
|
|
7
|
+
this.burgerTarget.classList.toggle('is-active');
|
|
8
|
+
this.menuTarget.classList.toggle('is-active');
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus";
|
|
2
|
+
|
|
3
|
+
export default class extends Controller {
|
|
4
|
+
static targets = ["tab", "content"];
|
|
5
|
+
|
|
6
|
+
showTabContent(event) {
|
|
7
|
+
event.preventDefault();
|
|
8
|
+
|
|
9
|
+
const id = event.currentTarget.dataset.tabContent;
|
|
10
|
+
this.showTabAndContentForId(id);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
showTabAndContentForId(id) {
|
|
14
|
+
this.manageTabs(id);
|
|
15
|
+
this.manageContent(id);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
manageTabs(id) {
|
|
19
|
+
this.tabTargets.forEach((tab) => {
|
|
20
|
+
if (tab.dataset.tabContent === id) {
|
|
21
|
+
tab.classList.add("is-active");
|
|
22
|
+
} else {
|
|
23
|
+
tab.classList.remove("is-active");
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
manageContent(id) {
|
|
29
|
+
this.contentTargets.forEach((content) => {
|
|
30
|
+
if (content.id === id) {
|
|
31
|
+
content.classList.remove("is-hidden");
|
|
32
|
+
} else {
|
|
33
|
+
content.classList.add("is-hidden");
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
data/config/importmap.rb
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module BulmaPhlex
|
|
4
|
+
module Rails
|
|
5
|
+
# # Form Builder
|
|
6
|
+
#
|
|
7
|
+
# This form builder wraps inputs with [Bulma Form Fields](https://bulma.io/documentation/form/general/#form-field).
|
|
8
|
+
#
|
|
9
|
+
# In addition to standard input options, it supports the following Bulma-specific options:
|
|
10
|
+
# - `suppress_label`: If true, the label will not be rendered.
|
|
11
|
+
# - `icon_left`: If set, the specified icon will be rendered on the left side of the input.
|
|
12
|
+
# - `icon_right`: If set, the specified icon will be rendered on the right side of the input.
|
|
13
|
+
# - `column`: If true, the input will be wrapped in a Bulma column (only within a `columns` block).
|
|
14
|
+
# - `grid`: If true, the input will be wrapped in a Bulma grid cell (only within a `grid` block).
|
|
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) }
|
|
32
|
+
|
|
33
|
+
# Fields declared in a column block will be wrapped in a Bulma column and carry
|
|
34
|
+
# the `column` class by default (fields can use the `column` option to set sizes).
|
|
35
|
+
def columns(min_breakpoint = nil, &)
|
|
36
|
+
@columns_flag = true
|
|
37
|
+
columns = @template.capture(&)
|
|
38
|
+
@columns_flag = false
|
|
39
|
+
|
|
40
|
+
@template.content_tag(:div, class: [:columns, min_breakpoint]) do
|
|
41
|
+
@template.concat(columns)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Fields declared in a fixed_grid block will be wrapped in a Bulma fixed grid and
|
|
46
|
+
# carry the `grid` class by default (fields can use the `grid` option to set sizes).
|
|
47
|
+
def fixed_grid(&)
|
|
48
|
+
# TODO: Use BulmaPhlex::FixedGrid for more options
|
|
49
|
+
@template.content_tag(:div, class: "fixed-grid") do
|
|
50
|
+
grid(&)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Fields declared in a grid block will be wrapped in a Bulma fixed grid and carry
|
|
55
|
+
# the `grid` class by default (fields can use the `grid` option to set sizes).
|
|
56
|
+
def grid(&)
|
|
57
|
+
@grid_flag = true
|
|
58
|
+
cells = @template.capture(&)
|
|
59
|
+
@grid_flag = false
|
|
60
|
+
|
|
61
|
+
# TODO: Use BulmaPhlex::Grid for more options
|
|
62
|
+
@template.content_tag(:div, class: "grid") do
|
|
63
|
+
@template.concat(cells)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
private
|
|
68
|
+
|
|
69
|
+
def wrap_field(method, options, &delivered)
|
|
70
|
+
options = options.dup
|
|
71
|
+
options[:class] = "input #{options[:class]}".rstrip
|
|
72
|
+
|
|
73
|
+
form_field_options = options.extract!(:icon_left, :icon_right, :column, :grid)
|
|
74
|
+
.with_defaults(column: @columns_flag, grid: @grid_flag)
|
|
75
|
+
|
|
76
|
+
form_field = FormField.new(**form_field_options) do |f|
|
|
77
|
+
f.label { label(method, class: "label").html_safe } unless options.delete(:suppress_label)
|
|
78
|
+
f.control { delivered.call(method, options) }
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
form_field.render_in(@template)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
data/lib/bulma_phlex/rails.rb
CHANGED
|
@@ -14,6 +14,7 @@ end
|
|
|
14
14
|
loader = Zeitwerk::Loader.for_gem_extension(BulmaPhlex)
|
|
15
15
|
loader.collapse("#{__dir__}/rails/components")
|
|
16
16
|
loader.collapse("#{__dir__}/rails/helpers")
|
|
17
|
+
loader.collapse("#{__dir__}/rails/models")
|
|
17
18
|
loader.setup
|
|
18
19
|
|
|
19
20
|
require "bulma_phlex/rails/engine"
|
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.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Todd Kummer
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 2026-01-24 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: actionpack
|
|
@@ -29,14 +29,14 @@ dependencies:
|
|
|
29
29
|
requirements:
|
|
30
30
|
- - ">="
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: 0.
|
|
32
|
+
version: 0.9.0
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - ">="
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: 0.
|
|
39
|
+
version: 0.9.0
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: phlex-rails
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -73,9 +73,15 @@ executables: []
|
|
|
73
73
|
extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
|
75
75
|
files:
|
|
76
|
+
- app/javascript/controllers/bulma_phlex/dropdown_controller.js
|
|
77
|
+
- app/javascript/controllers/bulma_phlex/file_input_display_controller.js
|
|
78
|
+
- app/javascript/controllers/bulma_phlex/navigation_bar_controller.js
|
|
79
|
+
- app/javascript/controllers/bulma_phlex/tabs_controller.js
|
|
80
|
+
- config/importmap.rb
|
|
76
81
|
- lib/bulma-phlex-rails.rb
|
|
77
82
|
- lib/bulma_phlex/rails.rb
|
|
78
83
|
- lib/bulma_phlex/rails/engine.rb
|
|
84
|
+
- lib/bulma_phlex/rails/form_builder.rb
|
|
79
85
|
- lib/bulma_phlex/rails/helpers/card_helper.rb
|
|
80
86
|
- lib/bulma_phlex/rails/helpers/table_helper.rb
|
|
81
87
|
- lib/bulma_phlex/rails/version.rb
|