Skip to main content

NavList

Struct NavList 

Source
pub struct NavList<S> { /* private fields */ }
Expand description

A list of links to the sections of an application, marking the one the page is in.

It is a <nav> named by its label, holding a list of links. The page passes its own Url, which the server writes with Route::url, and each link is compared with it by path, without the query string. A link to the page’s path has aria-current="page". A link to a path that the page’s path continues, such as /users on the page /users/7, has aria-current="true", so the section stays marked on the pages under it.

use hypersig::{Page, Route, Signals};
use hypersig_ui::NavList;
use serde::{Deserialize, Serialize};

#[derive(Signals, Serialize, Deserialize)]
struct Admin {
    name: String,
}

hypersig::routes! {
    fn pages(Router<()>);
    const HOME: Route = "/" => page;
    const USERS: Route = "/users" => page;
    const USER: Route<i32> = "/users/{id}" => page;
}

let sidebar = NavList::<Admin>::new("Main", USER.url(7))
    .item("Dashboard", HOME, ())
    .item("Users", USERS, ())
    .render();
let html = sidebar.render();
assert!(html.contains(r#"href="/users" aria-current="true""#));

Implementations§

Source§

impl<S> NavList<S>

Source

pub fn new(label: impl Into<String>, current: Url) -> Self

An empty list whose <nav> is named label, on the page at current.

Source

pub fn item<P: Params, Q: Search>( self, text: impl Into<String>, route: Route<P, Q>, args: Q::Args<P>, ) -> Self
where Q::Args<P>: Serialize,

Adds a link to route with the arguments args, as Route::url takes them.

Source

pub fn render(self) -> El<S>

The <nav> and its list.

Trait Implementations§

Source§

impl<S: Debug> Debug for NavList<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S> From<NavList<S>> for El<S>

Source§

fn from(list: NavList<S>) -> Self

Converts to this type from the input type.
Source§

impl<S> From<NavList<S>> for Node<S>

Source§

fn from(list: NavList<S>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<S> Freeze for NavList<S>

§

impl<S> RefUnwindSafe for NavList<S>

§

impl<S> Send for NavList<S>

§

impl<S> Sync for NavList<S>

§

impl<S> Unpin for NavList<S>

§

impl<S> UnsafeUnpin for NavList<S>

§

impl<S> UnwindSafe for NavList<S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.