Skip to main content

Adding tooltips

To add a template to a tooltip:

  • import the Tooltip component that should be a Svelte component
  • prepare you custom Svelte template
  • import your custom template
  • add the name of the template as the value of the Tooltip content attribute
  • wrap the Gantt tag into the Tooltip tag
  • use the internal api object to get access to the methods

Example:

<script>
import { getData } from "../data";
import { Gantt, Tooltip } from "@wx/svelte-gantt";
import MyTooltipContent from "../custom/MyTooltipContent.svelte";

const data = getData();
let api;
</script>

<Tooltip {api} content={MyTooltipContent}>
<Gantt
tasks={data.tasks}
links={data.links}
scales={data.scales}
bind:api
/>
</Tooltip>

Below is an example of the Svelte component for a tooltip

<script>
import { format } from "date-fns";
export let data;

const mask = "yyyy.MM.dd";
</script>

{#if data}
<div class="data">
<div class="text">
<span class="caption">{data.type}:</span>
{data.text}
</div>
<div class="text">
<span class="caption">start:</span>
{format(data.start, mask)}
</div>
<div class="text">
<span class="caption">end:</span>
{format(data.end, mask)}
</div>
</div>
{/if}

<style>
.data {
white-space: nowrap;
background-color: var(--wx-tooltip-background);
padding: 3px 8px;
}

.text {
font-family: var(--wx-font-family);
color: var(--wx-color-primary-font);
font-size: 13px;
text-transform: capitalize;
margin-bottom: 5px;
}

.text:last-child {
margin-bottom: 0;
}

.caption {
font-weight: 700;
}
</style>