aboutsummaryrefslogtreecommitdiff
path: root/src/components/font_control/font_control.js
blob: 6274780b866cb808afc76d86400627b7c35189e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { set } from 'vue'
import { library } from '@fortawesome/fontawesome-svg-core'
import {
  faChevronDown
} from '@fortawesome/free-solid-svg-icons'

library.add(
  faChevronDown
)

export default {
  props: [
    'name', 'label', 'value', 'fallback', 'options', 'no-inherit'
  ],
  data () {
    return {
      lValue: this.value,
      availableOptions: [
        this.noInherit ? '' : 'inherit',
        'custom',
        ...(this.options || []),
        'serif',
        'monospace',
        'sans-serif'
      ].filter(_ => _)
    }
  },
  beforeUpdate () {
    this.lValue = this.value
  },
  computed: {
    present () {
      return typeof this.lValue !== 'undefined'
    },
    dValue () {
      return this.lValue || this.fallback || {}
    },
    family: {
      get () {
        return this.dValue.family
      },
      set (v) {
        set(this.lValue, 'family', v)
        this.$emit('input', this.lValue)
      }
    },
    isCustom () {
      return this.preset === 'custom'
    },
    preset: {
      get () {
        if (this.family === 'serif' ||
            this.family === 'sans-serif' ||
            this.family === 'monospace' ||
            this.family === 'inherit') {
          return this.family
        } else {
          return 'custom'
        }
      },
      set (v) {
        this.family = v === 'custom' ? '' : v
      }
    }
  }
}