AppEditor.vue 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. const isError = computed(() => (props.error ? true : false))
  24. const forLabel = computed(() =>
  25. props.label ? props.label.toLowerCase().replace(/\s+/g, '-') : null
  26. )
  27. const ariaDescribedbyLabel = computed(
  28. () => props.label.toLowerCase().replace(/\s+/g, '-') + '-error'
  29. )
  30. </script>
  31. <template>
  32. <div class="field">
  33. <label v-if="label" :for="forLabel">{{ label }}</label>
  34. <Editor
  35. :read-only="readOnly"
  36. :model-value="modelValue"
  37. :editor-style="editorStyle"
  38. :placeholder="placeholder"
  39. @text-change="$emit('update:modelValue', $event.htmlValue)"
  40. >
  41. <template #toolbar>
  42. <slot name="toolbar" />
  43. </template>
  44. </Editor>
  45. <small
  46. v-if="error"
  47. :id="ariaDescribedbyLabel"
  48. :class="{ 'p-error': isError }"
  49. >
  50. {{ error }}
  51. </small>
  52. </div>
  53. </template>