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