AppEditor.vue 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <script setup>
  2. import { computed } from 'vue'
  3. const props = defineProps({
  4. label: {
  5. type: String,
  6. required: true,
  7. },
  8. readOnly: {
  9. type: Boolean,
  10. required: false,
  11. },
  12. placeholder: {
  13. type: String,
  14. required: true,
  15. },
  16. error: {
  17. type: String,
  18. default: null,
  19. },
  20. editorStyle: null,
  21. modelValue: null,
  22. })
  23. defineEmits(['update:modelValue'])
  24. const isError = computed(() => (props.error ? true : false))
  25. const forLabel = computed(() =>
  26. props.label ? props.label.toLowerCase().replace(/\s+/g, '-') : null
  27. )
  28. const ariaDescribedbyLabel = computed(() =>
  29. props.label ? props.label.toLowerCase().replace(/\s+/g, '-') + '-help' : null
  30. )
  31. </script>
  32. <template>
  33. <div class="field">
  34. <label v-if="label" :for="forLabel">{{ label }}</label>
  35. <Editor
  36. :read-only="readOnly"
  37. :model-value="modelValue"
  38. :editor-style="editorStyle"
  39. :placeholder="placeholder"
  40. @text-change="$emit('update:modelValue', $event.htmlValue)"
  41. >
  42. <template #toolbar>
  43. <slot name="toolbar" />
  44. </template>
  45. </Editor>
  46. <small
  47. v-if="error"
  48. :id="ariaDescribedbyLabel"
  49. :class="{ 'p-error': isError }"
  50. >
  51. {{ error }}
  52. </small>
  53. </div>
  54. </template>