Skip to content

Commit f473005

Browse files
committed
Tidy zn-tabs
1 parent db2a644 commit f473005

File tree

2 files changed

+102
-45
lines changed

2 files changed

+102
-45
lines changed

docs/pages/getting-started/example-page.md

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ for SEO purposes. We should be slotting everything in as children of the compone
3939
<zn-tabs flush primary-caption="Navigation" secondary-caption="Content">
4040
4141
<!-- This is the Navigation/Header for the Inner set of tabs -->
42-
<zn-header slot="top" caption="Customer" description="My Awesome Customer"
42+
<zn-header slot="top"
43+
caption="Customer"
44+
description="My Awesome Customer"
4345
navigation="[{&quot;title&quot;:&quot;Overview&quot;}, {&quot;title&quot;:&quot;Details&quot;, &quot;tab&quot;:&quot;details&quot;}]">
4446
</zn-header>
4547
@@ -64,6 +66,11 @@ for SEO purposes. We should be slotting everything in as children of the compone
6466
<!-- This is the content of the second tab -->
6567
<div id="2">
6668
<zn-pane>
69+
<zn-header slot="top"
70+
caption="Customer"
71+
description="My Awesome Customer"
72+
navigation="[{&quot;title&quot;:&quot;Overview&quot;}, {&quot;title&quot;:&quot;Details&quot;, &quot;tab&quot;:&quot;details&quot;}]">
73+
</zn-header>
6774
<!-- This is where your page content would be defined -->
6875
<zn-sp> <!-- Maybe zn-sp should be defaulted into the content? -->
6976
<zn-panel caption="Number 2">Something Something Darkside</zn-panel>
@@ -73,4 +80,80 @@ for SEO purposes. We should be slotting everything in as children of the compone
7380
7481
</zn-tabs>
7582
83+
```
84+
85+
## What we want it to look like
86+
87+
Ideally we want to merge `zn-panel` and `zn-tabs` into a single component, this is because they are both used to define
88+
the layout of the page but act in different ways.
89+
90+
We can used `tabbed` on the `zn-panel` component to define that it should be a tabbed layout, and then use the
91+
`zn-navbar` component to define the navigation for the tabs. We should remove the navigation attribute from the
92+
`zn-header` component and instead use the `zn-navbar` component to define the navigation for the inner tabs.
93+
94+
```html:preview
95+
96+
<style>
97+
.code-preview__preview {
98+
background-color: rgb(var(--zn-body)) !important;
99+
padding: 0 25px 0 0;
100+
}
101+
</style>
102+
103+
<zn-panel tabbed flush primary-caption="Navigation" secondary-caption="content">
104+
105+
<!-- This is the navigation for the first set of tabs -->
106+
<!-- highlight should change from highlight to pill-bar or something similar -->
107+
<zn-navbar slot="top"
108+
highlight
109+
navigation="[{&quot;title&quot;:&quot;John Doe&quot;,&quot;active&quot;:false,&quot;hintText&quot;:&quot;Overview&quot;,&quot;launchMode&quot;:&quot;page&quot;}]"
110+
dropdown="[{&quot;tab&quot;:&quot;2&quot;,&quot;title&quot;:&quot;Some Actions&quot;,&quot;type&quot;:&quot;dropdown&quot;}]">
111+
</zn-navbar>
112+
113+
<!-- This is the content of the first tab / default -->
114+
<!-- Can probably remove flush as they should all be by default -->
115+
<zn-panel flush tabbed primary-caption="Navigation" secondary-caption="Content">
116+
117+
<!-- This is the Navigation/Header for the Inner set of tabs -->
118+
<zn-header slot="top"
119+
caption="Customer"
120+
description="My Awesome Customer"
121+
navigation="[{&quot;title&quot;:&quot;Overview&quot;}, {&quot;title&quot;:&quot;Details&quot;, &quot;tab&quot;:&quot;details&quot;}]">
122+
</zn-header>
123+
124+
<!--This is the content of the first tab / default inside the first tab -->
125+
<div>
126+
<!-- This is where your page content would be defined -->
127+
<zn-sp>
128+
<zn-panel caption="Something">Data Points</zn-panel>
129+
<zn-panel caption="Another Thing">Other Points</zn-panel>
130+
</zn-sp>
131+
</div>
132+
133+
<!--This is the content of the second tab inside the first tab -->
134+
<div id="details">
135+
<!-- This is where your page content would be defined -->
136+
<zn-sp>
137+
<zn-panel caption="Awesome">this is an example of the details tab</zn-panel>
138+
</zn-sp>
139+
</div>
140+
</zn-panel>
141+
142+
<!-- This is the content of the second tab -->
143+
<div id="2">
144+
<zn-pane>
145+
<zn-header slot="top"
146+
caption="Customer"
147+
description="My Awesome Customer"
148+
navigation="[{&quot;title&quot;:&quot;Overview&quot;}, {&quot;title&quot;:&quot;Details&quot;, &quot;tab&quot;:&quot;details&quot;}]">
149+
</zn-header>
150+
<!-- This is where your page content would be defined -->
151+
<zn-sp> <!-- Maybe zn-sp should be defaulted into the content? -->
152+
<zn-panel caption="Number 2">Something Something Darkside</zn-panel>
153+
</zn-sp>
154+
</zn-pane>
155+
</div>
156+
157+
</zn-panel>
158+
76159
```

src/components/tabs/tabs.component.ts

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {Store} from "../../internal/storage";
77
import ZincElement from '../../internal/zinc-element';
88

99
import styles from './tabs.scss';
10-
import {HasSlotController} from "../../internal/slot";
1110

1211
/**
1312
* @summary Short summary of the component's intended use.
@@ -29,25 +28,15 @@ import {HasSlotController} from "../../internal/slot";
2928
export default class ZnTabs extends ZincElement {
3029
static styles: CSSResultGroup = unsafeCSS(styles);
3130

32-
private readonly hasSlotController = new HasSlotController(this, '[default]', 'actions', 'footer');
33-
3431
private _panel: HTMLElement | any;
3532
private _panels: Map<string, Element[]>;
3633
private _tabs: HTMLElement[] = [];
3734
private _actions: HTMLElement[] = [];
3835
private _knownUri: Map<string, string> = new Map<string, string>();
39-
// @ts-expect-error
40-
private storage: Storage;
4136

4237
@property({attribute: 'master-id', reflect: true}) masterId: string;
4338
@property({attribute: 'default-uri', type: String, reflect: true}) defaultUri = '';
4439

45-
@property() caption: string;
46-
47-
@property() description: string;
48-
49-
@property({attribute: 'header', type: String, reflect: true}) header = '';
50-
5140
@property({attribute: 'active', type: String, reflect: true}) _current = '';
5241
@property({attribute: 'split', type: Number, reflect: true}) _split: any;
5342
@property({attribute: 'split-min', type: Number, reflect: true}) _splitMin = 60;
@@ -58,7 +47,7 @@ export default class ZnTabs extends ZincElement {
5847
@property({attribute: 'no-prefetch', type: Boolean, reflect: true}) noPrefetch = false;
5948
// session storage if not local
6049
@property({attribute: 'local-storage', type: Boolean, reflect: true}) localStorage: boolean;
61-
@property({attribute: 'store-key'}) storeKey: any = null;
50+
@property({attribute: 'store-key'}) storeKey: string | null = null;
6251
@property({attribute: 'store-ttl', type: Number, reflect: true}) storeTtl = 0;
6352

6453
@property({attribute: 'padded', type: Boolean, reflect: true}) padded = false;
@@ -151,26 +140,22 @@ export default class ZnTabs extends ZincElement {
151140
}, 10);
152141

153142
this.addEventListener('zn-menu-select', () => {
154-
setTimeout(() => {
155-
this.reRegisterTabs()
156-
}, 200);
143+
setTimeout(this.reRegisterTabs, 200);
157144
}, {passive: true});
158145
}
159146

160147
_prepareTab(tabId: string) {
161-
for (let i = 0; i < this._tabs.length; i++)
162-
for (let i = 0; i < this._tabs.length; i++) {
163-
if (this._tabs[i].getAttribute('tab') == tabId) {
164-
return;
165-
}
148+
for (const tab of this._tabs) {
149+
if (tab.getAttribute('tab') === tabId) {
150+
return;
166151
}
152+
}
167153

168-
const uriTabs = deepQuerySelectorAll("[tab-uri]", this, '');
169-
for (let i = 0; i < uriTabs.length; i++) {
170-
const uri: any = uriTabs[i].getAttribute("tab-uri");
154+
for (const uriTab of deepQuerySelectorAll("[tab-uri]", this, '')) {
155+
const uri: string = uriTab.getAttribute("tab-uri")!;
171156
const eleTabId = this._uriToId(uri);
172157
if (eleTabId === tabId) {
173-
this._createUriPanel(uriTabs[i], uri, eleTabId);
158+
this._createUriPanel(uriTab, uri, eleTabId);
174159
// do not break, as multiple tabs can have the same uri
175160
}
176161
}
@@ -352,13 +337,15 @@ export default class ZnTabs extends ZincElement {
352337
if (this._panels.has(tabId)) {
353338
this._panels.delete(tabId);
354339
}
355-
for (let j = 0; j < this._tabs.length; j++) {
356-
if (this._tabs[j].getAttribute('tab') == tabId) {
357-
this._tabs[j].remove();
358-
this._tabs.splice(j, 1);
340+
341+
for (const tab of this._tabs) {
342+
if (tab.getAttribute('tab') === tabId) {
343+
tab.remove();
344+
this._tabs.splice(this._tabs.indexOf(tab), 1);
359345
}
360346
}
361-
if (this._current == tabId) {
347+
348+
if (this._current === tabId) {
362349
this.setActiveTab('', true, false);
363350
}
364351
}
@@ -367,6 +354,7 @@ export default class ZnTabs extends ZincElement {
367354
deepQuerySelectorAll('[tab]', this, 'zn-tabs').forEach(ele => {
368355
this._addTab(ele as HTMLElement);
369356
});
357+
370358
deepQuerySelectorAll('[tab-uri]', this, 'zn-tabs').forEach(ele => {
371359
if (ele.getAttribute('tab-uri') === "") {
372360
ele.setAttribute('tab', "");
@@ -386,13 +374,8 @@ export default class ZnTabs extends ZincElement {
386374
}
387375

388376
render() {
389-
const hasActionSlot = this.hasSlotController.test('actions');
390-
const hasHeader = this.header && this.header.length > 0;
391-
const hasCaption = this.caption && this.caption.length > 0;
392-
393-
394377
if (this._split > 0) {
395-
let storeKey: any = this.storeKey;
378+
let storeKey: string | null = this.storeKey;
396379
if (storeKey) {
397380
storeKey += "-split";
398381
}
@@ -426,15 +409,6 @@ export default class ZnTabs extends ZincElement {
426409
}
427410

428411
return html`
429-
${hasHeader || hasCaption || hasActionSlot ? html`
430-
<div id="header">
431-
${hasHeader ? html`<h1>${this.header}</h1>` : ''}
432-
${hasCaption ? html`<h2>${this.caption}</h2>` : ''}
433-
${hasActionSlot ? html`
434-
<div id="actions">
435-
<slot name="actions"></slot>
436-
</div>` : ''}
437-
</div>` : null}
438412
<slot name="top"></slot>
439413
<div id="mid">
440414
<slot name="left"></slot>

0 commit comments

Comments
 (0)