-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(web-twig): Tooltip can be opened by hover
- Loading branch information
1 parent
50b429b
commit 66758dc
Showing
8 changed files
with
72 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 17 additions & 14 deletions
31
apps/web-twig-demo/assets/scripts/tooltip-dismissible-via-js.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
import { Tooltip } from '@lmc-eu/spirit-web/src/js/index.esm'; | ||
|
||
const myTooltipEl = document.getElementById('my-dismissible-tooltip2'); | ||
const buttonId = 'my-dismissible-button'; | ||
const tooltipId = 'my-dismissible-tooltip-with-floating-ui'; | ||
const storageName = 'show-tooltip'; | ||
const myTooltipEl = document.getElementById(tooltipId); | ||
const myTooltip = new Tooltip(myTooltipEl); | ||
|
||
if (!window.localStorage.getItem('my-tooltip-twig')) { | ||
myTooltip.show(); | ||
// show tooltip if it was toggled | ||
if (window.localStorage.getItem(storageName)) { | ||
myTooltip.toggle(); | ||
} | ||
|
||
document.getElementById('my-dismissible-button').addEventListener('click', () => { | ||
myTooltip.show(); | ||
window.localStorage.removeItem('my-tooltip-twig'); | ||
}); | ||
// tooltip trigger button | ||
document.getElementById(buttonId).addEventListener('click', () => { | ||
const isToggled = window.localStorage.getItem(storageName); | ||
const isShown = myTooltip.isShown(); | ||
|
||
document | ||
.getElementById('my-dismissible-tooltip2') | ||
.querySelector('button') | ||
.addEventListener('click', () => { | ||
myTooltip.hide(); | ||
window.localStorage.setItem('my-tooltip-twig', 'true'); | ||
}); | ||
if (isToggled && !isShown) { | ||
window.localStorage.removeItem(storageName); | ||
} else { | ||
window.localStorage.setItem(storageName, 'true'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/web-twig/src/Resources/components/Tooltip/stories/TooltipEnableHover.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<TooltipWrapper UNSAFE_className="spirit-feature-tooltip-enable-data-placement d-inline-block"> | ||
<Button | ||
id="button-example-hover" | ||
aria-describedby="tooltip-example-hover" | ||
data-spirit-toggle="tooltip" | ||
data-spirit-target="#tooltip-example-hover" | ||
> | ||
I have a tooltip 😎 | ||
</Button> | ||
<Tooltip | ||
id="tooltip-example-hover" | ||
UNSAFE_className="is-hidden" | ||
placement="right" | ||
enableHover="true" | ||
> | ||
Hello there! | ||
</Tooltip> | ||
</TooltipWrapper> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,4 @@ | |
Close me | ||
</TooltipPopov> | ||
</TooltipWrapper> | ||
</span> | ||
</span> |