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" => "1.0",
33 "tight" => "1.25",
34 "snug" => "1.375",
35 "normal" => "1.5",
36 "relaxed" => "1.625",
37 "loose" => "2.0",
38 "default" => "normal",
40 _ => "1.5", }.to_string(),
42 _ => self.kind.get_properties_rem(),
44 };
45
46 css_attributes! {
47 "line-height" => line_height
48 }
49 }
50}
51
52impl TailwindLeading {
53 pub fn parse(pattern: &[&str], arbitrary: &TailwindArbitrary) -> Result<Self> {
55 Ok(Self {
56 kind: UnitValue::positive_parser(
57 "leading",
58 Self::check_valid,
59 true,
60 true,
61 false,
62 )(pattern, arbitrary)?,
63 })
64 }
65
66 pub fn check_valid(mode: &str) -> bool {
68 let set = BTreeSet::from_iter([
70 "none", "tight", "snug", "normal", "relaxed", "loose", "default",
71 ]);
72 set.contains(mode)
73 }
74}