Skip to content

Commit e636d62

Browse files
committed
Added view and view group
1 parent e57d845 commit e636d62

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed

src/nav/ViewElement.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import {
2+
LitElement, html, css, nothing,
3+
} from 'lit';
4+
5+
/**
6+
* ViewElement
7+
* This class is used to create a view, within a view group, which
8+
* displays one view at a time. In general you should use a
9+
* TabGroupElement as a controller for this view group to switch
10+
* between visible views.
11+
*
12+
* @example
13+
* <wc-view-group>
14+
* <wc-view name="view1" selected>View1</wc-tab>
15+
* <wc-view name="view2">View2</wc-tab>
16+
* <wc-view name="view3">View3</wc-tab>
17+
* <wc-view name="view4">View4</wc-tab>
18+
* </wc-view-group>
19+
*/
20+
export class ViewElement extends LitElement {
21+
static get localName() {
22+
return 'wc-view';
23+
}
24+
25+
static get properties() {
26+
return {
27+
/**
28+
* Whether the tab is selected. Only one tab within a group should
29+
* be selected at a time.
30+
* @type {Boolean}
31+
* @default false
32+
* @memberof TabElement
33+
*/
34+
selected: { type: Boolean },
35+
36+
/**
37+
* The name of the tab, for click events.
38+
* @type {String}
39+
* @default ''
40+
* @memberof TabElement
41+
*/
42+
name: { type: String },
43+
};
44+
}
45+
46+
static get styles() {
47+
return css``;
48+
}
49+
50+
get className() {
51+
const classes = [];
52+
if (this.selected) {
53+
classes.push('selected');
54+
}
55+
return classes.join(' ');
56+
}
57+
58+
render() {
59+
return html`
60+
<div class=${this.className || nothing}><slot></slot></div>
61+
`;
62+
}
63+
}

src/nav/ViewGroupElement.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import {
2+
LitElement, html, css, nothing,
3+
} from 'lit';
4+
5+
/**
6+
* ViewGroupElement
7+
* This class is used to create a view, within a view group, which
8+
* displays one view at a time. In general you should use a
9+
* TabGroupElement as a controller for this view group to switch
10+
* between visible views.
11+
*
12+
* @example
13+
* <wc-view-group>
14+
* <wc-view name="view1" selected>View1</wc-tab>
15+
* <wc-view name="view2">View2</wc-tab>
16+
* <wc-view name="view3">View3</wc-tab>
17+
* <wc-view name="view4">View4</wc-tab>
18+
* </wc-view-group>
19+
*/
20+
export class ViewGroupElement extends LitElement {
21+
static get localName() {
22+
return 'wc-view-group';
23+
}
24+
25+
static get properties() {
26+
return {
27+
/**
28+
* Whether the tab is selected. Only one tab within a group should
29+
* be selected at a time.
30+
* @type {Boolean}
31+
* @default false
32+
* @memberof TabElement
33+
*/
34+
selected: { type: Boolean },
35+
36+
/**
37+
* The name of the tab, for click events.
38+
* @type {String}
39+
* @default ''
40+
* @memberof TabElement
41+
*/
42+
name: { type: String },
43+
};
44+
}
45+
46+
static get styles() {
47+
return css``;
48+
}
49+
50+
get className() {
51+
const classes = [];
52+
if (this.selected) {
53+
classes.push('selected');
54+
}
55+
return classes.join(' ');
56+
}
57+
58+
render() {
59+
return html`
60+
<div class=${this.className || nothing}><slot></slot></div>
61+
`;
62+
}
63+
}

src/nav/nav.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { SideBarElement } from './SideBarElement';
1111
import { ContentElement } from './ContentElement';
1212
import { TabElement } from './TabElement';
1313
import { TabGroupElement } from './TabGroupElement';
14+
import { ViewElement } from './ViewElement';
15+
import { ViewGroupElement } from './ViewGroupElement';
1416

1517
// Web Components
1618
customElements.define(NavBarElement.localName, NavBarElement); // wc-navbar
@@ -22,3 +24,5 @@ customElements.define(SideBarElement.localName, SideBarElement); // wc-sidebar
2224
customElements.define(ContentElement.localName, ContentElement); // wc-content
2325
customElements.define(TabElement.localName, TabElement); // wc-tab
2426
customElements.define(TabGroupElement.localName, TabGroupElement); // wc-tab-group
27+
customElements.define(ViewElement.localName, ViewElement); // wc-view
28+
customElements.define(ViewGroupElement.localName, ViewGroupElement); // wc-view-group

0 commit comments

Comments
 (0)