File Coverage

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


line stmt bran cond sub pod time code
1             package Moonshine::Bootstrap::Component::Dropdown;
2              
3 7     7   213837 use Moonshine::Magic;
  7         118321  
  7         60  
4 7     7   4351 use Params::Validate qw/HASHREF SCALAR/;
  7         17  
  7         650  
5 7     7   72 use Moonshine::Util;
  7         18  
  7         93  
6              
7             extends(
8             'Moonshine::Bootstrap::Component',
9             'Moonshine::Bootstrap::Component::DropdownButton',
10             'Moonshine::Bootstrap::Component::DropdownUl',
11             );
12              
13             has(
14             dropdown_spec => sub {
15             {
16             tag => { default => 'div' },
17             dropup => 0,
18             button => { type => HASHREF },
19             ul => { type => HASHREF },
20             mid => { type => SCALAR },
21             };
22             }
23             );
24              
25             sub dropdown {
26 9     9   157955 my ($self) = shift;
27              
28 9   50     83 my ( $base_args, $build_args ) = $self->validate_build(
29             {
30             params => $_[0] // {},
31             spec => $self->dropdown_spec,
32             }
33             );
34              
35 9 100       108 my $drop_class = $build_args->{dropup} ? 'dropup' : 'dropdown';
36 9         340 $base_args->{class} = append_str( $drop_class, $base_args->{class} );
37              
38 9         128 my $base_element = Moonshine::Element->new($base_args);
39              
40             $base_element->add_child(
41             $self->dropdown_button(
42 9         125 { %{ $build_args->{button} }, id => $build_args->{mid} }
43             )
44 9         23948 );
45              
46             $base_element->add_child(
47             $self->dropdown_ul(
48             {
49 9         183 %{ $build_args->{ul} }, aria_labelledby => $build_args->{mid}
50             }
51             )
52 9         247 );
53              
54 9         474 return $base_element;
55             }
56              
57             1;
58              
59             __END__