-
Notifications
You must be signed in to change notification settings - Fork 13
MAJ des boutons de copy d'URL #1461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 11 commits
a9dd246
0040984
cd286fa
4281531
5a8c0c1
959c6de
ba10b0f
d304ea6
9498ef3
2c2995c
c1fe3c8
4585e5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| <script lang="ts" setup> | ||
| import { onMounted, ref, useTemplateRef } from "vue"; | ||
| import { RouteLocationRaw } from "vue-router"; | ||
| import router from "../../router"; | ||
|
|
||
| const props = withDefaults(defineProps<{ | ||
| icon: string; | ||
| label?: string; | ||
| successLabel?: string; | ||
| hiddenLabelSuffix?: string; | ||
| contentToCopy: string | RouteLocationRaw; | ||
| isWithinBtnGroup?: boolean; | ||
| }>(), { | ||
| label: "Copier le lien de partage", | ||
| successLabel: "Lien copié" | ||
| }); | ||
|
|
||
| const showSuccess = ref(false); | ||
|
|
||
| function copyContentToClipboard() { | ||
| if (showSuccess.value) return; | ||
|
|
||
| const content = typeof props.contentToCopy === "string" | ||
| ? props.contentToCopy | ||
| : window.location.origin + router.resolve(props.contentToCopy).fullPath; | ||
|
|
||
| navigator.clipboard.writeText(content).then(() => { | ||
| showSuccess.value = true; | ||
| }); | ||
|
|
||
| setTimeout(() => { | ||
| showSuccess.value = false; | ||
| }, 3500); | ||
| } | ||
|
|
||
| const initialButtonWidth = ref<string>(); | ||
| const copyButtonRef = useTemplateRef("copyButtonRef"); | ||
|
|
||
| onMounted(() => { | ||
| // FIXME: `setTimeout()` used to force computing element's width after prop is assigned | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fonctionne pas à tous les coups. Je suis preneur de solutions pour les reviewers ! |
||
| setTimeout(() => { | ||
| initialButtonWidth.value = `${copyButtonRef.value?.offsetWidth}px`; | ||
| }, 500); | ||
| }); | ||
| </script> | ||
|
|
||
| <template> | ||
| <button | ||
| ref="copyButtonRef" | ||
| type="button" | ||
| :class="[`fr-btn fr-btn--secondary fr-btn--icon-left ${showSuccess ? 'fr-icon-check-line copy-button--success' : icon} copy-button`, { | ||
| 'copy-button--within-btn-group fr-mb-0': isWithinBtnGroup | ||
| }]" | ||
| @click="copyContentToClipboard" | ||
| > | ||
| {{ showSuccess ? successLabel : label }} | ||
| <span v-if="hiddenLabelSuffix" class="fr-sr-only">{{ hiddenLabelSuffix }}</span> | ||
| </button> | ||
| </template> | ||
|
|
||
| <style scoped> | ||
| .copy-button { | ||
| &:not(.copy-button--within-btn-group) { | ||
| width: v-bind(initialButtonWidth) !important; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Super le Attention ça casse le côté responsive sur petits écrans, côté rapport ("within btn group"). Rajouter ici : max-width: 100%;Et sur flex-wrap: wrap;
max-width: 100%;
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bien vu ! D'ailleurs, j'ai l'impression que seul le |
||
| justify-content: center !important; | ||
| } | ||
| } | ||
|
|
||
| .copy-button--success { | ||
| color: var(--text-default-success) !important; | ||
| box-shadow: inset 0 0 0 1px var(--text-default-success) !important; | ||
| } | ||
| </style> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attention le comportement est étrange si on clic alors que le message de succès est déjà affiché et que le délai (
setTimeout) est en cours.Après la sélection du bouton "Copier le lien de partage", changer le
<button>par une<div>? Ainsi il ne sera plus possible de cliquer dessus ! Attention à la restitution aux aides techniques.Aussi, pour aller jusqu’au bout, on peut vérifier l’id retourné par le
setTimeout: ne pas relancer desetTimeouttant qu’un délai est en cours.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dans la méthode, j'ai rajouté ça pour ne rien faire si on montre déjà le succès. Et du coup ça relance pas un nouveau
setTimeout().