Text.vue 1.4 KB

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