Sha256: 310b19a4ba116a6d56d9da77ccec3965a31bbf040a4e20f3e3c47021921423e3

Contents?: true

Size: 1.98 KB

Versions: 18

Compression:

Stored size: 1.98 KB

Contents

# frozen_string_literal: true

module Primer
  module OpenProject
    # A view component for messages, inspired by the Primer Blankslate,
    # which serves a different use-case (messages for when data is missing).
    # We decided to wrap the Blankslate, because we don't want to have to adapt
    # lots of different usages if Primer decides to change the Blankslate
    # in a way that does not go well with our "misuse".
    class FeedbackMessage < Primer::Component
      status :open_project

      # @param icon_arguments [Hash] special arguments for the icon
      # @param loading [Boolean] Show a loading spinner instead of an icon
      # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
      def initialize(icon_arguments: {}, loading: false, **system_arguments)
        @system_arguments = system_arguments
        @icon_arguments = icon_arguments
        @system_arguments[:classes] = class_names(
          system_arguments[:classes],
          "FeedbackMessage"
        )

        @icon_arguments[:icon] ||= :"check-circle"
        @icon_arguments[:color] ||= :success

        @loading = loading

        @blankslate = Primer::Beta::Blankslate.new(**@system_arguments)
      end

      delegate :description?, :description, :with_description, :with_description_content,
               :heading?, :heading, :with_heading, :with_heading_content,
               :primary_action?, :primary_action, :with_primary_action, :with_primary_action_content,
               :secondary_action?, :secondary_action, :with_secondary_action, :with_secondary_action_content,
               to: :@blankslate

      private

      def before_render
        if @loading
          @blankslate.with_visual_image(src: asset_path("loading_indicator.svg"), alt: I18n.t(:label_loading))
        elsif @icon_arguments[:icon] != :none
          @blankslate.with_visual_icon(size: :medium, **@icon_arguments)
        end

        content
      end

      def render?
        heading.present?
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
openproject-primer_view_components-0.52.2 app/components/primer/open_project/feedback_message.rb
openproject-primer_view_components-0.52.1 app/components/primer/open_project/feedback_message.rb
openproject-primer_view_components-0.52.0 app/components/primer/open_project/feedback_message.rb
openproject-primer_view_components-0.51.0 app/components/primer/open_project/feedback_message.rb
openproject-primer_view_components-0.50.1 app/components/primer/open_project/feedback_message.rb
openproject-primer_view_components-0.50.0 app/components/primer/open_project/feedback_message.rb
openproject-primer_view_components-0.49.2 app/components/primer/open_project/feedback_message.rb
openproject-primer_view_components-0.49.1 app/components/primer/open_project/feedback_message.rb
openproject-primer_view_components-0.49.0 app/components/primer/open_project/feedback_message.rb
openproject-primer_view_components-0.48.2 app/components/primer/open_project/feedback_message.rb
openproject-primer_view_components-0.48.1 app/components/primer/open_project/feedback_message.rb
openproject-primer_view_components-0.48.0 app/components/primer/open_project/feedback_message.rb
openproject-primer_view_components-0.47.1 app/components/primer/open_project/feedback_message.rb
openproject-primer_view_components-0.47.0 app/components/primer/open_project/feedback_message.rb
openproject-primer_view_components-0.46.1 app/components/primer/open_project/feedback_message.rb
openproject-primer_view_components-0.46.0 app/components/primer/open_project/feedback_message.rb
openproject-primer_view_components-0.45.0 app/components/primer/open_project/feedback_message.rb
openproject-primer_view_components-0.44.3 app/components/primer/open_project/feedback_message.rb