-
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
Open
bellangerq
wants to merge
12
commits into
main
Choose a base branch
from
1441-maj-le-bouton-de-copie-de-lien-de-livrable
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a9dd246
feat: create copybutton component and use it on report page
bellangerq 0040984
feat: add copybutton component and use it, alone or within btn-group
bellangerq cd286fa
tests: update e2e tests wording
bellangerq 4281531
fix: spacing and wording
bellangerq 5a8c0c1
feat: add default labels value for copybutton
bellangerq 959c6de
fix: wrap button group in report page
bellangerq ba10b0f
fix: return if showsuccess is already true to avoid creating multiple…
bellangerq d304ea6
feat: add optionnal a11y label prop to copybutton
bellangerq 9498ef3
fix: update wording and some button tweaks
bellangerq 2c2995c
fix: correctly computed copy link button width in report page header
bellangerq c1fe3c8
fix: slighly increase settimeout delay
bellangerq 4585e5a
fix: hardly make copy button size dont change when content does
bellangerq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| <script lang="ts" setup> | ||
| import { ref } from "vue"; | ||
| import { RouteLocationRaw } from "vue-router"; | ||
| import router from "../../router"; | ||
|
|
||
| /** | ||
| * FIXME: trigger warning ⚠️ the code of the following component is a bit dirty. | ||
| * | ||
| * The goal is to create a button that changes its content | ||
| * when clicked without changing its size, in 2 different contexts. | ||
| */ | ||
| 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); | ||
| } | ||
| </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" | ||
| > | ||
| <template v-if="isWithinBtnGroup"> | ||
| {{ showSuccess ? successLabel : label }} | ||
| </template> | ||
|
|
||
| <span v-else class="copy-button-outer-wrapper" :style="{ '--content': `'${label}'` }"> | ||
| <span class="copy-button-inner-wrapper"> | ||
| <template v-if="showSuccess"> | ||
| <span class="fr-icon-check-line copy-button-success-icon" aria-hidden="true" /> | ||
| {{ successLabel }} | ||
| </template> | ||
| <template v-else> | ||
| {{ label }} | ||
| </template> | ||
| </span> | ||
| </span> | ||
|
|
||
| <span v-if="hiddenLabelSuffix" class="fr-sr-only">{{ hiddenLabelSuffix }}</span> | ||
| </button> | ||
| </template> | ||
|
|
||
| <style scoped> | ||
| .copy-button { | ||
| &:not(.copy-button--within-btn-group) { | ||
| .copy-button-outer-wrapper { | ||
| position: relative; | ||
|
|
||
| &::after { | ||
| content: var(--content); | ||
| visibility: hidden; | ||
| } | ||
|
|
||
| .copy-button-inner-wrapper { | ||
| position: absolute; | ||
| inset: 0; | ||
| display: flex; | ||
| gap: 0.5rem; | ||
| } | ||
|
|
||
| .copy-button-success-icon::before { | ||
| --icon-size: 1rem; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .copy-button--success { | ||
| color: var(--text-default-success) !important; | ||
| box-shadow: inset 0 0 0 1px var(--text-default-success) !important; | ||
|
|
||
| &:not(.copy-button--within-btn-group) { | ||
| .copy-button-inner-wrapper { | ||
| translate: 1.5rem; | ||
| } | ||
|
|
||
| &::before { | ||
| opacity: 0 !important; | ||
| } | ||
| } | ||
| } | ||
| </style> | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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().