Skip to content

set active pagination on render #1408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pgml-dashboard/src/components/pagination/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub struct Pagination {
count: usize,
timed: bool,
identifier: u16,
active_index: Option<usize>,
clickable: bool,
}

impl Pagination {
Expand All @@ -15,13 +17,27 @@ impl Pagination {
count,
timed: false,
identifier: identifier,
active_index: None,
clickable: true,
}
}

pub fn timed(mut self) -> Self {
self.timed = true;
self
}

// When the user wantes to set the active index on render.
pub fn active_index(mut self, index: usize) -> Self {
self.active_index = Some(index);
self
}

// Prevents hover states.
pub fn not_clickable(mut self) -> Self {
self.clickable = false;
self
}
}

component!(Pagination);
30 changes: 28 additions & 2 deletions pgml-dashboard/src/components/pagination/pagination.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
div[data-controller="pagination"] {
$active-color: #00E0FF;

.pagination-container {
display: flex;
Expand All @@ -15,6 +16,26 @@ div[data-controller="pagination"] {
transition: width 0.25s;
}

.pagination-item-container-animation {
animation: IndicatorGrow 0.3s;
animation-fill-mode: forwards;

.pagination-item {
background-color: $active-color;
width: 100%;
}
}

.pagination-item-container-animation-reverse {
animation: IndicatorShrink 0.3s;
animation-fill-mode: forwards;

.pagination-item {
background-color: #{$gray-700};
width: 100%;
}
}

.pagination-item-container-clickable:not(.pagination-item-active) {
cursor: pointer;
&:hover {
Expand All @@ -26,14 +47,14 @@ div[data-controller="pagination"] {

.pagination-item-active {
.pagination-item {
background-color: #00E0FF;
background-color: $active-color;
width: 100%;
}
}

.pagination-item-timed-active {
.pagination-item {
background-color: #00E0FF;
background-color: $active-color;
animation: IndicatorGrow 4500ms;
animation-fill-mode: forwards;
}
Expand All @@ -44,6 +65,11 @@ div[data-controller="pagination"] {
100% {width: 4rem;}
}

@keyframes IndicatorShrink {
0% {width: 4rem;}
100% {width: 1rem;}
}

.pagination-item {
width: 1rem;
height: 1rem;
Expand Down
13 changes: 10 additions & 3 deletions pgml-dashboard/src/components/pagination/template.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%
let active_class = if timed { "pagination-item-timed-active" } else { "pagination-item-active" };
let clickable_class = if timed { "" } else { "pagination-item-container-clickable" };
let clickable_class = if timed || !clickable { "" } else { "pagination-item-container-clickable" };
%>

<div
Expand All @@ -11,8 +11,15 @@
>
<div class="pagination-container w-100 mt-4 pt-3">
<% if count > 1 {
for i in 0..count { %>
<div class="pagination-item-container <%- clickable_class %>" data-pagination-target="paginationItem">
for i in 0..count {
let make_active = match active_index {
Some(index) if i == index => "pagination-item-container-animation",
Some(index) if i + 1 == index => "pagination-item-container-animation-reverse",
Some(index) if i == count - 1 && index == 0 => "pagination-item-container-animation-reverse",
_ => ""
};
%>
<div class="pagination-item-container <%- clickable_class %> <%- make_active %>" data-pagination-target="paginationItem">
<div class="pagination-item" data-action="click->pagination#change" data-pagination-index-param="<%- i %>"></div>
</div>
<% }
Expand Down
17 changes: 17 additions & 0 deletions pgml-dashboard/templates/content/playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,28 @@
use crate::components::cards::marketing::Slider as SliderCard;
use crate::components::icons::Checkmark;
use crate::components::Slider;
use crate::components::pagination::Pagination;
%>

<div class="min-height: 100vh;" data-controller="playground">
<h1 class="h1">Playground</h1>
<p>This is a space to display components.</p>

<div style="margin-bottom: 14rem;">
<%+ Pagination::new(3, 1)
.active_index(0)
.not_clickable() %>

<%+ Pagination::new(3, 1)
.active_index(1)
.not_clickable() %>

<%+ Pagination::new(3, 1)
.active_index(2)
.not_clickable() %>

</div>

<h3 class="h3">icons</h3>
<div class="mb-5">
<%+ GithubIcon::new() %>
Expand Down Expand Up @@ -271,3 +287,4 @@ <h3 class="h3">Inputs</h3>
])
)%>
</div>

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy