Checkbox.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <div
  3. class="
  4. flex-nowrap
  5. group
  6. hover:text-secondaryDark
  7. inline-flex
  8. items-center
  9. justify-center
  10. transition
  11. cursor-pointer
  12. "
  13. @click="$emit('change')"
  14. >
  15. <input
  16. id="checkbox"
  17. type="checkbox"
  18. name="checkbox"
  19. :checked="on"
  20. @change="$emit('change')"
  21. />
  22. <label
  23. for="checkbox"
  24. class="pl-0 font-semibold align-middle cursor-pointer"
  25. >
  26. <slot></slot>
  27. </label>
  28. </div>
  29. </template>
  30. <script>
  31. import { defineComponent } from "@nuxtjs/composition-api"
  32. export default defineComponent({
  33. props: {
  34. on: {
  35. type: Boolean,
  36. default: false,
  37. },
  38. },
  39. })
  40. </script>
  41. <style scoped lang="scss">
  42. input[type="checkbox"] {
  43. @apply appearance-none;
  44. @apply hidden;
  45. & + label {
  46. @apply inline-flex items-center justify-center;
  47. @apply cursor-pointer;
  48. &::before {
  49. @apply border-divider border-2;
  50. @apply rounded;
  51. @apply group-hover:border-accentDark;
  52. @apply inline-flex;
  53. @apply items-center;
  54. @apply justify-center;
  55. @apply text-transparent;
  56. @apply h-4;
  57. @apply w-4;
  58. @apply font-icon;
  59. @apply mr-3;
  60. @apply transition;
  61. content: "\e876";
  62. }
  63. }
  64. &:checked + label::before {
  65. @apply bg-accent;
  66. @apply border-accent;
  67. @apply text-accentContrast;
  68. }
  69. }
  70. </style>