Sha256: 4fe1c6c037e964cb9c18e9efd92de204f1402d224f1a2c171d91896567d80a05

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 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))
        else
          @blankslate.with_visual_icon(size: :medium, **@icon_arguments)
        end

        content
      end

      def render?
        heading.present?
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
openproject-primer_view_components-0.44.2 app/components/primer/open_project/feedback_message.rb
openproject-primer_view_components-0.44.1 app/components/primer/open_project/feedback_message.rb