Text.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. },
  33. data: {
  34. type: [String, Number],
  35. required: false,
  36. default: null
  37. }
  38. },
  39. setup (props, { emit }) {
  40. const edit: Ref<boolean> = ref(false)
  41. const inputValue: Ref<string|number|null> = ref(props.data)
  42. const update = () => {
  43. edit.value = false
  44. if (inputValue.value !== props.data) { emit('update', inputValue.value) }
  45. }
  46. const close = () => {
  47. edit.value = false
  48. inputValue.value = props.data
  49. }
  50. return {
  51. inputValue,
  52. edit,
  53. update,
  54. close
  55. }
  56. }
  57. })
  58. </script>
  59. <style lang="scss">
  60. .x-editable-input{
  61. input{
  62. padding: 0 !important;
  63. }
  64. .icons{
  65. padding: 5px;
  66. }
  67. }
  68. .edit-link{
  69. cursor: pointer;
  70. }
  71. </style>