Skip to content

Commit

Permalink
Merge pull request #1241 from betagouv/1216-hover-comments
Browse files Browse the repository at this point in the history
Ajout d'un DsfrTootlip on hover de l'infobulle commentaires
  • Loading branch information
pletelli authored Nov 8, 2024
2 parents 59e15b8 + cdc8bc9 commit 0a40c34
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions frontend/src/components/ElementCommentModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,27 @@
</ul>
</div>
</DsfrModal>
<button @click="infoModalOpened = true" :disabled="!hasInformationToShow">
<v-icon
:name="hasInformationToShow ? 'ri-chat-4-line' : 'ri-chat-off-line'"
:color="hasInformationToShow ? 'rgb(0, 0, 145)' : '#AAA'"
></v-icon>
</button>
<DsfrTooltip ref="tooltip" :onHover="true" :content="tooltipContent" class="tooltip-comments">
<button @click="infoModalOpened = true" :disabled="!hasInformationToShow">
<v-icon
:name="hasInformationToShow ? 'ri-chat-4-line' : 'ri-chat-off-line'"
:color="hasInformationToShow ? 'rgb(0, 0, 145)' : '#AAA'"
></v-icon>
</button>
</DsfrTooltip>
</div>
</template>

<script setup>
import { computed, ref } from "vue"
import { computed, ref, useTemplateRef, onMounted } from "vue"
import { getElementName } from "@/utils/elements"
const model = defineModel()
const tooltip = useTemplateRef("tooltip")
// Enlève le comportement par défaut de scroller vers le haut lors du click du DsfrTootlip
// en ajoutant un preventDefault du click
onMounted(() => tooltip.value?.$el?.nextElementSibling?.addEventListener?.("click", (e) => e.preventDefault()))
// Le backend sérialise les commentaires privés seulement si l'utilisateur.ice
// fait partie de l'administartion. Néanmoins, il y a des contextes où on ne
Expand All @@ -54,6 +61,14 @@ const elementName = computed(() => {
const maxQuantity = computed(() => element.value?.maxQuantity)
const constitutingSubstances = computed(() => element.value?.substances)
const tooltipContent = computed(() => {
let content = ""
if (element.value?.publicComments) content += `Commentaires :\n\n${element.value?.publicComments}`
if (element.value?.privateComments && !props.hidePrivateComments)
content += `\n\nCommentaires privés :\n\n${element.value?.privateComments}`
return content || "Pas de commentaires"
})
const infoModalOpened = ref(false)
const hasInformationToShow = computed(
() =>
Expand All @@ -63,3 +78,13 @@ const hasInformationToShow = computed(
constitutingSubstances.value?.length
)
</script>
<style scoped>
/* Il est nécessaire de surcharger certains styles di DSFRTooltip car un element a[href] est ajouté */
div :deep(.tooltip-comments) {
@apply !bg-none;
@apply !flex;
@apply !w-full;
@apply !justify-center;
}
</style>

0 comments on commit 0a40c34

Please sign in to comment.