Sha256: dee5fc7608aa373c513c17e83ecabaa5a28041ab87086d9f2f3d1acb8e06ca48

Contents?: true

Size: 1 KB

Versions: 25

Compression:

Stored size: 1 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, ->(**kwargs, &block) do
          Coco::App::Elements::Button.new(**kwargs, theme: :blank, size: :sm, icon: nil)
        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

25 entries across 25 versions & 1 rubygems

Version Path
coveragebook_components-0.7.10 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.7.9 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.7.8 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.7.7 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.7.6 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.7.5 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.7.4 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.7.3 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.7.2 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.7.1 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.7.0 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.6.5 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.6.4 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.6.3 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.6.2 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.6.1 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.6.0 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.5.7 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.5.6 app/components/coco/app/elements/snackbar/snackbar.rb
coveragebook_components-0.5.5 app/components/coco/app/elements/snackbar/snackbar.rb