Text.vue 1.6 KB

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