Text.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <!--
  2. -->
  3. <template>
  4. <main>
  5. <div v-if="edit" class="d-flex align-center x-editable-input">
  6. <UiInputText
  7. class="ma-0 pa-0"
  8. :type="type"
  9. :modelValue="inputValue"
  10. @update="$emit('update:modelValue', $event.target.value)"
  11. />
  12. <v-icon
  13. icon="fas fa-check"
  14. aria-hidden="false"
  15. class="valid icons text-ot-green"
  16. size="small"
  17. @click="update"
  18. />
  19. <v-icon
  20. icon="fas fa-times"
  21. aria-hidden="false"
  22. class="cancel icons text-ot-grey"
  23. size="small"
  24. @click="close"
  25. />
  26. </div>
  27. <div v-else class="edit-link" @click="edit=true">
  28. <slot name="xeditable.read" v-bind="{inputValue}" />
  29. </div>
  30. </main>
  31. </template>
  32. <script setup lang="ts">
  33. import {ref, Ref} from "@vue/reactivity";
  34. const props = defineProps({
  35. type: {
  36. type: String,
  37. required: false,
  38. default: null
  39. },
  40. data: {
  41. type: [String, Number],
  42. required: false,
  43. default: null
  44. }
  45. })
  46. const emit = defineEmits(['update'])
  47. const edit: Ref<boolean> = ref(false)
  48. const inputValue: Ref<string|number|null> = ref(props.data)
  49. const update = () => {
  50. edit.value = false
  51. if (inputValue.value !== props.data) { emit('update', inputValue.value) }
  52. }
  53. const close = () => {
  54. edit.value = false
  55. inputValue.value = props.data
  56. }
  57. </script>
  58. <style scoped lang="scss">
  59. .v-input {
  60. height: 24px;
  61. }
  62. .v-icon {
  63. padding: 2px;
  64. height: 24px;
  65. width: 24px;
  66. margin: 0 2px;
  67. }
  68. .edit-link {
  69. cursor: pointer;
  70. }
  71. </style>