Text.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. :modelValue="inputValue"
  13. @update="$emit('update:modelValue', $event.target.value)"
  14. />
  15. <v-icon
  16. icon="fas fa-check"
  17. aria-hidden="false"
  18. class="valid icons text-ot-green"
  19. size="small"
  20. @click="update"
  21. />
  22. <v-icon
  23. icon="fas fa-times"
  24. aria-hidden="false"
  25. class="cancel icons text-ot-grey"
  26. size="small"
  27. @click="close"
  28. />
  29. </div>
  30. <!-- Mode édition désactivé -->
  31. <div v-else class="edit-link d-flex align-center" @click="edit=true">
  32. <slot name="xeditable.read" v-bind="{inputValue}" />
  33. </div>
  34. </main>
  35. </template>
  36. <script setup lang="ts">
  37. import {ref, 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) { emit('update', inputValue.value) }
  56. }
  57. const close = () => {
  58. edit.value = false
  59. inputValue.value = props.data
  60. }
  61. </script>
  62. <style scoped lang="scss">
  63. .v-input {
  64. height: 24px;
  65. }
  66. .v-icon {
  67. padding: 2px;
  68. height: 24px;
  69. width: 24px;
  70. margin: 0 2px;
  71. }
  72. .edit-link {
  73. cursor: pointer;
  74. }
  75. </style>