Skip to content

Commit 3dd9e7f

Browse files
authored
Tooltip (#1429)
1 parent 656a1a7 commit 3dd9e7f

File tree

13 files changed

+124
-18
lines changed

13 files changed

+124
-18
lines changed

pgml-dashboard/src/components/chatbot/chatbot_controller.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,13 @@ export default class extends Controller {
400400

401401
showChatbotAlert(level, message) {
402402
const toastElement = createToast(message, level);
403-
showToast(toastElement, {
404-
autohide: true,
405-
delay: 7000,
406-
});
403+
404+
if (toastElement) {
405+
showToast(toastElement, {
406+
autohide: true,
407+
delay: 7000,
408+
});
409+
}
407410
}
408411

409412
hideExampleQuestions() {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// This file is automatically generated.
2+
// You shouldn't modify it manually.
3+
4+
// src/components/inputs/labels/with_tooltip
5+
pub mod with_tooltip;
6+
pub use with_tooltip::WithTooltip;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use pgml_components::{component, Component};
2+
use sailfish::TemplateOnce;
3+
4+
#[derive(TemplateOnce, Default)]
5+
#[template(path = "inputs/labels/with_tooltip/template.html")]
6+
pub struct WithTooltip {
7+
component: Component,
8+
tooltip: String,
9+
icon: String,
10+
html: bool,
11+
}
12+
13+
impl WithTooltip {
14+
pub fn new(component: Component) -> WithTooltip {
15+
WithTooltip {
16+
component,
17+
tooltip: String::new(),
18+
icon: "info".to_string(),
19+
html: false,
20+
}
21+
}
22+
23+
pub fn tooltip(mut self, tooltip: impl ToString) -> Self {
24+
self.tooltip = tooltip.to_string();
25+
self
26+
}
27+
28+
pub fn tooltip_text(self, tooltip: impl ToString) -> Self {
29+
self.tooltip(tooltip)
30+
}
31+
32+
pub fn tooltip_html(mut self, tooltip: impl ToString) -> Self {
33+
self.tooltip = tooltip.to_string();
34+
self.html = true;
35+
self
36+
}
37+
38+
pub fn icon(mut self, icon: impl ToString) -> Self {
39+
self.icon = icon.to_string();
40+
self
41+
}
42+
}
43+
44+
component!(WithTooltip);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<span
2+
data-controller="inputs-labels-with-tooltip enable-tooltip"
3+
class="d-inline-flex gap-1 align-items-top"
4+
>
5+
<span><%+ component %></span>
6+
<span
7+
data-bs-toggle="tooltip"
8+
data-bs-placement="right"
9+
data-bs-title="<%- tooltip %>"
10+
data-bs-html="<%= html %>"
11+
class="material-symbols-outlined fw-bold"
12+
>
13+
<%= icon %>
14+
</span>
15+
</span>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
span[data-controller="inputs-labels-with-tooltip enable-tooltip"] {
2+
span[data-bs-toggle="tooltip"] {
3+
color: #{$slate-tint-100};
4+
font-size: 1.2rem;
5+
}
6+
}

pgml-dashboard/src/components/inputs/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
pub mod checkbox;
66
pub use checkbox::Checkbox;
77

8+
// src/components/inputs/labels
9+
pub mod labels;
10+
811
// src/components/inputs/radio
912
pub mod radio;
1013
pub use radio::Radio;

pgml-dashboard/src/components/inputs/text/input/input.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
div[data-controller="inputs-text-input"] {
22
--bs-danger: #{$peach-shade-100};
33

4-
span.material-symbols-outlined {
4+
span.inputs-text-input-icon{
55
margin-left: -40px;
66
color: #{$slate-shade-100};
77

pgml-dashboard/src/components/inputs/text/input/template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
<% if let Some(icon) = icon { %>
2828
<span
29-
class="<%= icon_classes %>"
29+
class="<%= icon_classes %> inputs-text-input-icon"
3030
data-action="<%= icon_actions %>">
3131
<%= icon %>
3232
</span>

pgml-dashboard/src/components/pages/demo/template.html

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<% use crate::components::inputs::select::{Select, Option}; %>
99
<% use crate::components::inputs::{SwitchV2, Radio, Checkbox}; %>
1010
<% use crate::components::cards::{Rgb, Secondary, Primary}; %>
11+
<% use crate::components::inputs::labels::WithTooltip; %>
1112

1213
<div class="container" data-controller="pages-demo">
1314
<div class="py-5">
@@ -59,8 +60,14 @@
5960
</div>
6061

6162
<div class="py-5">
63+
<%
64+
let label = WithTooltip::new("Name".into())
65+
.tooltip("Your full name.")
66+
.icon("info");
67+
%>
68+
6269
<%+ Input::new()
63-
.label("What is your name?".into())
70+
.label(label.into())
6471
.icon("person")
6572
.placeholder("Enter your name")
6673
.name("name")
@@ -201,4 +208,16 @@
201208
</div>
202209
</div>
203210
</div>
211+
212+
<div class="py-5">
213+
<%+ WithTooltip::new("Model".into())
214+
.tooltip("A model is great, but two is better.")
215+
.icon("help_outline") %>
216+
</div>
217+
218+
<div class="py-5">
219+
<%+ WithTooltip::new("Model".into())
220+
.tooltip_html("A model is great<br>, but<br> two<br> is better.")
221+
.icon("help_outline") %>
222+
</div>
204223
</div>

pgml-dashboard/static/css/modules.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
@import "../../src/components/icons/checkmark/checkmark.scss";
2222
@import "../../src/components/icons/twitter/twitter.scss";
2323
@import "../../src/components/inputs/checkbox/checkbox.scss";
24+
@import "../../src/components/inputs/labels/with_tooltip/with_tooltip.scss";
2425
@import "../../src/components/inputs/radio/radio.scss";
2526
@import "../../src/components/inputs/range_group/range_group.scss";
2627
@import "../../src/components/inputs/range_group_v_2/range_group_v_2.scss";

0 commit comments

Comments
 (0)