Text.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <!--
  2. Affichage texte qui passe en mode édition lorsqu'on clique dessus
  3. Utilisé par exemple pour le choix de l'année active
  4. -->
  5. <template>
  6. <main>
  7. <!-- Mode édition activé -->
  8. <div v-if="edit" class="d-flex align-center x-editable-input">
  9. <UiInputText
  10. class="ma-0 pa-0"
  11. :type="type"
  12. v-model="inputValue"
  13. />
  14. <v-icon
  15. icon="fas fa-check"
  16. aria-hidden="false"
  17. class="valid icons text-primary"
  18. size="small"
  19. @click="update"
  20. />
  21. <v-icon
  22. icon="fas fa-times"
  23. aria-hidden="false"
  24. class="cancel icons text-neutral-strong"
  25. size="small"
  26. @click="close"
  27. />
  28. </div>
  29. <!-- Mode édition désactivé -->
  30. <div v-else class="edit-link d-flex align-center" @click="edit=true">
  31. <slot name="xeditable.read" v-bind="{inputValue}" />
  32. </div>
  33. </main>
  34. </template>
  35. <script setup lang="ts">
  36. import {ref, Ref} from "@vue/reactivity";
  37. const props = defineProps({
  38. type: {
  39. type: String,
  40. required: false,
  41. default: null
  42. },
  43. data: {
  44. type: [String, Number],
  45. required: false,
  46. default: null
  47. }
  48. })
  49. const emit = defineEmits(['update'])
  50. const edit: Ref<boolean> = ref(false)
  51. const inputValue: Ref<string|number|null> = ref(props.data)
  52. const update = () => {
  53. edit.value = false
  54. if (inputValue.value !== props.data) {
  55. emit('update', inputValue.value)
  56. }
  57. }
  58. const close = () => {
  59. edit.value = false
  60. inputValue.value = props.data
  61. }
  62. </script>
  63. <style scoped lang="scss">
  64. .v-input {
  65. height: 24px;
  66. }
  67. .v-icon {
  68. padding: 2px;
  69. height: 24px;
  70. width: 24px;
  71. margin: 0 2px;
  72. }
  73. .edit-link {
  74. cursor: pointer;
  75. }
  76. </style>