Created
January 17, 2021 00:36
-
-
Save chriskrycho/2c427b5ccd326796cb4dcab2111f4bdc to your computer and use it in GitHub Desktop.
stoplight
This file contains 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 Component from '@glimmer/component'; | |
import { tracked } from '@glimmer/tracking'; | |
export default class Container extends Component { | |
@tracked currentColor = 'red'; | |
@tracked mode = 'order'; | |
colors = ["red", "yellow", "green"]; | |
changeCurrentColor = () => { | |
const { colors, mode, currentColor } = this; | |
if (mode === "order") { | |
const idx = colors.indexOf(currentColor); | |
const next = idx === 2 ? 0 : idx + 1; | |
this.currentColor = colors[next]; | |
} else { | |
const idx = Math.floor(Math.random() * 3); | |
if (colors[idx] !== currentColor) { | |
this.currentColor = colors[idx]; | |
} else { | |
const nextColor = idx === 0 | |
? colors[idx + 1] | |
: colors[idx - 1]; | |
this.currentColor = nextColor; | |
} | |
} | |
} | |
toggleMode = () => { | |
this.mode = this.mode === "order" ? "random" : "order" | |
} | |
} |
This file contains 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 Controller from '@ember/controller'; | |
export default class ApplicationController extends Controller { | |
appName = 'Ember Twiddle'; | |
} |
This file contains 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 { helper } from '@ember/component/helper'; | |
export default helper(function eq([a, b]) { | |
return a === b; | |
}); |
This file contains 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
* { | |
font-family: sans-serif; | |
color: #333; | |
font-weight: 400; | |
box-sizing: border-box; | |
} | |
.container { | |
width: 200px; | |
margin: 50px auto; | |
display: grid; | |
justify-content: center; | |
gap: 10px; | |
} | |
.stop-light { | |
width: 118px; | |
height: 300px; | |
padding: 18px; | |
display: grid; | |
grid-template-rows: 1fr 1fr 1fr; | |
grid-template-columns: 1fr; | |
gap: 10px; | |
justify-content: center; | |
justify-self: center; | |
border: 1px solid black; | |
border-radius: 5px; | |
background: linear-gradient(217deg, #aaa, #000 70.71%); | |
} | |
.light { | |
width: 80px; | |
height: 80px; | |
border: 1px solid black; | |
border-radius: 50%; | |
background: white; | |
box-shadow: 0 0 0 #0000; | |
transition: box-shadow 0.15s ease-in; | |
} | |
.light--active { | |
background: radial-gradient(#fbe9e9, var(--color)); | |
box-shadow: 0 0 10px var(--color); | |
} | |
.light--active[data-color="red"] { | |
--color: #ff3c41; | |
} | |
.light--active[data-color="yellow"] { | |
--color: #ffdd40; | |
} | |
.light--active[data-color="green"] { | |
--color: #47cf73; | |
} | |
This file contains 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
{ | |
"version": "0.17.1", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
"ember": "3.18.1", | |
"ember-template-compiler": "3.18.1", | |
"ember-testing": "3.18.1" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment