Skip to content

Commit

Permalink
♻️ update logic due to values@2 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
noeldelgado committed May 25, 2020
1 parent 5e13f69 commit 794aac4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
19 changes: 6 additions & 13 deletions src/javascripts/components/ColorItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Text from '/components/Text';
export default class ColorItem extends Widget {

static CLASSNAMES = {
BASE: '-is-base-color',
BASE: '-is-base',
TINT: '-is-tint',
SHADE: '-is-shade',
LIGHT: '-is-light',
Expand Down Expand Up @@ -55,26 +55,19 @@ export default class ColorItem extends Widget {
* @param {Value} value - values.js instance
*/
update(value) {
const { TINT, SHADE, BASE, LIGHT, DARK } = this.constructor.CLASSNAMES;
const { isTint, isShade, isBaseColor } = value;
const { LIGHT, DARK } = this.constructor.CLASSNAMES;

this.color = value.hexString();

this.ariaLabelPercentage.setText([
isTint && 'tint',
isShade && 'shade',
isBaseColor && 'base color'
].filter(v => v));
this.percentageLabel.setText(`${value.percentage?.toFixed(2) ?? 0 |> Number}%`);
this.ariaLabelPercentage.setText(value.type);
this.percentageLabel.setText(`${value.weight?.toFixed(2) ?? 0 |> Number}%`);
this.hexLabel.setText(this.color);
this.element.style.backgroundColor = this.color;

this.element.classList.remove(...Object.values(this.constructor.CLASSNAMES));
this.element.classList.add(...[
isTint && TINT,
isShade && SHADE,
isBaseColor && BASE,
value.getBrightness() > 50 ? LIGHT : DARK
`-is-${value.type}`,
value.getBrightness() > 55 ? LIGHT : DARK
].filter(v => v));

return this;
Expand Down
2 changes: 1 addition & 1 deletion src/sass/components/color-item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
padding: 1.5rem;
background-color: rgba(0,0,0,0);

&.-is-base-color {
&.-is-base {
border: 2px solid rgba(0, 0, 0, 0.5);
box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.5);
}
Expand Down

0 comments on commit 794aac4

Please sign in to comment.