tailwind_css/modules/accessibility/screen_reader/
mod.rs1use crate::{css_attributes, CssAttributes, TailwindBuilder, TailwindInstance};
2use std::fmt::{Display, Formatter};
3
4#[doc=include_str!("readme.md")]
5#[derive(Debug)]
6pub struct TailwindScreenReader {
7 sr_only: bool,
8}
9
10impl Display for TailwindScreenReader {
11 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
12 if !self.sr_only {
13 f.write_str("not-")?
14 }
15 f.write_str("sr-only")
16 }
17}
18
19impl TailwindInstance for TailwindScreenReader {
20 fn attributes(&self, _: &TailwindBuilder) -> CssAttributes {
21 match self.sr_only {
22 true => {
23 css_attributes! {
24 "position" => "absolute",
25 "width" => "1px",
26 "height" => "1px",
27 "padding" => "0",
28 "margin" => "-1px",
29 "overflow" => "hidden",
30 "clip" => "rect(0,0,0,0)",
31 "white-space" => "nowrap",
32 "border-width" => "0",
33
34 }
35 },
36 false => {
37 css_attributes! {
38 "position" => "static",
39 "width" => "auto",
40 "height" => "auto",
41 "padding" => "0",
42 "margin" => "0",
43 "overflow" => "visible",
44 "clip" => "auto",
45 "white-space" => "normal",
46
47 }
48 },
49 }
50 }
51}
52
53impl TailwindScreenReader {
54 #[inline]
56 pub fn new(sr_only: bool) -> Self {
57 Self { sr_only }
58 }
59}