File tree Expand file tree Collapse file tree 4 files changed +71
-5
lines changed Expand file tree Collapse file tree 4 files changed +71
-5
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ pub struct Pagination {
7
7
count : usize ,
8
8
timed : bool ,
9
9
identifier : u16 ,
10
+ active_index : Option < usize > ,
11
+ clickable : bool ,
10
12
}
11
13
12
14
impl Pagination {
@@ -15,13 +17,27 @@ impl Pagination {
15
17
count,
16
18
timed : false ,
17
19
identifier : identifier,
20
+ active_index : None ,
21
+ clickable : true ,
18
22
}
19
23
}
20
24
21
25
pub fn timed ( mut self ) -> Self {
22
26
self . timed = true ;
23
27
self
24
28
}
29
+
30
+ // When the user wantes to set the active index on render.
31
+ pub fn active_index ( mut self , index : usize ) -> Self {
32
+ self . active_index = Some ( index) ;
33
+ self
34
+ }
35
+
36
+ // Prevents hover states.
37
+ pub fn not_clickable ( mut self ) -> Self {
38
+ self . clickable = false ;
39
+ self
40
+ }
25
41
}
26
42
27
43
component ! ( Pagination ) ;
Original file line number Diff line number Diff line change 1
1
div [data-controller = " pagination" ] {
2
+ $active-color : #00E0FF ;
2
3
3
4
.pagination-container {
4
5
display : flex ;
@@ -15,6 +16,26 @@ div[data-controller="pagination"] {
15
16
transition : width 0.25s ;
16
17
}
17
18
19
+ .pagination-item-container-animation {
20
+ animation : IndicatorGrow 0.3s ;
21
+ animation-fill-mode : forwards ;
22
+
23
+ .pagination-item {
24
+ background-color : $active-color ;
25
+ width : 100% ;
26
+ }
27
+ }
28
+
29
+ .pagination-item-container-animation-reverse {
30
+ animation : IndicatorShrink 0.3s ;
31
+ animation-fill-mode : forwards ;
32
+
33
+ .pagination-item {
34
+ background-color : #{$gray-700 } ;
35
+ width : 100% ;
36
+ }
37
+ }
38
+
18
39
.pagination-item-container-clickable :not (.pagination-item-active ) {
19
40
cursor : pointer ;
20
41
& :hover {
@@ -26,14 +47,14 @@ div[data-controller="pagination"] {
26
47
27
48
.pagination-item-active {
28
49
.pagination-item {
29
- background-color : #00E0FF ;
50
+ background-color : $active-color ;
30
51
width : 100% ;
31
52
}
32
53
}
33
54
34
55
.pagination-item-timed-active {
35
56
.pagination-item {
36
- background-color : #00E0FF ;
57
+ background-color : $active-color ;
37
58
animation : IndicatorGrow 4500ms ;
38
59
animation-fill-mode : forwards ;
39
60
}
@@ -44,6 +65,11 @@ div[data-controller="pagination"] {
44
65
100% {width : 4rem ;}
45
66
}
46
67
68
+ @keyframes IndicatorShrink {
69
+ 0% {width : 4rem ;}
70
+ 100% {width : 1rem ;}
71
+ }
72
+
47
73
.pagination-item {
48
74
width : 1rem ;
49
75
height : 1rem ;
Original file line number Diff line number Diff line change 1
1
< %
2
2
let active_class = if timed { "pagination-item-timed-active" } else { "pagination-item-active" };
3
- let clickable_class = if timed { "" } else { "pagination-item-container-clickable" };
3
+ let clickable_class = if timed || !clickable { "" } else { "pagination-item-container-clickable" };
4
4
%>
5
5
6
6
< div
11
11
>
12
12
< div class ="pagination-container w-100 mt-4 pt-3 ">
13
13
< % if count > 1 {
14
- for i in 0..count { %>
15
- < div class ="pagination-item-container <%- clickable_class %> " data-pagination-target ="paginationItem ">
14
+ for i in 0..count {
15
+ let make_active = match active_index {
16
+ Some(index) if i == index => "pagination-item-container-animation",
17
+ Some(index) if i + 1 == index => "pagination-item-container-animation-reverse",
18
+ Some(index) if i == count - 1 && index == 0 => "pagination-item-container-animation-reverse",
19
+ _ => ""
20
+ };
21
+ %>
22
+ < div class ="pagination-item-container <%- clickable_class %> <%- make_active %> " data-pagination-target ="paginationItem ">
16
23
< div class ="pagination-item " data-action ="click->pagination#change " data-pagination-index-param ="<%- i %> "> </ div >
17
24
</ div >
18
25
< % }
Original file line number Diff line number Diff line change 11
11
use crate::components::cards::marketing::Slider as SliderCard;
12
12
use crate::components::icons::Checkmark;
13
13
use crate::components::Slider;
14
+ use crate::components::pagination::Pagination;
14
15
%>
15
16
16
17
< div class ="min-height: 100vh; " data-controller ="playground ">
17
18
< h1 class ="h1 "> Playground</ h1 >
18
19
< p > This is a space to display components.</ p >
19
20
21
+ < div style ="margin-bottom: 14rem; ">
22
+ < %+ Pagination::new(3, 1)
23
+ .active_index(0)
24
+ .not_clickable() %>
25
+
26
+ < %+ Pagination::new(3, 1)
27
+ .active_index(1)
28
+ .not_clickable() %>
29
+
30
+ < %+ Pagination::new(3, 1)
31
+ .active_index(2)
32
+ .not_clickable() %>
33
+
34
+ </ div >
35
+
20
36
< h3 class ="h3 "> icons</ h3 >
21
37
< div class ="mb-5 ">
22
38
< %+ GithubIcon::new() %>
@@ -271,3 +287,4 @@ <h3 class="h3">Inputs</h3>
271
287
])
272
288
)%>
273
289
</ div >
290
+
You can’t perform that action at this time.
0 commit comments