Skip to content

Tooltip #1429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2024
Merged

Tooltip #1429

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pgml-dashboard/src/components/chatbot/chatbot_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,13 @@ export default class extends Controller {

showChatbotAlert(level, message) {
const toastElement = createToast(message, level);
showToast(toastElement, {
autohide: true,
delay: 7000,
});

if (toastElement) {
showToast(toastElement, {
autohide: true,
delay: 7000,
});
}
}

hideExampleQuestions() {
Expand Down
6 changes: 6 additions & 0 deletions pgml-dashboard/src/components/inputs/labels/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This file is automatically generated.
// You shouldn't modify it manually.

// src/components/inputs/labels/with_tooltip
pub mod with_tooltip;
pub use with_tooltip::WithTooltip;
44 changes: 44 additions & 0 deletions pgml-dashboard/src/components/inputs/labels/with_tooltip/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use pgml_components::{component, Component};
use sailfish::TemplateOnce;

#[derive(TemplateOnce, Default)]
#[template(path = "inputs/labels/with_tooltip/template.html")]
pub struct WithTooltip {
component: Component,
tooltip: String,
icon: String,
html: bool,
}

impl WithTooltip {
pub fn new(component: Component) -> WithTooltip {
WithTooltip {
component,
tooltip: String::new(),
icon: "info".to_string(),
html: false,
}
}

pub fn tooltip(mut self, tooltip: impl ToString) -> Self {
self.tooltip = tooltip.to_string();
self
}

pub fn tooltip_text(self, tooltip: impl ToString) -> Self {
self.tooltip(tooltip)
}

pub fn tooltip_html(mut self, tooltip: impl ToString) -> Self {
self.tooltip = tooltip.to_string();
self.html = true;
self
}

pub fn icon(mut self, icon: impl ToString) -> Self {
self.icon = icon.to_string();
self
}
}

component!(WithTooltip);
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<span
data-controller="inputs-labels-with-tooltip enable-tooltip"
class="d-inline-flex gap-1 align-items-top"
>
<span><%+ component %></span>
<span
data-bs-toggle="tooltip"
data-bs-placement="right"
data-bs-title="<%- tooltip %>"
data-bs-html="<%= html %>"
class="material-symbols-outlined fw-bold"
>
<%= icon %>
</span>
</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
span[data-controller="inputs-labels-with-tooltip enable-tooltip"] {
span[data-bs-toggle="tooltip"] {
color: #{$slate-tint-100};
font-size: 1.2rem;
}
}
3 changes: 3 additions & 0 deletions pgml-dashboard/src/components/inputs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
pub mod checkbox;
pub use checkbox::Checkbox;

// src/components/inputs/labels
pub mod labels;

// src/components/inputs/radio
pub mod radio;
pub use radio::Radio;
Expand Down
2 changes: 1 addition & 1 deletion pgml-dashboard/src/components/inputs/text/input/input.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
div[data-controller="inputs-text-input"] {
--bs-danger: #{$peach-shade-100};

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<% if let Some(icon) = icon { %>
<span
class="<%= icon_classes %>"
class="<%= icon_classes %> inputs-text-input-icon"
data-action="<%= icon_actions %>">
<%= icon %>
</span>
Expand Down
21 changes: 20 additions & 1 deletion pgml-dashboard/src/components/pages/demo/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<% use crate::components::inputs::select::{Select, Option}; %>
<% use crate::components::inputs::{SwitchV2, Radio, Checkbox}; %>
<% use crate::components::cards::{Rgb, Secondary, Primary}; %>
<% use crate::components::inputs::labels::WithTooltip; %>

<div class="container" data-controller="pages-demo">
<div class="py-5">
Expand Down Expand Up @@ -59,8 +60,14 @@
</div>

<div class="py-5">
<%
let label = WithTooltip::new("Name".into())
.tooltip("Your full name.")
.icon("info");
%>

<%+ Input::new()
.label("What is your name?".into())
.label(label.into())
.icon("person")
.placeholder("Enter your name")
.name("name")
Expand Down Expand Up @@ -201,4 +208,16 @@
</div>
</div>
</div>

<div class="py-5">
<%+ WithTooltip::new("Model".into())
.tooltip("A model is great, but two is better.")
.icon("help_outline") %>
</div>

<div class="py-5">
<%+ WithTooltip::new("Model".into())
.tooltip_html("A model is great<br>, but<br> two<br> is better.")
.icon("help_outline") %>
</div>
</div>
1 change: 1 addition & 0 deletions pgml-dashboard/static/css/modules.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
@import "../../src/components/icons/checkmark/checkmark.scss";
@import "../../src/components/icons/twitter/twitter.scss";
@import "../../src/components/inputs/checkbox/checkbox.scss";
@import "../../src/components/inputs/labels/with_tooltip/with_tooltip.scss";
@import "../../src/components/inputs/radio/radio.scss";
@import "../../src/components/inputs/range_group/range_group.scss";
@import "../../src/components/inputs/range_group_v_2/range_group_v_2.scss";
Expand Down
13 changes: 7 additions & 6 deletions pgml-dashboard/static/css/scss/components/_tooltips.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
.tooltip {
--bs-tooltip-bg: #{$primary};
--bs-tooltip-color: #fff;
--bs-tooltip-arrow-width: 0;
--bs-tooltip-arrow-height: 0;
--bs-tooltip-bg: #{$gray-800};
--bs-tooltip-color:#{$white};
--bs-tooltip-arrow-width: 29px;
--bs-tooltip-arrow-height: 14px;
--bs-tooltip-margin: 0 0 1rem 0;
--bs-tooltip-padding-y: 16px;
--bs-tooltip-padding-x: 16px;
--bs-tooltip-padding-y: 10px;
--bs-tooltip-padding-x: 10px;
--bs-tooltip-opacity: 1.0;
}
5 changes: 4 additions & 1 deletion pgml-dashboard/static/js/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export default class extends Controller {
navigator.clipboard.writeText(text)

const toastElement = createToast('Copied to clipboard');
showToast(toastElement);

if (toastElement) {
showToast(toastElement);
}
}

}
13 changes: 9 additions & 4 deletions pgml-dashboard/static/js/utilities/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ function createToast(message) {
toastElement.appendChild(toastBodyElement);

const container = document.getElementById("toast-container");
container.appendChild(toastElement);

// remove from DOM when no longer needed
toastElement.addEventListener("hidden.bs.toast", (e) => e.target.remove());
if (container) {
container.appendChild(toastElement);

return toastElement;
// remove from DOM when no longer needed
toastElement.addEventListener("hidden.bs.toast", (e) => e.target.remove());

return toastElement;
} else {
return null;
}
}

function showToast(toastElement, config) {
Expand Down