tailwind_css_fixes/systems/breakpoints/
mod.rs

1use std::collections::BTreeMap;
2
3mod traits;
4
5#[derive(Clone, Debug, Default)]
6pub struct BreakPointSystem {
7    inner: BTreeMap<String, BreakPoint>,
8}
9
10impl BreakPointSystem {
11    /// Builtin ranges
12    /// https://tailwindcss.com/docs/screens
13    pub fn builtin() -> Self {
14        let mut new = Self::default();
15        new.register("sm".to_string(), 640);
16        new.register("md".to_string(), 768);
17        new.register("lg".to_string(), 1024);
18        new.register("xl".to_string(), 1280);
19        new.register("2xl".to_string(), 1536);
20        new
21    }
22
23    pub fn try_get_width(&self, name: &str) -> Result<usize, String> {
24        match self.inner.get(name) {
25            Some(bp) => Ok(bp.width),
26            None => Err(format!("no such breakpoint: {}", name)),
27        }
28    }
29
30    #[inline]
31    pub fn register(&mut self, name: String, width: usize) -> Option<BreakPoint> {
32        self.inner.insert(name, BreakPoint { width })
33    }
34}
35
36#[derive(Clone, Debug)]
37pub struct BreakPoint {
38    /// min-width
39    /// unit: px
40    width: usize,
41}