logo

pleroma-fe

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

color_input.vue (3206B)


  1. <template>
  2. <div
  3. class="color-input style-control"
  4. :class="{ disabled: !present || disabled }"
  5. >
  6. <label
  7. :for="name"
  8. class="label"
  9. >
  10. {{ label }}
  11. </label>
  12. <Checkbox
  13. v-if="typeof fallback !== 'undefined' && showOptionalTickbox"
  14. :model-value="present"
  15. :disabled="disabled"
  16. class="opt"
  17. @update:modelValue="$emit('update:modelValue', typeof modelValue === 'undefined' ? fallback : undefined)"
  18. />
  19. <div class="input color-input-field">
  20. <input
  21. :id="name + '-t'"
  22. class="textColor unstyled"
  23. type="text"
  24. :value="modelValue || fallback"
  25. :disabled="!present || disabled"
  26. @input="$emit('update:modelValue', $event.target.value)"
  27. >
  28. <div
  29. v-if="validColor"
  30. class="validIndicator"
  31. :style="{backgroundColor: modelValue || fallback}"
  32. />
  33. <div
  34. v-else-if="transparentColor"
  35. class="transparentIndicator"
  36. />
  37. <div
  38. v-else-if="computedColor"
  39. class="computedIndicator"
  40. :style="{backgroundColor: fallback}"
  41. />
  42. <div
  43. v-else
  44. class="invalidIndicator"
  45. />
  46. <label class="nativeColor">
  47. <FAIcon icon="eye-dropper"/>
  48. <input
  49. :id="name"
  50. class="unstyled"
  51. type="color"
  52. :value="modelValue || fallback"
  53. :disabled="!present || disabled"
  54. @input="$emit('update:modelValue', $event.target.value)"
  55. >
  56. </label>
  57. </div>
  58. </div>
  59. </template>
  60. <script>
  61. import Checkbox from '../checkbox/checkbox.vue'
  62. import { hex2rgb } from '../../services/color_convert/color_convert.js'
  63. import { library } from '@fortawesome/fontawesome-svg-core'
  64. import {
  65. faEyeDropper
  66. } from '@fortawesome/free-solid-svg-icons'
  67. library.add(
  68. faEyeDropper
  69. )
  70. export default {
  71. components: {
  72. Checkbox
  73. },
  74. props: {
  75. // Name of color, used for identifying
  76. name: {
  77. required: true,
  78. type: String
  79. },
  80. // Readable label
  81. label: {
  82. required: true,
  83. type: String
  84. },
  85. // Color value, should be required but vue cannot tell the difference
  86. // between "property missing" and "property set to undefined"
  87. modelValue: {
  88. required: false,
  89. type: String,
  90. default: undefined
  91. },
  92. // Color fallback to use when value is not defeind
  93. fallback: {
  94. required: false,
  95. type: String,
  96. default: undefined
  97. },
  98. // Disable the control
  99. disabled: {
  100. required: false,
  101. type: Boolean,
  102. default: false
  103. },
  104. // Show "optional" tickbox, for when value might become mandatory
  105. showOptionalTickbox: {
  106. required: false,
  107. type: Boolean,
  108. default: true
  109. }
  110. },
  111. emits: ['update:modelValue'],
  112. computed: {
  113. present () {
  114. return typeof this.modelValue !== 'undefined'
  115. },
  116. validColor () {
  117. return hex2rgb(this.modelValue || this.fallback)
  118. },
  119. transparentColor () {
  120. return this.modelValue === 'transparent'
  121. },
  122. computedColor () {
  123. return this.modelValue && this.modelValue.startsWith('--')
  124. }
  125. }
  126. }
  127. </script>
  128. <style lang="scss" src="./color_input.scss"></style>