windjammer_ui/components/generated/
text.rs1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5#[derive(Clone, Debug, PartialEq, Copy)]
6pub enum TextSize {
7 Small,
8 Medium,
9 Large,
10 XLarge,
11}
12
13#[derive(Clone, Debug, PartialEq, Copy)]
14pub enum TextWeight {
15 Normal,
16 Bold,
17}
18
19#[derive(Debug, Clone, PartialEq)]
20pub struct Text {
21 pub content: String,
22 pub size: TextSize,
23 pub weight: TextWeight,
24 pub color: String,
25}
26
27impl Text {
28 #[inline]
29 pub fn new(content: String) -> Text {
30 Text {
31 content,
32 size: TextSize::Medium,
33 weight: TextWeight::Normal,
34 color: "".to_string(),
35 }
36 }
37 #[inline]
38 pub fn size(mut self, size: TextSize) -> Text {
39 self.size = size;
40 self
41 }
42 #[inline]
43 pub fn bold(mut self) -> Text {
44 self.weight = TextWeight::Bold;
45 self
46 }
47 #[inline]
48 pub fn color(mut self, color: String) -> Text {
49 self.color = color;
50 self
51 }
52}
53
54impl Renderable for Text {
55 #[inline]
56 fn render(self) -> String {
57 let size_class = match self.size {
58 TextSize::Small => "sm".to_string(),
59 TextSize::Medium => "md".to_string(),
60 TextSize::Large => "lg".to_string(),
61 TextSize::XLarge => "xl".to_string(),
62 };
63 let weight_class = match self.weight {
64 TextWeight::Normal => "normal".to_string(),
65 TextWeight::Bold => "bold".to_string(),
66 };
67 let style = {
68 if self.color != "" {
69 format!(" style='color: {};'", self.color)
70 } else {
71 "".to_string()
72 }
73 };
74 format!(
75 "<span class='wj-text {} {}'{}>{}</span>",
76 size_class, weight_class, style, self.content
77 )
78 }
79}