Class: Emjay::Components::MjAccordionTitle

Inherits:
BodyComponent show all
Defined in:
lib/emjay/components/body/mj_accordion_title.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_child_context, #get_shorthand_attr_value, #get_shorthand_border_value, #html_attributes, #render_children, #styles

Methods inherited from Emjay::Component

#get_attribute, #get_child_context, #get_content, #initialize, raw_element?

Constructor Details

This class inherits a constructor from Emjay::Component

Class Method Details

.allowed_attributesObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/emjay/components/body/mj_accordion_title.rb', line 25

def self.allowed_attributes
  {
    "background-color" => "color",
    "color" => "color",
    "font-size" => "unit(px)",
    "font-family" => "string",
    "font-weight" => "string",
    "padding-bottom" => "unit(px,%)",
    "padding-left" => "unit(px,%)",
    "padding-right" => "unit(px,%)",
    "padding-top" => "unit(px,%)",
    "padding" => "unit(px,%){1,4}"
  }
end

.component_nameObject



10
11
12
# File 'lib/emjay/components/body/mj_accordion_title.rb', line 10

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

.default_attributesObject



18
19
20
21
22
23
# File 'lib/emjay/components/body/mj_accordion_title.rb', line 18

def self.default_attributes
  {
    "font-size" => "13px",
    "padding" => "16px"
  }
end

.ending_tag?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/emjay/components/body/mj_accordion_title.rb', line 14

def self.ending_tag?
  true
end

Instance Method Details

#get_stylesObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/emjay/components/body/mj_accordion_title.rb', line 40

def get_styles
  {
    td: {
      "width" => "100%",
      "background-color" => get_attribute("background-color"),
      "color" => get_attribute("color"),
      "font-size" => get_attribute("font-size"),
      "font-family" => resolve_font_family,
      "font-weight" => get_attribute("font-weight"),
      "padding" => get_attribute("padding"),
      "padding-bottom" => get_attribute("padding-bottom"),
      "padding-left" => get_attribute("padding-left"),
      "padding-right" => get_attribute("padding-right"),
      "padding-top" => get_attribute("padding-top")
    },
    table: {
      "width" => "100%",
      "border-bottom" => get_attribute("border")
    },
    td2: {
      "padding" => "16px",
      "background" => get_attribute("background-color"),
      "vertical-align" => get_attribute("icon-align")
    },
    img: {
      "display" => "none",
      "width" => get_attribute("icon-width"),
      "height" => get_attribute("icon-height")
    }
  }
end

#renderObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/emjay/components/body/mj_accordion_title.rb', line 72

def render
  content_elements = [render_title, render_icons]
  content = if get_attribute("icon-position") == "right"
    content_elements
  else
    content_elements.reverse
  end.join("\n")

  table_attrs = html_attributes(
    cellspacing: "0",
    cellpadding: "0",
    style: :table
  )

  <<~HTML
    <div#{html_attributes(class: "mj-accordion-title")}>
      <table
        #{table_attrs}
      >
        <tbody>
          <tr>
            #{content}
          </tr>
        </tbody>
      </table>
    </div>
  HTML
end