2022-08-13 15:12:31 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Pajamas
|
|
|
|
class SpinnerComponent < Pajamas::Component
|
|
|
|
# @param [Symbol] color
|
|
|
|
# @param [Boolean] inline
|
|
|
|
# @param [String] label
|
|
|
|
# @param [Symbol] size
|
2023-01-13 00:05:48 +05:30
|
|
|
def initialize(color: :dark, inline: false, label: _("Loading"), size: :sm, **html_options)
|
2022-08-13 15:12:31 +05:30
|
|
|
@color = filter_attribute(color.to_sym, COLOR_OPTIONS)
|
|
|
|
@inline = inline
|
|
|
|
@label = label.presence
|
|
|
|
@size = filter_attribute(size.to_sym, SIZE_OPTIONS)
|
2023-01-13 00:05:48 +05:30
|
|
|
@html_options = html_options
|
2022-08-13 15:12:31 +05:30
|
|
|
end
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
COLOR_OPTIONS = [:light, :dark].freeze
|
|
|
|
SIZE_OPTIONS = [:sm, :md, :lg, :xl].freeze
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def spinner_class
|
2023-01-13 00:05:48 +05:30
|
|
|
["gl-spinner", "gl-spinner-#{@size}", "gl-spinner-#{@color} gl-vertical-align-text-bottom!"]
|
2022-08-13 15:12:31 +05:30
|
|
|
end
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
def html_options
|
|
|
|
options = format_options(options: @html_options, css_classes: "gl-spinner-container")
|
|
|
|
options[:role] = "status"
|
|
|
|
options
|
|
|
|
end
|
2022-08-13 15:12:31 +05:30
|
|
|
end
|
|
|
|
end
|