cabin_tailwind/utilities/
from.rs1use std::fmt;
4
5use crate::{Length, Property, Utility};
6
7pub struct FromColor(pub(crate) &'static str);
8
9include!(concat!(env!("OUT_DIR"), "/from-color.rs"));
10
11pub fn percent(x: i16) -> Property<Length> {
15 Property("--tw-gradient-from-position", Length::Percent(f32::from(x)))
16}
17
18pub fn percentf(x: f32) -> Property<Length> {
22 Property("--tw-gradient-from-position", Length::Percent(x))
23}
24
25impl Utility for FromColor {
26 fn declarations(&self, f: &mut dyn fmt::Write) -> fmt::Result {
27 writeln!(
28 f,
29 "--tw-gradient-from: {} var(--tw-gradient-from-position);",
30 self.0
31 )?;
32 writeln!(
34 f,
35 "--tw-gradient-to: {}00 var(--tw-gradient-to-position);",
36 match self.0 {
37 "inherit" | "current" => "#FFFFFF",
38 "transparent" => "#000000",
39 color => color,
40 }
41 )?;
42 writeln!(
43 f,
44 "--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to);"
45 )?;
46 Ok(())
47 }
48}