SW-3317 move toast to design system * chore: Move toast to design-system and add interaction tests * Move toast to design-system and add storybook tests * Merge branch 'master' of bitbucket.org:scandic-swap/web into SW-3317-move-toast-to-design-system * merge * move sonner dependency to @scandic-hotels/design-system Approved-by: Anton Gunnarsson
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
"use client"
|
|
|
|
import { useIntl } from "react-intl"
|
|
|
|
import { Button } from "@scandic-hotels/design-system/Button"
|
|
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
|
import { toast } from "@scandic-hotels/design-system/Toast"
|
|
import { Typography } from "@scandic-hotels/design-system/Typography"
|
|
|
|
import styles from "./copyMembershipIdButton.module.css"
|
|
|
|
interface CopyMembershipIdButtonProps {
|
|
membershipNumber: string
|
|
}
|
|
|
|
export default function CopyMembershipIdButton({
|
|
membershipNumber,
|
|
}: CopyMembershipIdButtonProps) {
|
|
const intl = useIntl()
|
|
|
|
function handleCopy() {
|
|
try {
|
|
navigator.clipboard.writeText(membershipNumber)
|
|
toast.success(
|
|
intl.formatMessage({
|
|
defaultMessage: "Membership ID copied to clipboard",
|
|
})
|
|
)
|
|
} catch {
|
|
toast.error(
|
|
intl.formatMessage({
|
|
defaultMessage: "Failed to copy",
|
|
})
|
|
)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className={styles.container}>
|
|
<Typography variant="Body/Supporting text (caption)/smBold">
|
|
<code data-hj-suppress className={styles.membershipCode}>
|
|
{membershipNumber}
|
|
</code>
|
|
</Typography>
|
|
<Button
|
|
onClick={handleCopy}
|
|
className={styles.copyButton}
|
|
variant="Text"
|
|
size="Small"
|
|
>
|
|
<MaterialIcon icon="content_copy" color="CurrentColor" />
|
|
</Button>
|
|
</div>
|
|
)
|
|
}
|