logo

pleroma-fe

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

checkbox.vue (2413B)


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