logo

pleroma-fe

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

color_input.vue (3735B)


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