aboutsummaryrefslogtreecommitdiff
path: root/src/components/font_control/font_control.vue
blob: 424f6259b7e2d2d05de8b384ff4c9a07f0d32120 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<template>
<div class="font-control style-control">
  <label :for="preset === 'custom' ? name : name + '-font-switcher'" class="label">
    {{label}}
  </label>
  <input
    v-if="typeof fallback !== 'undefined'"
    class="opt exlcude-disabled"
    type="checkbox"
    :id="name + '-o'"
    :checked="present"
    @input="$emit('input', typeof value === 'undefined' ? fallback : undefined)">
  <label v-if="typeof fallback !== 'undefined'" class="opt-l" :for="name + '-o'"></label>
  <label :for="name + '-font-switcher'" class="select" :disabled="!present">
    <select
      :disabled="!present"
      v-model="preset"
      class="font-switcher"
      id="name + '-font-switcher'">
      <option v-for="option in options" :value="option">
        {{ option }}
      </option>
    </select>
    <i class="icon-down-open"/>
  </label>
  <input
    v-if="preset === 'custom'"
    class="custom-font"
    type="text"
    id="name"
    v-model="family">
</div>
</template>

<script>
import { set } from 'vue'

export default {
  props: [
    'name', 'label', 'value', 'fallback', 'options'
  ],
  data () {
    return {
      lValue: this.value
    }
  },
  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)
      }
    },
    preset: {
      get () {
        console.log(this.family)
        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
      }
    }
  }
}
</script>

<style lang="scss">
@import '../../_variables.scss';
.font-control {
  input.custom-font {
    min-width: 10em;
  }
}
</style>