bulma-phlex-rails 0.2.0 → 0.2.1
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/version.rb +1 -1
- metadata +6 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9ccde325abe028d8ab12fb8dfbcd754814274554029fffe1c443c21d0936c6e1
|
|
4
|
+
data.tar.gz: 0e526e0539626fa8b17780e9ce1db8edc2d81b68c4808fa0fcb108dad44e1944
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fca248f599cd3f0793a37864c791e451b8e9019639e093dea13b27dc5a5443dc21b85959201f14763a896edf8f094c22907fd45854b74c6302dce3f5712430e0
|
|
7
|
+
data.tar.gz: 0e7e6196221edf59fb6c1303d4ef0e74d30522dfbb37e9c7c2ff8a15f3e90f33a6c3f65c142776ce1f9a53d155ab8e6860c909335bafe9ccd464e25c11b3d64e
|
|
@@ -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
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bulma-phlex-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Todd Kummer
|
|
@@ -73,6 +73,11 @@ 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
|