@nyaruka/temba-components 0.73.0 → 0.75.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -161,12 +161,6 @@ export class Dropdown extends RapidElement {
161
161
  }
162
162
 
163
163
  if (changedProperties.has('open')) {
164
- if (this.open) {
165
- this.classList.add('open');
166
- } else {
167
- this.classList.remove('open');
168
- }
169
-
170
164
  this.ensureOnScreen();
171
165
  }
172
166
  }
@@ -179,10 +173,29 @@ export class Dropdown extends RapidElement {
179
173
 
180
174
  if (dropdown) {
181
175
  // dropdown will go off the screen, let's push it up
176
+ const toggle = this.querySelector('div[slot="toggle"]');
182
177
  if (dropdown.getBoundingClientRect().bottom > window.innerHeight) {
183
- const toggle = this.querySelector('div[slot="toggle"]');
184
- dropdown.style.bottom =
185
- this.offsetY + toggle.clientHeight + 10 + 'px';
178
+ if (this.bottom) {
179
+ dropdown.style.top = toggle.clientHeight + 'px';
180
+ } else {
181
+ dropdown.style.top = '';
182
+ dropdown.style.bottom = toggle.clientHeight + 'px';
183
+ }
184
+ } else if (dropdown.getBoundingClientRect().top < 0) {
185
+ if (this.bottom) {
186
+ dropdown.style.top = toggle.clientHeight + 'px';
187
+ } else {
188
+ dropdown.style.top = toggle.clientHeight + 'px';
189
+ dropdown.style.bottom = '';
190
+ }
191
+ }
192
+
193
+ if (dropdown.getBoundingClientRect().right > window.innerWidth) {
194
+ dropdown.style.left = '';
195
+ dropdown.style.right = 0 + 'px';
196
+ } else if (dropdown.getBoundingClientRect().left < 0) {
197
+ dropdown.style.left = 0 + 'px';
198
+ dropdown.style.right = '';
186
199
  }
187
200
  }
188
201
  }, 100);
@@ -160,11 +160,11 @@ export class ContentMenu extends RapidElement {
160
160
  </temba-button>`;
161
161
  })}
162
162
  ${this.items && this.items.length > 0
163
- ? html` <temba-dropdown
163
+ ? html`<temba-dropdown
164
164
  arrowsize="8"
165
165
  arrowoffset="-12"
166
- offsetx="-200"
167
166
  offsety="6"
167
+ bottom
168
168
  >
169
169
  <div slot="toggle" class="toggle">
170
170
  <temba-icon name="menu" size="1.5"></temba-icon>
@@ -1,12 +1,19 @@
1
- import { css, html, TemplateResult } from 'lit';
1
+ import { css, html, PropertyValueMap, TemplateResult } from 'lit';
2
2
  import { ifDefined } from 'lit/directives/if-defined.js';
3
3
  import { property } from 'lit/decorators.js';
4
4
  import { CustomEventType } from '../interfaces';
5
5
  import { RapidElement } from '../RapidElement';
6
- import { debounce, fetchResults, getClasses, renderAvatar } from '../utils';
6
+ import {
7
+ debounce,
8
+ fetchResults,
9
+ getClasses,
10
+ renderAvatar,
11
+ throttle,
12
+ } from '../utils';
7
13
  import { Icon } from '../vectoricon';
8
14
  import { Dropdown } from '../dropdown/Dropdown';
9
15
  import { NotificationList } from './NotificationList';
16
+ import { ResizeElement } from '../ResizeElement';
10
17
  export interface MenuItem {
11
18
  id?: string;
12
19
  vanity_id?: string;
@@ -53,7 +60,7 @@ const findItem = (
53
60
  return { item: null, index: -1 };
54
61
  };
55
62
 
56
- export class TembaMenu extends RapidElement {
63
+ export class TembaMenu extends ResizeElement {
57
64
  static get styles() {
58
65
  return css`
59
66
  :host {
@@ -340,6 +347,78 @@ export class TembaMenu extends RapidElement {
340
347
  overflow-y: scroll;
341
348
  }
342
349
 
350
+ .mobile.root {
351
+ height: 100vh;
352
+ }
353
+
354
+ .mobile.root.fully-collapsed {
355
+ height: initial;
356
+ }
357
+
358
+ .root.fully-collapsed.mobile .level.level-0 {
359
+ flex-direction: row;
360
+ }
361
+
362
+ .root.fully-collapsed.mobile .level.level-0 > .item {
363
+ display: none;
364
+ }
365
+
366
+ .root.fully-collapsed.mobile .level.level-0 .expand-icon {
367
+ max-height: 100%;
368
+ padding: 1em;
369
+ }
370
+
371
+ .mobile.fully-collapsed.root {
372
+ flex-direction: column;
373
+ }
374
+
375
+ .mobile.fully-collapsed.root .level-0 {
376
+ padding-top: 0px !important;
377
+ }
378
+
379
+ .mobile.fully-collapsed .level-1 {
380
+ display: none;
381
+ }
382
+
383
+ .mobile .level-1 {
384
+ flex-grow: 1;
385
+ }
386
+
387
+ .mobile .level-1 .item {
388
+ max-width: inherit;
389
+ min-width: inherit;
390
+ }
391
+
392
+ .mobile .level-1 .section {
393
+ max-width: inherit;
394
+ min-width: inherit;
395
+ }
396
+
397
+ .mobile.fully-collapsed .item {
398
+ }
399
+
400
+ .mobile .expand-icon {
401
+ transition: none;
402
+ transform: rotate(-90deg);
403
+ align-self: center;
404
+ }
405
+
406
+ .mobile.fully-collapsed .level-0 .empty {
407
+ flex-grow: 1;
408
+ }
409
+
410
+ .mobile.fully-collapsed .top-spacer {
411
+ flex-grow: 0;
412
+ }
413
+
414
+ .mobile.fully-collapsed #dd-workspace {
415
+ display: none;
416
+ }
417
+
418
+ .mobile.fully-collapsed .expand-icon {
419
+ transform: none;
420
+ }
421
+
343
422
  .level-2 {
344
423
  background: #fbfbfb;
345
424
  overflow-y: auto;
@@ -733,6 +812,7 @@ export class TembaMenu extends RapidElement {
733
812
  parent,
734
813
  });
735
814
  }
815
+
736
816
  return;
737
817
  }
738
818
 
@@ -760,10 +840,14 @@ export class TembaMenu extends RapidElement {
760
840
  this.handleItemClicked(null, parent);
761
841
  }
762
842
 
763
- if (this.collapsed) {
843
+ if (this.collapsed && !this.isMobile()) {
764
844
  this.collapsed = false;
765
845
  }
766
846
 
847
+ if (this.isMobile()) {
848
+ this.collapsed = true;
849
+ }
850
+
767
851
  if (menuItem.trigger) {
768
852
  this.fireCustomEvent(CustomEventType.ButtonClicked, {
769
853
  item: menuItem,
@@ -1031,10 +1115,7 @@ export class TembaMenu extends RapidElement {
1031
1115
  ${menuItem.level === 0
1032
1116
  ? menuItem.avatar
1033
1117
  ? icon
1034
- : html`<temba-tip
1035
- style="display:flex;"
1036
- text="${menuItem.name}"
1037
- position="right"
1118
+ : html`<temba-tip style="display:flex;" text="${menuItem.name}"
1038
1119
  >${icon}</temba-tip
1039
1120
  >`
1040
1121
  : html`${icon}${collapsedIcon}`}
@@ -1079,6 +1160,7 @@ export class TembaMenu extends RapidElement {
1079
1160
  arrowSize="0"
1080
1161
  drop_align="left"
1081
1162
  mask
1163
+ id="dd-${menuItem.id}"
1082
1164
  >
1083
1165
  <div slot="toggle">${item}</div>
1084
1166
  <div slot="dropdown" style="width:300px;overflow:hidden;">
@@ -1103,18 +1185,20 @@ export class TembaMenu extends RapidElement {
1103
1185
  let items = this.root.items || [];
1104
1186
  const levels = [];
1105
1187
 
1188
+ const expandIcon = this.isMobile() ? Icon.menu : Icon.menu_collapse;
1189
+
1106
1190
  levels.push(
1107
1191
  html`<div class="level level-0 ${this.submenu ? 'hidden' : ''}">
1108
1192
  <div class="top">
1109
1193
  <div class="expand-icon" @click=${this.handleExpand}>
1110
1194
  <temba-icon
1111
- name="${Icon.menu_collapse}"
1112
- class="collapse"
1113
- class="expand"
1195
+ name="${expandIcon}"
1196
+ class="collapse expand"
1114
1197
  size="1.4"
1115
1198
  ></temba-icon>
1116
1199
  </div>
1117
1200
  </div>
1201
+ <div class="top-spacer"></div>
1118
1202
 
1119
1203
  ${items
1120
1204
  .filter(item => !item.bottom)
@@ -1153,6 +1237,8 @@ export class TembaMenu extends RapidElement {
1153
1237
  items = null;
1154
1238
  }
1155
1239
 
1240
+ const collapseIcon = this.isMobile() ? Icon.close : Icon.menu_collapse;
1241
+
1156
1242
  if (items && items.length > 0 && !selected.inline) {
1157
1243
  levels.push(
1158
1244
  html`<div
@@ -1175,8 +1261,8 @@ export class TembaMenu extends RapidElement {
1175
1261
 
1176
1262
  ${index == 0 && !this.collapsed
1177
1263
  ? html`<temba-icon
1178
- name=${Icon.menu_collapse}
1179
- size="1.1"
1264
+ name=${collapseIcon}
1265
+ size="1.5"
1180
1266
  @click=${this.handleCollapse}
1181
1267
  ></temba-icon>`
1182
1268
  : null}
@@ -1203,6 +1289,7 @@ export class TembaMenu extends RapidElement {
1203
1289
  class="${getClasses({
1204
1290
  root: true,
1205
1291
  'fully-collapsed': this.collapsed,
1292
+ mobile: this.isMobile(),
1206
1293
  })}"
1207
1294
  >
1208
1295
  ${levels}
@@ -1,10 +1,10 @@
1
1
  import { PropertyValueMap, css, html } from 'lit';
2
- import { RapidElement } from '../RapidElement';
3
2
  import { getClasses } from '../utils';
4
3
  import { property } from 'lit/decorators.js';
5
4
  import { CustomEventType } from '../interfaces';
5
+ import { ResizeElement } from '../ResizeElement';
6
6
 
7
- export class Resizer extends RapidElement {
7
+ export class Resizer extends ResizeElement {
8
8
  static styles = css`
9
9
  :host {
10
10
  display: block;