-
-
Save fkleuver/d62b6a01124ab6760554d90d740e972f to your computer and use it in GitHub Desktop.
Aurelia theme engine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Dumber Gist</title> | |
| <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no"> | |
| <base href="/"> | |
| </head> | |
| <!-- | |
| Dumber Gist uses dumber bundler, the default bundle file | |
| is /dist/entry-bundle.js. | |
| The starting module is pointed to "main" (data-main attribute on script) | |
| which is your src/main.js. | |
| --> | |
| <body> | |
| <my-app></my-app> | |
| <script src="/dist/entry-bundle.js" data-main="main"></script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "dependencies": { | |
| "aurelia": "dev" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default [ | |
| { | |
| name: 'theme-gray', | |
| variables: { | |
| '--color-100': '#F7FAFC', | |
| '--color-200': '#EDF2F7', | |
| '--color-300': '#E2E8F0', | |
| '--color-400': '#CBD5E0', | |
| '--color-500': '#A0AEC0', | |
| '--color-600': '#718096', | |
| '--color-700': '#4A5568', | |
| '--color-800': '#2D3748', | |
| '--color-900': '#1A202C' | |
| }, | |
| }, | |
| { | |
| name: 'theme-red', | |
| variables: { | |
| '--color-100': '#FFF5F5', | |
| '--color-200': '#FED7D7', | |
| '--color-300': '#FEB2B2', | |
| '--color-400': '#FC8181', | |
| '--color-500': '#F56565', | |
| '--color-600': '#E53E3E', | |
| '--color-700': '#C53030', | |
| '--color-800': '#9B2C2C', | |
| '--color-900': '#742A2A' | |
| }, | |
| }, | |
| { | |
| name: 'theme-green', | |
| variables: { | |
| '--color-100': '#F0FFF4', | |
| '--color-200': '#C6F6D5', | |
| '--color-300': '#9AE6B4', | |
| '--color-400': '#68D391', | |
| '--color-500': '#48BB78', | |
| '--color-600': '#38A169', | |
| '--color-700': '#2F855A', | |
| '--color-800': '#276749', | |
| '--color-900': '#22543D' | |
| }, | |
| }, | |
| { | |
| name: 'theme-blue', | |
| variables: { | |
| '--color-100': '#EBF8FF', | |
| '--color-200': '#BEE3F8', | |
| '--color-300': '#90CDF4', | |
| '--color-400': '#63B3ED', | |
| '--color-500': '#4299E1', | |
| '--color-600': '#3182CE', | |
| '--color-700': '#2B6CB0', | |
| '--color-800': '#2C5282', | |
| '--color-900': '#2A4365' | |
| }, | |
| }, | |
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| :root { | |
| /* Assume Gray Color Theme */ | |
| --color-100: #F7FAFC; | |
| --color-200: #EDF2F7; | |
| --color-300: #E2E8F0; | |
| --color-400: #CBD5E0; | |
| --color-500: #A0AEC0; | |
| --color-600: #718096; | |
| --color-700: #4A5568; | |
| --color-800: #2D3748; | |
| --color-900: #1A202C; | |
| /* Color Theme reference */ | |
| --color-lightest: var(--color-100); | |
| --color-lighter: var(--color-200); | |
| --color-light: var(--color-300); | |
| --color-normal-light: var(--color-400); | |
| --color-normal: var(--color-500); | |
| --color-normal-dark: var(--color-600); | |
| --color-dark: var(--color-700); | |
| --color-darker: var(--color-800); | |
| --color-darkest: var(--color-900); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Aurelia, { StyleConfiguration } from 'aurelia'; | |
| import { MyApp } from './my-app'; | |
| import main from './main.css'; | |
| Aurelia | |
| .register( | |
| StyleConfiguration.shadowDOM({ sharedStyles: [main] }), | |
| ) | |
| .app(MyApp) | |
| .start(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| h1 { | |
| color: var(--color-400); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <use-shadow-dom></use-shadow-dom> | |
| <import from="./my-element"></import> | |
| <h1>${message}</h1> | |
| <my-element></my-element> | |
| <select value.bind="theme" | |
| change.trigger="theme.applyTo(style)" | |
| style="margin-top: 10px;"> | |
| <option repeat.for="item of themes" | |
| model.bind="item"> | |
| ${item.name} | |
| </option> | |
| </select> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {Theme} from './theme'; | |
| export class MyApp { | |
| themes = []; | |
| message = 'Hello Aurelia 2!'; | |
| style = document.documentElement.style; | |
| async beforeBind() { | |
| this.themes = (await import('./data')).default.map(Theme.fromJSON); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| :host { | |
| display: block; | |
| background-color: var(--color-darker); | |
| color: var(--color-lighter); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <use-shadow-dom></use-shadow-dom> | |
| Hello World |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class MyElement { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class Theme { | |
| constructor(name, css) { | |
| this.name = name; | |
| this.css = css; | |
| this.keys = Object.keys(css); | |
| } | |
| applyTo(style) { | |
| for (const key of this.keys) { | |
| style.setProperty(key, this.css[key]); | |
| } | |
| } | |
| static fromJSON(json) { | |
| return new Theme(json.name, json.variables); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment