File Coverage

blib/lib/Moonshine/Bootstrap/Component/ProgressBar.pm
Criterion Covered Total %
statement 18 18 100.0
branch 4 4 100.0
condition 1 2 50.0
subroutine 3 3 100.0
pod n/a
total 26 27 96.3


line stmt bran cond sub pod time code
1             package Moonshine::Bootstrap::Component::ProgressBar;
2              
3 6     6   225204 use Moonshine::Magic;
  6         131084  
  6         49  
4              
5 6     6   3558 use Moonshine::Util;
  6         15  
  6         73  
6              
7             lazy_components qw/span/;
8              
9             extends 'Moonshine::Bootstrap::Component';
10              
11             has(
12             progress_bar_spec => sub {
13             {
14             tag => { default => 'div' },
15             class_base => { default => 'progress-bar' },
16             role => { default => 'progressbar' },
17             aria_valuenow => 1,
18             aria_valuemin => { default => "0" },
19             aria_valuemax => { default => 100 },
20             style => { default => ["min-width:3em;"] },
21             switch_base => { default => 'progress-bar-' },
22             striped => 0,
23             show => 0,
24             animated => 0,
25             };
26             }
27             );
28              
29             sub progress_bar {
30 28     28   77653 my ($self) = shift;
31              
32 28   50     190 my ( $base_args, $build_args ) = $self->validate_build(
33             {
34             params => $_[0] // {},
35             spec => $self->progress_bar_spec,
36             }
37             );
38              
39 28 100       221 if ( $build_args->{striped} ) {
40 7         34 $base_args->{class} = prepend_str('progress-bar-striped', $base_args->{class});
41             }
42              
43              
44 28         96 my $percent = $base_args->{aria_valuenow} . "%";
45              
46 28         41 push @{ $base_args->{style} }, sprintf 'width:%s;', $percent;
  28         101  
47              
48 28         139 my $base_element = Moonshine::Element->new($base_args);
49              
50 28 100       53633 if ( $build_args->{show} ) {
51 18         65 $base_element->data($percent);
52             }
53             else {
54 10         105 $base_element->add_child(
55             $self->span( { class => 'sr-only', data => $percent } )
56             );
57             }
58              
59 28         23069 return $base_element;
60             }
61              
62             1;
63              
64             __END__