Sha256: 1d239dc10dbb05ba21afb3809cf5e75b51cdd20fc588b7b810e755ee3757a89d

Contents?: true

Size: 1.71 KB

Versions: 108

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

module Primer
  module Beta
    # Use `ProgressBar` to visualize task completion.
    class ProgressBar < Primer::Component
      status :beta

      # Use the Item slot to add an item to the progress bar
      #
      # @param percentage [Integer] The percent complete
      # @param bg [Symbol] The background color
      # @param kwargs [Hash] The same arguments as <%= link_to_system_arguments_docs %>.
      renders_many :items, lambda { |percentage: 0, bg: :success_emphasis, **system_arguments|
        deny_tag_argument(**system_arguments)
        system_arguments[:tag] = :span
        system_arguments[:bg] = bg
        system_arguments[:style] = join_style_arguments(system_arguments[:style], "width: #{percentage}%;")
        system_arguments[:classes] = class_names("Progress-item", system_arguments[:classes])

        Primer::BaseComponent.new(**system_arguments)
      }

      SIZE_DEFAULT = :default

      SIZE_MAPPINGS = {
        SIZE_DEFAULT => "",
        :small => "Progress--small",
        :large => "Progress--large"
      }.freeze

      SIZE_OPTIONS = SIZE_MAPPINGS.keys

      # @param size [Symbol] <%= one_of(Primer::Beta::ProgressBar::SIZE_OPTIONS) %> Increases height.
      # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
      def initialize(size: SIZE_DEFAULT, **system_arguments)
        @system_arguments = deny_tag_argument(**system_arguments)
        @system_arguments[:classes] = class_names(
          @system_arguments[:classes],
          "Progress",
          SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)]
        )
        @system_arguments[:tag] = :span
      end

      def render?
        items?
      end
    end
  end
end

Version data entries

108 entries across 108 versions & 2 rubygems

Version Path
openproject-primer_view_components-0.35.2 app/components/primer/beta/progress_bar.rb
openproject-primer_view_components-0.35.1 app/components/primer/beta/progress_bar.rb
primer_view_components-0.26.1 app/components/primer/beta/progress_bar.rb
openproject-primer_view_components-0.35.0 app/components/primer/beta/progress_bar.rb
primer_view_components-0.26.0 app/components/primer/beta/progress_bar.rb
openproject-primer_view_components-0.34.0 app/components/primer/beta/progress_bar.rb
openproject-primer_view_components-0.33.2 app/components/primer/beta/progress_bar.rb
openproject-primer_view_components-0.33.1 app/components/primer/beta/progress_bar.rb
openproject-primer_view_components-0.33.0 app/components/primer/beta/progress_bar.rb
primer_view_components-0.25.1 app/components/primer/beta/progress_bar.rb
openproject-primer_view_components-0.32.1 app/components/primer/beta/progress_bar.rb
openproject-primer_view_components-0.32.0 app/components/primer/beta/progress_bar.rb
openproject-primer_view_components-0.29.1 app/components/primer/beta/progress_bar.rb
openproject-primer_view_components-0.29.0 app/components/primer/beta/progress_bar.rb
primer_view_components-0.23.0 app/components/primer/beta/progress_bar.rb
openproject-primer_view_components-0.28.1 app/components/primer/beta/progress_bar.rb
openproject-primer_view_components-0.28.0 app/components/primer/beta/progress_bar.rb
openproject-primer_view_components-0.27.0 app/components/primer/beta/progress_bar.rb
openproject-primer_view_components-0.26.0 app/components/primer/beta/progress_bar.rb
openproject-primer_view_components-0.25.1 app/components/primer/beta/progress_bar.rb