# controls.js

# Description

Mixin additional functionality for active controls.

# API

# Props

Name Type Description Default
value [String, Number] Sync value required
onClick Function Callback on click () => {}

# Events

Name Description
change Emit on value change
click Emit on click

@/src/mixins/controls.js

export default {
  props: {
    value: {
      type: [String, Number],
      required: true,
    },
    onClick: {
      type: Function,
      required: false,
      default: () => {},
    },
  },

  computed: {
    control: {
      get() {
        return this.value;
      },
      set(value) {
        this.$emit('update:value', value);
        this.$emit('change', value);
      },
    },
  },

  methods: {
    click(event) {
      this.$emit('click');
      if (this.onClick) this.onClick(event);
    },
  },
};