Text.vue 1.7 KB

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