checkbox.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <label
  3. class="checkbox"
  4. :class="{ disabled, indeterminate }"
  5. >
  6. <input
  7. type="checkbox"
  8. :disabled="disabled"
  9. :checked="modelValue"
  10. :indeterminate="indeterminate"
  11. @change="$emit('update:modelValue', $event.target.checked)"
  12. >
  13. <i class="checkbox-indicator" />
  14. <span
  15. v-if="!!$slots.default"
  16. class="label"
  17. >
  18. <slot />
  19. </span>
  20. </label>
  21. </template>
  22. <script>
  23. export default {
  24. props: [
  25. 'modelValue',
  26. 'indeterminate',
  27. 'disabled'
  28. ],
  29. emits: ['update:modelValue']
  30. }
  31. </script>
  32. <style lang="scss">
  33. @import '../../_variables.scss';
  34. .checkbox {
  35. position: relative;
  36. display: inline-block;
  37. min-height: 1.2em;
  38. &-indicator {
  39. position: relative;
  40. padding-left: 1.2em;
  41. }
  42. &-indicator::before {
  43. position: absolute;
  44. right: 0;
  45. top: 0;
  46. display: block;
  47. content: '✓';
  48. transition: color 200ms;
  49. width: 1.1em;
  50. height: 1.1em;
  51. border-radius: $fallback--checkboxRadius;
  52. border-radius: var(--checkboxRadius, $fallback--checkboxRadius);
  53. box-shadow: 0px 0px 2px black inset;
  54. box-shadow: var(--inputShadow);
  55. background-color: $fallback--fg;
  56. background-color: var(--input, $fallback--fg);
  57. vertical-align: top;
  58. text-align: center;
  59. line-height: 1.1em;
  60. font-size: 1.1em;
  61. color: transparent;
  62. overflow: hidden;
  63. box-sizing: border-box;
  64. }
  65. &.disabled {
  66. .checkbox-indicator::before,
  67. .label {
  68. opacity: .5;
  69. }
  70. .label {
  71. color: $fallback--faint;
  72. color: var(--faint, $fallback--faint);
  73. }
  74. }
  75. input[type=checkbox] {
  76. display: none;
  77. &:checked + .checkbox-indicator::before {
  78. color: $fallback--text;
  79. color: var(--inputText, $fallback--text);
  80. }
  81. &:indeterminate + .checkbox-indicator::before {
  82. content: '–';
  83. color: $fallback--text;
  84. color: var(--inputText, $fallback--text);
  85. }
  86. }
  87. & > span {
  88. margin-left: .5em;
  89. }
  90. }
  91. </style>