UNPKG

@haxtheweb/simple-colors

Version:

Automated conversion of simple-colors/

73 lines (65 loc) 2.55 kB
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes"> <title>SimpleColors: simple-colors Demo</title> <script src="../../../node_modules/@haxtheweb/deduping-fix/deduping-fix.js"></script> <script type="module"> import "@haxtheweb/demo-snippet/demo-snippet.js"; </script> <style> simple-colors-picker-demo { background-color: var(--simple-colors-default-theme-accent-1); color: var(--simple-colors-default-theme-grey-12); border: 1px solid var(--simple-colors-default-theme-accent-6); } </style> </head> <body> <div class="vertical-section-container centered"> <h1>Extending Simple Colors to Custom Elements</h1> <p> You can extend the styles, properties, behaviors of simple colors to any custom element, so that the element can be styled based on its own <tt>accent-color</tt> and <tt>dark</tt> attributes. </p> <p>See <a href="/components/@haxtheweb/simple-colors/lib/demo/simple-colors-swatches.js">SimpleColorsSwatches</a> for a real-world example.</p> <pre> <strong>import { SimpleColors } from "<em>path/to/</em>/simple-colors.js";</strong> class <em>MyElement</em> <strong>extends SimpleColors</strong> { static get styles() { return [ <strong>super.styles, //required to get colors</strong> css` :host { display: block;<em> /* example CSS setting the background to the default accent color and a contrasting greyscale text color */ background-color: var(--simple-colors-default-theme-accent-1); color: var(--simple-colors-default-theme-grey-12); ...</em> }` ]; } <em>...</em> /** * life cycle, element is afixed to the DOM */ constructor() { super();<em> /* example that make component dark pink by default */ this.accentColor = "pink"; this.dark = true; ...</em> } <em>...</em> export { <em>MyElement</em> }; customElements.define(<em>MyElement</em>.tag, <em>MyElement</em>); </pre> </div> </body> </html>