logo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::collections::BTreeMap;

mod traits;

#[derive(Clone, Debug, Default)]
pub struct BreakPointSystem {
    inner: BTreeMap<String, BreakPoint>,
}

impl BreakPointSystem {
    /// Builtin ranges
    /// https://tailwindcss.com/docs/screens
    pub fn builtin() -> Self {
        let mut new = Self::default();
        new.register("sm".to_string(), 640);
        new.register("md".to_string(), 768);
        new.register("lg".to_string(), 1024);
        new.register("xl".to_string(), 1280);
        new.register("2xl".to_string(), 1536);
        new
    }

    #[inline]
    pub fn register(&mut self, name: String, width: usize) -> Option<BreakPoint> {
        self.inner.insert(name, BreakPoint { width })
    }
}

#[derive(Clone, Debug)]
pub struct BreakPoint {
    /// min-width
    /// unit: px
    width: usize,
}