yew_bootstrap/component/
lead.rs

1use yew::prelude::*;
2
3use crate::util::Color;
4
5/// # Lead component
6/// Use Lead to make a paragraph stand out.
7///
8/// See [LeadProps] for a listing of properties
9///
10/// ## Example
11/// ```rust
12/// use yew::prelude::*;
13/// use yew_bootstrap::component::Lead;
14/// fn test() -> Html {
15///     html!{
16///         <Lead>
17///             {"This is a lead paragraph. It stands out from regular paragraphs."}
18///         </Lead>
19///     }
20/// }
21/// ```
22pub struct Lead {}
23
24/// # Properties of [Lead]
25#[derive(Properties, Clone, PartialEq)]
26pub struct LeadProps {
27    /// CSS class
28    #[prop_or_default]
29    pub class: String,
30
31    /// Inner components
32    #[prop_or_default]
33    pub children: Children,
34
35    /// Color style, default [Color::Dark]
36    #[prop_or(Color::Dark)]
37    pub style: Color,
38
39    /// Optional text placed before the children
40    #[prop_or_default]
41    pub text: String,
42}
43
44impl Component for Lead {
45    type Message = ();
46    type Properties = LeadProps;
47
48    fn create(_ctx: &Context<Self>) -> Self {
49        Self {}
50    }
51
52    fn view(&self, ctx: &Context<Self>) -> Html {
53        let props = ctx.props();
54        let mut classes = Classes::new();
55        classes.push("lead");
56        classes.push(format!("text-{}", props.style));
57        classes.push(props.class.clone());
58
59        html! {
60            <p class={classes}>
61                { &props.text }
62                { for props.children.iter() }
63            </p>
64        }
65    }
66}