@@ -21,17 +21,62 @@ export class ViewGroupElement extends LitElement {
21
21
return 'wc-view-group' ;
22
22
}
23
23
24
+ constructor ( ) {
25
+ super ( ) ;
26
+ this . backgroundColor = 'light' ;
27
+ }
28
+
24
29
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
+ } ;
26
40
}
27
41
28
42
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
+ ` ;
30
72
}
31
73
32
74
// eslint-disable-next-line class-methods-use-this
33
75
get className ( ) {
34
76
const classes = [ ] ;
77
+ if ( this . backgroundColor ) {
78
+ classes . push ( `bg-color-${ this . backgroundColor } ` ) ;
79
+ }
35
80
return classes . join ( ' ' ) ;
36
81
}
37
82
@@ -41,8 +86,23 @@ export class ViewGroupElement extends LitElement {
41
86
` ;
42
87
}
43
88
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
+ */
44
95
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 ;
47
107
}
48
108
}
0 commit comments