Checkbox.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <div
  3. class="
  4. cursor-pointer
  5. flex-nowrap
  6. group
  7. inline-flex
  8. items-center
  9. justify-center
  10. transition
  11. hover:text-secondaryDark
  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="cursor-pointer pl-0 align-middle font-semibold"
  25. >
  26. <slot></slot>
  27. </label>
  28. </div>
  29. </template>
  30. <script setup lang="ts">
  31. withDefaults(
  32. defineProps<{
  33. on: Boolean
  34. }>(),
  35. {
  36. on: false,
  37. }
  38. )
  39. </script>
  40. <style scoped lang="scss">
  41. input[type="checkbox"] {
  42. @apply appearance-none;
  43. @apply hidden;
  44. & + label {
  45. @apply inline-flex items-center justify-center;
  46. @apply cursor-pointer;
  47. &::before {
  48. @apply border-divider border-2;
  49. @apply rounded;
  50. @apply group-hover:border-accentDark;
  51. @apply inline-flex;
  52. @apply items-center;
  53. @apply justify-center;
  54. @apply text-transparent;
  55. @apply h-4;
  56. @apply w-4;
  57. @apply font-icon;
  58. @apply mr-3;
  59. @apply transition;
  60. content: "\e876";
  61. }
  62. }
  63. &:checked + label::before {
  64. @apply bg-accent;
  65. @apply border-accent;
  66. @apply text-accentContrast;
  67. }
  68. }
  69. </style>