Class: Emjay::Components::MjAccordionElement

Inherits:
BodyComponent show all
Defined in:
lib/emjay/components/body/mj_accordion_element.rb

Instance Attribute Summary

Attributes inherited from Emjay::Component

#attributes, #context, #props

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BodyComponent

#get_box_widths, #get_shorthand_attr_value, #get_shorthand_border_value, #html_attributes, #render_children, #styles

Methods inherited from Emjay::Component

ending_tag?, #get_attribute, #get_content, #initialize, raw_element?

Constructor Details

This class inherits a constructor from Emjay::Component

Class Method Details

.allowed_attributesObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/emjay/components/body/mj_accordion_element.rb', line 17

def self.allowed_attributes
  {
    "background-color" => "color",
    "border" => "string",
    "font-family" => "string",
    "icon-align" => "enum(top,middle,bottom)",
    "icon-width" => "unit(px,%)",
    "icon-height" => "unit(px,%)",
    "icon-wrapped-url" => "string",
    "icon-wrapped-alt" => "string",
    "icon-unwrapped-url" => "string",
    "icon-unwrapped-alt" => "string",
    "icon-position" => "enum(left,right)"
  }
end

.component_nameObject



9
10
11
# File 'lib/emjay/components/body/mj_accordion_element.rb', line 9

def self.component_name
  "mj-accordion-element"
end

.default_attributesObject



13
14
15
# File 'lib/emjay/components/body/mj_accordion_element.rb', line 13

def self.default_attributes
  {}
end

Instance Method Details

#get_child_contextObject



49
50
51
# File 'lib/emjay/components/body/mj_accordion_element.rb', line 49

def get_child_context
  @context.merge(elementFontFamily: get_attribute("font-family"))
end

#get_stylesObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/emjay/components/body/mj_accordion_element.rb', line 33

def get_styles
  {
    td: {
      "padding" => "0px",
      "background-color" => get_attribute("background-color")
    },
    label: {
      "font-size" => "13px",
      "font-family" => get_attribute("font-family")
    },
    input: {
      "display" => "none"
    }
  }
end

#renderObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/emjay/components/body/mj_accordion_element.rb', line 53

def render
  tr_attrs = html_attributes(class: get_attribute("css-class"))
  td_attrs = html_attributes(style: :td)
  label_attrs = html_attributes(
    class: "mj-accordion-element",
    style: :label
  )
  input_attrs = html_attributes(
    class: "mj-accordion-checkbox",
    type: "checkbox",
    style: :input
  )

  input_html = ConditionalTag.conditional_tag(
    "<input#{input_attrs} />",
    negation: true
  )

  <<~HTML
    <tr
      #{tr_attrs}
    >
      <td#{td_attrs}>
        <label
          #{label_attrs}
        >
          #{input_html}
          <div>
            #{handle_missing_children}
          </div>
        </label>
      </td>
    </tr>
  HTML
end