rustyle_css/
responsive.rs1pub mod breakpoints {
5 pub const MOBILE: &str = "";
7 pub const TABLET: &str = "(min-width: 768px)";
9 pub const DESKTOP: &str = "(min-width: 1024px)";
11 pub const LARGE: &str = "(min-width: 1280px)";
13 pub const XLARGE: &str = "(min-width: 1536px)";
15}
16
17pub struct MediaQuery {
19 condition: String,
20}
21
22impl MediaQuery {
23 pub fn new(condition: &str) -> Self {
25 Self {
26 condition: condition.to_string(),
27 }
28 }
29
30 pub fn condition(&self) -> &str {
32 &self.condition
33 }
34
35 pub fn min_width(width: &str) -> Self {
37 Self {
38 condition: format!("(min-width: {})", width),
39 }
40 }
41
42 pub fn max_width(width: &str) -> Self {
44 Self {
45 condition: format!("(max-width: {})", width),
46 }
47 }
48
49 pub fn min_height(height: &str) -> Self {
51 Self {
52 condition: format!("(min-height: {})", height),
53 }
54 }
55
56 pub fn max_height(height: &str) -> Self {
58 Self {
59 condition: format!("(max-height: {})", height),
60 }
61 }
62
63 pub fn and(self, other: Self) -> Self {
65 Self {
66 condition: format!("{} and {}", self.condition, other.condition),
67 }
68 }
69}
70
71pub fn responsive_style(mobile: &str, tablet: Option<&str>, desktop: Option<&str>) -> String {
73 let mut styles = vec![mobile.to_string()];
74
75 if let Some(t) = tablet {
76 styles.push(format!("@media {} {{ {} }}", breakpoints::TABLET, t));
77 }
78
79 if let Some(d) = desktop {
80 styles.push(format!("@media {} {{ {} }}", breakpoints::DESKTOP, d));
81 }
82
83 styles.join("\n")
84}