Class: Emjay::Components::MjSection

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

Direct Known Subclasses

MjWrapper

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



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/emjay/components/body/mj_section.rb', line 14

def self.allowed_attributes
  {
    "background-color" => "color",
    "background-url" => "string",
    "background-repeat" => "enum(repeat,no-repeat)",
    "background-size" => "string",
    "background-position" => "string",
    "background-position-x" => "string",
    "background-position-y" => "string",
    "border" => "string",
    "border-bottom" => "string",
    "border-left" => "string",
    "border-radius" => "string",
    "border-right" => "string",
    "border-top" => "string",
    "direction" => "enum(ltr,rtl)",
    "full-width" => "enum(full-width,false,)",
    "padding" => "unit(px,%){1,4}",
    "padding-top" => "unit(px,%)",
    "padding-bottom" => "unit(px,%)",
    "padding-left" => "unit(px,%)",
    "padding-right" => "unit(px,%)",
    "text-align" => "enum(left,center,right)",
    "text-padding" => "unit(px,%){1,4}"
  }
end

.component_nameObject



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

def self.component_name
  "mj-section"
end

.default_attributesObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/emjay/components/body/mj_section.rb', line 41

def self.default_attributes
  {
    "background-repeat" => "repeat",
    "background-size" => "auto",
    "background-position" => "top center",
    "direction" => "ltr",
    "padding" => "20px 0",
    "text-align" => "center",
    "text-padding" => "4px 4px 4px 0"
  }
end

Instance Method Details

#get_child_contextObject



53
54
55
56
57
58
59
# File 'lib/emjay/components/body/mj_section.rb', line 53

def get_child_context
  widths = get_box_widths
  @context.merge(
    container_width: "#{widths[:box]}px",
    gap: get_attribute("gap")
  )
end

#get_stylesObject



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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/emjay/components/body/mj_section.rb', line 61

def get_styles
  container_width = @context[:container_width]
  full_width = full_width?
  has_border_radius = has_border_radius?
  is_first = @props[:index] == 0

  background = if has_background?
    {
      "background" => get_background,
      "background-position" => get_background_string,
      "background-repeat" => get_attribute("background-repeat"),
      "background-size" => get_attribute("background-size")
    }
  else
    {
      "background" => get_attribute("background-color"),
      "background-color" => get_attribute("background-color")
    }
  end

  {
    tableFullwidth: {
      **(full_width ? background : {}),
      "width" => "100%"
    },
    table: {
      **(full_width ? {} : background),
      "width" => "100%",
      **(has_border_radius ? {"border-collapse" => "separate"} : {})
    },
    td: {
      "border" => get_attribute("border"),
      "border-bottom" => get_attribute("border-bottom"),
      "border-left" => get_attribute("border-left"),
      "border-right" => get_attribute("border-right"),
      "border-top" => get_attribute("border-top"),
      "border-radius" => get_attribute("border-radius"),
      "direction" => get_attribute("direction"),
      "font-size" => "0px",
      "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"),
      "text-align" => get_attribute("text-align")
    },
    div: {
      **(full_width ? {} : background),
      "margin" => "0px auto",
      "max-width" => container_width,
      "border-radius" => get_attribute("border-radius"),
      **(has_border_radius ? {"overflow" => "hidden"} : {}),
      "margin-top" => ((!is_first) ? @context[:gap] : nil)
    },
    innerDiv: {
      "line-height" => "0",
      "font-size" => "0"
    }
  }
end

#renderObject



122
123
124
# File 'lib/emjay/components/body/mj_section.rb', line 122

def render
  full_width? ? render_full_width : render_simple
end