From f9247b85208c45a9568989d5f8e0353b5b2d55b1 Mon Sep 17 00:00:00 2001 From: Dan <39170265+chillenberger@users.noreply.github.com> Date: Mon, 15 Apr 2024 16:09:54 -0600 Subject: [PATCH] allow user to set active pagination on render with animation --- .../src/components/pagination/mod.rs | 16 ++++++++++ .../src/components/pagination/pagination.scss | 30 +++++++++++++++++-- .../src/components/pagination/template.html | 13 ++++++-- .../templates/content/playground.html | 17 +++++++++++ 4 files changed, 71 insertions(+), 5 deletions(-) diff --git a/pgml-dashboard/src/components/pagination/mod.rs b/pgml-dashboard/src/components/pagination/mod.rs index 2b69a7b70..f82d3568a 100644 --- a/pgml-dashboard/src/components/pagination/mod.rs +++ b/pgml-dashboard/src/components/pagination/mod.rs @@ -7,6 +7,8 @@ pub struct Pagination { count: usize, timed: bool, identifier: u16, + active_index: Option, + clickable: bool, } impl Pagination { @@ -15,6 +17,8 @@ impl Pagination { count, timed: false, identifier: identifier, + active_index: None, + clickable: true, } } @@ -22,6 +26,18 @@ impl Pagination { 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); diff --git a/pgml-dashboard/src/components/pagination/pagination.scss b/pgml-dashboard/src/components/pagination/pagination.scss index 5382ca4e5..8e8afc88b 100644 --- a/pgml-dashboard/src/components/pagination/pagination.scss +++ b/pgml-dashboard/src/components/pagination/pagination.scss @@ -1,4 +1,5 @@ div[data-controller="pagination"] { + $active-color: #00E0FF; .pagination-container { display: flex; @@ -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 { @@ -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; } @@ -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; diff --git a/pgml-dashboard/src/components/pagination/template.html b/pgml-dashboard/src/components/pagination/template.html index cc5d3be88..6fa15a815 100644 --- a/pgml-dashboard/src/components/pagination/template.html +++ b/pgml-dashboard/src/components/pagination/template.html @@ -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" }; %>
<% if count > 1 { - for i in 0..count { %> -
+ 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", + _ => "" + }; + %> +
<% } diff --git a/pgml-dashboard/templates/content/playground.html b/pgml-dashboard/templates/content/playground.html index 9267702df..144d4130b 100644 --- a/pgml-dashboard/templates/content/playground.html +++ b/pgml-dashboard/templates/content/playground.html @@ -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; %>

Playground

This is a space to display components.

+
+ <%+ 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() %> + +
+

icons

<%+ GithubIcon::new() %> @@ -271,3 +287,4 @@

Inputs

]) )%>
+ 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