tailwind_css_fixes/modules/typography/leading/
mod.rs1use super::*;
2
3#[doc=include_str!("readme.md")]
4#[derive(Debug, Clone)]
5pub struct TailwindLeading {
6 kind: UnitValue,
7}
8
9impl<T> From<T> for TailwindLeading
11where
12 T: Into<UnitValue>,
13{
14 fn from(kind: T) -> Self {
15 Self { kind: kind.into() }
16 }
17}
18
19
20impl Display for TailwindLeading {
21 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
22 write!(f, "leading-{}", self.kind)
23 }
24}
25
26impl TailwindInstance for TailwindLeading {
27 fn attributes(&self, _: &TailwindBuilder) -> CssAttributes {
28 let line_height = match &self.kind {
30 UnitValue::Keyword(k) => match k.as_str() {
31 "none" => format!("{}rem", 1.0),
33 "tight" => format!("{}rem", 1.25),
34 "snug" => format!("{}rem", 1.375),
35 "relaxed" => format!("{}rem", 1.625),
36 "loose" => format!("{}rem", 2.0),
37 "normal" => "normal".to_string(),
39 _ => format!("{}rem", 1.5), },
41 _ => self.kind.get_properties_rem(),
43 };
44
45 css_attributes! {
46 "line-height" => line_height
47 }
48 }
49}
50
51impl TailwindLeading {
52 pub fn parse(pattern: &[&str], arbitrary: &TailwindArbitrary) -> Result<Self> {
54 Ok(Self {
55 kind: UnitValue::positive_parser(
56 "leading",
57 Self::check_valid,
58 true,
59 true,
60 false,
61 )(pattern, arbitrary)?,
62 })
63 }
64
65 pub fn check_valid(mode: &str) -> bool {
67 let set = BTreeSet::from_iter([
69 "none", "tight", "snug", "normal", "relaxed", "loose", "default",
70 ]);
71 set.contains(mode)
72 }
73}