Skip to content
Snippets Groups Projects
Commit 6e3de745 authored by Tögl, Christina's avatar Tögl, Christina
Browse files

Optimize tooltip components

parent cc1d25bb
No related branches found
No related tags found
No related merge requests found
Pipeline #55696 passed
...@@ -10,7 +10,6 @@ export class ButtonTooltip extends ScopedElementsMixin(DBPLitElement) { ...@@ -10,7 +10,6 @@ export class ButtonTooltip extends ScopedElementsMixin(DBPLitElement) {
constructor() { constructor() {
super(); super();
this.tippy = '';
this.textContent = 'missing text.'; this.textContent = 'missing text.';
this.buttonText = 'submit'; this.buttonText = 'submit';
this.addEventListener('click', this._handleClick); this.addEventListener('click', this._handleClick);
...@@ -21,7 +20,6 @@ export class ButtonTooltip extends ScopedElementsMixin(DBPLitElement) { ...@@ -21,7 +20,6 @@ export class ButtonTooltip extends ScopedElementsMixin(DBPLitElement) {
static get properties() { static get properties() {
return { return {
...super.properties, ...super.properties,
tippy: { type: Object, attribute: false },
textContent: { type: String, attribute: 'text-content' }, textContent: { type: String, attribute: 'text-content' },
buttonText: { type: String, attribute: 'button-text' }, buttonText: { type: String, attribute: 'button-text' },
type: { type: String }, type: { type: String },
...@@ -30,11 +28,23 @@ export class ButtonTooltip extends ScopedElementsMixin(DBPLitElement) { ...@@ -30,11 +28,23 @@ export class ButtonTooltip extends ScopedElementsMixin(DBPLitElement) {
} }
firstUpdated() { firstUpdated() {
this.setOrUpdateTippy();
}
tippy(this._('#info-tooltip-button'), { setOrUpdateTippy() {
content: this.textContent, if (this._('#info-tooltip-button')) {
appendTo: this.shadowRoot, if (this._('#info-tooltip-button')._tippy) {
}); this._('#info-tooltip-button')._tippy.setProps({
content: this.textContent,
appendTo: this.shadowRoot,
});
} else {
tippy(this._('#info-tooltip-button'), {
content: this.textContent,
appendTo: this.shadowRoot,
});
}
}
} }
_handleClick(event) { _handleClick(event) {
...@@ -74,9 +84,7 @@ export class ButtonTooltip extends ScopedElementsMixin(DBPLitElement) { ...@@ -74,9 +84,7 @@ export class ButtonTooltip extends ScopedElementsMixin(DBPLitElement) {
const tippy2CSS = commonUtils.getAssetURL(tippy2CSSPath); const tippy2CSS = commonUtils.getAssetURL(tippy2CSSPath);
if (this._('#info-tooltip-button')) { this.setOrUpdateTippy();
this.tippy = tippy(this._('#info-tooltip-button'), { content: this.textContent });
}
return html` return html`
<link rel="stylesheet" href="${tippy2CSS}"> <link rel="stylesheet" href="${tippy2CSS}">
......
...@@ -50,6 +50,7 @@ export class TooltipDemo extends ScopedElementsMixin(DBPLitElement) { ...@@ -50,6 +50,7 @@ export class TooltipDemo extends ScopedElementsMixin(DBPLitElement) {
css` css`
h1.title {margin-bottom: 1em;} h1.title {margin-bottom: 1em;}
div.container {margin-bottom: 1.5em; padding-left:20px;} div.container {margin-bottom: 1.5em; padding-left:20px;}
.group { display: flex; flex-direction: auto; column-gap: 3px; }
` `
]; ];
} }
...@@ -83,12 +84,12 @@ export class TooltipDemo extends ScopedElementsMixin(DBPLitElement) { ...@@ -83,12 +84,12 @@ export class TooltipDemo extends ScopedElementsMixin(DBPLitElement) {
<div class="container"> <div class="container">
<h2>Button with Tooltip</h2> <h2>Button with Tooltip</h2>
<p>Add a tooltip info to your submit/reset button.</p> <p>Add a tooltip info to your submit/reset button.</p>
<form action="/"> <form action="/" class="group">
<label for="text">Text</label> <label for="text">Text</label>
<input type="text" id="text" name="text" value="" placeholder="text"> <input type="text" id="text" name="text" value="" placeholder="text">
<dbp-button-tooltip button-text="save" text-content="submit to server"></dbp-button-tooltip> <div><dbp-button-tooltip button-text="save" text-content="submit to server"></dbp-button-tooltip></div>
<dbp-button-tooltip button-text="reset" text-content="clear all inputs" type="reset"></dbp-button-tooltip> <div><dbp-button-tooltip button-text="reset" text-content="clear all inputs" type="reset"></dbp-button-tooltip></div>
<dbp-button-tooltip button-text="silent" text-content="does nothing" type="btn"></dbp-button-tooltip> <div><dbp-button-tooltip button-text="silent" text-content="does nothing" type="btn"></dbp-button-tooltip></div>
</form> </form>
</div> </div>
</section> </section>
......
...@@ -11,7 +11,6 @@ export class TooltipElement extends ScopedElementsMixin(DBPLitElement) { ...@@ -11,7 +11,6 @@ export class TooltipElement extends ScopedElementsMixin(DBPLitElement) {
constructor() { constructor() {
super(); super();
this.tippy = '';
this.textContent = 'missing text.'; this.textContent = 'missing text.';
this.iconName = ''; this.iconName = '';
} }
...@@ -25,18 +24,29 @@ export class TooltipElement extends ScopedElementsMixin(DBPLitElement) { ...@@ -25,18 +24,29 @@ export class TooltipElement extends ScopedElementsMixin(DBPLitElement) {
static get properties() { static get properties() {
return { return {
...super.properties, ...super.properties,
tippy: { type: Object, attribute: false },
textContent: { type: String, attribute: 'text-content' }, textContent: { type: String, attribute: 'text-content' },
iconName: { type: String, attribute: 'icon-name' }, iconName: { type: String, attribute: 'icon-name' },
}; };
} }
firstUpdated() { firstUpdated() {
this.setOrUpdateTippy();
}
tippy(this._('#tooltip-icon'), { setOrUpdateTippy() {
content: this.textContent, if (this._('#tooltip-icon')) {
appendTo: this.shadowRoot, if (this._('#tooltip-icon')._tippy) {
}); this._('#tooltip-icon')._tippy.setProps({
content: this.textContent,
appendTo: this.shadowRoot,
});
} else {
tippy(this._('#tooltip-icon'), {
content: this.textContent,
appendTo: this.shadowRoot,
});
}
}
} }
static get styles() { static get styles() {
...@@ -59,9 +69,7 @@ export class TooltipElement extends ScopedElementsMixin(DBPLitElement) { ...@@ -59,9 +69,7 @@ export class TooltipElement extends ScopedElementsMixin(DBPLitElement) {
const tippy2CSS = commonUtils.getAssetURL(tippy2CSSPath); const tippy2CSS = commonUtils.getAssetURL(tippy2CSSPath);
if (this._('#tooltip-icon')) { this.setOrUpdateTippy();
this.tippy = tippy(this._('#tooltip-icon'), { content: this.textContent });
}
return html` return html`
<link rel="stylesheet" href="${tippy2CSS}"> <link rel="stylesheet" href="${tippy2CSS}">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment