Advertisement
allnamesweretaken

mixin

Oct 19th, 2019
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // mixin
  2. import Vue from 'vue'
  3. import { Component } from 'vue-mixin-decorator'
  4. import { settings } from '../..'
  5. import {
  6.   ColorData,
  7.   ColorStyles,
  8.   ColorConfig,
  9.   DefaultColors,
  10. } from './color.interface'
  11.  
  12. const defaultColors: DefaultColors = {
  13.   white: '#fff',
  14.   black: '#000',
  15.   light: '#fafafa',
  16.   dark: '#4f4f4f',
  17.   primary: '#42a5f5',
  18.   secondary: '#e3f2ff',
  19.   tertiary: '#e3f2ff',
  20. }
  21.  
  22. const colorValidator = x =>
  23.   Object.keys({ ...settings.colors, ...defaultColors }).includes(x)
  24.  
  25. const Props = Vue.extend({
  26.   props: {
  27.     color: {
  28.       type: String,
  29.       validator: colorValidator,
  30.     },
  31.   },
  32. })
  33.  
  34. @Component
  35. export class ColorMixin extends Props {
  36.   _color: ColorData = {
  37.     hex: false,
  38.     colors: defaultColors,
  39.   }
  40.  
  41.   get colorStyles(): ColorStyles {
  42.     if (this.color)
  43.       return {
  44.         color: this._color.colors[this.color],
  45.       }
  46.   }
  47.  
  48.   colorConfig(cfg: ColorConfig) {
  49.     if (cfg.hex) this._color.hex = cfg.hex
  50.     if (cfg.colors) {
  51.       const cfgColors = cfg.colors
  52.       Object.keys(cfgColors).forEach(k => {
  53.         // this._color is undefined ?!
  54.         this._color.colors[k] = cfgColors[k]
  55.       })
  56.     }
  57.   }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement