Skip to content

Update styles documentation #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script type="module" src="./my-element.js"></script>

<my-element></my-element>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { LitElement, html, css } from 'lit';
import { customElement } from 'lit/decorators';

@customElement('my-element')
export class MyElement extends LitElement {
static styles = css`
p {
color: green;
}
`;
protected render() {
return html`<p>I am green!</p>`;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"files": {
"my-element.ts": {},
"index.html": {}

},
"importMap": {
"imports": {
"lit": "https://cdn.skypack.dev/lit",
"lit/": "https://cdn.skypack.dev/lit/"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<script type="module" src="./my-element.js"></script>

<my-element></my-element>
<my-element class="blue"></my-element>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { LitElement, html, css } from 'lit';
import { customElement } from 'lit/decorators/custom-element';

@customElement('my-element')
export class MyElement extends LitElement {
static styles = css`
:host {
display: block;
background-color: lightgray;
padding: 8px;
}
:host(.blue) {
background-color: aliceblue;
color: darkgreen;
}
`;
protected render() {
return html`Hello World`;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"files": {
"my-element.ts": {},
"index.html": {}
},
"importMap": {
"imports": {
"lit": "https://cdn.skypack.dev/lit",
"lit/": "https://cdn.skypack.dev/lit/"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script src="./my-element.js" type="module"></script>

<my-element></my-element>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { LitElement, html, css } from 'lit';
import { customElement, property } from 'lit/decorators';
import { classMap } from 'lit/directives/class-map';
import { styleMap } from 'lit/directives/style-map';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its fine to just do import {customElement, property} from 'lit/decorators'; (at least that's what I've been doing in examples...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


@customElement('my-element')
export class MyElement extends LitElement {
static styles = css`
.someclass { border: 1px solid red; padding: 4px; }
.anotherclass { background-color: navy; }
`;
@property()
classes = { someclass: true, anotherclass: true };
@property()
styles = { color: 'lightgreen', fontFamily: 'Roboto' };
protected render() {
return html`
<div class=${classMap(this.classes)} style=${styleMap(this.styles)}>
Some content
</div>
`;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"files": {
"my-element.ts": {},
"index.html": {}
},
"importMap": {
"imports": {
"lit": "https://cdn.skypack.dev/lit",
"lit/": "https://cdn.skypack.dev/lit/"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script type="module" src="./my-element.js"></script>

<my-element>
<p>Slotted paragraph</p>
<span slot="hi">Slotted span inside a div</span>
</my-element>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { LitElement, html, css } from 'lit';
import { customElement } from 'lit/decorators';

@customElement('my-element')
export class MyElement extends LitElement {
static styles = css`
::slotted(*) { font-family: Roboto; }
::slotted(p) { color: blue; }
div ::slotted(*) { color: red; }
`;
protected render() {
return html`
<slot></slot>
<div><slot name="hi"></slot></div>
`;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"files": {
"my-element.ts": {},
"index.html": {}
},
"importMap": {
"imports": {
"lit": "https://cdn.skypack.dev/lit",
"lit/": "https://cdn.skypack.dev/lit/"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script type="module" src="./my-element.js"></script>

<my-element></my-element>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { css } from 'lit';
import { customElement } from 'lit/decorators';
import { SuperElement } from './super-element.js';

@customElement('my-element')
export class MyElement extends SuperElement {
static get styles() {
return [
super.styles,
css`div {
color: red;
}`
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"files": {
"my-element.ts": {},
"super-element.ts": {},
"index.html": {}
},
"importMap": {
"imports": {
"lit": "https://cdn.skypack.dev/lit",
"lit/": "https://cdn.skypack.dev/lit/"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { LitElement, html, css } from 'lit';
import { customElement } from 'lit/decorators';

@customElement('super-element')
export class SuperElement extends LitElement {
static styles = css`
div {
border: 1px solid gray;
padding: 8px;
}
`;
protected render() {
return html`
<div>Content</div>
`;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script type="module" src="./my-element.js"></script>

<style>
html {
--theme-primary: green;
--theme-secondary: aliceblue;
--theme-warning: red;
--theme-font-family: Roboto;
}
my-element {
--my-element-text-color: var(--theme-primary);
--my-element-background-color: var(--theme-secondary);
--my-element-font-family: var(--theme-font-family);
}
.warning {
--my-element-text-color: var(--theme-warning);
}
</style>
<my-element></my-element>
<my-element class="warning"></my-element>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { LitElement, html, css } from 'lit';
import { customElement } from 'lit/decorators';

@customElement('my-element')
export class MyElement extends LitElement {
static styles = css`
:host {
color: var(--my-element-text-color, black);
background: var(--my-element-background-color, white);
font-family: var(--my-element-font-family, Roboto);
display: block;
padding: 8px;
margin: 8px;
}
`;
protected render() {
return html`<div>Hello World</div>`;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"files": {
"my-element.ts": {},
"index.html": {}
},
"importMap": {
"imports": {
"lit": "https://cdn.skypack.dev/lit",
"lit/": "https://cdn.skypack.dev/lit/"
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading