lightning_ui_kit 0.1.2 → 0.1.3
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/assets/builds/lightning_ui_kit.css +444 -64
- data/app/assets/builds/lightning_ui_kit.js +2 -2
- data/app/assets/builds/lightning_ui_kit.js.map +4 -4
- data/app/components/lightning_ui_kit/badge_component.rb +30 -5
- data/app/components/lightning_ui_kit/banner_component.rb +1 -1
- data/app/components/lightning_ui_kit/checkbox_component.html.erb +1 -1
- data/app/components/lightning_ui_kit/dropzone_component.html.erb +82 -0
- data/app/components/lightning_ui_kit/dropzone_component.rb +61 -0
- data/app/components/lightning_ui_kit/errors.rb +34 -0
- data/app/components/lightning_ui_kit/file_input_component.html.erb +50 -0
- data/app/components/lightning_ui_kit/file_input_component.rb +62 -0
- data/app/components/lightning_ui_kit/input_component.html.erb +21 -14
- data/app/components/lightning_ui_kit/input_component.rb +17 -2
- data/app/components/lightning_ui_kit/select_component.html.erb +23 -3
- data/app/components/lightning_ui_kit/select_component.rb +31 -1
- data/app/components/lightning_ui_kit/switch_component.html.erb +8 -1
- data/app/components/lightning_ui_kit/switch_component.rb +12 -1
- data/app/components/lightning_ui_kit/textarea_component.html.erb +15 -8
- data/app/components/lightning_ui_kit/textarea_component.rb +17 -2
- data/app/javascript/lightning_ui_kit/controllers/dropzone_controller.js +76 -0
- data/app/javascript/lightning_ui_kit/index.js +5 -0
- data/config/locales/en.yml +3 -0
- data/lib/lightning_ui_kit/engine.rb +0 -1
- data/lib/lightning_ui_kit/version.rb +1 -1
- metadata +9 -2
@@ -1,10 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class LightningUiKit::SwitchComponent < LightningUiKit::BaseComponent
|
4
|
-
|
4
|
+
include LightningUiKit::Errors
|
5
|
+
|
6
|
+
def initialize(name:, form: nil, label: nil, error: nil, description: nil, enabled: false, disabled: false, **options)
|
5
7
|
@name = name
|
6
8
|
@form = form
|
7
9
|
@label = label
|
10
|
+
@error = error
|
8
11
|
@description = description
|
9
12
|
@enabled = enabled
|
10
13
|
@disabled = disabled
|
@@ -28,4 +31,12 @@ class LightningUiKit::SwitchComponent < LightningUiKit::BaseComponent
|
|
28
31
|
end
|
29
32
|
end
|
30
33
|
end
|
34
|
+
|
35
|
+
def error_data
|
36
|
+
{slot: "error"}.merge(@options[:error_data] || {}).tap do |data|
|
37
|
+
if @disabled
|
38
|
+
data[:disabled] = "true"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
31
42
|
end
|
@@ -2,12 +2,12 @@
|
|
2
2
|
class: "[&>[data-slot=label]+[data-slot=control]]:mt-3 [&>[data-slot=label]+[data-slot=description]]:mt-1 [&>[data-slot=description]+[data-slot=control]]:mt-3 [&>[data-slot=control]+[data-slot=description]]:mt-3 [&>[data-slot=control]+[data-slot=error]]:mt-3 *:data-[slot=label]:font-medium",
|
3
3
|
data:
|
4
4
|
) do %>
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
<% if @label %>
|
6
|
+
<%= tag.label(
|
7
|
+
@label,
|
8
|
+
class: "text-base/6 text-zinc-950 select-none data-disabled:opacity-50 sm:text-sm/6",
|
9
|
+
data: label_data
|
10
|
+
) %>
|
11
11
|
<% end %>
|
12
12
|
<% if @description %>
|
13
13
|
<%= tag.p(
|
@@ -25,7 +25,7 @@
|
|
25
25
|
cols: @cols,
|
26
26
|
multiple: @multiple,
|
27
27
|
data: input_data,
|
28
|
-
class: "relative block w-full appearance-none rounded-lg px-[calc(--spacing(3.5)-1px)] py-[calc(--spacing(2.5)-1px)] sm:px-[calc(--spacing(3)-1px)] sm:py-[calc(--spacing(1.5)-1px)] text-base/6 text-zinc-950 placeholder:text-zinc-500 sm:text-sm/6 border border-zinc-950/10
|
28
|
+
class: "relative block w-full appearance-none rounded-lg px-[calc(--spacing(3.5)-1px)] py-[calc(--spacing(2.5)-1px)] sm:px-[calc(--spacing(3)-1px)] sm:py-[calc(--spacing(1.5)-1px)] text-base/6 text-zinc-950 placeholder:text-zinc-500 sm:text-sm/6 border border-zinc-950/10 hover:border-zinc-950/20 bg-transparent focus:outline-hidden data-invalid:border-red-500 data-invalid:hover:border-red-500 dark:data-invalid:hover:border-red-500 data-disabled:border-zinc-950/20",
|
29
29
|
disabled: @disabled,
|
30
30
|
autofocus: @autofocus
|
31
31
|
) %>
|
@@ -39,10 +39,17 @@
|
|
39
39
|
cols: @cols,
|
40
40
|
multiple: @multiple,
|
41
41
|
data: input_data,
|
42
|
-
class: "relative block w-full appearance-none rounded-lg px-[calc(--spacing(3.5)-1px)] py-[calc(--spacing(2.5)-1px)] sm:px-[calc(--spacing(3)-1px)] sm:py-[calc(--spacing(1.5)-1px)] text-base/6 text-zinc-950 placeholder:text-zinc-500 sm:text-sm/6 border border-zinc-950/10
|
42
|
+
class: "relative block w-full appearance-none rounded-lg px-[calc(--spacing(3.5)-1px)] py-[calc(--spacing(2.5)-1px)] sm:px-[calc(--spacing(3)-1px)] sm:py-[calc(--spacing(1.5)-1px)] text-base/6 text-zinc-950 placeholder:text-zinc-500 sm:text-sm/6 border border-zinc-950/10 hover:border-zinc-950/20 bg-transparent focus:outline-hidden data-invalid:border-red-500 data-invalid:hover:border-red-500 dark:data-invalid:hover:border-red-500 data-disabled:border-zinc-950/20",
|
43
43
|
disabled: @disabled,
|
44
44
|
autofocus: @autofocus
|
45
45
|
) %>
|
46
46
|
</span>
|
47
47
|
<% end %>
|
48
|
+
<% if has_errors? %>
|
49
|
+
<%= tag.p(
|
50
|
+
error_messages,
|
51
|
+
class: "text-base/6 text-red-600 data-disabled:opacity-50 sm:text-sm/6",
|
52
|
+
data: error_data
|
53
|
+
) %>
|
54
|
+
<% end %>
|
48
55
|
<% end %>
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class LightningUiKit::TextareaComponent < LightningUiKit::BaseComponent
|
4
|
-
|
4
|
+
include LightningUiKit::Errors
|
5
|
+
|
6
|
+
def initialize(name:, value: nil, autofocus: false, label: nil, form: nil, type: :text, error: nil, description: nil, disabled: false, multiple: false, rows: 3, cols: nil, **options)
|
5
7
|
@name = name
|
6
8
|
@value = value
|
7
9
|
@disabled = disabled
|
@@ -9,6 +11,7 @@ class LightningUiKit::TextareaComponent < LightningUiKit::BaseComponent
|
|
9
11
|
@rows = rows
|
10
12
|
@multiple = multiple
|
11
13
|
@cols = cols
|
14
|
+
@error = error
|
12
15
|
@label = label
|
13
16
|
@form = form
|
14
17
|
@type = type
|
@@ -21,7 +24,11 @@ class LightningUiKit::TextareaComponent < LightningUiKit::BaseComponent
|
|
21
24
|
end
|
22
25
|
|
23
26
|
def input_data
|
24
|
-
@options[:input_data] || {}
|
27
|
+
(@options[:input_data] || {}).tap do |data|
|
28
|
+
if has_errors?
|
29
|
+
data[:invalid] = "true"
|
30
|
+
end
|
31
|
+
end
|
25
32
|
end
|
26
33
|
|
27
34
|
def label_data
|
@@ -39,4 +46,12 @@ class LightningUiKit::TextareaComponent < LightningUiKit::BaseComponent
|
|
39
46
|
end
|
40
47
|
end
|
41
48
|
end
|
49
|
+
|
50
|
+
def error_data
|
51
|
+
{slot: "error"}.merge(@options[:error_data] || {}).tap do |data|
|
52
|
+
if @disabled
|
53
|
+
data[:disabled] = "true"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
42
57
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
2
|
+
import { DirectUpload } from "@rails/activestorage"
|
3
|
+
|
4
|
+
class Upload {
|
5
|
+
constructor(file, controller) {
|
6
|
+
this.controller = controller
|
7
|
+
this.file = file;
|
8
|
+
this.directUpload = new DirectUpload(file, this.controller.inputTarget.dataset.directUploadUrl, this);
|
9
|
+
}
|
10
|
+
|
11
|
+
process() {
|
12
|
+
this.insertUpload();
|
13
|
+
|
14
|
+
this.directUpload.create((error, blob) => {
|
15
|
+
if (error) {
|
16
|
+
const fileContainer = this.controller.filesTarget.querySelector(`#upload_${this.directUpload.id}`)
|
17
|
+
const status = fileContainer.querySelector("[data-lui-dropzone-target='status']")
|
18
|
+
status.textContent = "Failed. " + error
|
19
|
+
status.classList.add("text-red-500")
|
20
|
+
} else {
|
21
|
+
const hiddenField = document.createElement('input')
|
22
|
+
hiddenField.setAttribute("type", "hidden");
|
23
|
+
hiddenField.setAttribute("value", blob.signed_id);
|
24
|
+
hiddenField.name = this.controller.inputTarget.name
|
25
|
+
this.controller.filesTarget.querySelector(`#upload_${this.directUpload.id}`).appendChild(hiddenField)
|
26
|
+
}
|
27
|
+
});
|
28
|
+
}
|
29
|
+
|
30
|
+
insertUpload() {
|
31
|
+
const template = this.controller.templateTarget.content.cloneNode(true)
|
32
|
+
template.querySelector('#\\#NEW_FILE').id = `upload_${this.directUpload.id}`
|
33
|
+
template.querySelector("[data-lui-dropzone-target='filename']").textContent = this.file.name
|
34
|
+
template.querySelector("[data-lui-dropzone-target='status']").textContent = "Uploading..."
|
35
|
+
|
36
|
+
this.controller.filesTarget.appendChild(template)
|
37
|
+
}
|
38
|
+
|
39
|
+
directUploadWillStoreFileWithXHR(request) {
|
40
|
+
request.upload.addEventListener("progress", (event) => this.updateProgress(event));
|
41
|
+
}
|
42
|
+
|
43
|
+
updateProgress(event) {
|
44
|
+
const progress = ((event.loaded / event.total) * 100).toFixed(0)
|
45
|
+
const status = progress == 100 ? "Uploaded" : "Uploading..."
|
46
|
+
|
47
|
+
const fileContainer = this.controller.filesTarget.querySelector(`#upload_${this.directUpload.id}`)
|
48
|
+
fileContainer.querySelector("[data-lui-dropzone-target='status']").textContent = status
|
49
|
+
fileContainer.querySelector("[data-lui-dropzone-target='progressbar']").style.width = `${progress}%`
|
50
|
+
fileContainer.querySelector("[data-lui-dropzone-target='percentage-progress']").textContent = `${progress}%`
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
export default class extends Controller {
|
55
|
+
static targets = ["input", "template", "files"]
|
56
|
+
|
57
|
+
selectFiles(_event) {
|
58
|
+
this.inputTarget.click()
|
59
|
+
}
|
60
|
+
|
61
|
+
uploadFiles(event) {
|
62
|
+
event.preventDefault();
|
63
|
+
const files = event.dataTransfer ? event.dataTransfer.files : event.target.files;
|
64
|
+
[...files].forEach(f => new Upload(f, this).process())
|
65
|
+
}
|
66
|
+
|
67
|
+
activate(event) {
|
68
|
+
event.preventDefault()
|
69
|
+
}
|
70
|
+
|
71
|
+
removeFile(event) {
|
72
|
+
event.preventDefault()
|
73
|
+
const container = event.target.closest("[data-lui-dropzone-target='file']")
|
74
|
+
container.remove()
|
75
|
+
}
|
76
|
+
}
|
@@ -2,6 +2,9 @@ const namespace = 'lui'
|
|
2
2
|
|
3
3
|
import { Application } from "@hotwired/stimulus"
|
4
4
|
|
5
|
+
import * as ActiveStorage from "@rails/activestorage"
|
6
|
+
ActiveStorage.start()
|
7
|
+
|
5
8
|
const application = Application.start()
|
6
9
|
window.Stimulus = application
|
7
10
|
|
@@ -14,6 +17,7 @@ import ModalController from './controllers/modal_controller'
|
|
14
17
|
import RevealController from './controllers/reveal_controller'
|
15
18
|
import SwitchController from './controllers/switch_controller'
|
16
19
|
import DropdownController from './controllers/dropdown_controller'
|
20
|
+
import DropzoneController from './controllers/dropzone_controller'
|
17
21
|
|
18
22
|
export function registerLuiControllers(application) {
|
19
23
|
application.register(`${namespace}-clipboard`, ClipboardController)
|
@@ -25,6 +29,7 @@ export function registerLuiControllers(application) {
|
|
25
29
|
application.register(`${namespace}-reveal`, RevealController)
|
26
30
|
application.register(`${namespace}-switch`, SwitchController)
|
27
31
|
application.register(`${namespace}-dropdown`, DropdownController)
|
32
|
+
application.register(`${namespace}-dropzone`, DropzoneController)
|
28
33
|
}
|
29
34
|
registerLuiControllers(application)
|
30
35
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lightning_ui_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Koval
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -128,6 +128,11 @@ files:
|
|
128
128
|
- app/components/lightning_ui_kit/dropdown/item_component.rb
|
129
129
|
- app/components/lightning_ui_kit/dropdown_component.html.erb
|
130
130
|
- app/components/lightning_ui_kit/dropdown_component.rb
|
131
|
+
- app/components/lightning_ui_kit/dropzone_component.html.erb
|
132
|
+
- app/components/lightning_ui_kit/dropzone_component.rb
|
133
|
+
- app/components/lightning_ui_kit/errors.rb
|
134
|
+
- app/components/lightning_ui_kit/file_input_component.html.erb
|
135
|
+
- app/components/lightning_ui_kit/file_input_component.rb
|
131
136
|
- app/components/lightning_ui_kit/input_component.html.erb
|
132
137
|
- app/components/lightning_ui_kit/input_component.rb
|
133
138
|
- app/components/lightning_ui_kit/link_component.html.erb
|
@@ -161,12 +166,14 @@ files:
|
|
161
166
|
- app/javascript/lightning_ui_kit/controllers/checkbox_controller.js
|
162
167
|
- app/javascript/lightning_ui_kit/controllers/clipboard_controller.js
|
163
168
|
- app/javascript/lightning_ui_kit/controllers/dropdown_controller.js
|
169
|
+
- app/javascript/lightning_ui_kit/controllers/dropzone_controller.js
|
164
170
|
- app/javascript/lightning_ui_kit/controllers/main_controller.js
|
165
171
|
- app/javascript/lightning_ui_kit/controllers/modal_controller.js
|
166
172
|
- app/javascript/lightning_ui_kit/controllers/reveal_controller.js
|
167
173
|
- app/javascript/lightning_ui_kit/controllers/switch_controller.js
|
168
174
|
- app/javascript/lightning_ui_kit/index.js
|
169
175
|
- config/initializers/heroicons.rb
|
176
|
+
- config/locales/en.yml
|
170
177
|
- lib/lightning_ui_kit.rb
|
171
178
|
- lib/lightning_ui_kit/engine.rb
|
172
179
|
- lib/lightning_ui_kit/version.rb
|