use super::*;
#[doc=include_str!("readme.md")]
#[derive(Debug, Clone)]
pub struct TailwindLeading {
kind: UnitValue,
}
impl<T> From<T> for TailwindLeading
where
T: Into<UnitValue>,
{
fn from(kind: T) -> Self {
Self { kind: kind.into() }
}
}
impl Display for TailwindLeading {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "leading-{}", self.kind)
}
}
impl TailwindInstance for TailwindLeading {
fn attributes(&self, _: &TailwindBuilder) -> CssAttributes {
let line_height = match &self.kind {
UnitValue::Keyword(k) => match k.as_str() {
"none" => "1.0",
"tight" => "1.25",
"snug" => "1.375",
"normal" => "1.5",
"relaxed" => "1.625",
"loose" => "2.0",
"default" => "normal",
_ => "1.5", }.to_string(),
_ => self.kind.get_properties_rem(),
};
css_attributes! {
"line-height" => line_height
}
}
}
impl TailwindLeading {
pub fn parse(pattern: &[&str], arbitrary: &TailwindArbitrary) -> Result<Self> {
Ok(Self {
kind: UnitValue::positive_parser(
"leading",
Self::check_valid,
true,
true,
false,
)(pattern, arbitrary)?,
})
}
pub fn check_valid(mode: &str) -> bool {
let set = BTreeSet::from_iter([
"none", "tight", "snug", "normal", "relaxed", "loose", "default",
]);
set.contains(mode)
}
}