From 2c29a10c0c1fbc77101a31ce1124bc0949412a4b Mon Sep 17 00:00:00 2001 From: Andrew Seier Date: Mon, 16 Dec 2024 09:58:04 -0800 Subject: [PATCH] Updates demo styles and improves error messages. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes: * Uses `static get styles()` for demo / test elements. † * Uses brackets in error messaging — e.g., “ -
${rank}
- `; + return html`
${rank}
`; }; } } diff --git a/demo/index.js b/demo/index.js index 77bfb68..5eff270 100644 --- a/demo/index.js +++ b/demo/index.js @@ -9,42 +9,45 @@ const logo = `\ `; class HelloElement extends XElement { - static template(html) { - return () => { - return html` - -
- `; + static template(html) { + return () => { + return html`
`; }; } diff --git a/test/test-computed-properties.js b/test/test-computed-properties.js index 869590d..241ede9 100644 --- a/test/test-computed-properties.js +++ b/test/test-computed-properties.js @@ -4,6 +4,29 @@ import { it, assert } from './x-test.js'; let _count = 0; class TestElement extends XElement { + static get styles() { + const styleSheet = new CSSStyleSheet(); + styleSheet.replaceSync(`\ + #calculation { + background-color: lightgreen; + padding: 10px; + } + + :host([negative]) #calculation { + background-color: lightcoral; + } + + :host([underline]) #calculation { + text-decoration: underline; + } + + :host([italic]) #calculation { + font-style: italic; + } + `); + return [styleSheet]; + } + static get properties() { return { c: { @@ -84,27 +107,7 @@ class TestElement extends XElement { static template(html) { return ({ a, b, c }) => { - return html` - - ${a} + ${b} = ${c} - `; + return html`${a} + ${b} = ${c}`; }; } } diff --git a/test/test-observed-properties.js b/test/test-observed-properties.js index c583b4c..86172fe 100644 --- a/test/test-observed-properties.js +++ b/test/test-observed-properties.js @@ -2,6 +2,24 @@ import XElement from '../x-element.js'; import { assert, it } from './x-test.js'; class TestElement extends XElement { + static get styles() { + const styleSheet = new CSSStyleSheet(); + styleSheet.replaceSync(`\ + :host #container { + transition-property: box-shadow; + transition-duration: 300ms; + transition-timing-function: linear; + box-shadow: 0 0 0 1px black; + padding: 10px; + } + + :host([popped]) #container { + box-shadow: 0 0 10px 0 black; + } + `); + return [styleSheet]; + } + static get properties() { return { a: { @@ -64,19 +82,6 @@ class TestElement extends XElement { static template(html) { return ({ changes }) => { return html` -
Changes: