module Maglove module Widgets class Listitem < Base def identifier "listitem" end def defaults { background_color: "#18B545", text_color: "#FFFFFF", arrow_color: "#FFFFFF", size: "md", badge: nil, badge_color: "#FFFFFF", badge_background: "rgba(255, 255, 255, 0.25)", badge_width: "24px", title: "Title", subtitle: nil, subtitle_style: "normal", image_source: nil } end def styles style_string @options, :border_color, :background_color end module Helpers def listitem_widget(options = {}) widget_block(Widgets::Listitem.new(options)) do |widget| haml_tag :a, { class: "list-item list-item-#{widget.options[:size]}", href: (widget.options[:href] or "#"), style: widget.styles } do if widget.options[:icon] haml_tag :i, { class: "list-item-icon fa fa-#{widget.options[:icon]}" } end if widget.options[:image_source] image_style = style_string(widget.options) do |sb| sb.add(:background_image, widget.options[:image_source], "url(<%= value %>)") end haml_tag :div, { class: "list-item-image", style: image_style } end haml_tag :div, { class: "list-item-main" } do haml_tag :div, { class: "list-item-title", style: "color: #{widget.options[:text_color]}" } do haml_concat(widget.options[:title]) end if widget.options[:subtitle] haml_tag :div, { class: "list-item-subtitle", style: "color: #{widget.options[:text_color]}; font-style: #{widget.options[:subtitle_style]}" } do haml_concat(widget.options[:subtitle]) end end end if widget.options[:badge] haml_tag :div, { class: "list-item-badge" } do haml_tag :span, { style: "color: #{widget.options[:badge_color]}; background-color: #{widget.options[:badge_background]}; width: #{widget.options[:badge_width]};" } do haml_concat(widget.options[:badge]) end end end if widget.options[:href] haml_tag :i, { class: "list-item-arrow fa fa-angle-right", style: "color: #{widget.options[:arrow_color]}" } end end end end end end end end