logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://anongit.hacktivis.me/git/pleroma-fe.git/

checkbox.vue (2737B)


  1. <template>
  2. <label
  3. class="checkbox"
  4. :class="{ disabled, indeterminate, 'indeterminate-fix': indeterminateTransitionFix }"
  5. >
  6. <span
  7. v-if="!!$slots.before"
  8. class="label -before"
  9. :class="{ faint: disabled }"
  10. >
  11. <slot name="before" />
  12. </span>
  13. <input
  14. type="checkbox"
  15. class="visible-for-screenreader-only"
  16. :disabled="disabled"
  17. :checked="modelValue"
  18. :indeterminate="indeterminate"
  19. @change="$emit('update:modelValue', $event.target.checked)"
  20. >
  21. <i
  22. class="input -checkbox checkbox-indicator"
  23. :aria-hidden="true"
  24. :class="{ disabled }"
  25. @transitionend.capture="onTransitionEnd"
  26. />
  27. <span
  28. v-if="!!$slots.default"
  29. class="label -after"
  30. :class="{ faint: disabled }"
  31. >
  32. <slot />
  33. </span>
  34. </label>
  35. </template>
  36. <script>
  37. export default {
  38. props: [
  39. 'modelValue',
  40. 'indeterminate',
  41. 'disabled'
  42. ],
  43. emits: ['update:modelValue'],
  44. data: (vm) => ({
  45. indeterminateTransitionFix: vm.indeterminate
  46. }),
  47. watch: {
  48. indeterminate (e) {
  49. if (e) {
  50. this.indeterminateTransitionFix = true
  51. }
  52. }
  53. },
  54. methods: {
  55. onTransitionEnd () {
  56. if (!this.indeterminate) {
  57. this.indeterminateTransitionFix = false
  58. }
  59. }
  60. }
  61. }
  62. </script>
  63. <style lang="scss">
  64. @import "../../mixins";
  65. .checkbox {
  66. position: relative;
  67. display: inline-block;
  68. min-height: 1.2em;
  69. &-indicator,
  70. & .label {
  71. vertical-align: middle;
  72. }
  73. & > &-indicator {
  74. /* Reset .input stuff */
  75. padding: 0;
  76. margin: 0;
  77. position: relative;
  78. line-height: inherit;
  79. display: inline-block;
  80. width: 1.2em;
  81. height: 1.2em;
  82. box-shadow: none;
  83. }
  84. &-indicator::before {
  85. position: absolute;
  86. inset: 0;
  87. display: block;
  88. content: "✓";
  89. transition: color 200ms;
  90. width: 1.1em;
  91. height: 1.1em;
  92. border-radius: var(--roundness);
  93. box-shadow: var(--shadow);
  94. background-color: var(--background);
  95. vertical-align: top;
  96. text-align: center;
  97. line-height: 1.1em;
  98. font-size: 1.1em;
  99. color: transparent;
  100. overflow: hidden;
  101. box-sizing: border-box;
  102. }
  103. .disabled {
  104. .checkbox-indicator::before {
  105. background-color: var(--background);
  106. }
  107. }
  108. input[type="checkbox"] {
  109. &:checked + .checkbox-indicator::before {
  110. color: var(--text);
  111. }
  112. &:indeterminate + .checkbox-indicator::before {
  113. content: "–";
  114. color: var(--text);
  115. }
  116. }
  117. &.indeterminate-fix {
  118. input[type="checkbox"] + .checkbox-indicator::before {
  119. content: "–";
  120. }
  121. }
  122. & > .label {
  123. &.-after {
  124. margin-left: 0.5em;
  125. }
  126. &.-before {
  127. margin-right: 0.5em;
  128. }
  129. }
  130. }
  131. </style>