tailwind_css/modules/typography/text/text_overflow/
mod.rs1use super::*;
2
3#[doc=include_str!("readme.md")]
4#[derive(Debug, Clone)]
5pub struct TailwindTextOverflow {
6 kind: TextOverflow,
7}
8
9#[derive(Debug, Clone)]
10enum TextOverflow {
11 Truncate,
12 Standard(String),
13 Arbitrary(TailwindArbitrary),
14}
15
16impl Display for TailwindTextOverflow {
17 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
18 match &self.kind {
19 TextOverflow::Truncate => write!(f, "truncate"),
20 TextOverflow::Standard(s) => write!(f, "font-overflow-{}", s),
21 TextOverflow::Arbitrary(s) => write!(f, "font-overflow-{}", s.get_class()),
22 }
23 }
24}
25
26impl TailwindInstance for TailwindTextOverflow {
27 fn attributes(&self, _: &TailwindBuilder) -> CssAttributes {
28 let align = match &self.kind {
29 TextOverflow::Truncate =>
30 return css_attributes! {
31 "overflow" => "hidden",
32 "text-overflow" => "ellipsis",
33 "white-space" => "nowrap",
34 },
35 TextOverflow::Standard(s) => s.to_string(),
36 TextOverflow::Arbitrary(s) => s.get_properties(),
37 };
38 css_attributes! {
39 "text-overflow" => align
40 }
41 }
42}
43
44impl TailwindTextOverflow {
45 pub const Truncate: Self = Self { kind: TextOverflow::Truncate };
47 pub fn parse(pattern: &[&str], arbitrary: &TailwindArbitrary) -> Result<Self> {
49 let kind = match pattern {
50 [] => TextOverflow::Arbitrary(arbitrary.to_owned()),
51 _ => {
52 let input = pattern.join("-");
53 debug_assert!(Self::check_valid(&input));
54 TextOverflow::Standard(input)
55 },
56 };
57 Ok(Self { kind })
58 }
59 pub fn check_valid(mode: &str) -> bool {
61 let set = BTreeSet::from_iter(vec!["clip", "ellipsis", "inherit", "initial", "revert", "unset"]);
62 set.contains(mode)
63 }
64}