@nyaruka/temba-components 0.81.0 → 0.82.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.
- package/CHANGELOG.md +6 -0
- package/dist/temba-components.js +34 -37
- package/dist/temba-components.js.map +1 -1
- package/out-tsc/src/select/Select.js +62 -60
- package/out-tsc/src/select/Select.js.map +1 -1
- package/out-tsc/src/tabpane/Tab.js +11 -11
- package/out-tsc/src/tabpane/Tab.js.map +1 -1
- package/out-tsc/src/tabpane/TabPane.js +49 -34
- package/out-tsc/src/tabpane/TabPane.js.map +1 -1
- package/package.json +1 -1
- package/src/select/Select.ts +70 -66
- package/src/tabpane/Tab.ts +14 -11
- package/src/tabpane/TabPane.ts +59 -36
|
@@ -15,6 +15,7 @@ export class TabPane extends RapidElement {
|
|
|
15
15
|
this.focusedName = false;
|
|
16
16
|
this.index = -1;
|
|
17
17
|
this.refresh = '';
|
|
18
|
+
this.tabs = [];
|
|
18
19
|
}
|
|
19
20
|
static get styles() {
|
|
20
21
|
return css `
|
|
@@ -209,6 +210,10 @@ export class TabPane extends RapidElement {
|
|
|
209
210
|
.check {
|
|
210
211
|
margin-left: 0.4em;
|
|
211
212
|
}
|
|
213
|
+
|
|
214
|
+
.pane {
|
|
215
|
+
display: flex;
|
|
216
|
+
}
|
|
212
217
|
`;
|
|
213
218
|
}
|
|
214
219
|
handleTabClick(event) {
|
|
@@ -217,31 +222,35 @@ export class TabPane extends RapidElement {
|
|
|
217
222
|
event.stopPropagation();
|
|
218
223
|
this.requestUpdate('index');
|
|
219
224
|
}
|
|
225
|
+
handleSlotChange() {
|
|
226
|
+
const tabs = [];
|
|
227
|
+
for (const t of this.children) {
|
|
228
|
+
if (t.tagName === 'TEMBA-TAB') {
|
|
229
|
+
const tab = t;
|
|
230
|
+
tabs.push(tab);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
this.tabs = tabs;
|
|
234
|
+
}
|
|
235
|
+
firstUpdated(changes) {
|
|
236
|
+
super.firstUpdated(changes);
|
|
237
|
+
this.shadowRoot.addEventListener('slotchange', this.handleSlotChange.bind(this));
|
|
238
|
+
}
|
|
220
239
|
updated(changedProperties) {
|
|
221
240
|
super.updated(changedProperties);
|
|
222
|
-
if (changedProperties.has('index')) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
const tab = tabs[i];
|
|
227
|
-
tab.selected = i == this.index;
|
|
228
|
-
if (tab.selected) {
|
|
229
|
-
tab.style.display = 'flex';
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
tab.style.display = 'none';
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
241
|
+
if (changedProperties.has('index') || changedProperties.has('tabs')) {
|
|
242
|
+
this.tabs.forEach((tab, index) => {
|
|
243
|
+
tab.selected = index == this.index;
|
|
244
|
+
});
|
|
236
245
|
this.fireEvent(CustomEventType.ContextChanged);
|
|
237
246
|
}
|
|
238
247
|
// if our current tab is hidden, select the first visible one
|
|
239
|
-
if (this.index >
|
|
240
|
-
const
|
|
241
|
-
if (
|
|
242
|
-
for (let i = 0; i < tabs.length; i++) {
|
|
243
|
-
const
|
|
244
|
-
if (!
|
|
248
|
+
if (this.index > this.tabs.length) {
|
|
249
|
+
const tab = this.tabs[this.index];
|
|
250
|
+
if (tab && tab.hidden) {
|
|
251
|
+
for (let i = 0; i < this.tabs.length; i++) {
|
|
252
|
+
const other = this.tabs[i];
|
|
253
|
+
if (other && !other.hidden) {
|
|
245
254
|
this.index = i;
|
|
246
255
|
return;
|
|
247
256
|
}
|
|
@@ -249,27 +258,30 @@ export class TabPane extends RapidElement {
|
|
|
249
258
|
}
|
|
250
259
|
}
|
|
251
260
|
}
|
|
261
|
+
setTabDetails(index, details) {
|
|
262
|
+
if (index < this.tabs.length) {
|
|
263
|
+
const tab = this.tabs[index];
|
|
264
|
+
tab.count = details.count;
|
|
265
|
+
tab.hidden = details.hidden;
|
|
266
|
+
this.requestUpdate();
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
// not ready yet, set the tab details later
|
|
270
|
+
setTimeout(() => {
|
|
271
|
+
this.setTabDetails(index, details);
|
|
272
|
+
}, 100);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
252
275
|
getCurrentTab() {
|
|
253
|
-
return this.
|
|
276
|
+
return this.tabs[this.index];
|
|
254
277
|
}
|
|
255
278
|
getTab(index) {
|
|
256
|
-
return this.
|
|
279
|
+
return this.tabs[index];
|
|
257
280
|
}
|
|
258
281
|
handleTabContentChanged() {
|
|
259
282
|
this.requestUpdate();
|
|
260
283
|
}
|
|
261
|
-
getTabs() {
|
|
262
|
-
const tabs = [];
|
|
263
|
-
for (const t of this.children) {
|
|
264
|
-
if (t.tagName === 'TEMBA-TAB') {
|
|
265
|
-
const tab = t;
|
|
266
|
-
tabs.push(tab);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
return tabs;
|
|
270
|
-
}
|
|
271
284
|
render() {
|
|
272
|
-
const tabs = this.getTabs();
|
|
273
285
|
return html `
|
|
274
286
|
${this.bottom
|
|
275
287
|
? html `<div
|
|
@@ -292,7 +304,7 @@ export class TabPane extends RapidElement {
|
|
|
292
304
|
focusedname: this.focusedName,
|
|
293
305
|
})}"
|
|
294
306
|
>
|
|
295
|
-
${tabs.map((tab, index) => html `
|
|
307
|
+
${this.tabs.map((tab, index) => html `
|
|
296
308
|
<div
|
|
297
309
|
@click=${this.handleTabClick}
|
|
298
310
|
data-index=${index}
|
|
@@ -365,4 +377,7 @@ __decorate([
|
|
|
365
377
|
__decorate([
|
|
366
378
|
property({ type: String })
|
|
367
379
|
], TabPane.prototype, "refresh", void 0);
|
|
380
|
+
__decorate([
|
|
381
|
+
property({ type: Array, attribute: false })
|
|
382
|
+
], TabPane.prototype, "tabs", void 0);
|
|
368
383
|
//# sourceMappingURL=TabPane.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TabPane.js","sourceRoot":"","sources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,CAAC,IAAI;KACT,CAAC;IACJ,CAAC;CACF;AArKC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;yCACX;AAGjB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;0CACV;AAIlB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;uCACb;AAIf;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;4CACR;AAGpB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;sCAChB;AAGX;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wCACd","sourcesContent":["import { css, html, TemplateResult } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { CustomEventType } from '../interfaces';\nimport { RapidElement } from '../RapidElement';\nimport { getClasses } from '../utils';\nimport { Tab } from './Tab';\n\nexport class TabPane extends RapidElement {\n static get styles() {\n return css`\n :host {\n display: flex;\n flex-direction: column;\n min-height: 0;\n flex-grow: 1;\n }\n\n .tabs {\n display: flex;\n align-items: stretch;\n }\n\n .tab {\n user-select: none;\n padding: 0.5em 0.7em;\n margin: 0em 0em;\n cursor: pointer;\n display: flex;\n font-size: 1.01em;\n align-items: center;\n border-radius: var(--curvature);\n border-bottom-right-radius: 0px;\n border-bottom-left-radius: 0px;\n border: 0px solid rgba(0, 0, 0, 0.45);\n color: var(--color-text-dark);\n --icon-color: var(--color-text-dark);\n white-space: nowrap;\n transition: all 100ms linear;\n }\n\n .focusedname .tab .name {\n transition: all 0s linear !important;\n }\n\n .focusedname .tab.selected .name {\n transition: all 200ms linear !important;\n }\n\n .tab.hidden {\n display: none;\n }\n\n .tab temba-icon {\n }\n\n .tab .name {\n margin-left: 0.4em;\n max-width: 80px;\n overflow: hidden;\n transition: max-width 500ms ease-in-out, margin 500ms ease-in-out;\n white-space: nowrap;\n text-overflow: ellipsis;\n }\n\n .tab .badge {\n margin-left: 0.4em;\n }\n\n @media (max-width: 900px) {\n .collapses .tab .name {\n max-width: 0px;\n margin: 0;\n }\n }\n\n @media (max-width: 600px) {\n .collapses .tab .badge {\n display: none;\n }\n }\n\n .focusedname .tab.selected {\n transform: none;\n }\n\n .focusedname .tab .name {\n max-width: 0px;\n margin: 0;\n transition: max-width 200ms linear, margin 200ms linear;\n }\n\n .focusedname .tab.selected .name {\n margin-left: 0.4em;\n max-width: 200px;\n }\n\n .tab {\n transform: scale(0.9) translate(0em, -0.05em);\n --icon-color: #aaa;\n color: #aaa;\n }\n\n .tab.selected {\n }\n\n .tab.selected,\n .tab.selected:hover {\n cursor: default;\n box-shadow: 0px -3px 3px 1px rgba(0, 0, 0, 0.02);\n background: var(--focused-tab-color, #fff);\n transform: scale(1) translateY(0em);\n --icon-color: #666;\n color: #666;\n }\n\n .bottom .tab.selected {\n }\n\n .tab:hover {\n --icon-color: #666;\n color: #666;\n background: rgba(0, 0, 0, 0.02);\n }\n\n .pane {\n display: flex;\n flex-direction: column;\n flex-grow: 1;\n background: var(--focused-tab-color, #fff);\n border-radius: var(--curvature);\n box-shadow: var(\n --tabs-shadow,\n rgba(0, 0, 0, 0.1) 0px 1px 3px 0px,\n rgba(0, 0, 0, 0.03) 0px 1px 2px 0px\n );\n min-height: 0;\n }\n\n .pane.first {\n border-top-left-radius: 0px;\n overflow: hidden;\n }\n\n .badge {\n }\n\n .count {\n border-radius: 99px;\n background: rgba(0, 0, 0, 0.05);\n color: rgba(0, 0, 0, 0.5);\n font-size: 0.6em;\n font-weight: 400;\n padding: 0.1em 0.4em;\n min-width: 1em;\n text-align: center;\n }\n\n .notify .count {\n background: var(--color-alert);\n color: #fff;\n }\n\n .bottom.tabs .tab {\n border-radius: 0em;\n }\n\n .bottom.pane {\n border-radius: 0em;\n }\n\n .bottom.pane.first {\n border-bottom-left-radius: 0px;\n }\n\n .bottom .tab.first {\n border-bottom-left-radius: var(--curvature);\n }\n\n .embedded.pane {\n box-shadow: none;\n margin: 0;\n }\n\n .embedded.tabs {\n margin: 0;\n }\n\n .embedded .tab {\n }\n\n .embedded.tabs .tab.selected {\n box-shadow: none !important;\n }\n\n .embedded.pane {\n // padding: 0.3em;\n }\n\n .check {\n margin-left: 0.4em;\n }\n `;\n }\n\n @property({ type: Boolean })\n embedded = false;\n\n @property({ type: Boolean })\n collapses = false;\n\n // are the tabs on the bottom of the pane?\n @property({ type: Boolean })\n bottom = false;\n\n // Only shows the name if the tab is focused\n @property({ type: Boolean })\n focusedName = false;\n\n @property({ type: Number })\n index = -1;\n\n @property({ type: String })\n refresh = '';\n\n private handleTabClick(event: MouseEvent): void {\n this.index = parseInt(\n (event.currentTarget as HTMLDivElement).dataset.index\n );\n event.preventDefault();\n event.stopPropagation();\n this.requestUpdate('index');\n }\n\n public updated(changedProperties: Map<string, any>) {\n super.updated(changedProperties);\n if (changedProperties.has('index')) {\n const tabs = this.getTabs();\n if (tabs.length > this.index) {\n for (let i = 0; i < tabs.length; i++) {\n const tab = tabs[i];\n tab.selected = i == this.index;\n if (tab.selected) {\n tab.style.display = 'flex';\n } else {\n tab.style.display = 'none';\n }\n }\n }\n this.fireEvent(CustomEventType.ContextChanged);\n }\n\n // if our current tab is hidden, select the first visible one\n if (this.index > -1) {\n const tabs = this.getTabs();\n if (this.getTab(this.index).hidden) {\n for (let i = 0; i < tabs.length; i++) {\n const tab = this.getTab(i);\n if (!tab.hidden) {\n this.index = i;\n return;\n }\n }\n }\n }\n }\n\n public getCurrentTab(): Tab {\n return this.getTabs()[this.index];\n }\n\n public getTab(index: number): Tab {\n return this.getTabs()[index];\n }\n\n public handleTabContentChanged() {\n this.requestUpdate();\n }\n\n public getTabs(): Tab[] {\n const tabs: Tab[] = [];\n for (const t of this.children) {\n if (t.tagName === 'TEMBA-TAB') {\n const tab = t as Tab;\n tabs.push(tab);\n }\n }\n return tabs;\n }\n\n public render(): TemplateResult {\n const tabs = this.getTabs();\n\n return html`\n ${this.bottom\n ? html`<div\n class=\"pane ${getClasses({\n first: this.index == 0,\n embedded: this.embedded,\n bottom: this.bottom,\n })}\"\n >\n <slot></slot>\n </div>`\n : null}\n\n <div\n class=\"tabs ${getClasses({\n tabs: true,\n bottom: this.bottom,\n collapses: this.collapses,\n embedded: this.embedded,\n focusedname: this.focusedName,\n })}\"\n >\n ${tabs.map(\n (tab, index) => html`\n <div\n @click=${this.handleTabClick}\n data-index=${index}\n class=\"${getClasses({\n tab: true,\n first: index == 0,\n selected: index == this.index,\n hidden: tab.hidden,\n notify: tab.notify,\n })}\"\n style=\"${tab.selectionColor && index == this.index\n ? `color:${tab.selectionColor};--icon-color:${tab.selectionColor};`\n : ''} ${tab.selectionBackground && index == this.index\n ? `background-color:${tab.selectionBackground};`\n : ''}\"\n >\n ${tab.icon ? html`<temba-icon name=${tab.icon} />` : null}\n <div class=\"name\">${tab.name}</div>\n ${tab.hasBadge()\n ? html`\n <div class=\"badge\">\n ${tab.count > 0\n ? html`<div class=\"count\">\n ${tab.count.toLocaleString()}\n </div>`\n : null}\n </div>\n `\n : null}\n ${tab.checked\n ? html`<temba-icon class=\"check\" name=\"check\"></temba-icon>`\n : null}\n </div>\n `\n )}\n\n <div style=\"flex-grow:1\"></div>\n <div style=\"display:flex; align-items:center\">\n <slot name=\"tab-right\"></slot>\n </div>\n </div>\n ${!this.bottom\n ? html`<div\n class=\"pane ${getClasses({\n first: this.index == 0,\n embedded: this.embedded,\n bottom: this.bottom,\n })}\"\n >\n <slot></slot>\n </div>`\n : null}\n `;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TabPane.js","sourceRoot":"","sources":["../../../src/tabpane/TabPane.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAoC,MAAM,KAAK,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,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BACvB,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,CAAC;gBACtB,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,MAAM,EAAE,IAAI,CAAC,MAAM;aACpB,CAAC;;;iBAGG;YACT,CAAC,CAAC,IAAI;KACT,CAAC;IACJ,CAAC;CACF;AAxLC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;yCACX;AAGjB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;0CACV;AAIlB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;uCACb;AAIf;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;4CACR;AAGpB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;sCAChB;AAGX;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wCACd;AAGb;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;qCAC3B","sourcesContent":["import { css, html, PropertyValueMap, TemplateResult } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { CustomEventType } from '../interfaces';\nimport { RapidElement } from '../RapidElement';\nimport { getClasses } from '../utils';\nimport { Tab } from './Tab';\n\nexport class TabPane extends RapidElement {\n static get styles() {\n return css`\n :host {\n display: flex;\n flex-direction: column;\n min-height: 0;\n flex-grow: 1;\n }\n\n .tabs {\n display: flex;\n align-items: stretch;\n }\n\n .tab {\n user-select: none;\n padding: 0.5em 0.7em;\n margin: 0em 0em;\n cursor: pointer;\n display: flex;\n font-size: 1.01em;\n align-items: center;\n border-radius: var(--curvature);\n border-bottom-right-radius: 0px;\n border-bottom-left-radius: 0px;\n border: 0px solid rgba(0, 0, 0, 0.45);\n color: var(--color-text-dark);\n --icon-color: var(--color-text-dark);\n white-space: nowrap;\n transition: all 100ms linear;\n }\n\n .focusedname .tab .name {\n transition: all 0s linear !important;\n }\n\n .focusedname .tab.selected .name {\n transition: all 200ms linear !important;\n }\n\n .tab.hidden {\n display: none;\n }\n\n .tab temba-icon {\n }\n\n .tab .name {\n margin-left: 0.4em;\n max-width: 80px;\n overflow: hidden;\n transition: max-width 500ms ease-in-out, margin 500ms ease-in-out;\n white-space: nowrap;\n text-overflow: ellipsis;\n }\n\n .tab .badge {\n margin-left: 0.4em;\n }\n\n @media (max-width: 900px) {\n .collapses .tab .name {\n max-width: 0px;\n margin: 0;\n }\n }\n\n @media (max-width: 600px) {\n .collapses .tab .badge {\n display: none;\n }\n }\n\n .focusedname .tab.selected {\n transform: none;\n }\n\n .focusedname .tab .name {\n max-width: 0px;\n margin: 0;\n transition: max-width 200ms linear, margin 200ms linear;\n }\n\n .focusedname .tab.selected .name {\n margin-left: 0.4em;\n max-width: 200px;\n }\n\n .tab {\n transform: scale(0.9) translate(0em, -0.05em);\n --icon-color: #aaa;\n color: #aaa;\n }\n\n .tab.selected {\n }\n\n .tab.selected,\n .tab.selected:hover {\n cursor: default;\n box-shadow: 0px -3px 3px 1px rgba(0, 0, 0, 0.02);\n background: var(--focused-tab-color, #fff);\n transform: scale(1) translateY(0em);\n --icon-color: #666;\n color: #666;\n }\n\n .bottom .tab.selected {\n }\n\n .tab:hover {\n --icon-color: #666;\n color: #666;\n background: rgba(0, 0, 0, 0.02);\n }\n\n .pane {\n display: flex;\n flex-direction: column;\n flex-grow: 1;\n background: var(--focused-tab-color, #fff);\n border-radius: var(--curvature);\n box-shadow: var(\n --tabs-shadow,\n rgba(0, 0, 0, 0.1) 0px 1px 3px 0px,\n rgba(0, 0, 0, 0.03) 0px 1px 2px 0px\n );\n min-height: 0;\n }\n\n .pane.first {\n border-top-left-radius: 0px;\n overflow: hidden;\n }\n\n .badge {\n }\n\n .count {\n border-radius: 99px;\n background: rgba(0, 0, 0, 0.05);\n color: rgba(0, 0, 0, 0.5);\n font-size: 0.6em;\n font-weight: 400;\n padding: 0.1em 0.4em;\n min-width: 1em;\n text-align: center;\n }\n\n .notify .count {\n background: var(--color-alert);\n color: #fff;\n }\n\n .bottom.tabs .tab {\n border-radius: 0em;\n }\n\n .bottom.pane {\n border-radius: 0em;\n }\n\n .bottom.pane.first {\n border-bottom-left-radius: 0px;\n }\n\n .bottom .tab.first {\n border-bottom-left-radius: var(--curvature);\n }\n\n .embedded.pane {\n box-shadow: none;\n margin: 0;\n }\n\n .embedded.tabs {\n margin: 0;\n }\n\n .embedded .tab {\n }\n\n .embedded.tabs .tab.selected {\n box-shadow: none !important;\n }\n\n .embedded.pane {\n // padding: 0.3em;\n }\n\n .check {\n margin-left: 0.4em;\n }\n\n .pane {\n display: flex;\n }\n `;\n }\n\n @property({ type: Boolean })\n embedded = false;\n\n @property({ type: Boolean })\n collapses = false;\n\n // are the tabs on the bottom of the pane?\n @property({ type: Boolean })\n bottom = false;\n\n // Only shows the name if the tab is focused\n @property({ type: Boolean })\n focusedName = false;\n\n @property({ type: Number })\n index = -1;\n\n @property({ type: String })\n refresh = '';\n\n @property({ type: Array, attribute: false })\n tabs: Tab[] = [];\n\n private handleTabClick(event: MouseEvent): void {\n this.index = parseInt(\n (event.currentTarget as HTMLDivElement).dataset.index\n );\n event.preventDefault();\n event.stopPropagation();\n this.requestUpdate('index');\n }\n\n public handleSlotChange() {\n const tabs: Tab[] = [];\n for (const t of this.children) {\n if (t.tagName === 'TEMBA-TAB') {\n const tab = t as Tab;\n tabs.push(tab);\n }\n }\n this.tabs = tabs;\n }\n\n public firstUpdated(\n changes: PropertyValueMap<any> | Map<PropertyKey, unknown>\n ): void {\n super.firstUpdated(changes);\n this.shadowRoot.addEventListener(\n 'slotchange',\n this.handleSlotChange.bind(this)\n );\n }\n\n public updated(changedProperties: Map<string, any>) {\n super.updated(changedProperties);\n if (changedProperties.has('index') || changedProperties.has('tabs')) {\n this.tabs.forEach((tab, index) => {\n tab.selected = index == this.index;\n });\n this.fireEvent(CustomEventType.ContextChanged);\n }\n\n // if our current tab is hidden, select the first visible one\n if (this.index > this.tabs.length) {\n const tab = this.tabs[this.index];\n if (tab && tab.hidden) {\n for (let i = 0; i < this.tabs.length; i++) {\n const other = this.tabs[i];\n if (other && !other.hidden) {\n this.index = i;\n return;\n }\n }\n }\n }\n }\n\n public setTabDetails(\n index: number,\n details: { count: number; hidden: boolean }\n ) {\n if (index < this.tabs.length) {\n const tab = this.tabs[index];\n tab.count = details.count;\n tab.hidden = details.hidden;\n this.requestUpdate();\n } else {\n // not ready yet, set the tab details later\n setTimeout(() => {\n this.setTabDetails(index, details);\n }, 100);\n }\n }\n\n public getCurrentTab(): Tab {\n return this.tabs[this.index];\n }\n\n public getTab(index: number): Tab {\n return this.tabs[index];\n }\n\n public handleTabContentChanged() {\n this.requestUpdate();\n }\n\n public render(): TemplateResult {\n return html`\n ${this.bottom\n ? html`<div\n class=\"pane ${getClasses({\n first: this.index == 0,\n embedded: this.embedded,\n bottom: this.bottom,\n })}\"\n >\n <slot></slot>\n </div>`\n : null}\n\n <div\n class=\"tabs ${getClasses({\n tabs: true,\n bottom: this.bottom,\n collapses: this.collapses,\n embedded: this.embedded,\n focusedname: this.focusedName,\n })}\"\n >\n ${this.tabs.map(\n (tab, index) => html`\n <div\n @click=${this.handleTabClick}\n data-index=${index}\n class=\"${getClasses({\n tab: true,\n first: index == 0,\n selected: index == this.index,\n hidden: tab.hidden,\n notify: tab.notify,\n })}\"\n style=\"${tab.selectionColor && index == this.index\n ? `color:${tab.selectionColor};--icon-color:${tab.selectionColor};`\n : ''} ${tab.selectionBackground && index == this.index\n ? `background-color:${tab.selectionBackground};`\n : ''}\"\n >\n ${tab.icon ? html`<temba-icon name=${tab.icon} />` : null}\n <div class=\"name\">${tab.name}</div>\n ${tab.hasBadge()\n ? html`\n <div class=\"badge\">\n ${tab.count > 0\n ? html`<div class=\"count\">\n ${tab.count.toLocaleString()}\n </div>`\n : null}\n </div>\n `\n : null}\n ${tab.checked\n ? html`<temba-icon class=\"check\" name=\"check\"></temba-icon>`\n : null}\n </div>\n `\n )}\n\n <div style=\"flex-grow:1\"></div>\n <div style=\"display:flex; align-items:center\">\n <slot name=\"tab-right\"></slot>\n </div>\n </div>\n ${!this.bottom\n ? html`<div\n class=\"pane ${getClasses({\n first: this.index == 0,\n embedded: this.embedded,\n bottom: this.bottom,\n })}\"\n >\n <slot></slot>\n </div>`\n : null}\n `;\n }\n}\n"]}
|
package/package.json
CHANGED
package/src/select/Select.ts
CHANGED
|
@@ -508,6 +508,75 @@ export class Select extends FormElement {
|
|
|
508
508
|
|
|
509
509
|
private lruCache = lru(20, 60000);
|
|
510
510
|
|
|
511
|
+
public handleSlotChange() {
|
|
512
|
+
if (this.staticOptions.length === 0) {
|
|
513
|
+
for (const child of this.children) {
|
|
514
|
+
if (child.tagName === 'TEMBA-OPTION') {
|
|
515
|
+
const option: any = {};
|
|
516
|
+
for (const attribute of child.attributes) {
|
|
517
|
+
option[attribute.name] = attribute.value;
|
|
518
|
+
}
|
|
519
|
+
this.staticOptions.push(option);
|
|
520
|
+
|
|
521
|
+
if (
|
|
522
|
+
child.getAttribute('selected') !== null ||
|
|
523
|
+
this.getValue(option) == this.value
|
|
524
|
+
) {
|
|
525
|
+
if (this.getAttribute('multi') !== null) {
|
|
526
|
+
this.addValue(option);
|
|
527
|
+
} else {
|
|
528
|
+
this.setValues([option]);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
public firstUpdated(changedProperties: any) {
|
|
537
|
+
super.firstUpdated(changedProperties);
|
|
538
|
+
this.anchorElement = this.shadowRoot.querySelector('.select-container');
|
|
539
|
+
this.anchorExpressions = this.shadowRoot.querySelector('#anchor');
|
|
540
|
+
this.shadowRoot.addEventListener(
|
|
541
|
+
'slotchange',
|
|
542
|
+
this.handleSlotChange.bind(this)
|
|
543
|
+
);
|
|
544
|
+
|
|
545
|
+
this.handleSlotChange();
|
|
546
|
+
if (this.values.length === 0 && (!this.placeholder || this.value)) {
|
|
547
|
+
if (this.staticOptions.length == 0 && this.endpoint) {
|
|
548
|
+
const value = this.value;
|
|
549
|
+
// see if we need fetch to select an option
|
|
550
|
+
fetchResults(this.endpoint).then((results: any) => {
|
|
551
|
+
if (results && results.length > 0) {
|
|
552
|
+
if (value) {
|
|
553
|
+
// if we started with a value, see if we can find it in the results
|
|
554
|
+
const existing = results.find(option => {
|
|
555
|
+
return this.getValue(option) === value;
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
if (existing) {
|
|
559
|
+
this.setValues([existing]);
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
this.setValues([results[0]]);
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
} else {
|
|
567
|
+
if (this.getAttribute('multi') !== null) {
|
|
568
|
+
this.addValue(this.staticOptions[0]);
|
|
569
|
+
} else {
|
|
570
|
+
this.setValues([this.staticOptions[0]]);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
if (this.searchable && this.staticOptions.length === 0) {
|
|
576
|
+
this.quietMillis = 200;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
511
580
|
public updated(changedProperties: Map<string, any>) {
|
|
512
581
|
super.updated(changedProperties);
|
|
513
582
|
|
|
@@ -1111,70 +1180,6 @@ export class Select extends FormElement {
|
|
|
1111
1180
|
];
|
|
1112
1181
|
}
|
|
1113
1182
|
|
|
1114
|
-
public firstUpdated(changedProperties: any) {
|
|
1115
|
-
super.firstUpdated(changedProperties);
|
|
1116
|
-
|
|
1117
|
-
this.anchorElement = this.shadowRoot.querySelector('.select-container');
|
|
1118
|
-
this.anchorExpressions = this.shadowRoot.querySelector('#anchor');
|
|
1119
|
-
|
|
1120
|
-
// wait until children are created before adding our static options
|
|
1121
|
-
const value = this.value;
|
|
1122
|
-
window.setTimeout(() => {
|
|
1123
|
-
for (const child of this.children) {
|
|
1124
|
-
if (child.tagName === 'TEMBA-OPTION') {
|
|
1125
|
-
const option: any = {};
|
|
1126
|
-
for (const attribute of child.attributes) {
|
|
1127
|
-
option[attribute.name] = attribute.value;
|
|
1128
|
-
}
|
|
1129
|
-
this.staticOptions.push(option);
|
|
1130
|
-
|
|
1131
|
-
if (
|
|
1132
|
-
child.getAttribute('selected') !== null ||
|
|
1133
|
-
this.getValue(option) == this.value
|
|
1134
|
-
) {
|
|
1135
|
-
if (this.getAttribute('multi') !== null) {
|
|
1136
|
-
this.addValue(option);
|
|
1137
|
-
} else {
|
|
1138
|
-
this.setValues([option]);
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
if (this.values.length === 0 && (!this.placeholder || value)) {
|
|
1145
|
-
if (this.staticOptions.length == 0 && this.endpoint) {
|
|
1146
|
-
// see if we need to auto select the first item but need to fetch it
|
|
1147
|
-
fetchResults(this.endpoint).then((results: any) => {
|
|
1148
|
-
if (results && results.length > 0) {
|
|
1149
|
-
if (value) {
|
|
1150
|
-
// if we started with a value, see if we can find it in the results
|
|
1151
|
-
const existing = results.find(option => {
|
|
1152
|
-
return this.getValue(option) === value;
|
|
1153
|
-
});
|
|
1154
|
-
|
|
1155
|
-
if (existing) {
|
|
1156
|
-
this.setValues([existing]);
|
|
1157
|
-
return;
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
this.setValues([results[0]]);
|
|
1161
|
-
}
|
|
1162
|
-
});
|
|
1163
|
-
} else {
|
|
1164
|
-
if (this.getAttribute('multi') !== null) {
|
|
1165
|
-
this.addValue(this.staticOptions[0]);
|
|
1166
|
-
} else {
|
|
1167
|
-
this.setValues([this.staticOptions[0]]);
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
|
-
if (this.searchable && this.staticOptions.length === 0) {
|
|
1173
|
-
this.quietMillis = 200;
|
|
1174
|
-
}
|
|
1175
|
-
}, 100);
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
1183
|
private handleArrowClick(event: MouseEvent): void {
|
|
1179
1184
|
if (this.visibleOptions.length > 0) {
|
|
1180
1185
|
this.visibleOptions = [];
|
|
@@ -1317,8 +1322,7 @@ export class Select extends FormElement {
|
|
|
1317
1322
|
.hideErrors=${this.hideErrors}
|
|
1318
1323
|
?disabled=${this.disabled}
|
|
1319
1324
|
>
|
|
1320
|
-
|
|
1321
|
-
|
|
1325
|
+
<slot></slot>
|
|
1322
1326
|
<div class="wrapper-bg">
|
|
1323
1327
|
<div
|
|
1324
1328
|
tabindex="0"
|
package/src/tabpane/Tab.ts
CHANGED
|
@@ -7,20 +7,14 @@ export class Tab extends RapidElement {
|
|
|
7
7
|
static get styles() {
|
|
8
8
|
return css`
|
|
9
9
|
:host {
|
|
10
|
-
display:
|
|
10
|
+
display: none;
|
|
11
11
|
flex-direction: column;
|
|
12
|
-
flex-grow: 1;
|
|
13
12
|
min-height: 0;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
slot {
|
|
17
|
-
// display: none;
|
|
18
|
-
|
|
13
|
+
}
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// flex-grow: 1;
|
|
15
|
+
:host(.selected) {
|
|
16
|
+
display: flex;
|
|
17
|
+
flex-grow: 1;
|
|
24
18
|
}
|
|
25
19
|
`;
|
|
26
20
|
}
|
|
@@ -52,6 +46,15 @@ export class Tab extends RapidElement {
|
|
|
52
46
|
@property({ type: Boolean })
|
|
53
47
|
checked = false;
|
|
54
48
|
|
|
49
|
+
public updated(
|
|
50
|
+
changes: PropertyValueMap<any> | Map<PropertyKey, unknown>
|
|
51
|
+
): void {
|
|
52
|
+
super.updated(changes);
|
|
53
|
+
if (changes.has('selected')) {
|
|
54
|
+
this.classList.toggle('selected', this.selected);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
55
58
|
public hasBadge() {
|
|
56
59
|
return this.count > 0;
|
|
57
60
|
}
|
package/src/tabpane/TabPane.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { css, html, TemplateResult } from 'lit';
|
|
1
|
+
import { css, html, PropertyValueMap, TemplateResult } from 'lit';
|
|
2
2
|
import { property } from 'lit/decorators.js';
|
|
3
3
|
import { CustomEventType } from '../interfaces';
|
|
4
4
|
import { RapidElement } from '../RapidElement';
|
|
@@ -199,6 +199,10 @@ export class TabPane extends RapidElement {
|
|
|
199
199
|
.check {
|
|
200
200
|
margin-left: 0.4em;
|
|
201
201
|
}
|
|
202
|
+
|
|
203
|
+
.pane {
|
|
204
|
+
display: flex;
|
|
205
|
+
}
|
|
202
206
|
`;
|
|
203
207
|
}
|
|
204
208
|
|
|
@@ -222,6 +226,9 @@ export class TabPane extends RapidElement {
|
|
|
222
226
|
@property({ type: String })
|
|
223
227
|
refresh = '';
|
|
224
228
|
|
|
229
|
+
@property({ type: Array, attribute: false })
|
|
230
|
+
tabs: Tab[] = [];
|
|
231
|
+
|
|
225
232
|
private handleTabClick(event: MouseEvent): void {
|
|
226
233
|
this.index = parseInt(
|
|
227
234
|
(event.currentTarget as HTMLDivElement).dataset.index
|
|
@@ -231,31 +238,43 @@ export class TabPane extends RapidElement {
|
|
|
231
238
|
this.requestUpdate('index');
|
|
232
239
|
}
|
|
233
240
|
|
|
241
|
+
public handleSlotChange() {
|
|
242
|
+
const tabs: Tab[] = [];
|
|
243
|
+
for (const t of this.children) {
|
|
244
|
+
if (t.tagName === 'TEMBA-TAB') {
|
|
245
|
+
const tab = t as Tab;
|
|
246
|
+
tabs.push(tab);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
this.tabs = tabs;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
public firstUpdated(
|
|
253
|
+
changes: PropertyValueMap<any> | Map<PropertyKey, unknown>
|
|
254
|
+
): void {
|
|
255
|
+
super.firstUpdated(changes);
|
|
256
|
+
this.shadowRoot.addEventListener(
|
|
257
|
+
'slotchange',
|
|
258
|
+
this.handleSlotChange.bind(this)
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
234
262
|
public updated(changedProperties: Map<string, any>) {
|
|
235
263
|
super.updated(changedProperties);
|
|
236
|
-
if (changedProperties.has('index')) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
const tab = tabs[i];
|
|
241
|
-
tab.selected = i == this.index;
|
|
242
|
-
if (tab.selected) {
|
|
243
|
-
tab.style.display = 'flex';
|
|
244
|
-
} else {
|
|
245
|
-
tab.style.display = 'none';
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
264
|
+
if (changedProperties.has('index') || changedProperties.has('tabs')) {
|
|
265
|
+
this.tabs.forEach((tab, index) => {
|
|
266
|
+
tab.selected = index == this.index;
|
|
267
|
+
});
|
|
249
268
|
this.fireEvent(CustomEventType.ContextChanged);
|
|
250
269
|
}
|
|
251
270
|
|
|
252
271
|
// if our current tab is hidden, select the first visible one
|
|
253
|
-
if (this.index >
|
|
254
|
-
const
|
|
255
|
-
if (
|
|
256
|
-
for (let i = 0; i < tabs.length; i++) {
|
|
257
|
-
const
|
|
258
|
-
if (!
|
|
272
|
+
if (this.index > this.tabs.length) {
|
|
273
|
+
const tab = this.tabs[this.index];
|
|
274
|
+
if (tab && tab.hidden) {
|
|
275
|
+
for (let i = 0; i < this.tabs.length; i++) {
|
|
276
|
+
const other = this.tabs[i];
|
|
277
|
+
if (other && !other.hidden) {
|
|
259
278
|
this.index = i;
|
|
260
279
|
return;
|
|
261
280
|
}
|
|
@@ -264,32 +283,36 @@ export class TabPane extends RapidElement {
|
|
|
264
283
|
}
|
|
265
284
|
}
|
|
266
285
|
|
|
286
|
+
public setTabDetails(
|
|
287
|
+
index: number,
|
|
288
|
+
details: { count: number; hidden: boolean }
|
|
289
|
+
) {
|
|
290
|
+
if (index < this.tabs.length) {
|
|
291
|
+
const tab = this.tabs[index];
|
|
292
|
+
tab.count = details.count;
|
|
293
|
+
tab.hidden = details.hidden;
|
|
294
|
+
this.requestUpdate();
|
|
295
|
+
} else {
|
|
296
|
+
// not ready yet, set the tab details later
|
|
297
|
+
setTimeout(() => {
|
|
298
|
+
this.setTabDetails(index, details);
|
|
299
|
+
}, 100);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
267
303
|
public getCurrentTab(): Tab {
|
|
268
|
-
return this.
|
|
304
|
+
return this.tabs[this.index];
|
|
269
305
|
}
|
|
270
306
|
|
|
271
307
|
public getTab(index: number): Tab {
|
|
272
|
-
return this.
|
|
308
|
+
return this.tabs[index];
|
|
273
309
|
}
|
|
274
310
|
|
|
275
311
|
public handleTabContentChanged() {
|
|
276
312
|
this.requestUpdate();
|
|
277
313
|
}
|
|
278
314
|
|
|
279
|
-
public getTabs(): Tab[] {
|
|
280
|
-
const tabs: Tab[] = [];
|
|
281
|
-
for (const t of this.children) {
|
|
282
|
-
if (t.tagName === 'TEMBA-TAB') {
|
|
283
|
-
const tab = t as Tab;
|
|
284
|
-
tabs.push(tab);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
return tabs;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
315
|
public render(): TemplateResult {
|
|
291
|
-
const tabs = this.getTabs();
|
|
292
|
-
|
|
293
316
|
return html`
|
|
294
317
|
${this.bottom
|
|
295
318
|
? html`<div
|
|
@@ -312,7 +335,7 @@ export class TabPane extends RapidElement {
|
|
|
312
335
|
focusedname: this.focusedName,
|
|
313
336
|
})}"
|
|
314
337
|
>
|
|
315
|
-
${tabs.map(
|
|
338
|
+
${this.tabs.map(
|
|
316
339
|
(tab, index) => html`
|
|
317
340
|
<div
|
|
318
341
|
@click=${this.handleTabClick}
|