Skip to main content

Accordion

Struct Accordion 

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

A stack of sections, each a native <details> whose <summary> opens and closes it.

The browser handles the keyboard and announces each summary as a button that is expanded or collapsed, and the find-in-page search opens a closed section that holds a match. An exclusive accordion gives its sections one name, so the browser closes the open one when another opens.

use hypersig::Signals;
use hypersig::html::p;
use hypersig_ui::Accordion;
use serde::{Deserialize, Serialize};

#[derive(Signals, Serialize, Deserialize)]
struct Faq {}

let faq = Accordion::<Faq>::exclusive("faq")
    .item("Is it accessible?", p().text("It follows the WAI-ARIA patterns."))
    .item("Is it styled?", p().text("It looks like shadcn/ui."));
assert!(faq.render().render().contains(r#"name="faq""#));

Implementations§

Source§

impl<S> Accordion<S>

Source

pub fn new() -> Self

An accordion whose sections open and close independently.

Source

pub fn exclusive(name: &'static str) -> Self

An accordion that keeps at most one section open, grouped by name.

Sections with the same name close each other wherever they are on the page, as radio buttons with one name do, and nothing checks that each name is used once.

§Panics

Panics if name is empty or holds a character other than an ASCII letter, digit, -, or _.

Source

pub fn item(self, title: impl Into<String>, content: impl Into<Node<S>>) -> Self

Adds a section titled title whose content is content.

Source

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

The sections, in a <div>.

Trait Implementations§

Source§

impl<S: Debug> Debug for Accordion<S>

Source§

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

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

impl<S> Default for Accordion<S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<S> From<Accordion<S>> for El<S>

Source§

fn from(accordion: Accordion<S>) -> Self

Converts to this type from the input type.
Source§

impl<S> From<Accordion<S>> for Node<S>

Source§

fn from(accordion: Accordion<S>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<S> Freeze for Accordion<S>

§

impl<S> RefUnwindSafe for Accordion<S>

§

impl<S> Send for Accordion<S>

§

impl<S> Sync for Accordion<S>

§

impl<S> Unpin for Accordion<S>

§

impl<S> UnsafeUnpin for Accordion<S>

§

impl<S> UnwindSafe for Accordion<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.