Skip to content

Commit b4446ab

Browse files
authored
feat: Popover adds tooltip prop (#164)
1 parent aa793e1 commit b4446ab

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

demo/src/components/demo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn Demo(demo_code: DemoCode, #[prop(optional)] children: Option<Children>) -
6868
view! {
6969
<div class="demo-demo__view">{children()}</div>
7070
<div class="demo-demo__toolbar" class=("demo-demo__toolbar--code", move || !is_show_code.get())>
71-
<Popover>
71+
<Popover tooltip=true>
7272
<PopoverTrigger slot>
7373
<span on:click=move |_| is_show_code.update(|show| *show = !*show) class="demo-demo__toolbar-btn">
7474
{

demo_markdown/docs/popover/mod.md

+16
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,28 @@ view! {
129129
}
130130
```
131131

132+
### Tooltip
133+
134+
```rust demo
135+
view! {
136+
<Space>
137+
<Popover tooltip=true>
138+
<PopoverTrigger slot>
139+
<Button>"Hover"</Button>
140+
</PopoverTrigger>
141+
"Content"
142+
</Popover>
143+
</Space>
144+
}
145+
```
146+
132147
### Popover Props
133148

134149
| Name | Type | Default | Description |
135150
| --------- | ----------------------------------- | ----------------------- | ----------------------------- |
136151
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Content class of the popover. |
137152
| placement | `PopoverPlacement` | `PopoverPlacement::Top` | Popover placement. |
153+
| tooltip | `bool` | `false` | Tooltip. |
138154
| children | `Children` | | The content inside popover. |
139155

140156
### Popover Slots

thaw/src/popover/mod.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,26 @@ pub fn Popover(
2121
#[prop(optional)] trigger_type: PopoverTriggerType,
2222
popover_trigger: PopoverTrigger,
2323
#[prop(optional)] placement: PopoverPlacement,
24+
#[prop(optional)] tooltip: bool,
2425
children: Children,
2526
) -> impl IntoView {
2627
mount_style("popover", include_str!("./popover.css"));
2728
let theme = use_theme(Theme::light);
2829
let css_vars = create_memo(move |_| {
2930
let mut css_vars = String::new();
3031
theme.with(|theme| {
31-
css_vars.push_str(&format!(
32-
"--thaw-background-color: {};",
33-
theme.time_picker.panel_background_color
34-
));
32+
let background_color = if tooltip {
33+
&theme.popover.tooltip_background_color
34+
} else {
35+
&theme.popover.background_color
36+
};
37+
css_vars.push_str(&format!("--thaw-background-color: {};", background_color));
38+
let font_color = if tooltip {
39+
"#fff"
40+
} else {
41+
&theme.common.font_color
42+
};
43+
css_vars.push_str(&format!("--thaw-font-color: {};", font_color));
3544
});
3645
css_vars
3746
});
@@ -129,7 +138,7 @@ pub fn Popover(
129138
let:display
130139
>
131140
<div
132-
class="thaw-popover"
141+
class=if tooltip { "thaw-popover thaw-popover--tooltip" } else { "thaw-popover" }
133142
style=move || {
134143
display.get().map(|d| d.to_string()).unwrap_or_else(|| css_vars.get())
135144
}

thaw/src/popover/popover.css

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
position: relative;
33
padding: 8px 14px;
44
background-color: var(--thaw-background-color);
5+
color: var(--thaw-font-color);
56
border-radius: 3px;
67
transform-origin: inherit;
78
}

thaw/src/popover/theme.rs

+3
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@ use crate::theme::ThemeMethod;
33
#[derive(Clone)]
44
pub struct PopoverTheme {
55
pub background_color: String,
6+
pub tooltip_background_color: String,
67
}
78

89
impl ThemeMethod for PopoverTheme {
910
fn light() -> Self {
1011
Self {
1112
background_color: "#fff".into(),
13+
tooltip_background_color: "#262626".into(),
1214
}
1315
}
1416

1517
fn dark() -> Self {
1618
Self {
1719
background_color: "#48484e".into(),
20+
tooltip_background_color: "#48484e".into(),
1821
}
1922
}
2023
}

0 commit comments

Comments
 (0)