all files / src/select/ option.vue

100% Statements 5/5
100% Branches 2/2
100% Functions 3/3
100% Lines 5/5
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                                        18×         18×                                                    
<template>
  <div class="am-options-item" :data-name="value" :class="{active,disabled}" @click="onClick">
    <slot></slot>
  </div>
</template>
<script>
export default {
  name: "amOption",
  inject: ["root", "selected"],
  props: {
    value: {
      type: String,
      default: ""
    },
    disabled: {
      type: Boolean,
      default: false
    },
  },
  data() {
    return {
      active: false
    };
  },
  created() {
    this.root.addItem(this);
  },
  methods: {
    onClick() {
      if(this.disabled){
        return false
      }
      this.$emit("update:selected", this.value);
    }
  }
};
</script>
<style lang="scss" scoped>
@import "var";
.am-options-item {
  padding: 4px 8px;
  transition: background 0.2s;
  cursor: pointer;
  &:not(.disabled):hover {
    background: rgba($blue, 0.1);
  }
  &.active {
    background: rgba($blue, 0.3);
  }
  &.disabled{
    color: #bbb;
    cursor: not-allowed;
  }
}
</style>