-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added highlight and button to copy potential beneficiary email in dis…
…cussion
- Loading branch information
1 parent
cd34d80
commit 45da7e4
Showing
15 changed files
with
52 additions
and
62 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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
5 changes: 0 additions & 5 deletions
5
libs/react-design-system/src/immersionFacile/components/copy-button/CopyButton.scss
This file was deleted.
Oops, something went wrong.
This file contains 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
5 changes: 0 additions & 5 deletions
5
libs/react-design-system/src/immersionFacile/components/copy-button/CopyButton.styles.ts
This file was deleted.
Oops, something went wrong.
50 changes: 16 additions & 34 deletions
50
libs/react-design-system/src/immersionFacile/components/copy-button/CopyButton.tsx
This file contains 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 |
---|---|---|
@@ -1,56 +1,38 @@ | ||
import { fr } from "@codegouvfr/react-dsfr"; | ||
import React, { useState } from "react"; | ||
import Button, { ButtonProps } from "@codegouvfr/react-dsfr/Button"; | ||
import React from "react"; | ||
import { useStyles } from "tss-react/dsfr"; | ||
import Styles from "./CopyButton.styles"; | ||
import { useCopyButton } from "./useCopyButton"; | ||
|
||
export type CopyButtonProperties = { | ||
textToCopy: string; | ||
withBorder?: boolean; | ||
className?: string; | ||
} & ({ label: string; withIcon: boolean } | { withIcon: true }); | ||
export type CopyButtonProperties = ButtonProps.Common & | ||
ButtonProps.AsButton & { | ||
textToCopy: string; | ||
label?: string; | ||
withIcon?: boolean; | ||
}; | ||
|
||
export const CopyButton = (props: CopyButtonProperties) => { | ||
const { cx } = useStyles(); | ||
const [isCopied, setIsCopied] = useState(false); | ||
|
||
const onCopyButtonClick = (stringToCopy: string) => { | ||
navigator.clipboard | ||
.writeText(stringToCopy) | ||
.then(() => { | ||
setIsCopied(true); | ||
setTimeout(() => { | ||
setIsCopied(false); | ||
}, 3_000); | ||
}) | ||
|
||
.catch((error) => console.error(error)); | ||
}; | ||
|
||
const copyButtonIsDisabled = isCopied; | ||
|
||
const defaultLabel = "label" in props ? props.label : ""; | ||
const copyButtonLabel = isCopied ? "Copié !" : defaultLabel; | ||
const { onCopyButtonClick, copyButtonIsDisabled, copyButtonLabel } = | ||
useCopyButton(props.label); | ||
|
||
return ( | ||
<button | ||
<Button | ||
type="button" | ||
disabled={copyButtonIsDisabled} | ||
onClick={() => onCopyButtonClick(props.textToCopy)} | ||
size="small" | ||
priority="tertiary" | ||
className={cx( | ||
fr.cx( | ||
"fr-btn", | ||
"fr-btn--sm", | ||
"fr-btn--tertiary-no-outline", | ||
"fr-py-0", | ||
"fr-px-2v", | ||
props.withIcon && "fr-icon-clipboard-fill", | ||
props.withIcon && "fr-btn--icon-left", | ||
), | ||
props.withBorder && Styles.copyButtonBorder, | ||
props.className, | ||
)} | ||
type="button" | ||
> | ||
{copyButtonLabel} | ||
</button> | ||
</Button> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
libs/react-design-system/src/immersionFacile/components/copy-button/index.ts
This file contains 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./CopyButton"; | ||
export * from "./useCopyButton"; |
File renamed without changes.