cabin_tailwind/utilities/
via.rs

1//! Set the color stops in background gradients.
2
3use std::fmt;
4
5use crate::{Length, Property, Utility};
6
7pub struct ViaColor(pub(crate) &'static str);
8
9include!(concat!(env!("OUT_DIR"), "/via-color.rs"));
10
11/// ```css
12/// --tw-gradient-via-position: {x}%;
13/// ```
14pub fn percent(x: i16) -> Property<Length> {
15    Property("--tw-gradient-via-position", Length::Percent(f32::from(x)))
16}
17
18/// ```css
19/// --tw-gradient-via-position: {x}%;
20/// ```
21pub fn percentf(x: f32) -> Property<Length> {
22    Property("--tw-gradient-via-position", Length::Percent(x))
23}
24
25impl Utility for ViaColor {
26    fn declarations(&self, f: &mut dyn fmt::Write) -> fmt::Result {
27        // TODO: better handling of colors (handle non six digit hex inputs)
28        writeln!(
29            f,
30            "--tw-gradient-to: {}00 var(--tw-gradient-to-position);",
31            match self.0 {
32                "inherit" | "current" => "#FFFFFF",
33                "transparent" => "#000000",
34                color => color,
35            }
36        )?;
37        writeln!(
38            f,
39            "--tw-gradient-stops: var(--tw-gradient-from), inherit var(--tw-gradient-via-position), var(--tw-gradient-to);"
40        )?;
41        Ok(())
42    }
43}