An open API service indexing awesome lists of open source software.

https://github.com/simbleau/cssugar

A CSS library for Rust, focusing on ergnomic abstractions.
https://github.com/simbleau/cssugar

Last synced: 10 months ago
JSON representation

A CSS library for Rust, focusing on ergnomic abstractions.

Awesome Lists containing this project

README

          

# 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:
- https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units

# Examples

## Numbers, lengths, and percentages
[Read more](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units#numbers_lengths_and_percentages)
```rs
use cssugar::prelude::*;

#[function_component(SizedButton)]
pub fn sized_button() -> Html {
let size = Vw(100) - Px(300);
let button_css = format!("width: ${size};");
html! {
{ "CLICK ME!" }
}
}
```

Expected Output:
> `CLICK ME!`

## Colors
[Read more](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units#color)
```rs
use cssugar::prelude::*;

#[function_component(SizedButton)]
pub fn sized_button() -> Html {
let color = Color::rgb(255, 0, 0).blend(BLACK);
let label_css = format!("color: ${color};");
html! {
{ "I am dark red!" }
}
}
```
Expected Output:
> `I am dark red!`

## Images
[Read more](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units#images)
TODO

## Functions
[Read more](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units#functions)
```rs
use cssugar::prelude::*;

#[function_component(SizedButton)]
pub fn sized_button() -> Html {
let l1 = Length::Vw(100.);
let l2 = Length::Px(300.);
let size = l1.min(l2);
let button_css = format!("width: ${size};");
html! {
{ "CLICK ME!" }
}
}
```
Expected Output:
> `CLICK ME!`