Class: Emjay::Components::MjCarousel
- Inherits:
-
BodyComponent
- Object
- Emjay::Component
- BodyComponent
- Emjay::Components::MjCarousel
- Defined in:
- lib/emjay/components/body/mj_carousel.rb
Instance Attribute Summary
Attributes inherited from Emjay::Component
Class Method Summary collapse
Instance Method Summary collapse
- #component_head_style(_breakpoint = nil) ⇒ Object
- #get_child_context ⇒ Object
- #get_styles ⇒ Object
-
#initialize(initial_data = {}) ⇒ MjCarousel
constructor
A new instance of MjCarousel.
- #render ⇒ Object
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, raw_element?
Constructor Details
#initialize(initial_data = {}) ⇒ MjCarousel
Returns a new instance of MjCarousel.
51 52 53 54 |
# File 'lib/emjay/components/body/mj_carousel.rb', line 51 def initialize(initial_data = {}) super @carousel_id = GenRandomHexString.call(16) end |
Class Method Details
.allowed_attributes ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/emjay/components/body/mj_carousel.rb', line 29 def self.allowed_attributes { "align" => "enum(left,center,right)", "border-radius" => "string", "container-background-color" => "color", "icon-width" => "unit(px,%)", "left-icon" => "string", "padding" => "unit(px,%){1,4}", "padding-top" => "unit(px,%)", "padding-bottom" => "unit(px,%)", "padding-left" => "unit(px,%)", "padding-right" => "unit(px,%)", "right-icon" => "string", "thumbnails" => "enum(visible,hidden,supported)", "tb-border" => "string", "tb-border-radius" => "string", "tb-hover-border-color" => "color", "tb-selected-border-color" => "color", "tb-width" => "unit(px,%)" } end |
.component_name ⇒ Object
10 11 12 |
# File 'lib/emjay/components/body/mj_carousel.rb', line 10 def self.component_name "mj-carousel" end |
.default_attributes ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/emjay/components/body/mj_carousel.rb', line 14 def self.default_attributes { "align" => "center", "border-radius" => "6px", "icon-width" => "44px", "left-icon" => "https://i.imgur.com/xTh3hln.png", "right-icon" => "https://i.imgur.com/os7o9kz.png", "thumbnails" => "visible", "tb-border" => "2px solid transparent", "tb-border-radius" => "6px", "tb-hover-border-color" => "#fead0d", "tb-selected-border-color" => "#cccccc" } end |
Instance Method Details
#component_head_style(_breakpoint = nil) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/emjay/components/body/mj_carousel.rb', line 56 def component_head_style(_breakpoint = nil) children = @props[:children] || [] length = children.length return "" if length == 0 carousel_css = build_carousel_css(length) fallback = build_fallback_css(length) "\n#{carousel_css}\n#{fallback}" end |
#get_child_context ⇒ Object
109 110 111 |
# File 'lib/emjay/components/body/mj_carousel.rb', line 109 def get_child_context @context.merge(thumbnails: get_attribute("thumbnails")) end |
#get_styles ⇒ Object
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 |
# File 'lib/emjay/components/body/mj_carousel.rb', line 67 def get_styles { carousel: { div: { "display" => "table", "width" => "100%", "table-layout" => "fixed", "text-align" => "center", "font-size" => "0px" }, table: { "caption-side" => "top", "display" => "table-caption", "table-layout" => "fixed", "width" => "100%" } }, images: { td: { "padding" => "0px" } }, controls: { div: { "display" => "none", "mso-hide" => "all" }, img: { "display" => "block", "width" => get_attribute("icon-width"), "height" => "auto" }, td: { "font-size" => "0px", "display" => "none", "mso-hide" => "all", "padding" => "0px" } } } end |
#render ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/emjay/components/body/mj_carousel.rb', line 113 def render children = @props[:children] || [] carousel_html = ConditionalTag.mso_conditional_tag( render_carousel_content(children), negation: true ) fallback_html = render_fallback(children) <<~HTML #{carousel_html} #{fallback_html} HTML end |