Skip to main content

whisker_css/prop/
display.rs

1//! `display` and `direction` properties.
2
3use crate::css::Css;
4use crate::keyword::{Direction, Display};
5
6impl Css {
7    /// Sets `display`. Lynx default: `linear`.
8    /// <https://lynxjs.org/api/css/properties/display>
9    pub fn display(self, v: Display) -> Self {
10        self.push("display", v)
11    }
12
13    /// Sets `display: none` — element is removed from the layout tree.
14    pub fn display_none(self) -> Self {
15        self.push("display", Display::None)
16    }
17
18    /// Sets `display: flex` — opt into CSS flexbox.
19    pub fn display_flex(self) -> Self {
20        self.push("display", Display::Flex)
21    }
22
23    /// Sets `display: grid` — opt into CSS grid.
24    pub fn display_grid(self) -> Self {
25        self.push("display", Display::Grid)
26    }
27
28    /// Sets `display: linear` — Lynx default linear layout.
29    pub fn display_linear(self) -> Self {
30        self.push("display", Display::Linear)
31    }
32
33    /// Sets `display: relative` — Lynx relative-positioning container.
34    pub fn display_relative(self) -> Self {
35        self.push("display", Display::Relative)
36    }
37
38    /// Sets `direction`. Lynx default: `ltr`.
39    /// <https://lynxjs.org/api/css/properties/direction>
40    pub fn direction(self, v: Direction) -> Self {
41        self.push("direction", v)
42    }
43}
44
45#[cfg(test)]
46mod tests {
47    use crate::keyword::{Direction, Display};
48    use crate::Css;
49
50    #[test]
51    fn display_keyword() {
52        let s = Css::new().display(Display::Flex);
53        assert_eq!(s.to_string(), "display: flex;");
54    }
55
56    #[test]
57    fn display_shortcuts() {
58        assert_eq!(Css::new().display_none().to_string(), "display: none;");
59        assert_eq!(Css::new().display_flex().to_string(), "display: flex;");
60        assert_eq!(Css::new().display_grid().to_string(), "display: grid;");
61        assert_eq!(Css::new().display_linear().to_string(), "display: linear;");
62        assert_eq!(
63            Css::new().display_relative().to_string(),
64            "display: relative;"
65        );
66    }
67
68    #[test]
69    fn direction_keywords() {
70        assert_eq!(
71            Css::new().direction(Direction::Ltr).to_string(),
72            "direction: ltr;"
73        );
74        assert_eq!(
75            Css::new().direction(Direction::Rtl).to_string(),
76            "direction: rtl;"
77        );
78    }
79}