Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | 125x 130x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 137x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 7x 7x 7x 7x 7x 7x 6x 6x 6x 6x 6x 6x 6x 6x 26x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 7x 1x 1x 1x 1x 1x 1x 7x 125x 14x 14x 14x 14x 7x 14x 125x 1x 1x 1x 1x 125x 1x 1x 1x 1x 1x 1x 1x 1x 1x 125x 125x 125x 125x 125x 125x 129x 124x 124x 124x 124x 129x 129x 129x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x | import { TemplateResult, html, css } from 'lit';
import { property } from 'lit/decorators.js';
import { CustomEventType } from '../interfaces';
import { RapidElement } from '../RapidElement';
import { getUrl, WebResponse } from '../utils';
const HEADERS = {
'X-Temba-Content-Menu': '1',
'X-Temba-Spa': '1'
};
export interface ContentMenuItem {
type: string;
as_button: boolean;
label: string;
url: string;
disabled: boolean;
modal_id: string;
on_submit: string;
primary: boolean;
title: string;
on_click: null;
link_class: string;
}
export enum ContentMenuItemType {
LINK = 'link',
JS = 'js',
URL_POST = 'url_post',
MODAX = 'modax',
DIVIDER = 'divider'
}
export class ContentMenu extends RapidElement {
static get styles() {
return css`
.container {
display: flex;
align-items: center;
}
temba-dropdown {
/* as a flex item of .container this z-index takes effect and
creates a stacking context — keep it in sync with the popup's
z-index inside temba-dropdown (9000) so the open menu clears
floating windows like the simulator (5000). This also keeps
the closed toggle above those windows, intentionally: the
menu has to stay clickable when a floating window overlaps
the header. Scoped here rather than on :host so the action
buttons rendered alongside keep their normal stacking. */
z-index: 9000;
}
.button_item,
.primary_button_item {
margin-left: 1rem;
}
temba-button {
margin-right: 0.5rem;
align-self: center;
}
.toggle {
--icon-color: rgb(102, 102, 102);
padding: 0.4em;
}
.toggle:hover {
background: rgba(0, 0, 0, 0.05);
border-radius: var(--curvature);
--icon-color: rgb(136, 136, 136);
}
.dropdown {
padding: 1rem 1.5rem;
color: rgb(45, 45, 45);
z-index: 50;
min-width: 200px;
}
.divider {
border-bottom: 1px solid rgb(237, 237, 237);
margin: 1rem -1.5em;
}
.item {
white-space: nowrap;
margin: 0.2em 0em;
font-size: 1.1rem;
cursor: pointer;
font-weight: 400;
}
.item:hover {
color: var(--color-link-primary);
}
`;
}
@property({ type: String })
endpoint: string;
@property({ type: Number })
legacy: number;
@property({ type: Array, attribute: false })
buttons: ContentMenuItem[] = [];
@property({ type: Array, attribute: false })
items: ContentMenuItem[] = [];
@property({ type: Boolean })
arrowTopLeft: boolean;
private fetchContentMenu() {
const url = this.endpoint;
if (url) {
const legacy = this.legacy;
const headers = HEADERS;
if (legacy) {
delete headers['Temba-Spa'];
}
//ok, fetch the content menu
getUrl(url, null, headers)
.then((response: WebResponse) => {
const json = response.json;
const contentMenu = json.items as ContentMenuItem[];
//populate (or initialize) the buttons and items
if (contentMenu) {
this.buttons = contentMenu.filter((item) => item.as_button);
this.items = contentMenu.filter((item) => !item.as_button);
} else {
this.buttons = [];
this.items = [];
}
//fire custom loaded event type when we're finished
this.fireCustomEvent(CustomEventType.Loaded, {
buttons: this.buttons,
items: this.items
});
})
.catch((error: any) => {
this.fireCustomEvent(CustomEventType.Loaded, {
buttons: this.buttons,
items: this.items
});
console.error(error);
});
}
}
public refresh() {
this.fetchContentMenu();
}
protected updated(changes: Map<string, any>) {
super.updated(changes);
if (changes.has('endpoint') || changes.has('legacy')) {
this.fetchContentMenu();
}
}
private getTopCenter(el: Element): { x: number; y: number } {
const rect = el.getBoundingClientRect();
return { x: rect.left + rect.width / 2, y: rect.top };
}
private handleItemClicked(item: ContentMenuItem, event: MouseEvent) {
const el = event.currentTarget as Element;
const origin = el
? this.getTopCenter(el)
: { x: event.clientX, y: event.clientY };
this.fireCustomEvent(CustomEventType.Selection, {
item,
event,
originX: origin.x,
originY: origin.y
});
}
public render(): TemplateResult {
return html`
<div class="container">
${this.buttons.map((button) => {
return html`<temba-button
class="${button.primary ? 'primary_button_item' : 'button_item'}"
name=${button.label}
@click=${(event) => this.handleItemClicked(button, event)}
>
${button.label}
</temba-button>`;
})}
${this.items && this.items.length > 0
? html`<temba-dropdown>
<div slot="toggle" class="toggle">
<temba-icon name="menu" size="1.5"></temba-icon>
</div>
<div slot="dropdown" class="dropdown">
${this.items.map((item) => {
if (item.type === ContentMenuItemType.DIVIDER) {
return html` <div class="divider"></div>`;
} else {
return html` <div
class="item"
name=${item.label}
@click=${(event) => this.handleItemClicked(item, event)}
>
${item.label}
</div>`;
}
})}
</div>
</temba-dropdown>`
: null}
</div>
`;
}
}
|