File size: 2,418 Bytes
4d70170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<script lang="ts">
import type { PropType } from 'vue'
import { computed, defineComponent } from 'vue'
import type { PluginSettingsItem } from '@vue/devtools-api'
import type { Plugin } from '.'

export default defineComponent({
  props: {
    plugin: {
      type: Object as PropType<Plugin>,
      required: true,
    },

    id: {
      type: String,
      required: true,
    },

    schema: {
      type: Object as PropType<PluginSettingsItem>,
      required: true,
    },

    value: {
      required: true,
    },
  },
  emits: ['update:value'],
  setup(props, { emit }) {
    const model = computed({
      get() {
        return props.value
      },
      set(value) {
        emit('update:value', value)
      },
    })

    function onLabelClick() {
      if (props.schema.type === 'boolean') {
        model.value = !model.value
      }
    }

    return {
      model,
      onLabelClick,
    }
  },
})
</script>

<template>
  <div
    class="flex items-start px-6 py-2 hover:bg-green-50 dark:hover:bg-green-900"
    @click="onLabelClick()"
  >
    <div class="flex-1 select-none text-sm py-1.5">
      <div>{{ schema.label }}</div>
      <div
        v-if="schema.description"
        class="opacity-75 text-xs"
      >
        {{ schema.description }}
      </div>
    </div>
    <div class="w-1/2">
      <div
        v-if="schema.type === 'boolean'"
        class="my-2 w-full h-[max-content]"
        @click.stop
      >
        <VueSwitch
          v-model="model"
          class="w-full extend-left"
        />
      </div>

      <template v-else-if="schema.type === 'choice'">
        <VueGroup
          v-if="schema.component === 'button-group'"
          v-model="model"
          class="extend w-full"
        >
          <VueGroupButton
            v-for="(option, index) of schema.options"
            :key="index"
            :value="option.value"
            :label="option.label"
          />
        </VueGroup>

        <VueSelect
          v-else
          v-model="model"
          class="w-full"
        >
          <VueSelectButton
            v-for="(option, index) of schema.options"
            :key="index"
            :value="option.value"
            :label="option.label"
          />
        </VueSelect>
      </template>

      <VueInput
        v-else-if="schema.type === 'text'"
        v-model="model"
        class="w-full"
      />
    </div>
  </div>
</template>