Skip to content

Instantly share code, notes, and snippets.

@amk221
Last active April 1, 2019 10:20
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 amk221/27bd5d06d94c17529a7491d304a3f105 to your computer and use it in GitHub Desktop.
Save amk221/27bd5d06d94c17529a7491d304a3f105 to your computer and use it in GitHub Desktop.
Ember Brand colours component in Styleguide
import Component from '@ember/component';
import layout from './template';
const { getComputedStyle } = window;
/**
* This component is used in the styleguide to look up our brand colours
* and render them.
*
* To be used in conjunction with:
*
* .brand-colours::before {
* content: quote(inspect($brand-colours));
* }
*
*/
export default Component.extend({
layout,
classNames: ['brand-colours'],
didInsertElement() {
this._super(...arguments);
this.set('colours', this._getColours());
},
_getColours() {
return getComputedStyle(this.element, ':before')
.content.match(/\((.*)\)/)[1]
.split(', ')
.reduce((result, current) => {
const [name, colour] = current.split(': ');
result[name] = colour;
return result;
}, {});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment