Skip to content

Commit ebb19e3

Browse files
author
Steve Orvell
authored
Update styles documentation (#126)
* Update/embed styles examples and some editing for consistency * Refinements to examples and text
1 parent eee099e commit ebb19e3

File tree

98 files changed

+343
-1524
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+343
-1524
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<script type="module" src="./my-element.js"></script>
2+
3+
<my-element></my-element>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { LitElement, html, css } from 'lit';
2+
import { customElement } from 'lit/decorators';
3+
4+
@customElement('my-element')
5+
export class MyElement extends LitElement {
6+
static styles = css`
7+
p {
8+
color: green;
9+
}
10+
`;
11+
protected render() {
12+
return html`<p>I am green!</p>`;
13+
}
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"files": {
3+
"my-element.ts": {},
4+
"index.html": {}
5+
6+
},
7+
"importMap": {
8+
"imports": {
9+
"lit": "https://cdn.skypack.dev/lit",
10+
"lit/": "https://cdn.skypack.dev/lit/"
11+
}
12+
}
13+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<script type="module" src="./my-element.js"></script>
2+
3+
<my-element></my-element>
4+
<my-element class="blue"></my-element>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { LitElement, html, css } from 'lit';
2+
import { customElement } from 'lit/decorators/custom-element';
3+
4+
@customElement('my-element')
5+
export class MyElement extends LitElement {
6+
static styles = css`
7+
:host {
8+
display: block;
9+
background-color: lightgray;
10+
padding: 8px;
11+
}
12+
:host(.blue) {
13+
background-color: aliceblue;
14+
color: darkgreen;
15+
}
16+
`;
17+
protected render() {
18+
return html`Hello World`;
19+
}
20+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"files": {
3+
"my-element.ts": {},
4+
"index.html": {}
5+
},
6+
"importMap": {
7+
"imports": {
8+
"lit": "https://cdn.skypack.dev/lit",
9+
"lit/": "https://cdn.skypack.dev/lit/"
10+
}
11+
}
12+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<script src="./my-element.js" type="module"></script>
2+
3+
<my-element></my-element>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { LitElement, html, css } from 'lit';
2+
import { customElement, property } from 'lit/decorators';
3+
import { classMap } from 'lit/directives/class-map';
4+
import { styleMap } from 'lit/directives/style-map';
5+
6+
@customElement('my-element')
7+
export class MyElement extends LitElement {
8+
static styles = css`
9+
.someclass { border: 1px solid red; padding: 4px; }
10+
.anotherclass { background-color: navy; }
11+
`;
12+
@property()
13+
classes = { someclass: true, anotherclass: true };
14+
@property()
15+
styles = { color: 'lightgreen', fontFamily: 'Roboto' };
16+
protected render() {
17+
return html`
18+
<div class=${classMap(this.classes)} style=${styleMap(this.styles)}>
19+
Some content
20+
</div>
21+
`;
22+
}
23+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"files": {
3+
"my-element.ts": {},
4+
"index.html": {}
5+
},
6+
"importMap": {
7+
"imports": {
8+
"lit": "https://cdn.skypack.dev/lit",
9+
"lit/": "https://cdn.skypack.dev/lit/"
10+
}
11+
}
12+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script type="module" src="./my-element.js"></script>
2+
3+
<my-element>
4+
<p>Slotted paragraph</p>
5+
<span slot="hi">Slotted span inside a div</span>
6+
</my-element>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { LitElement, html, css } from 'lit';
2+
import { customElement } from 'lit/decorators';
3+
4+
@customElement('my-element')
5+
export class MyElement extends LitElement {
6+
static styles = css`
7+
::slotted(*) { font-family: Roboto; }
8+
::slotted(p) { color: blue; }
9+
div ::slotted(*) { color: red; }
10+
`;
11+
protected render() {
12+
return html`
13+
<slot></slot>
14+
<div><slot name="hi"></slot></div>
15+
`;
16+
}
17+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"files": {
3+
"my-element.ts": {},
4+
"index.html": {}
5+
},
6+
"importMap": {
7+
"imports": {
8+
"lit": "https://cdn.skypack.dev/lit",
9+
"lit/": "https://cdn.skypack.dev/lit/"
10+
}
11+
}
12+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<script type="module" src="./my-element.js"></script>
2+
3+
<my-element></my-element>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { css } from 'lit';
2+
import { customElement } from 'lit/decorators';
3+
import { SuperElement } from './super-element.js';
4+
5+
@customElement('my-element')
6+
export class MyElement extends SuperElement {
7+
static get styles() {
8+
return [
9+
super.styles,
10+
css`div {
11+
color: red;
12+
}`
13+
];
14+
}
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"files": {
3+
"my-element.ts": {},
4+
"super-element.ts": {},
5+
"index.html": {}
6+
},
7+
"importMap": {
8+
"imports": {
9+
"lit": "https://cdn.skypack.dev/lit",
10+
"lit/": "https://cdn.skypack.dev/lit/"
11+
}
12+
}
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { LitElement, html, css } from 'lit';
2+
import { customElement } from 'lit/decorators';
3+
4+
@customElement('super-element')
5+
export class SuperElement extends LitElement {
6+
static styles = css`
7+
div {
8+
border: 1px solid gray;
9+
padding: 8px;
10+
}
11+
`;
12+
protected render() {
13+
return html`
14+
<div>Content</div>
15+
`;
16+
}
17+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<script type="module" src="./my-element.js"></script>
2+
3+
<style>
4+
html {
5+
--theme-primary: green;
6+
--theme-secondary: aliceblue;
7+
--theme-warning: red;
8+
--theme-font-family: Roboto;
9+
}
10+
my-element {
11+
--my-element-text-color: var(--theme-primary);
12+
--my-element-background-color: var(--theme-secondary);
13+
--my-element-font-family: var(--theme-font-family);
14+
}
15+
.warning {
16+
--my-element-text-color: var(--theme-warning);
17+
}
18+
</style>
19+
<my-element></my-element>
20+
<my-element class="warning"></my-element>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { LitElement, html, css } from 'lit';
2+
import { customElement } from 'lit/decorators';
3+
4+
@customElement('my-element')
5+
export class MyElement extends LitElement {
6+
static styles = css`
7+
:host {
8+
color: var(--my-element-text-color, black);
9+
background: var(--my-element-background-color, white);
10+
font-family: var(--my-element-font-family, Roboto);
11+
display: block;
12+
padding: 8px;
13+
margin: 8px;
14+
}
15+
`;
16+
protected render() {
17+
return html`<div>Hello World</div>`;
18+
}
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"files": {
3+
"my-element.ts": {},
4+
"index.html": {}
5+
},
6+
"importMap": {
7+
"imports": {
8+
"lit": "https://cdn.skypack.dev/lit",
9+
"lit/": "https://cdn.skypack.dev/lit/"
10+
}
11+
}
12+
}

packages/lit-dev-content/site/_includes/projects/style/classmap/index.html

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/lit-dev-content/site/_includes/projects/style/classmap/my-element.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

packages/lit-dev-content/site/_includes/projects/style/classmap/project.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/lit-dev-content/site/_includes/projects/style/customproperties/index.html

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/lit-dev-content/site/_includes/projects/style/customproperties/my-element.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/lit-dev-content/site/_includes/projects/style/customproperties/project.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/lit-dev-content/site/_includes/projects/style/host/index.html

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/lit-dev-content/site/_includes/projects/style/host/my-element.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)