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
use crate::{css_attributes, CssAttribute, TailwindBuilder, TailwindInstance};
use std::{
    collections::BTreeSet,
    fmt::{Display, Formatter},
};

#[derive(Copy, Clone, Debug)]
enum BackgroundSize {
    Auto,
    Cover,
    Contain,
}

#[doc = include_str!("readme.md")]
#[derive(Copy, Clone, Debug)]
pub struct TailwindBackgroundSize {
    kind: BackgroundSize,
}

impl Display for BackgroundSize {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Auto => write!(f, "auto"),
            Self::Cover => write!(f, "cover"),
            Self::Contain => write!(f, "contain"),
        }
    }
}

impl Display for TailwindBackgroundSize {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "bg-{}", self.kind)
    }
}

impl TailwindInstance for TailwindBackgroundSize {
    fn attributes(&self, _: &TailwindBuilder) -> BTreeSet<CssAttribute> {
        css_attributes! {
            "background-size" => self.kind
        }
    }
}

impl TailwindBackgroundSize {
    /// `bg-auto`
    pub const Auto: Self = Self { kind: BackgroundSize::Auto };
    /// `bg-cover`
    pub const Cover: Self = Self { kind: BackgroundSize::Cover };
    /// `bg-contain`
    pub const Contain: Self = Self { kind: BackgroundSize::Contain };
}