patternfly_yew/components/
badge.rs

1//! Badge
2use yew::prelude::*;
3
4/// Properties for [`Badge`]
5#[derive(Clone, PartialEq, Properties)]
6pub struct BadgeProperties {
7    /// Optional Attributes
8    #[prop_or_default]
9    pub children: Html,
10    #[prop_or_default]
11    pub class: Classes,
12    #[prop_or_default]
13    pub read: bool,
14    #[prop_or_default]
15    pub screen_reader_text: AttrValue,
16}
17
18/// Badge component
19///
20/// > A **badge** is used to annotate other information like a label or an object name.
21///
22/// See: <https://www.patternfly.org/components/badge>
23///
24/// ## Properties
25///
26/// Defined by [`BadgeProperties`].
27#[function_component(Badge)]
28pub fn badge(props: &BadgeProperties) -> Html {
29    let mut class = classes!("pf-v5-c-badge");
30    if props.read {
31        class.push("pf-m-read");
32    } else {
33        class.push("pf-m-unread");
34    }
35    class.extend(props.class.clone());
36    html! {
37        <span {class}>
38            { props.children.clone() }
39            if !props.screen_reader_text.is_empty() {
40                <span class="pf-v5-u-screen-reader">{ props.screen_reader_text.clone() }</span>
41            }
42        </span>
43    }
44}