Class: Maglev::Uikit::ImageLibrary::CardComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/maglev/uikit/image_library/card_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseComponent

#button_class_names

Constructor Details

#initialize(image:, delete_path:, picker_attributes: nil) ⇒ CardComponent

Returns a new instance of CardComponent.



9
10
11
12
13
14
15
16
17
18
# File 'app/components/maglev/uikit/image_library/card_component.rb', line 9

def initialize(image:, delete_path:, picker_attributes: nil)
  @id = image[:id]
  @image_url = image[:image_url]
  @filename = image[:filename]
  @width = image[:width]
  @height = image[:height]
  @byte_size = image[:byte_size]
  @delete_path = delete_path
  @picker_attributes = picker_attributes
end

Instance Attribute Details

#byte_sizeObject (readonly)

Returns the value of attribute byte_size.



7
8
9
# File 'app/components/maglev/uikit/image_library/card_component.rb', line 7

def byte_size
  @byte_size
end

#delete_pathObject (readonly)

Returns the value of attribute delete_path.



7
8
9
# File 'app/components/maglev/uikit/image_library/card_component.rb', line 7

def delete_path
  @delete_path
end

#filenameObject (readonly)

Returns the value of attribute filename.



7
8
9
# File 'app/components/maglev/uikit/image_library/card_component.rb', line 7

def filename
  @filename
end

#heightObject (readonly)

Returns the value of attribute height.



7
8
9
# File 'app/components/maglev/uikit/image_library/card_component.rb', line 7

def height
  @height
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'app/components/maglev/uikit/image_library/card_component.rb', line 7

def id
  @id
end

#image_urlObject (readonly)

Returns the value of attribute image_url.



7
8
9
# File 'app/components/maglev/uikit/image_library/card_component.rb', line 7

def image_url
  @image_url
end

#picker_attributesObject (readonly)

Returns the value of attribute picker_attributes.



7
8
9
# File 'app/components/maglev/uikit/image_library/card_component.rb', line 7

def picker_attributes
  @picker_attributes
end

#widthObject (readonly)

Returns the value of attribute width.



7
8
9
# File 'app/components/maglev/uikit/image_library/card_component.rb', line 7

def width
  @width
end

Instance Method Details

#picker_event_image_payloadObject



31
32
33
34
35
36
37
38
39
40
# File 'app/components/maglev/uikit/image_library/card_component.rb', line 31

def picker_event_image_payload
  {
    id: id,
    filename: filename,
    url: image_url,
    width: width,
    height: height,
    byte_size: byte_size
  }
end

#picker_event_nameObject



42
43
44
# File 'app/components/maglev/uikit/image_library/card_component.rb', line 42

def picker_event_name
  "image-selected-#{picker_attributes[:source]}"
end

#picker_event_payloadObject



24
25
26
27
28
29
# File 'app/components/maglev/uikit/image_library/card_component.rb', line 24

def picker_event_payload
  {
    source: picker_attributes[:source],
    image: picker_event_image_payload
  }.to_json
end

#picker_mode?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'app/components/maglev/uikit/image_library/card_component.rb', line 20

def picker_mode?
  picker_attributes.present? && picker_attributes[:picker].present?
end

#width_and_height?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'app/components/maglev/uikit/image_library/card_component.rb', line 46

def width_and_height?
  width.present? && height.present?
end