1 import {Component} from "./component";
3 export class SettingAppColorPicker extends Component {
7 this.colorInput = this.$refs.input;
8 this.lightColorInput = this.$refs.lightInput;
10 this.colorInput.addEventListener('change', this.updateColor.bind(this));
11 this.colorInput.addEventListener('input', this.updateColor.bind(this));
15 * Update the app colors as a preview, and create a light version of the color.
18 const hexVal = this.colorInput.value;
19 const rgb = this.hexToRgb(hexVal);
20 const rgbLightVal = 'rgba('+ [rgb.r, rgb.g, rgb.b, '0.15'].join(',') +')';
22 this.lightColorInput.value = rgbLightVal;
24 const customStyles = document.getElementById('custom-styles');
25 const oldColor = customStyles.getAttribute('data-color');
26 const oldColorLight = customStyles.getAttribute('data-color-light');
28 customStyles.innerHTML = customStyles.innerHTML.split(oldColor).join(hexVal);
29 customStyles.innerHTML = customStyles.innerHTML.split(oldColorLight).join(rgbLightVal);
31 customStyles.setAttribute('data-color', hexVal);
32 customStyles.setAttribute('data-color-light', rgbLightVal);
36 * Covert a hex color code to rgb components.
37 * @attribution https://stackoverflow.com/a/5624139
39 * @returns {{r: Number, g: Number, b: Number}}
42 const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
44 r: result ? parseInt(result[1], 16) : 0,
45 g: result ? parseInt(result[2], 16) : 0,
46 b: result ? parseInt(result[3], 16) : 0