-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdb-overflow-menu.tsx
85 lines (74 loc) · 2.28 KB
/
db-overflow-menu.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { Component, Element, h, Prop } from '@stencil/core';
import { DbLinkType } from '../db-link/db-link-type';
import { getDefaultLinkData, parseData } from '../../utils/utils';
@Component({
tag: 'db-overflow-menu',
styleUrl: 'db-overflow-menu.scss'
})
export class DbOverflowMenu {
/**
* The data attribute can be used to generate overflow-menu by data.
*/
@Prop({ reflect: true }) data?: string;
/**
* The opposite attribute, changes the behaviour: overflow-menu -> right.
*/
@Prop({ reflect: true }) opposite: boolean;
/**
* The summary attribute, shows a text for accessibility.
*/
@Prop({ reflect: true }) summary = '';
/**
* Define an icon by it's identifier (like e.g. _download_, compare to [DB UI Icons](https://db-ui.github.io/core/patterns/base-icons/index.html)) to get displayed in front of the elements content.
*/
@Prop({ reflect: true }) icon?: string;
private compData: DbLinkType[];
private hasItemsWrapper: boolean;
get children(): Element[] {
return this._children;
}
set children(value: Element[]) {
this._children = value;
}
private _children: Element[];
@Element() host: HTMLDbOverflowMenuElement;
componentWillLoad() {
if (this.data) {
this.compData = parseData(this.data);
} else {
this._children = Array.from(this.host.children);
if (this.children.find((child) => child.tagName.toLowerCase() === 'li')) {
this.hasItemsWrapper = true;
} else {
this.host.innerHTML = '';
}
}
}
render() {
return (
<details
class="cmp-overflow-menu"
data-horizontal-position={this.opposite && 'opposite'}
>
<summary>
{this.icon ? <db-icon icon={this.icon} /> : this.summary}
</summary>
{this.compData && (
<menu type="toolbar" innerHTML={getDefaultLinkData(this.compData)} />
)}
{!this.compData && (
<menu type="toolbar">
{!this.hasItemsWrapper &&
this._children.map((child, index) => (
<li
key={`cmp-overflow-menu-${index}`}
innerHTML={child.outerHTML}
/>
))}
{this.hasItemsWrapper && <slot />}
</menu>
)}
</details>
);
}
}