windjammer_ui/components/generated/
badge.rs1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5#[derive(Clone, Debug, PartialEq, Copy)]
6pub enum BadgeVariant {
7 Default,
8 Primary,
9 Success,
10 Warning,
11 Danger,
12 Error,
13 Info,
14}
15
16#[derive(Clone, Debug, PartialEq, Copy)]
17pub enum BadgeSize {
18 Small,
19 Medium,
20 Large,
21}
22
23#[derive(Debug, Clone, PartialEq)]
24pub struct Badge {
25 pub text: String,
26 pub variant: BadgeVariant,
27 pub size: BadgeSize,
28}
29
30impl Badge {
31 #[inline]
32 pub fn new(text: String) -> Badge {
33 Badge {
34 text,
35 variant: BadgeVariant::Default,
36 size: BadgeSize::Medium,
37 }
38 }
39 #[inline]
40 pub fn variant(mut self, variant: BadgeVariant) -> Badge {
41 self.variant = variant;
42 self
43 }
44 #[inline]
45 pub fn size(mut self, size: BadgeSize) -> Badge {
46 self.size = size;
47 self
48 }
49}
50
51impl Renderable for Badge {
52 #[inline]
53 fn render(self) -> String {
54 let variant_class = match self.variant {
55 BadgeVariant::Default => "wj-badge-default".to_string(),
56 BadgeVariant::Primary => "wj-badge-primary".to_string(),
57 BadgeVariant::Success => "wj-badge-success".to_string(),
58 BadgeVariant::Warning => "wj-badge-warning".to_string(),
59 BadgeVariant::Danger => "wj-badge-danger".to_string(),
60 BadgeVariant::Error => "wj-badge-danger".to_string(),
61 BadgeVariant::Info => "wj-badge-info".to_string(),
62 };
63 let size_class = match self.size {
64 BadgeSize::Small => "wj-badge-sm".to_string(),
65 BadgeSize::Medium => "wj-badge-md".to_string(),
66 BadgeSize::Large => "wj-badge-lg".to_string(),
67 };
68 format!(
69 "<span class='wj-badge {} {}'>{}</span>",
70 variant_class, size_class, self.text
71 )
72 }
73}