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
use crate::*; /// A badge component for displaying status indicators. /// /// # Arguments /// /// - `VirtualNode`: The props node containing color, text, and on_click. /// /// # Returns /// /// - `VirtualNode`: A styled span badge element. pub fn my_badge(props: VirtualNode) -> VirtualNode { let color: String = props .try_get_prop(&Attribute::Other("color".to_string())) .unwrap_or_else(|| "#4f46e5".to_string()); let text_prop: String = props .try_get_prop(&Attribute::Other("text".to_string())) .unwrap_or_default(); let on_click: Option<NativeEventHandler> = props.try_get_callback("on_click"); rsx! { span { class: c_badge() style: {background: {color};} onclick: on_click text_prop } } }