Text.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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} from "@vue/reactivity";
  37. import type {Ref} from "@vue/reactivity";
  38. const props = defineProps({
  39. type: {
  40. type: String,
  41. required: false,
  42. default: null
  43. },
  44. data: {
  45. type: [String, Number],
  46. required: false,
  47. default: null
  48. }
  49. })
  50. const emit = defineEmits(['update'])
  51. const edit: Ref<boolean> = ref(false)
  52. const inputValue: Ref<string|number|null> = ref(props.data)
  53. const update = () => {
  54. edit.value = false
  55. if (inputValue.value !== props.data) {
  56. emit('update', inputValue.value)
  57. }
  58. }
  59. const close = () => {
  60. edit.value = false
  61. inputValue.value = props.data
  62. }
  63. </script>
  64. <style scoped lang="scss">
  65. .v-input {
  66. height: 24px;
  67. }
  68. .v-icon {
  69. padding: 2px;
  70. height: 24px;
  71. width: 24px;
  72. margin: 0 2px;
  73. }
  74. .edit-link {
  75. cursor: pointer;
  76. }
  77. </style>