pub struct Token<T> { /* private fields */ }Expand description
A named value of type T, written as the custom property --<name>.
Token::var reads it as var(--<name>, <default>), so a page without a
Theme shows the default. A Theme sets it for the whole page, and
Style::token for one element and those inside it.
Two tokens with the same name are one custom property to the browser, and nothing checks that each name is used once.
use hypersig_style::value::{Color, px};
use hypersig_style::{Media, Style, Theme, Token};
let brand = Token::new("brand", Color::hex(0xb83f45));
let button = Style::new().background_color(brand.var()).padding(px(8));
let theme = Theme::new().on(Media::Dark, Theme::new().set(&brand, Color::hex(0xff6b6b)));
assert!(theme.to_css().contains("@media (prefers-color-scheme: dark){:root{--brand:#ff6b6b}}"));Implementations§
Source§impl<T: TokenValue> Token<T>
impl<T: TokenValue> Token<T>
Trait Implementations§
impl<T: PartialEq> StructuralPartialEq for Token<T>
Auto Trait Implementations§
impl<T> Freeze for Token<T>where
T: Freeze,
impl<T> RefUnwindSafe for Token<T>where
T: RefUnwindSafe,
impl<T> Send for Token<T>where
T: Send,
impl<T> Sync for Token<T>where
T: Sync,
impl<T> Unpin for Token<T>where
T: Unpin,
impl<T> UnsafeUnpin for Token<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Token<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more