Class: Yattho::Beta::ProgressBar

Inherits:
Component
  • Object
show all
Defined in:
app/components/yattho/beta/progress_bar.rb

Overview

Use ‘ProgressBar` to visualize task completion.

Constant Summary collapse

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

Constants inherited from Component

Component::INVALID_ARIA_LABEL_TAGS

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods inherited from Component

deprecated?, generate_id

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from TestSelectorHelper

#add_test_selector

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(size: SIZE_DEFAULT, **system_arguments) ⇒ ProgressBar

Returns a new instance of ProgressBar.

Examples:

Default

<%= render(Yattho::Beta::ProgressBar.new) do |component| %>
  <% component.with_item(percentage: 25) %>
<% end %>

Small

<%= render(Yattho::Beta::ProgressBar.new(size: :small)) do |component| %>
  <% component.with_item(bg: :accent_emphasis, percentage: 50) %>
<% end %>

Large

<%= render(Yattho::Beta::ProgressBar.new(size: :large)) do |component| %>
  <% component.with_item(bg: :danger_emphasis, percentage: 75) %>
<% end %>

Multiple items

<%= render(Yattho::Beta::ProgressBar.new) do |component| %>
  <% component.with_item(percentage: 10) %>
  <% component.with_item(bg: :accent_emphasis, percentage: 20) %>
  <% component.with_item(bg: :danger_emphasis, percentage: 30) %>
<% end %>

Parameters:

  • size (Symbol) (defaults to: SIZE_DEFAULT)

    <%= one_of(Yattho::Beta::ProgressBar::SIZE_OPTIONS) %> Increases height.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



57
58
59
60
61
62
63
64
65
# File 'app/components/yattho/beta/progress_bar.rb', line 57

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

Instance Method Details

#render?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/components/yattho/beta/progress_bar.rb', line 67

def render?
  items?
end