Skip to content

Commit

Permalink
fixup! Docs(web): Add Tooltip demo #DS-914
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelklibani committed Sep 18, 2023
1 parent 12fa95c commit 67d4c46
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
16 changes: 16 additions & 0 deletions packages/web/src/scss/components/Tooltip/dismissible-tooltip.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Tooltip from '../../../js/Tooltip.ts';

const myTooltipEl = document.getElementById('my-dismissible-tooltip2');
const myTooltip = new Tooltip(myTooltipEl);

// Remove 'my-tooltip' key from localStorage to show tooltip again.
// localStorage.removeItem('my-tooltip');

if (!window.localStorage.getItem('my-tooltip')) {
myTooltip.show();
}

document.getElementById('my-dismissible-tooltip2-button').addEventListener('click', () => {
myTooltip.hide();
window.localStorage.setItem('my-tooltip', true);
});
19 changes: 3 additions & 16 deletions packages/web/src/scss/components/Tooltip/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ <h2 class="docs-Heading">Tooltip on Click (JavaScript)</h2>
<button
type="button"
id="tooltip-trigger"
class="Button Button--primary Button--medium mb-800"
class="Button Button--primary Button--medium"
data-spirit-target="#my-js-controlled-tooltip"
data-spirit-toggle="tooltip"
>
Expand Down Expand Up @@ -129,6 +129,8 @@ <h2 class="docs-Heading">Dismissible Tooltip via JS API</h2>
Saves data to local storage.
</p>

<script type="module" src="dismissible-tooltip.mjs"></script>

<div class="TooltipWrapper d-inline-block">
<button class="Button Button--primary Button--medium" aria-describedby="my-dismissible-tooltip2">I have a tooltip 😎</button>
<div id="my-dismissible-tooltip2" class="Tooltip Tooltip--right Tooltip--dismissible is-hidden">
Expand All @@ -150,21 +152,6 @@ <h2 class="docs-Heading">Dismissible Tooltip via JS API</h2>
</div>
</div>

<script type="module">
import Tooltip from '../../../js/Tooltip.ts';
const myTooltipEl = document.getElementById('my-dismissible-tooltip2');
const myTooltip = new Tooltip(myTooltipEl);

if(!window.localStorage.getItem('my-tooltip')) {
myTooltip.show();
}

document.getElementById('my-dismissible-tooltip2-button').addEventListener('click', () => {
myTooltip.hide();
window.localStorage.setItem('my-tooltip', true);
});
</script>

</section>
<section id="advanced-positioning" class="docs-Section">

Expand Down

0 comments on commit 67d4c46

Please sign in to comment.