design_system/atoms/tooltip/
tooltip.rs

1use css_in_rust::Style;
2use yew::prelude::*;
3
4#[derive(Debug)]
5pub struct Tooltip {
6    link: ComponentLink<Self>,
7    style: Style,
8    props: Props,
9}
10
11#[derive(Debug)]
12pub enum Msg {}
13
14#[derive(Clone, PartialEq, Properties, Debug)]
15pub struct Props {
16    #[prop_or_default]
17    pub children: Children,
18    #[prop_or_default]
19    pub class: String,
20    #[prop_or_default]
21    pub title: String,
22}
23
24impl Component for Tooltip {
25  type Message = Msg;
26  type Properties = Props;
27
28  fn create(props: Self::Properties, link: ComponentLink<Self>) -> Self {
29    let style =
30      Style::create("tooltip", include_str!("tooltip.scss")).expect("An error occured while creating the style.");
31
32    Tooltip {
33      link,
34      style,
35      props: props.to_owned(),
36    }
37  }
38
39  fn update(&mut self, _msg: Self::Message) -> ShouldRender {
40    true
41  }
42
43  fn change(&mut self, _props: Self::Properties) -> ShouldRender {
44    true
45  }
46
47  fn view(&self) -> Html {
48    html! {
49      <div
50        class=Classes::from(self.props.class.to_string()).extend(self.style.to_string()).extend("tooltip")
51      >
52        <span>
53          { self.props.title.clone() }
54          { self.props.children.clone() }
55        </span>
56      </div>
57    }
58  }
59}