Text.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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} 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. }
  30. },
  31. setup(props, {emit}){
  32. const edit = ref(false)
  33. const inputValue = ref(props.data)
  34. const update = () =>{
  35. edit.value = false
  36. if(inputValue.value !== props.data)
  37. emit('update', inputValue.value)
  38. }
  39. const close = () =>{
  40. edit.value = false
  41. inputValue.value = props.data
  42. }
  43. return {
  44. inputValue,
  45. edit,
  46. update,
  47. close
  48. }
  49. }
  50. })
  51. </script>
  52. <style lang="scss">
  53. .x-editable-input{
  54. input{
  55. padding: 0 !important;
  56. }
  57. .icons{
  58. padding: 5px;
  59. }
  60. }
  61. .edit-link{
  62. cursor: pointer;
  63. }
  64. </style>