leptos_css/typography.rs
1use std::fmt;
2
3use crate::checked_value::impl_checked_value;
4use crate::serialization::CssWriteTo;
5
6/// CSS font-weight values.
7///
8/// Represents the `font-weight` CSS property as a typed enum rather than a raw string.
9/// Numeric weights range from 100 (thinnest) to 900 (boldest), with keyword aliases
10/// for common values.
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12#[non_exhaustive]
13pub enum FontWeight {
14 /// Weight 100 — Thin / Hairline.
15 W100,
16 /// Weight 200 — Extra Light / Ultra Light.
17 W200,
18 /// Weight 300 — Light.
19 W300,
20 /// Weight 400 — Normal / Regular (same as `WNormal`).
21 W400,
22 /// Weight 500 — Medium.
23 W500,
24 /// Weight 600 — Semi Bold / Demi Bold.
25 W600,
26 /// Weight 700 — Bold (same as `WBold`).
27 W700,
28 /// Weight 800 — Extra Bold / Ultra Bold.
29 W800,
30 /// Weight 900 — Black / Heavy.
31 W900,
32 /// Keyword `lighter` — one relative step lighter than the inherited weight.
33 WLighter,
34 /// Keyword `normal` — equivalent to weight 400.
35 WNormal,
36 /// Keyword `bold` — equivalent to weight 700.
37 WBold,
38 /// Keyword `bolder` — one relative step bolder than the inherited weight.
39 WBolder,
40}
41
42impl CssWriteTo for FontWeight {
43 fn css_fmt<W: fmt::Write>(&self, w: &mut W) -> fmt::Result {
44 match self {
45 Self::W100 => w.write_str("100"),
46 Self::W200 => w.write_str("200"),
47 Self::W300 => w.write_str("300"),
48 Self::W400 => w.write_str("400"),
49 Self::W500 => w.write_str("500"),
50 Self::W600 => w.write_str("600"),
51 Self::W700 => w.write_str("700"),
52 Self::W800 => w.write_str("800"),
53 Self::W900 => w.write_str("900"),
54 Self::WLighter => w.write_str("lighter"),
55 Self::WNormal => w.write_str("normal"),
56 Self::WBold => w.write_str("bold"),
57 Self::WBolder => w.write_str("bolder"),
58 }
59 }
60}
61
62impl_checked_value!(FontWeight);