dioxus_bootstrap_css/
placeholder.rs1use dioxus::prelude::*;
2
3use crate::types::{Color, Size};
4
5#[derive(Clone, PartialEq, Props)]
30pub struct PlaceholderProps {
31 #[props(default = 100)]
33 pub width: u8,
34 #[props(default)]
36 pub color: Option<Color>,
37 #[props(default)]
39 pub size: Size,
40 #[props(default)]
42 pub wave: bool,
43 #[props(default)]
45 pub glow: bool,
46 #[props(default = "span".to_string())]
48 pub tag: String,
49 #[props(default)]
51 pub class: String,
52}
53
54#[component]
55pub fn Placeholder(props: PlaceholderProps) -> Element {
56 let col = format!("col-{}", props.width.min(12));
57 let color_class = match &props.color {
58 Some(c) => format!(" bg-{c}"),
59 None => String::new(),
60 };
61 let size_class = match props.size {
62 Size::Sm => " placeholder-sm",
63 Size::Lg => " placeholder-lg",
64 Size::Md => "",
65 };
66
67 let full_class = if props.class.is_empty() {
68 format!("placeholder {col}{color_class}{size_class}")
69 } else {
70 format!("placeholder {col}{color_class}{size_class} {}", props.class)
71 };
72
73 let animation = if props.wave {
74 "placeholder-wave"
75 } else if props.glow {
76 "placeholder-glow"
77 } else {
78 ""
79 };
80
81 if animation.is_empty() {
82 rsx! {
83 span { class: "{full_class}", "aria-hidden": "true" }
84 }
85 } else {
86 rsx! {
87 p { class: "{animation}",
88 span { class: "{full_class}", "aria-hidden": "true" }
89 }
90 }
91 }
92}
93
94#[derive(Clone, PartialEq, Props)]
102pub struct PlaceholderParagraphProps {
103 #[props(default = 3)]
105 pub lines: usize,
106 #[props(default)]
108 pub wave: bool,
109 #[props(default)]
111 pub glow: bool,
112 #[props(default)]
114 pub class: String,
115}
116
117#[component]
118pub fn PlaceholderParagraph(props: PlaceholderParagraphProps) -> Element {
119 let animation = if props.wave {
120 " placeholder-wave"
121 } else if props.glow {
122 " placeholder-glow"
123 } else {
124 ""
125 };
126
127 let full_class = if props.class.is_empty() {
128 animation.trim().to_string()
129 } else {
130 format!("{} {}", animation.trim(), props.class)
131 };
132
133 let widths = [7, 9, 6, 8, 5, 10, 7, 4, 11, 6];
135
136 rsx! {
137 p { class: "{full_class}",
138 for i in 0..props.lines {
139 {
140 let w = widths[i % widths.len()];
141 let cls = format!("placeholder col-{w}");
142 rsx! {
143 span {
144 class: "{cls}",
145 "aria-hidden": "true",
146 }
147 " "
148 }
149 }
150 }
151 }
152 }
153}