tailwind_rs_core/utilities/grid/
gap.rs

1//! Grid gap utilities for tailwind-rs
2
3use crate::classes::ClassBuilder;
4use crate::utilities::spacing::SpacingValue;
5use serde::{Deserialize, Serialize};
6use std::fmt;
7
8/// Grid gap values
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
10pub enum GridGap {
11    /// Gap 0
12    Gap0,
13    /// Gap 1
14    Gap1,
15    /// Gap 2
16    Gap2,
17    /// Gap 3
18    Gap3,
19    /// Gap 4
20    Gap4,
21    /// Gap 5
22    Gap5,
23    /// Gap 6
24    Gap6,
25    /// Gap 8
26    Gap8,
27    /// Gap 10
28    Gap10,
29    /// Gap 12
30    Gap12,
31    /// Gap 16
32    Gap16,
33    /// Gap 20
34    Gap20,
35    /// Gap 24
36    Gap24,
37    /// Gap 32
38    Gap32,
39    /// Gap 40
40    Gap40,
41    /// Gap 48
42    Gap48,
43    /// Gap 56
44    Gap56,
45    /// Gap 64
46    Gap64,
47}
48
49impl fmt::Display for GridGap {
50    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51        match self {
52            GridGap::Gap0 => write!(f, "gap-0"),
53            GridGap::Gap1 => write!(f, "gap-1"),
54            GridGap::Gap2 => write!(f, "gap-2"),
55            GridGap::Gap3 => write!(f, "gap-3"),
56            GridGap::Gap4 => write!(f, "gap-4"),
57            GridGap::Gap5 => write!(f, "gap-5"),
58            GridGap::Gap6 => write!(f, "gap-6"),
59            GridGap::Gap8 => write!(f, "gap-8"),
60            GridGap::Gap10 => write!(f, "gap-10"),
61            GridGap::Gap12 => write!(f, "gap-12"),
62            GridGap::Gap16 => write!(f, "gap-16"),
63            GridGap::Gap20 => write!(f, "gap-20"),
64            GridGap::Gap24 => write!(f, "gap-24"),
65            GridGap::Gap32 => write!(f, "gap-32"),
66            GridGap::Gap40 => write!(f, "gap-40"),
67            GridGap::Gap48 => write!(f, "gap-48"),
68            GridGap::Gap56 => write!(f, "gap-56"),
69            GridGap::Gap64 => write!(f, "gap-64"),
70        }
71    }
72}
73
74/// Trait for adding grid gap utilities to a class builder
75pub trait GridGapUtilities {
76    fn grid_gap(self, gap: GridGap) -> Self;
77    fn gap(self, gap: SpacingValue) -> Self;
78}
79
80impl GridGapUtilities for ClassBuilder {
81    fn grid_gap(self, gap: GridGap) -> Self {
82        self.class(gap.to_string())
83    }
84
85    fn gap(self, gap: SpacingValue) -> Self {
86        self.class(format!("gap-{}", gap.to_class_name()))
87    }
88}
89
90#[cfg(test)]
91mod tests {
92    use super::*;
93
94    #[test]
95    fn test_grid_gap_display() {
96        assert_eq!(GridGap::Gap0.to_string(), "gap-0");
97        assert_eq!(GridGap::Gap1.to_string(), "gap-1");
98        assert_eq!(GridGap::Gap2.to_string(), "gap-2");
99        assert_eq!(GridGap::Gap4.to_string(), "gap-4");
100    }
101
102    #[test]
103    fn test_grid_gap_utilities() {
104        let classes = ClassBuilder::new().grid_gap(GridGap::Gap4).build();
105
106        assert!(classes.to_css_classes().contains("gap-4"));
107    }
108}