Skip to main content

basecoat_core/classes/
tooltip.rs

1use crate::props::tooltip::TooltipProps;
2
3/// Returns the canonical CSS class string for a tooltip trigger wrapper.
4///
5/// Upstream basecoat implements tooltips via CSS using `data-tooltip` and
6/// `data-side` attributes on the trigger element — no dedicated CSS class.
7/// This function returns the extra class if provided, otherwise empty string.
8pub fn tooltip(p: &TooltipProps) -> String {
9    match &p.class {
10        Some(extra) if !extra.is_empty() => extra.to_string(),
11        _ => String::new(),
12    }
13}
14
15#[cfg(test)]
16mod tests {
17    use super::*;
18    use crate::props::tooltip::TooltipProps;
19    use std::borrow::Cow;
20
21    #[test]
22    fn no_class_by_default() {
23        let p = TooltipProps {
24            content: Cow::Borrowed("Hello"),
25            ..Default::default()
26        };
27        assert_eq!(tooltip(&p), "");
28    }
29}