Skip to content

Commit c8799a2

Browse files
committed
Updates
1 parent 366c29f commit c8799a2

File tree

2 files changed

+77
-20
lines changed

2 files changed

+77
-20
lines changed

src/index.html

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,19 @@ <h1>Tab & View Group</h1>
7878
<wc-tab name="tab-icons">Icons</wc-tab>
7979
</wc-tab-group>
8080
<wc-view-group id="view-group" backgroundColor="light">
81-
<wc-view name="tab-tables">
82-
TABLES CONTENT
81+
<wc-view name="tab-tables" selected>
82+
<div class="container">
83+
<h1>Tables</h1>
84+
85+
<!-- Table of data -->
86+
<wc-table id="table" backgroundColor="black" stripedRows>Table of Fruit</wc-table>
87+
<script>
88+
document.getElementById('table').data = [
89+
{ fruit: 'apple', color: 'green', weight: '100gr' },
90+
{ fruit: 'banana', color: 'yellow', weight: '140gr' }
91+
];
92+
</script>
93+
</div>
8394
</wc-view>
8495
<wc-view name="tab-buttons">
8596
BUTTONS CONTENT
@@ -95,20 +106,6 @@ <h1>Tab & View Group</h1>
95106
</div>
96107
<hr>
97108

98-
<div class="container">
99-
<h1>Tables</h1>
100-
101-
<!-- Table of data -->
102-
<wc-table id="table" backgroundColor="black" stripedRows>Table of Fruit</wc-table>
103-
<script>
104-
document.getElementById('table').data = [
105-
{ fruit: 'apple', color: 'green', weight: '100gr' },
106-
{ fruit: 'banana', color: 'yellow', weight: '140gr' }
107-
];
108-
</script>
109-
</div>
110-
<hr>
111-
112109
<div class="container">
113110
<h1>Buttons</h1>
114111

src/nav/ViewGroupElement.js

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,62 @@ export class ViewGroupElement extends LitElement {
2121
return 'wc-view-group';
2222
}
2323

24+
constructor() {
25+
super();
26+
this.backgroundColor = 'light';
27+
}
28+
2429
static get properties() {
25-
return {};
30+
return {
31+
/**
32+
* Background color of the view group, one of light or dark
33+
*
34+
* @type {String}
35+
* @default light
36+
* @memberof TabGroupElement
37+
*/
38+
backgroundColor: { type: String },
39+
};
2640
}
2741

2842
static get styles() {
29-
return css``;
43+
return css`
44+
div {
45+
position: relative;
46+
height: 100vh;
47+
}
48+
::slotted(wc-view) {
49+
position: absolute;
50+
top: 0;
51+
left: 0;
52+
right: 0;
53+
bottom: 0;
54+
transition: visibility 0.2s, opacity 0.2s;
55+
}
56+
::slotted(wc-view[selected]) {
57+
opacity: 1;
58+
flex: 1 0;
59+
}
60+
::slotted(wc-view:not([selected])) {
61+
opacity: 0;
62+
flex: 0 0;
63+
}
64+
65+
/* light theme */
66+
div.bg-color-light {
67+
border-bottom: 1px solid var(--grey-40-color);
68+
border-left: 1px solid var(--grey-40-color);
69+
border-right: 1px solid var(--grey-40-color);
70+
}
71+
`;
3072
}
3173

3274
// eslint-disable-next-line class-methods-use-this
3375
get className() {
3476
const classes = [];
77+
if (this.backgroundColor) {
78+
classes.push(`bg-color-${this.backgroundColor}`);
79+
}
3580
return classes.join(' ');
3681
}
3782

@@ -41,8 +86,23 @@ export class ViewGroupElement extends LitElement {
4186
`;
4287
}
4388

89+
/**
90+
* Select a view by name, and deselect all other view
91+
*
92+
* @param {String} name: The name of the tab to select
93+
* @returns The node that was selected, or null
94+
*/
4495
select(name) {
45-
// TODO
46-
console.log('select', this, name);
96+
const views = this.querySelectorAll('wc-view');
97+
let selectedNode = null;
98+
views.forEach((view) => {
99+
if (view.name === name && !view.selected) {
100+
view.setAttribute('selected', 'selected');
101+
selectedNode = view;
102+
} else if (view.name !== name && view.selected) {
103+
view.removeAttribute('selected');
104+
}
105+
});
106+
return selectedNode;
47107
}
48108
}

0 commit comments

Comments
 (0)