Skip to content

Commit ed37156

Browse files
committed
Updated
1 parent 803023b commit ed37156

16 files changed

+547
-114
lines changed

src/app/CanvasElement.js

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,30 @@ import { LitElement, html, css, nothing } from 'lit';
66
* This class is used to contain content boxes which are stacked
77
* vertically or horizontally within the canvas.
88
*
9+
* @property {Boolean} vertical - Fill the canvas vertically rather than horizontally, default false
10+
* @property {String} backgroundColor - Background color of the canvas, light or dark, default light
11+
*
912
* @example
10-
* <w2-canvas vertical>
11-
* <w2-canvas-content>....</w2-canvas-content>
12-
* <w2-canvas-content>....</w2-canvas-content>
13-
* <w2-canvas-content>....</w2-canvas-content>
14-
* </w2-canvas>
13+
* <wc-canvas vertical>
14+
* <wc-canvas-content>....</wc-canvas-content>
15+
* <wc-canvas-content>....</wc-canvas-content>
16+
* <wc-canvas-content>....</wc-canvas-content>
17+
* </wc-canvas>
1518
*/
1619
export class CanvasElement extends LitElement {
1720
static get localName() {
18-
return 'w2-canvas';
21+
return 'wc-canvas';
1922
}
2023

2124
constructor() {
2225
super();
2326
this.backgroundColor = 'light';
27+
this.vertical = false;
2428
}
2529

2630
static get properties() {
2731
return {
28-
/**
29-
* @property {Boolean} vertical - Fill the canvas vertically rather than horizontally
30-
*/
3132
vertical: { type: Boolean },
32-
33-
/**
34-
* @property {String} backgroundColor - Background color of the canvas
35-
* @default 'light'
36-
*/
3733
backgroundColor: { type: String },
3834
};
3935
}
@@ -57,47 +53,61 @@ export class CanvasElement extends LitElement {
5753
flex-direction: column;
5854
}
5955
60-
/* Any canvas section is in flexbox mode */
61-
::slotted(w2-canvas-section),::slotted(w2-canvas-navbar) {
56+
/* Any canvas section is in flexbox mode with a fixed size */
57+
::slotted(wc-canvas-section),::slotted(wc-canvas-navbar) {
6258
display: flex;
63-
flex: 0 0;
64-
justify-content: center;
59+
justify-content: start;
6560
border-style: none;
6661
}
6762
6863
/* The first section in vertical mode gets a border below */
69-
div.vertical > ::slotted(w2-canvas-navbar:first-child),div.vertical > ::slotted(w2-canvas-section:first-child) {
64+
div.vertical > ::slotted(wc-canvas-navbar:first-child),div.vertical > ::slotted(wc-canvas-section:first-child) {
7065
min-height: 40px;
7166
border-bottom-style: solid;
7267
}
68+
7369
/* The first section in horizontal mode gets a border right */
74-
div:not(.vertical) > ::slotted(w2-canvas-navbar:first-child), div:not(.vertical) > ::slotted(w2-canvas-section:first-child) {
70+
div:not(.vertical) > ::slotted(wc-canvas-navbar:first-child), div:not(.vertical) > ::slotted(wc-canvas-section:first-child) {
7571
min-width: 60px;
7672
border-right-style: solid;
7773
}
74+
7875
/* The last section in vertical mode gets a border above */
79-
div.vertical > ::slotted(w2-canvas-navbar:last-child),div.vertical > ::slotted(w2-canvas-section:last-child) {
76+
div.vertical > ::slotted(wc-canvas-navbar:last-child),div.vertical > ::slotted(wc-canvas-section:last-child) {
8077
min-height: 30px;
8178
border-top-style: solid;
8279
}
80+
8381
/* The last section in horizonal mode gets a border left */
84-
div:not(.vertical) > ::slotted(w2-canvas-navbar:last-child),div:not(.vertical) > ::slotted(w2-canvas-section:last-child) {
82+
div:not(.vertical) > ::slotted(wc-canvas-navbar:last-child),div:not(.vertical) > ::slotted(wc-canvas-section:last-child) {
8583
min-width: 60px;
8684
border-left-style: solid;
8785
}
8886
8987
/* Flex containers stretch */
90-
::slotted(w2-canvas-section[flex]) {
88+
::slotted(wc-canvas-section[flex]) {
9189
flex: 999 0;
9290
overflow: auto;
9391
}
9492
9593
/* Light theme setting colours and border widths */
96-
div.bg-color-light ::slotted(w2-canvas-navbar) {
97-
background-color: var(--light-color);
98-
color: var(--dark-color);
99-
border-color: var(--grey-20-color);
100-
border-width: 1px;
94+
div.bg-color-light {
95+
& ::slotted(wc-canvas-navbar), ::slotted(wc-canvas-section) {
96+
background-color: var(--light-color);
97+
color: var(--dark-color);
98+
border-color: var(--grey-20-color);
99+
border-width: 1px;
100+
}
101+
}
102+
103+
/* Dark theme setting colours and border widths */
104+
div.bg-color-dark {
105+
& ::slotted(wc-canvas-navbar), ::slotted(wc-canvas-section) {
106+
background-color: var(--dark-color);
107+
color: var(--light-color);
108+
border-color: var(--grey-40-color);
109+
border-width: 1px;
110+
}
101111
}
102112
`;
103113
}

src/app/CanvasNavbarElement.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ import { CanvasSectionElement } from './CanvasSectionElement';
77
* This class is a navigaton used to contain content boxes which are stacked
88
* vertically or horizontally within the canvas.
99
*
10+
* @property {Boolean} hidden - Whether the navigation is hidden, default false
11+
*
1012
* @example
11-
* <w2-canvas vertical>
12-
* <w2-canvas-navbar>....</w2-canvas-navbar>
13-
* <w2-canvas-section>....</w2-canvas-section>
14-
* <w2-canvas-navbar>....</w2-canvas-navbar>
15-
* </w2-canvas>
13+
* <wc-canvas vertical>
14+
* <wc-canvas-navbar>....</wc-canvas-navbar>
15+
* <wc-canvas-section>....</wc-canvas-section>
16+
* <wc-canvas-navbar>....</wc-canvas-navbar>
17+
* </wc-canvas>
1618
*/
17-
export class CanvasElement extends CanvasSectionElement {
19+
export class CanvasNavbarElement extends CanvasSectionElement {
1820
static get localName() {
19-
return 'w2-canvas-navbar';
21+
return 'wc-canvas-navbar';
2022
}
2123

2224
constructor() {
@@ -26,18 +28,15 @@ export class CanvasElement extends CanvasSectionElement {
2628

2729
static get properties() {
2830
return {
29-
/**
30-
* @property {Boolean} hidden - Whether the navigation is hidden
31-
*/
3231
hidden: { type: Boolean },
3332
};
3433
}
3534

3635
static get styles() {
3736
return css`
38-
.hidden {
39-
display: none;
40-
}
37+
.hidden {
38+
display: none;
39+
}
4140
`;
4241
}
4342

@@ -49,7 +48,6 @@ export class CanvasElement extends CanvasSectionElement {
4948
`;
5049
}
5150

52-
// eslint-disable-next-line class-methods-use-this
5351
get className() {
5452
const classes = [];
5553
if (this.hidden) {

src/app/CanvasSectionElement.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,30 @@ import { LitElement, html, css, nothing } from 'lit';
77
* vertically or horizontally within a canvas. The content
88
* boxes can be flexed to fill the available space.
99
*
10+
* @property {Boolean} flex - Flex the element to fill the available space, default false
11+
*
1012
* @example
11-
* <w2-canvas vertical>
12-
* <w2-canvas-section>....</w2-canvas-section>
13-
* <w2-canvas-section>....</w2-canvas-section>
14-
* <w2-canvas-section>....</w2-canvas-section>
15-
* </w2-canvas>
13+
* <wc-canvas vertical>
14+
* <wc-canvas-section>....</wc-canvas-section>
15+
* <wc-canvas-section>....</wc-canvas-section>
16+
* <wc-canvas-section>....</wc-canvas-section>
17+
* </wc-canvas>
1618
*/
1719
export class CanvasSectionElement extends LitElement {
1820
static get localName() {
19-
return 'w2-canvas-section';
21+
return 'wc-canvas-section';
2022
}
2123

2224
static get properties() {
2325
return {
24-
/**
25-
* @property {Boolean} flex - Flex the element to fill the available space
26-
*/
2726
flex: { type: Boolean },
2827
};
2928
}
3029

3130
static get styles() {
3231
return css`
33-
:host {}
34-
div {
35-
left: 0;
36-
right: 0;
37-
border: 1px solid red;
32+
.flex {
33+
flex: 999 0;
3834
}
3935
`;
4036
}

src/app/NavGroupElement.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { LitElement, html, css, nothing } from 'lit';
2+
3+
/**
4+
* @class NavGroupElement
5+
*
6+
* This class is used to contain a list of navigation items, either horizontally or vertically.
7+
*
8+
* @property {Boolean} vertical - Fill the canvas vertically rather than horizontally, default false
9+
* @property {Boolean} flex - Take up all available space, default false
10+
*
11+
* @example
12+
* <wc-nav-group name="group" vertical>
13+
* <wc-nav>....</wc-nav>
14+
* <wc-nav-spacer></wc-nav-spacer>
15+
* <wc-nav>....</wc-nav>
16+
* </wc-nav-group>
17+
*/
18+
export class NavGroupElement extends LitElement {
19+
static get localName() {
20+
return 'wc-nav-group';
21+
}
22+
23+
constructor() {
24+
super();
25+
this.vertical = false;
26+
}
27+
28+
static get properties() {
29+
return {
30+
vertical: { type: Boolean },
31+
flex: { type: Boolean },
32+
};
33+
}
34+
35+
static get styles() {
36+
return css`
37+
ul {
38+
display: flex;
39+
flex-direction: row;
40+
list-style-type: none;
41+
padding: 0;
42+
margin: 0;
43+
}
44+
ul.vertical {
45+
flex-direction: column;
46+
}
47+
`;
48+
}
49+
50+
render() {
51+
return html`
52+
<ul class=${this.className || nothing}>
53+
<slot></slot>
54+
</ul>
55+
`;
56+
}
57+
58+
get className() {
59+
const classes = [];
60+
if (this.vertical) {
61+
classes.push('vertical');
62+
}
63+
if (this.flex) {
64+
classes.push('flex');
65+
}
66+
return classes.join(' ');
67+
}
68+
}

src/app/NavItemElement.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { LitElement, html, css, nothing } from 'lit';
2+
3+
/**
4+
* @class NavItemElement
5+
*
6+
* This class is used as a navigation item within a group of navigational items
7+
*
8+
* @property {Boolean} vertical - Fill the canvas vertically rather than horizontally, default false
9+
*
10+
* @example
11+
* <wc-nav-group name="group" vertical>
12+
* <wc-nav-item name="item-top">....</wc-nav-item>
13+
* <wc-nav-spacer></wc-nav-spacer>
14+
* <wc-nav-item name="item-bottom">....</wc-nav-item>
15+
* </wc-nav-group>
16+
*/
17+
export class NavItemElement extends LitElement {
18+
static get localName() {
19+
return 'wc-nav-item';
20+
}
21+
22+
constructor() {
23+
super();
24+
this.vertical = false;
25+
}
26+
27+
static get properties() {
28+
return {
29+
vertical: { type: Boolean },
30+
};
31+
}
32+
33+
static get styles() {
34+
return css``;
35+
}
36+
37+
render() {
38+
return html`
39+
<li class=${this.className || nothing}>
40+
<slot></slot>
41+
</li>
42+
`;
43+
}
44+
45+
get className() {
46+
const classes = [];
47+
if (this.vertical) {
48+
classes.push('vertical');
49+
}
50+
return classes.join(' ');
51+
}
52+
}

src/app/NavSpacerElement.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { LitElement, html, css, nothing } from 'lit';
2+
3+
/**
4+
* @class NavSpacerElement
5+
*
6+
* This class is used as a spacer to separate navigation items to push siblings apart
7+
*
8+
* @example
9+
* <wc-nav-group name="group" vertical>
10+
* <wc-nav-item name="item-top">....</wc-nav-item>
11+
* <wc-nav-spacer></wc-nav-spacer>
12+
* <wc-nav-item name="item-bottom">....</wc-nav-item>
13+
* </wc-nav-group>
14+
*/
15+
export class NavSpacerElement extends LitElement {
16+
static get localName() {
17+
return 'wc-nav-spacer';
18+
}
19+
20+
static get styles() {
21+
return css``;
22+
}
23+
24+
render() {
25+
return html`
26+
<li class=${this.classes.join(' ') || nothing}></li>
27+
`;
28+
}
29+
30+
// eslint-disable-next-line class-methods-use-this
31+
get classes() {
32+
const classes = [];
33+
classes.push('spacer');
34+
return classes;
35+
}
36+
}

src/app/app.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ import './app.css';
44
// Classes
55
import { CanvasElement } from './CanvasElement';
66
import { CanvasSectionElement } from './CanvasSectionElement';
7+
import { CanvasNavbarElement } from './CanvasNavbarElement';
8+
import { NavGroupElement } from './NavGroupElement';
9+
import { NavItemElement } from './NavItemElement';
10+
import { NavSpacerElement } from './NavSpacerElement';
711

812
// Web Components
9-
customElements.define(CanvasElement.localName, CanvasElement); // w2-canvas
10-
customElements.define(CanvasSectionElement.localName, CanvasSectionElement); // w2-canvas-section
13+
customElements.define(CanvasElement.localName, CanvasElement); // wc-canvas
14+
customElements.define(CanvasSectionElement.localName, CanvasSectionElement); // wc-canvas-section
15+
customElements.define(CanvasNavbarElement.localName, CanvasNavbarElement); // wc-canvas-navbar
16+
customElements.define(NavGroupElement.localName, NavGroupElement); // wc-nav-group
17+
customElements.define(NavItemElement.localName, NavItemElement); // wc-nav-item
18+
customElements.define(NavSpacerElement.localName, NavSpacerElement); // wc-nav-spacer

0 commit comments

Comments
 (0)