Checkbox.vue 1.3 KB

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