Text.vue 1.5 KB

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