Sha256: 093eab5e210f864ac303c81ff0acd632b2370fc4db323d8f1a7d7a512ec0d8c2

Contents?: true

Size: 1.01 KB

Versions: 23

Compression:

Stored size: 1.01 KB

Contents

module Coco
  module App
    module Elements
      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
            icon(**icon_opts, name: icon_name, spin: spin)
          end
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
coveragebook_components-0.12.2 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.12.1 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.12.0 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.11.0 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.10.1.beta.2 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.10.1.beta.1 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.10.1.beta.0 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.10.0 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.9.1 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.9.0 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.8.9 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.8.8 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.8.7 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.8.6 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.8.5 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.8.4 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.8.3 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.8.2 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.8.1 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.8.0 app/components/coco/app/elements/snackbar/snackbar.rb