File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed
Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ module RubyUI
4+ class Progress < Base
5+ def initialize ( value : 0 , **attrs )
6+ @value = value . to_f . clamp ( 0 , 100 )
7+
8+ super ( **attrs )
9+ end
10+
11+ def view_template
12+ div ( **attrs ) do
13+ div ( **indicator_attrs )
14+ end
15+ end
16+
17+ private
18+
19+ def default_attrs
20+ {
21+ role : "progressbar" ,
22+ aria_valuenow : @value ,
23+ aria_valuemin : 0 ,
24+ aria_valuemax : 100 ,
25+ aria_valuetext : "#{ @value } %" ,
26+ class : "relative h-2 overflow-hidden rounded-full bg-primary/20 [&>*]:bg-primary"
27+ }
28+ end
29+
30+ def indicator_attrs
31+ {
32+ class : "h-full w-full flex-1" ,
33+ style : "transform: translateX(-#{ 100 - @value } %)"
34+ }
35+ end
36+ end
37+ end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require "test_helper"
4+
5+ class RubyUI ::ProgressTest < ComponentTest
6+ def test_render
7+ output = phlex do
8+ RubyUI ::Progress ( value : 50 )
9+ end
10+
11+ assert_match ( /aria-valuemin="0"/ , output )
12+ assert_match ( /aria-valuemax="100"/ , output )
13+ assert_match ( /aria-valuenow="50.0"/ , output )
14+ assert_match ( /aria-valuetext="50.0%"/ , output )
15+ assert_match ( /translateX\( -50.0%\) / , output )
16+ end
17+ end
You can’t perform that action at this time.
0 commit comments