Sha256: 8b98fb3025169431d4ec9a01e370282d345bdb940abf8d7aba825d5dfe3ccc6a

Contents?: true

Size: 885 Bytes

Versions: 19

Compression:

Stored size: 885 Bytes

Contents

module Coco
  class Snackbar < Coco::Component
    include Concerns::WithIcon
    include Concerns::ActsAsNotification

    THEME_ICONS = {
      positive: :check,
      warning: :alert_triangle,
      negative: :alert_circle,
      pending: :loader_2
    }.freeze

    accepts_option :theme, from: [:positive, :warning, :negative, :pending]

    renders_one :action, ->(*args, **kwargs, &block) do
      coco_button(*args, **kwargs, theme: :blank, size: :sm, icon: nil, &block)
    end

    before_render do
      theme = get_option_value(:theme)

      unless tag_attr?(:id)
        set_tag_attr(:id, "snackbar-#{rand(1000)}")
      end

      if !icon? && theme.present?
        icon_opts = get_option_group(:icon).values
        icon_name = THEME_ICONS[theme]
        spin = theme == :pending
        with_icon(**icon_opts, name: icon_name, spin: spin)
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
coveragebook_components-0.19.3 app/components/coco/messaging/snackbar/snackbar.rb
coveragebook_components-0.19.2 app/components/coco/messaging/snackbar/snackbar.rb
coveragebook_components-0.19.1 app/components/coco/messaging/snackbar/snackbar.rb
coveragebook_components-0.19.0 app/components/coco/messaging/snackbar/snackbar.rb
coveragebook_components-0.18.8 app/components/coco/messaging/snackbar/snackbar.rb
coveragebook_components-0.18.7 app/components/coco/messaging/snackbar/snackbar.rb
coveragebook_components-0.18.0 app/components/coco/messaging/snackbar/snackbar.rb
coveragebook_components-0.17.7 app/components/coco/messaging/snackbar/snackbar.rb
coveragebook_components-0.17.6 app/components/coco/messaging/snackbar/snackbar.rb
coveragebook_components-0.17.5 app/components/coco/messaging/snackbar/snackbar.rb
coveragebook_components-0.17.4 app/components/coco/messaging/snackbar/snackbar.rb
coveragebook_components-0.17.3 app/components/coco/messaging/snackbar/snackbar.rb
coveragebook_components-0.17.2 app/components/coco/messaging/snackbar/snackbar.rb
coveragebook_components-0.17.1 app/components/coco/messaging/snackbar/snackbar.rb
coveragebook_components-0.17.0 app/components/coco/messaging/snackbar/snackbar.rb
coveragebook_components-0.16.0 app/components/coco/messaging/snackbar/snackbar.rb
coveragebook_components-0.15.0 app/components/coco/messaging/snackbar/snackbar.rb
coveragebook_components-0.14.0 app/components/coco/messaging/snackbar/snackbar.rb
coveragebook_components-0.13.1 app/components/coco/messaging/snackbar/snackbar.rb