Sha256: 361432a946d4682f919974913475c79ccb001ffa86e7cf9e1f38acec91c54716

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

module AmaLayout
  class NotificationDecorator
    include AmaLayout::DraperReplacement
    extend AmaLayout::DraperReplacement

    ICONS = {
      notice: {
        icon_class: 'fa-info',
        colour_class: 'right-sidebar__content-icon--blue' # currently not in use
      },
      warning: {
        icon_class: 'fa-exclamation',
        colour_class: 'right-sidebar__content-icon--orange'
      },
      alert: {
        icon_class: 'fa-exclamation-triangle',
        colour_class: 'right-sidebar__content-icon--red'
      }
    }.freeze

    def created_at
      "#{time_elapsed} ago".humanize
    end

    def icon
      h.content_tag :div, class: icon_data.fetch(:colour_class) do
        klass = icon_data.fetch(:icon_class)
        h.content_tag :i, nil, class: "fa #{klass} right-sidebar__notice-icon"
      end
    end

    def active_class
      active? ? 'right-sidebar__content--active' : 'right-sidebar__content--inactive'
    end

    private

    def icon_data
      @icon_data ||= ICONS.fetch(type)
    end

    def time_elapsed
      h.time_ago_in_words(object.created_at, include_seconds: true)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ama_layout-7.0.1 lib/ama_layout/decorators/notification_decorator.rb
ama_layout-5.12.0 lib/ama_layout/decorators/notification_decorator.rb
ama_layout-7.0.pre lib/ama_layout/decorators/notification_decorator.rb