How do I access and exchange variables between custom elements? I have the following files ...
tip.html
<template> <div class="tip-container"> <content select="tip-trigger"></content> <content select="tip-content"></content> </div> </template>
tip.js
export class Tip {}
Tip-trigger.html
<template> <span class="tip-trigger" click.trigger="showTip()"> <content></content> </span> </template>
tip-trigger.js
export class TipTrigger { showTip() { console.debug(this); } }
Tip-content.html
<template> <span class="tip"> <content></content> <span class="tip__close tip__close--default">ร</span> <span class="tip__color"></span> </span> </template>
tip-content.js
export class TipContent {}
In my Tip class, I would like to have the variable name visible . When showTip visible fires, showTip will be set to true, which I would then use to add the class to tip-content.html. How can I share variables between these custom elements?
The idea is to create an element for displaying tooltips, where any type of content can be a trigger, and any type of content can be displayed at startup. Basic example:
<tip> <tip-trigger><button>?</button></tip-trigger> <tip-content><div>Here is some helpful info...</div></tip-content> </tip>
source share