index.vue 1.49 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
<template>
  <label
    :class="cusClass" class="toggle toggle-positive toggle-check"
    @click="checked">
    <input :checked="value" :disabled="disable" type="checkbox">
    <div class="track">
      <div class="handle"/>
    </div>
  </label>
</template>

<script>
export default {
JingChao's avatar
JingChao committed
14
  name: 'HSwitch',
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    disable: {
      type: Boolean,
      default: false,
    },
    cusClass: {
      type: String,
      default: '',
    },
  },
  data () {
    return {
      // clickValue: false
    }
  },
  computed: {
JingChao's avatar
JingChao committed
35

36 37 38 39 40 41
  },
  watch: {
  },
  methods: {
    checked () {
      if (!this.disable) {
JingChao's avatar
JingChao committed
42
        this.$emit('input', !this.value)
43 44 45 46 47 48 49 50
        this.$emit('switchClick', !this.value)
      }
    },
  },
}
</script>

<style lang="less" scoped>
Nature's avatar
Nature committed
51
 @import "../../common/styles/variables";
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
  .toggle-check {
    display: -webkit-flex;
    display: flex;
    -webkit-justify-content: space-between;
    justify-content: space-between;
    -webkit-align-items: center;
    align-items: center;

    .track {
      width: 40px;
      height: 25px;
      margin-right: 2.5px;
      border-radius: 15px;
      .handle {
        width: 22.5px;
        height: 22.5px;
        top: 3.5px;
        left: 2.5px;
      }
    }
  }

  .toggle.toggle-positive input:checked + .track {
    border-color: @switch-box-bg;
    background-color: @switch-box-bg;

    .handle {
      width: 22.5px;
      height: 22.5px;
      top: 3.5px;
      left: 9px;
    }
  }
</style>