Class: LightningUiKit::DropzoneComponent
Instance Method Summary
collapse
-
#classes ⇒ Object
-
#data ⇒ Object
-
#description_data ⇒ Object
-
#error_data ⇒ Object
-
#initialize(name:, value: nil, label: nil, form: nil, description: nil, multiple: false, accept: nil, disabled: false, placeholder: nil, error: nil, **options) ⇒ DropzoneComponent
constructor
A new instance of DropzoneComponent.
-
#input_data ⇒ Object
-
#label_data ⇒ Object
Methods included from Errors
#error_messages, #has_errors?, #infer_errors_from_association
#merge_classes
#heroicon
Constructor Details
#initialize(name:, value: nil, label: nil, form: nil, description: nil, multiple: false, accept: nil, disabled: false, placeholder: nil, error: nil, **options) ⇒ DropzoneComponent
Returns a new instance of DropzoneComponent.
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'app/components/lightning_ui_kit/dropzone_component.rb', line 6
def initialize(name:, value: nil, label: nil, form: nil, description: nil, multiple: false, accept: nil, disabled: false, placeholder: nil, error: nil, **options)
@name = name
@value = value
@disabled = disabled
@accept = accept
@multiple = multiple
@error = error
@label = label
@form = form
@description = description
@placeholder = placeholder
@options = options
end
|
Instance Method Details
#classes ⇒ Object
20
21
22
|
# File 'app/components/lightning_ui_kit/dropzone_component.rb', line 20
def classes
merge_classes(["lui:space-y-4 lui:[&>[data-slot=label]+[data-slot=control]]:mt-3 lui:[&>[data-slot=label]+[data-slot=description]]:mt-1 lui:[&>[data-slot=description]+[data-slot=control]]:mt-3 lui:[&>[data-slot=control]+[data-slot=description]]:mt-3 lui:[&>[data-slot=control]+[data-slot=error]]:mt-3 lui:*:data-[slot=label]:font-medium", @options[:class]].compact.join(" "))
end
|
#data ⇒ Object
24
25
26
|
# File 'app/components/lightning_ui_kit/dropzone_component.rb', line 24
def data
{controller: "lui-dropzone"}.merge(@options[:data] || {})
end
|
#description_data ⇒ Object
46
47
48
49
50
51
52
|
# File 'app/components/lightning_ui_kit/dropzone_component.rb', line 46
def description_data
{slot: "description"}.merge(@options[:description_data] || {}).tap do |data|
if @disabled
data[:disabled] = "true"
end
end
end
|
#error_data ⇒ Object
54
55
56
57
58
59
60
|
# File 'app/components/lightning_ui_kit/dropzone_component.rb', line 54
def error_data
{slot: "error"}.merge(@options[:error_data] || {}).tap do |data|
if @disabled
data[:disabled] = "true"
end
end
end
|
28
29
30
31
32
33
34
35
36
|
# File 'app/components/lightning_ui_kit/dropzone_component.rb', line 28
def input_data
(@options[:input_data] || {}).tap do |data|
data[:lui_dropzone_target] = "input"
data[:action] = "dragover->lui-dropzone#activate drop->lui-dropzone#uploadFiles change->lui-dropzone#uploadFiles"
if has_errors?
data[:invalid] = "true"
end
end
end
|
#label_data ⇒ Object
38
39
40
41
42
43
44
|
# File 'app/components/lightning_ui_kit/dropzone_component.rb', line 38
def label_data
{slot: "label"}.merge(@options[:label_data] || {}).tap do |data|
if @disabled
data[:disabled] = "true"
end
end
end
|