Convert DashboardRow to component
This commit is contained in:
parent
ae8a3d0ade
commit
4fe76fe596
@ -2,26 +2,15 @@ use leptos::html::Ul;
|
||||
use leptos::leptos_dom::*;
|
||||
use leptos::*;
|
||||
use leptos_use::{use_element_size, UseElementSizeReturn, use_scroll, UseScrollReturn};
|
||||
use crate::components::dashboard_tile::DashboardTile;
|
||||
use crate::components::dashboard_tile::*;
|
||||
use leptos_icons::*;
|
||||
|
||||
/// A row of dashboard tiles, with a title
|
||||
pub struct DashboardRow {
|
||||
pub title: String,
|
||||
pub tiles: Vec<Box<dyn DashboardTile>>,
|
||||
}
|
||||
|
||||
impl DashboardRow {
|
||||
pub fn new(title: String, tiles: Vec<Box<dyn DashboardTile>>) -> Self {
|
||||
Self {
|
||||
title,
|
||||
tiles,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoView for DashboardRow {
|
||||
fn into_view(self) -> View {
|
||||
#[component]
|
||||
pub fn DashboardRow(
|
||||
#[prop(into)] title: TextProp,
|
||||
/*#[prop(default=vec![])]*/ tiles: Vec<DashboardTile>,
|
||||
) -> impl IntoView {
|
||||
let list_ref = create_node_ref::<Ul>();
|
||||
|
||||
// Scroll functions attempt to align the left edge of the scroll area with the left edge of a tile
|
||||
@ -93,7 +82,7 @@ impl IntoView for DashboardRow {
|
||||
view! {
|
||||
<div class="dashboard-tile-row">
|
||||
<div class="dashboard-tile-row-title-row">
|
||||
<h2>{self.title}</h2>
|
||||
<h2>{title}</h2>
|
||||
<div class="dashboard-tile-row-scroll-btn">
|
||||
<button on:click=scroll_left tabindex=-1 style=scroll_left_hidden>
|
||||
<Icon class="dashboard-tile-row-scroll" icon=icondata::FiChevronLeft />
|
||||
@ -104,15 +93,22 @@ impl IntoView for DashboardRow {
|
||||
</div>
|
||||
</div>
|
||||
<ul _ref={list_ref}>
|
||||
{self.tiles.into_iter().map(|tile_info| {
|
||||
{tiles.into_iter().map(|tile| {
|
||||
view! {
|
||||
<li>
|
||||
{ tile_info.into_view() }
|
||||
<div class="dashboard-tile">
|
||||
<a href={tile.link}>
|
||||
<img src={tile.image_path} alt="dashboard-tile" />
|
||||
<p class="dashboard-tile-title">{tile.title}</p>
|
||||
<p class="dashboard-tile-description">
|
||||
{tile.description}
|
||||
</p>
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
}
|
||||
}).collect::<Vec<_>>()}
|
||||
</ul>
|
||||
</div>
|
||||
}.into_view()
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,13 @@
|
||||
use leptos::leptos_dom::*;
|
||||
use leptos::*;
|
||||
|
||||
pub trait DashboardTile {
|
||||
fn image_path(&self) -> String;
|
||||
fn title(&self) -> String;
|
||||
fn link(&self) -> String;
|
||||
fn description(&self) -> Option<String> { None }
|
||||
}
|
||||
|
||||
impl IntoView for &dyn DashboardTile {
|
||||
fn into_view(self) -> View {
|
||||
let link = self.link();
|
||||
|
||||
view! {
|
||||
<div class="dashboard-tile">
|
||||
<a href={link}>
|
||||
<img src={self.image_path()} alt="dashboard-tile" />
|
||||
<p class="dashboard-tile-title">{self.title()}</p>
|
||||
<p class="dashboard-tile-description">
|
||||
{self.description().unwrap_or_default()}
|
||||
</p>
|
||||
</a>
|
||||
</div>
|
||||
}.into_view()
|
||||
}
|
||||
#[slot]
|
||||
pub struct DashboardTile {
|
||||
#[prop(into)]
|
||||
image_path: TextProp,
|
||||
#[prop(into)]
|
||||
title: TextProp,
|
||||
#[prop(into)]
|
||||
link: TextProp,
|
||||
#[prop(into, optional)]
|
||||
description: Option<TextProp>,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user