Text.vue 1.6 KB

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