tailwind_rs_core/utilities/grid/
gap.rs1use crate::classes::ClassBuilder;
4use crate::utilities::spacing::SpacingValue;
5use serde::{Deserialize, Serialize};
6use std::fmt;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
10pub enum GridGap {
11 Gap0,
13 Gap1,
15 Gap2,
17 Gap3,
19 Gap4,
21 Gap5,
23 Gap6,
25 Gap8,
27 Gap10,
29 Gap12,
31 Gap16,
33 Gap20,
35 Gap24,
37 Gap32,
39 Gap40,
41 Gap48,
43 Gap56,
45 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
74pub 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()
105 .grid_gap(GridGap::Gap4)
106 .build();
107
108 assert!(classes.to_css_classes().contains("gap-4"));
109 }
110}