Class: Polaris::ProgressBarComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/polaris/progress_bar_component.rb

Constant Summary collapse

COLOR_DEFAULT =
:highlight
COLOR_MAPPINGS =
{
  COLOR_DEFAULT => "Polaris-ProgressBar--colorHighlight",
  :primary => "Polaris-ProgressBar--colorPrimary",
  :success => "Polaris-ProgressBar--colorSuccess",
  :critical => "Polaris-ProgressBar--colorCritical"
}
COLOR_OPTIONS =
COLOR_MAPPINGS.keys
SIZE_DEFAULT =
:medium
SIZE_MAPPINGS =
{
  SIZE_DEFAULT => "Polaris-ProgressBar--sizeMedium",
  :small => "Polaris-ProgressBar--sizeSmall",
  :large => "Polaris-ProgressBar--sizeLarge"
}
SIZE_OPTIONS =
SIZE_MAPPINGS.keys

Constants included from ViewHelper

ViewHelper::POLARIS_HELPERS, ViewHelper::POLARIS_TEXT_STYLES

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods included from ViewHelper

#polaris_body_styles, #polaris_html_classes, #polaris_html_styles, #polaris_icon_source

Methods included from StylesListHelper

#styles_list

Methods included from OptionHelper

#append_option, #prepend_option

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #fetch_or_fallback_nested

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(animated: true, color: COLOR_DEFAULT, progress: 0, size: SIZE_DEFAULT, **system_arguments) ⇒ ProgressBarComponent

Returns a new instance of ProgressBarComponent.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/components/polaris/progress_bar_component.rb', line 22

def initialize(
  animated: true,
  color: COLOR_DEFAULT,
  progress: 0,
  size: SIZE_DEFAULT,
  **system_arguments
)
  @system_arguments = system_arguments
  @system_arguments[:tag] = :div
  @system_arguments[:classes] = class_names(
    @system_arguments[:classes],
    "Polaris-ProgressBar",
    COLOR_MAPPINGS[fetch_or_fallback(COLOR_OPTIONS, color, COLOR_DEFAULT)],
    SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)]
  )

  @animated = animated
  @progress = progress
end

Instance Method Details

#progress_argumentsObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/components/polaris/progress_bar_component.rb', line 42

def progress_arguments
  {tag: "div"}.tap do |args|
    args[:classes] = class_names(
      "Polaris-ProgressBar__Indicator",
      "Polaris-ProgressBar__IndicatorAppearDone"
    )
    args[:style] = styles_list(
      "--pc-progress-bar-duration": @animated ? "500ms" : "0ms",
      "--pc-progress-bar-percent": @progress / 100.0
    )
  end
end