Skip to content

Commit 8ede520

Browse files
committed
Updates to tabs
1 parent 775e4ec commit 8ede520

File tree

4 files changed

+121
-1
lines changed

4 files changed

+121
-1
lines changed

src/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@
4747
</wc-nav>
4848
</wc-sidebar>
4949
<wc-content>
50+
51+
<div class="container">
52+
<h1>Tab Group</h1>
53+
54+
<wc-tab-group backgroundColor="primary">
55+
<wc-tab name="tab-tables" selected>Tables</wc-tab>
56+
<wc-tab name="tab-buttons">Buttons</wc-tab>
57+
<wc-tab name="tab-badges">Badges</wc-tab>
58+
<wc-tab name="tab-icons">Icons</wc-tab>
59+
<wc-tab name="tab-diabled">Disabled</wc-tab>
60+
</wc-tab-group>
61+
</div>
62+
<hr>
63+
5064
<div class="container">
5165
<h1>Tables</h1>
5266

src/nav/TabElement.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,17 @@ export class TabElement extends LitElement {
5353
return css``;
5454
}
5555

56-
// eslint-disable-next-line class-methods-use-this
56+
get className() {
57+
const classes = [];
58+
if (this.selected) {
59+
classes.push('selected');
60+
}
61+
if (this.disabled) {
62+
classes.push('disabled');
63+
}
64+
return classes.join(' ');
65+
}
66+
5767
render() {
5868
return html`
5969
<li class=${this.className || nothing}><slot></slot></li>

src/nav/TabGroupElement.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import {
2+
LitElement, html, css, nothing,
3+
} from 'lit';
4+
5+
/**
6+
* TabGroupElement
7+
* This class is used to create a tab group, which
8+
* displays a tabbed navigation horizontally and allows
9+
* selection of one tab within the group.
10+
*
11+
* @example
12+
* <wc-tab-group>
13+
* <wc-tab name="tab1" selected>Tab1</wc-tab>
14+
* <wc-tab name="tab2">Tab2</wc-tab>
15+
* <wc-tab name="tab3">Tab3</wc-tab>
16+
* <wc-tab name="tab4" disabled>Tab4</wc-tab>
17+
* </wc-tab-group>
18+
*/
19+
export class TabGroupElement extends LitElement {
20+
static get localName() {
21+
return 'wc-tab-group';
22+
}
23+
24+
static get properties() {
25+
return {
26+
27+
/**
28+
* Background color of the tab group, one of primary, secondary, light, white, dark, black
29+
*
30+
* @type {String}
31+
* @default primary
32+
* @memberof TabGroupElement
33+
*/
34+
backgroundColor: { type: String },
35+
36+
/**
37+
* If true, tab group is hidden and takes up no space
38+
*
39+
* @type {Boolean}
40+
* @default false
41+
* @memberof TabGroupElement
42+
*/
43+
hidden: { type: Boolean },
44+
};
45+
}
46+
47+
static get styles() {
48+
return css`
49+
ul {
50+
display: flex;
51+
margin: 0;
52+
border: 0;
53+
padding: 0;
54+
padding-left: 4px;
55+
list-style: none;
56+
border-bottom: 1px solid red;
57+
}
58+
::slotted(wc-tab) {
59+
border: 1px solid red;
60+
border-bottom: none;
61+
padding: 10px;
62+
margin-right: 4px;
63+
border-top-left-radius: 5px;
64+
border-top-right-radius: 5px;
65+
cursor: pointer;
66+
}
67+
ul.bg-color-primary {
68+
border-color: var(--grey-80-color);
69+
}
70+
.bg-color-primary ::slotted(wc-tab) {
71+
background-color: var(--primary-color);
72+
color: var(--white-color);
73+
border-color: var(--grey-80-color);
74+
}
75+
`;
76+
}
77+
78+
get className() {
79+
const classes = [];
80+
if (this.backgroundColor) {
81+
classes.push(`bg-color-${this.backgroundColor}`);
82+
}
83+
if (this.hidden) {
84+
classes.push('hidden');
85+
}
86+
return classes.join(' ');
87+
}
88+
89+
render() {
90+
return html`
91+
<ul class=${this.className || nothing}><slot></slot></ul>
92+
`;
93+
}
94+
}

src/nav/nav.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { CanvasElement } from './CanvasElement';
1010
import { SideBarElement } from './SideBarElement';
1111
import { ContentElement } from './ContentElement';
1212
import { TabElement } from './TabElement';
13+
import { TabGroupElement } from './TabGroupElement';
1314

1415
// Web Components
1516
customElements.define(NavBarElement.localName, NavBarElement); // wc-navbar
@@ -20,3 +21,4 @@ customElements.define(CanvasElement.localName, CanvasElement); // wc-canvas
2021
customElements.define(SideBarElement.localName, SideBarElement); // wc-sidebar
2122
customElements.define(ContentElement.localName, ContentElement); // wc-content
2223
customElements.define(TabElement.localName, TabElement); // wc-tab
24+
customElements.define(TabGroupElement.localName, TabGroupElement); // wc-tab-group

0 commit comments

Comments
 (0)