Last active
April 1, 2019 10:20
-
-
Save amk221/27bd5d06d94c17529a7491d304a3f105 to your computer and use it in GitHub Desktop.
Ember Brand colours component in Styleguide
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 '@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