cabin_tailwind/utilities/
to.rs

1//! Set the color stops in background gradients.
2
3use std::fmt;
4
5use crate::{Length, Property, Utility};
6
7pub struct ToColor(pub(crate) &'static str);
8
9include!(concat!(env!("OUT_DIR"), "/to-color.rs"));
10
11/// ```css
12/// --tw-gradient-to-position: {x}%;
13/// ```
14pub fn percent(x: i16) -> Property<Length> {
15    Property("--tw-gradient-to-position", Length::Percent(f32::from(x)))
16}
17
18/// ```css
19/// --tw-gradient-to-position: {x}%;
20/// ```
21pub fn percentf(x: f32) -> Property<Length> {
22    Property("--tw-gradient-to-position", Length::Percent(x))
23}
24
25impl Utility for ToColor {
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: {}FF var(--tw-gradient-to-position);",
31            self.0
32        )?;
33        Ok(())
34    }
35
36    fn order(&self) -> usize {
37        // Take precedence over from color.
38        1
39    }
40}