Skip to content

Instantly share code, notes, and snippets.

@chancancode
Last active November 14, 2019 00:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chancancode/e55043ce86b0a7fd2117 to your computer and use it in GitHub Desktop.
Save chancancode/e55043ce86b0a7fd2117 to your computer and use it in GitHub Desktop.
<random-color>
<random-color fill={{true}}>So</random-color>
<random-color glow={{true}}>many</random-color>
<random-color fill={{true}} glow={{true}}>colors</random-color>!!!
import Ember from 'ember';
// Returns a random integer from 0 up to (and excluding) max
function randomInteger(max) {
return Math.floor( Math.random() * max );
}
// Returns a random color in rgb(x,y,z) format
function randomColor() {
let r = randomInteger(256),
g = randomInteger(256),
b = randomInteger(256);
return `rgb(${r},${g},${b})`;
}
// Returns a text-shadow for the "glow" effect
function randomGlow() {
return `0px 0px 4px ${ randomColor() }`;
}
export default Ember.GlimmerComponent.extend({
setColor() {
if (this.attrs.fill) {
this.element.style.color = randomColor();
}
if (this.attrs.glow) {
this.element.style.textShadow = randomGlow();
}
},
didInsertElement() {
this.setColor();
},
click() {
this.setColor();
}
});
<span>{{yield}}</span>
body {
margin: 12px 16px;
font-family: "Comic Sans MS", "Comic Sans", cursive;
font-size: 20pt;
letter-spacing: 2px;
}
::moz-selection { background-color: transparent; }
::selection { background-color: transparent; }
{
"version": "0.4.10",
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"hax": "https://cdn.rawgit.com/chancancode/5b7b95b6268d51cdcaae/raw/92e0654083305c73cd601381a6cea705be9f8890/hax.js",
"ember": "http://builds.emberjs.com/canary/ember.debug.js",
"ember-template-compiler": "http://builds.emberjs.com/canary/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment