Skip to content

Commit

Permalink
feat: collapse gv-tree by default + add tooltip when closed
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdiw authored and loriepisicchio committed Jan 29, 2024
1 parent 697c2d9 commit b5d6bb0
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/molecules/gv-tree/gv-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { classMap } from 'lit/directives/class-map.js';
*
* @attr {Array} items - list of items and subitems to be displayed in the menu MenuItem: {name: String, value: any, children: Array<MenuItem>}
* @attr {Boolean} closed - allows to close the menu
* @attr {String} closedTooltip - tooltip shown when closed and hovering over icon
* @attr {Object} selectedItem - the item selected
*
* @cssprop {Color} [--gv-tree--bgc=var(--gv-theme-neutral-color-lightest, #ffffff)] - Background color
Expand All @@ -44,6 +45,7 @@ export class GvTree extends LitElement {
return {
items: { type: Array },
closed: { type: Boolean, reflect: true },
closedTooltip: { type: String },
selectedItem: { type: Object },
};
}
Expand Down Expand Up @@ -177,7 +179,8 @@ export class GvTree extends LitElement {

constructor() {
super();
this.closed = false;
this.closed = true;
this.closedTooltip = 'Expand';
}

_onSelect(menuItem, e) {
Expand Down Expand Up @@ -233,18 +236,23 @@ export class GvTree extends LitElement {
dispatchCustomEvent(this, 'toggle', { closed: this.closed });
}

_getIcon() {
const innerContent = this.closed
? html`<gv-popover position="right">
<gv-icon shape="text:menu" @click=${this._toggleMenu}></gv-icon>
<div slot="popover">${this.closedTooltip}</div>
</gv-popover>`
: html` <gv-icon shape="navigation:angle-double-left" @click=${this._toggleMenu}></gv-icon>`;
return html`<div class="switch">${innerContent}</div>`;
}

render() {
const classes = {
tree: true,
closed: this.closed,
};
return html`
<div class=${classMap(classes)}>
<div class="switch">
<gv-icon shape="${this.closed ? 'text:menu' : 'navigation:angle-double-left'}" @click=${this._toggleMenu}></gv-icon>
</div>
${html`<div class="main-tree-menu">${this._getMenu(this.items)}</div>`}
</div>
<div class=${classMap(classes)}>${this._getIcon()} ${html`<div class="main-tree-menu">${this._getMenu(this.items)}</div>`}</div>
`;
}
}
Expand Down

0 comments on commit b5d6bb0

Please sign in to comment.