Guest User

Untitled

a guest
Apr 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. <template>
  2. <div class="my-2">
  3. <div class="toggle">
  4. <input type="checkbox" :id="id" :name="id" value="1" v-on:change="updateValue($event.target.value)" :checked="isChecked" />
  5. <label :for="id"></label>
  6. </div>
  7. <p class="inline-block">{{ label }}</p>
  8. </div>
  9. </template>
  10.  
  11. <style lang="scss">
  12. .toggle {
  13. display: inline-block;
  14. position: relative;
  15. cursor: pointer;
  16. height: 2rem;
  17. width: 4rem;
  18. background: #3490dc;
  19. border-radius: 9999px;
  20. margin-bottom: 1rem;
  21.  
  22. input[type=checkbox] {
  23. visibility: hidden;
  24. }
  25.  
  26. label {
  27. display: block;
  28. width: 22px;
  29. height: 22px;
  30. border-radius: 50%;
  31.  
  32. transition: all .5s ease;
  33. cursor: pointer;
  34. position: absolute;
  35. top: 5px;
  36. z-index: 1;
  37. left: 7px;
  38. background: #ddd;
  39. }
  40.  
  41. input[type=checkbox]:checked + label {
  42. left: 35px;
  43. background: #FFF;
  44. }
  45. }
  46. </style>
  47.  
  48. <script>
  49. export default {
  50. props: ['id', 'label', 'value'],
  51.  
  52. methods: {
  53. updateValue: function () {
  54. let value = 0
  55.  
  56. if(this.value === 0) {
  57. value = 1
  58. }
  59.  
  60. this.$emit('input', value)
  61. }
  62. },
  63.  
  64. computed: {
  65. isChecked() {
  66. return this.value === 1
  67. }
  68. }
  69. }
  70. </script>
Add Comment
Please, Sign In to add comment