CSSugar
A CSS values and units library for Rust, focusing on ergnomic abstractions.
Goal
The goal is to wrap all CSS values and units in an ergonomic, rusty way. This is primarily for ecosystem tooling built around Yew and Stylist.
Read more:
Examples
Numbers, lengths, and percentages
use cssugar::units::{Px, Vw};
#[function_component(SizedButton)]
pub fn sized_button() -> Html {
let size = Vw(100) - Px(300);
let button_css = format!("width: ${size};");
html! {
<button style={button_css}>{ "CLICK ME!" }</button>
}
}
Expected Output:
<button style="width: calc(100vw - 300px);">CLICK ME!</button>
Colors
use cssugar::colors::{Color, BLACK};
#[function_component(SizedButton)]
pub fn sized_button() -> Html {
let color = Color::rgb(255, 0, 0).blend(BLACK);
let label_css = format!("color: ${color};");
html! {
<label style={label_css}>{ "I am dark red!" }</label>
}
}
Expected Output:
<label style="color: rgba(128, 0, 0, 1.0);">I am dark red!</label>
Images
Read more TODO
Strings and Identifiers
Read more TODO
Functions
use cssugar::colors::{Color, BLACK};
#[function_component(SizedButton)]
pub fn sized_button() -> Html {
let color = Color::rgb(255, 0, 0).blend(BLACK);
let label_css = format!("color: ${color};");
html! {
<label style={label_css}>{ "I am dark red!" }</label>
}
}
Expected Output:
<label style="color: rgba(128, 0, 0, 1.0);">I am dark red!</label>