Class: Ariadne::ProgressBarComponent

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

Overview

Bar used to show a progress in an activity, supports single bars or multiple bars within one component use aria-labelledby and aria-describedby to describe the progress bar’s purpose

Constant Summary collapse

DEFAULT_TAGS =
{
  wrapper: :div,
  item: :div,
}
DEFAULT_CLASSES =
{
  wrapper: "ariadne-flex ariadne-gap-1 ariadne-bg-slate-200 ariadne-rounded-md ariadne-overflow-hidden",
  item: "",
}
DEFAULT_ATTRIBUTES =
{
  wrapper: {
    role: "progressbar",
    "data-controller": "accumulator",
    "aria-valuenow": 0,
  },
  item: { "data-accumulator-target": "sum" },
}
BAR_SIZES =
{
  sm: "ariadne-h-2",
  md: "ariadne-h-3",
  lg: "ariadne-h-4",
}

Constants inherited from Component

Component::BASE_HIDDEN_CLASS, Component::BASE_MAIN_CLASSES, Component::BASE_WRAPPER_CLASSES, Component::INVALID_ARIA_LABEL_TAGS

Constants included from ActionViewExtensions::FormHelper

ActionViewExtensions::FormHelper::DEFAULT_FORM_CLASSES

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::INTEGER_TYPES, FetchOrFallbackHelper::InvalidValueError, FetchOrFallbackHelper::TRUE_OR_FALSE

Instance Method Summary collapse

Methods included from ActionViewExtensions::FormHelper

#ariadne_form_with

Methods included from ClassNameHelper

#merge_class_names

Methods included from LoggerHelper

#logger, #silence_deprecations?, #silence_warnings?

Methods included from FetchOrFallbackHelper

#check_incoming_attribute, #check_incoming_tag, #check_incoming_value, #fetch_or_raise, #fetch_or_raise_boolean, #fetch_or_raise_integer

Constructor Details

#initialize(tag: DEFAULT_TAGS[:wrapper], min: 0, max: 100, classes: "", size: :md, attributes: {}) ⇒ ProgressBarComponent

Returns a new instance of ProgressBarComponent.

Examples:

Default


<%= render(Ariadne::ProgressBarComponent.new) { "Example" } %>

Parameters:

  • tag (Symbol, String) (defaults to: DEFAULT_TAGS[:wrapper])

    The rendered tag name.

  • classes (String) (defaults to: "")

    <%= link_to_classes_docs %>

  • attributes (Hash) (defaults to: {})

    <%= link_to_attributes_docs %>



50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/components/ariadne/progress_bar_component.rb', line 50

def initialize(tag: DEFAULT_TAGS[:wrapper], min: 0, max: 100, classes: "", size: :md, attributes: {})
  @tag = check_incoming_tag(DEFAULT_TAGS[:wrapper], tag)
  @classes = merge_class_names(DEFAULT_CLASSES[:wrapper], classes)

  @min = min
  @max = max
  @size = size
  @attributes = DEFAULT_ATTRIBUTES[:wrapper].merge({
    "aria-valuemin": @min,
    "aria-valuemax": @max,
  }).merge(attributes)
end