-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make a component to the pagination buttons
- Loading branch information
1 parent
9c4d3d2
commit 385af89
Showing
3 changed files
with
79 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod blog_content; | ||
pub mod button_link; | ||
pub mod pagination_buttons; | ||
|
||
mod header; | ||
pub use header::*; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use crate::components::icons::StrToIcon; | ||
use leptos::{component, view, IntoAttribute, IntoView}; | ||
|
||
#[component] | ||
pub fn PaginationButtons( | ||
hide: bool, | ||
current_page: Option<usize>, | ||
max_page: usize, | ||
) -> impl IntoView { | ||
view! { | ||
<> | ||
|
||
{if hide { | ||
view! { <></> } | ||
} else { | ||
let page_number = current_page.unwrap_or(0); | ||
let hide_next_page_button = page_number >= max_page && max_page != 0; | ||
view! { | ||
<> | ||
<PreviousPageButton page=current_page/> | ||
<NextPageButton page=current_page hide=hide_next_page_button/> | ||
</> | ||
} | ||
}} | ||
</> | ||
} | ||
} | ||
|
||
#[component] | ||
pub fn PreviousPageButton(page: Option<usize>) -> impl IntoView { | ||
let page = page.unwrap_or(0); | ||
|
||
if page == 0 { | ||
return view! { <></> }; | ||
} | ||
|
||
let previous_page = if page == 1 { | ||
"..".to_string() | ||
} else { | ||
format!("../pages/{}.html", page - 1) | ||
}; | ||
|
||
view! { | ||
<> | ||
<a | ||
href=previous_page | ||
class="bg-orange-500 hover:bg-orange-600 text-white font-semibold py-2 px-4 rounded flex items-center justify-between gap-2" | ||
> | ||
<StrToIcon v="next" class="fill-white rotate-180" size=16/> | ||
"Pagina anterior" | ||
</a> | ||
</> | ||
} | ||
} | ||
|
||
#[component] | ||
pub fn NextPageButton(page: Option<usize>, hide: bool) -> impl IntoView { | ||
if hide { | ||
return view! { <></> }; | ||
} | ||
|
||
let page = page.unwrap_or(0); | ||
|
||
view! { | ||
<> | ||
<a | ||
href=format!("../pages/{}.html", page + 1) | ||
class="bg-orange-500 hover:bg-orange-600 text-white font-semibold py-2 px-4 rounded flex items-center justify-between gap-2" | ||
> | ||
"Siguiente pagina" | ||
<StrToIcon v="next" class="fill-white" size=16/> | ||
</a> | ||
</> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters