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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#[cfg(test)]
mod test;
use super::*;

#[doc = include_str!("screen-reader.md")]
#[derive(Debug)]
pub struct TailwindScreenReader {
    sr_only: bool,
}

impl Display for TailwindScreenReader {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        if !self.sr_only {
            f.write_str("not-")?
        }
        f.write_str("sr-only")
    }
}

impl TailwindInstance for TailwindScreenReader {
    fn attributes(&self, _: &TailwindBuilder) -> BTreeSet<CssAttribute> {
        match self.sr_only {
            true => {
                css_attributes! {
                    "position" => "absolute",
                    "width" => "1px",
                    "height" => "1px",
                    "padding" => "0",
                    "margin" => "-1px",
                    "overflow" => "hidden",
                    "clip" => "rect(0,0,0,0)",
                    "white-space" => "nowrap",
                    "border-width" => "0",
                }
            }
            false => {
                css_attributes! {
                    "position" => "static",
                    "width" => "auto",
                    "height" => "auto",
                    "padding" => "0",
                    "margin" => "0",
                    "overflow" => "visible",
                    "clip" => "auto",
                    "white-space" => "normal",
                }
            }
        }
    }
}

impl TailwindScreenReader {
    #[inline]
    pub fn new(sr_only: bool) -> Self {
        Self { sr_only }
    }
}