Skip to main content

basecoat_core/props/
tooltip.rs

1use crate::{AttrMap, BasecoatProps, Children};
2use std::borrow::Cow;
3
4/// Tooltip side — maps to `data-side` attribute on the trigger element.
5/// Upstream basecoat implements tooltips purely via CSS using `data-tooltip`
6/// and `data-side` attributes — no JS controller needed.
7#[derive(Clone, Debug, PartialEq, Eq, Default)]
8pub enum TooltipSide {
9    #[default]
10    Top,
11    Right,
12    Bottom,
13    Left,
14}
15
16impl std::fmt::Display for TooltipSide {
17    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18        let s = match self {
19            TooltipSide::Top => "top",
20            TooltipSide::Right => "right",
21            TooltipSide::Bottom => "bottom",
22            TooltipSide::Left => "left",
23        };
24        f.write_str(s)
25    }
26}
27
28/// Tooltip — CSS-only via `data-tooltip` and optional `data-side` attributes.
29/// No separate container element needed — the tooltip wraps the trigger.
30#[derive(BasecoatProps, Default, Clone, Debug)]
31pub struct TooltipProps {
32    /// The tooltip text (goes into `data-tooltip`).
33    #[prop(into)]
34    pub content: Cow<'static, str>,
35    #[prop(default)]
36    pub side: TooltipSide,
37    #[prop(optional, into)]
38    pub class: Option<Cow<'static, str>>,
39    #[prop(extend)]
40    pub attrs: AttrMap,
41    /// The trigger element (button, link, etc.) rendered inside.
42    pub children: Children,
43}