Class: Shadcn::Progress::Component
- Inherits:
-
ApplicationViewComponent
- Object
- ViewComponent::Base
- ApplicationViewComponent
- Shadcn::Progress::Component
- Defined in:
- app/components/shadcn/progress/component.rb
Overview
Port of registry/new-york-v4/ui/progress.tsx
Reproduces the ARIA surface and the data-state / data-value / data-max
attributes Radix puts on both the root and the indicator.
Constant Summary collapse
- INDICATOR_CLASSES =
"h-full w-full flex-1 bg-primary transition-all"
Constants inherited from ApplicationViewComponent
ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from ApplicationViewComponent
Instance Method Summary collapse
- #call ⇒ Object
- #element_attributes(**defaults) ⇒ Object
-
#initialize(value: nil, max: 100, **attributes) ⇒ Component
constructor
A new instance of Component.
- #state ⇒ Object
Methods inherited from ApplicationViewComponent
#css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name
Constructor Details
#initialize(value: nil, max: 100, **attributes) ⇒ Component
Returns a new instance of Component.
20 21 22 23 24 |
# File 'app/components/shadcn/progress/component.rb', line 20 def initialize(value: nil, max: 100, **attributes) @value = value @max = max super(**attributes) end |
Instance Attribute Details
#max ⇒ Object (readonly)
Returns the value of attribute max.
18 19 20 |
# File 'app/components/shadcn/progress/component.rb', line 18 def max @max end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
18 19 20 |
# File 'app/components/shadcn/progress/component.rb', line 18 def value @value end |
Instance Method Details
#call ⇒ Object
44 45 46 |
# File 'app/components/shadcn/progress/component.rb', line 44 def call render_element(body: indicator) end |
#element_attributes(**defaults) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/components/shadcn/progress/component.rb', line 32 def element_attributes(**defaults) super(**{ role: "progressbar", "aria-valuemax" => max, "aria-valuemin" => 0, "aria-valuenow" => value, "data-state" => state, "data-value" => value, "data-max" => max }.merge(defaults)) end |
#state ⇒ Object
26 27 28 29 30 |
# File 'app/components/shadcn/progress/component.rb', line 26 def state return "indeterminate" if value.nil? value >= max ? "complete" : "loading" end |