yewprint/
text.rs

1use yew::prelude::*;
2use yew::virtual_dom::AttrValue;
3
4#[derive(Clone, PartialEq, Properties)]
5pub struct TextProps {
6    #[prop_or_default]
7    pub ellipsize: bool,
8    #[prop_or_default]
9    pub children: Children,
10    #[prop_or_default]
11    pub class: Classes,
12    /// Wrap text in `span` instead of `div`.
13    #[prop_or_default]
14    pub inline: bool,
15    #[prop_or_default]
16    pub title: Option<AttrValue>,
17    #[prop_or_default]
18    pub style: Option<AttrValue>,
19}
20
21#[function_component(Text)]
22pub fn text(
23    TextProps {
24        ellipsize,
25        children,
26        class,
27        inline,
28        title,
29        style,
30    }: &TextProps,
31) -> Html {
32    html! {
33        <@{if *inline { "span" } else { "div"}}
34            class={classes!(
35                ellipsize.then_some("bp3-text-overflow-ellipsis"),
36                class.clone(),
37            )}
38            {style}
39            {title}
40        >
41            {children.clone()}
42        </@>
43    }
44}