Skip to main content

ToggleGroup

Struct ToggleGroup 

Source
pub struct ToggleGroup<S, T> { /* private fields */ }
Expand description

A group of toggles named label that picks one value of selected.

It follows the WAI-ARIA radio group pattern, since exactly one toggle is on at a time. The group has role="radiogroup" and each toggle role="radio" with aria-checked. Tab enters the group at the toggle whose value selected holds, and the arrow keys, Home, and End move between toggles and pick the one they reach, through El::roving_focus. While selected holds a value no toggle has, Tab skips the group.

use hypersig::Signals;
use hypersig_ui::ToggleGroup;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Copy, PartialEq)]
enum Align {
    Left,
    Center,
    Right,
}

#[derive(Signals, Serialize, Deserialize)]
struct Text {
    align: Align,
}

let align = ToggleGroup::new("Alignment", Text::align())
    .item(Align::Left, "Left")
    .item(Align::Center, "Center")
    .item(Align::Right, "Right");
let html = align.render().render();
assert!(html.contains(r#"role="radiogroup""#));
assert!(html.contains(r#"role="radio""#));

Implementations§

Source§

impl<S, T: Serialize + PartialEq> ToggleGroup<S, T>

Source

pub fn new(label: impl Into<String>, selected: Sig<S, T>) -> Self

An empty group named label for assistive technology.

Source

pub fn item(self, value: T, text: impl Into<String>) -> Self

Adds a toggle showing text that picks value.

Source

pub fn icon_item( self, value: T, label: impl Into<String>, icon: impl Into<Node<S>>, ) -> Self

Adds a toggle showing icon that picks value, named label.

Source

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

The toggles in a <div>.

Trait Implementations§

Source§

impl<S: Debug, T: Debug> Debug for ToggleGroup<S, T>

Source§

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

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

impl<S, T: Serialize + PartialEq> From<ToggleGroup<S, T>> for El<S>

Source§

fn from(group: ToggleGroup<S, T>) -> Self

Converts to this type from the input type.
Source§

impl<S, T: Serialize + PartialEq> From<ToggleGroup<S, T>> for Node<S>

Source§

fn from(group: ToggleGroup<S, T>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<S, T> Freeze for ToggleGroup<S, T>

§

impl<S, T> RefUnwindSafe for ToggleGroup<S, T>
where T: RefUnwindSafe,

§

impl<S, T> Send for ToggleGroup<S, T>
where T: Send,

§

impl<S, T> Sync for ToggleGroup<S, T>
where T: Sync,

§

impl<S, T> Unpin for ToggleGroup<S, T>
where T: Unpin,

§

impl<S, T> UnsafeUnpin for ToggleGroup<S, T>

§

impl<S, T> UnwindSafe for ToggleGroup<S, T>
where T: UnwindSafe,

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.

§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<S, N> IntoNode<S> for N
where N: Into<Node<S>>,

Source§

fn into_node(self) -> Node<S>

Converts self into a node.
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more