2023-10-23 23:33:39 +02:00
|
|
|
import { useMemo } from "react"
|
|
|
|
import Image from "next/image"
|
|
|
|
import classNames from "clsx"
|
2021-10-24 05:48:06 +02:00
|
|
|
|
2023-10-23 23:33:39 +02:00
|
|
|
import type { ProviderOAuth } from "../../../models/OAuth"
|
|
|
|
import styles from "./SocialMediaButton.module.css"
|
2022-04-07 16:54:05 +02:00
|
|
|
|
|
|
|
export type SocialMedia = ProviderOAuth
|
2021-10-24 05:48:06 +02:00
|
|
|
|
|
|
|
type SocialMediaColors = {
|
|
|
|
[key in SocialMedia]: string
|
|
|
|
}
|
|
|
|
|
|
|
|
const socialMediaColors: SocialMediaColors = {
|
2023-10-23 23:33:39 +02:00
|
|
|
Discord: "#404EED",
|
|
|
|
GitHub: "#24292E",
|
|
|
|
Google: "#FCFCFC",
|
2021-10-24 05:48:06 +02:00
|
|
|
}
|
|
|
|
|
2022-01-07 21:21:38 +01:00
|
|
|
const className =
|
2023-10-23 23:33:39 +02:00
|
|
|
"py-2 px-6 inline-flex outline-none items-center font-paragraph rounded-lg cursor-pointer transition duration-300 ease-in-out hover:opacity-80 focus:outline-none"
|
2022-01-07 21:21:38 +01:00
|
|
|
|
|
|
|
interface SocialMediaChildrenProps {
|
|
|
|
socialMedia: SocialMedia
|
|
|
|
}
|
|
|
|
|
|
|
|
const SocialMediaChildren: React.FC<SocialMediaChildrenProps> = (props) => {
|
|
|
|
const { socialMedia } = props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Image
|
2022-04-07 16:54:05 +02:00
|
|
|
quality={100}
|
2022-01-07 21:21:38 +01:00
|
|
|
width={20}
|
|
|
|
height={20}
|
|
|
|
src={`/images/svg/web/${socialMedia}.svg`}
|
|
|
|
alt={socialMedia}
|
|
|
|
/>
|
2023-10-23 23:33:39 +02:00
|
|
|
<span className="ml-2">{socialMedia}</span>
|
2022-01-07 21:21:38 +01:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface SocialMediaButtonProps
|
2023-10-23 23:33:39 +02:00
|
|
|
extends React.ComponentPropsWithRef<"button">,
|
2022-01-07 21:21:38 +01:00
|
|
|
SocialMediaChildrenProps {}
|
|
|
|
|
2021-10-24 05:48:06 +02:00
|
|
|
export const SocialMediaButton: React.FC<SocialMediaButtonProps> = (props) => {
|
2022-01-07 21:21:38 +01:00
|
|
|
const { socialMedia, className: givenClassName, ...rest } = props
|
2021-10-24 05:48:06 +02:00
|
|
|
|
|
|
|
const socialMediaColor = useMemo(() => {
|
|
|
|
return socialMediaColors[socialMedia]
|
|
|
|
}, [socialMedia])
|
|
|
|
|
|
|
|
return (
|
2022-12-13 22:31:32 +01:00
|
|
|
<button
|
|
|
|
{...rest}
|
|
|
|
style={{ background: socialMediaColor }}
|
|
|
|
className={classNames(
|
|
|
|
className,
|
2023-10-23 23:33:39 +02:00
|
|
|
styles["button"],
|
2022-12-13 22:31:32 +01:00
|
|
|
{
|
2023-10-23 23:33:39 +02:00
|
|
|
[styles["buttonGoogle"] as string]: socialMedia === "Google",
|
|
|
|
[styles["buttonMedia"] as string]: socialMedia !== "Google",
|
2022-12-13 22:31:32 +01:00
|
|
|
},
|
2023-10-23 23:33:39 +02:00
|
|
|
givenClassName,
|
2022-12-13 22:31:32 +01:00
|
|
|
)}
|
|
|
|
>
|
|
|
|
<SocialMediaChildren socialMedia={socialMedia} />
|
|
|
|
</button>
|
2021-10-24 05:48:06 +02:00
|
|
|
)
|
|
|
|
}
|
2022-01-07 21:21:38 +01:00
|
|
|
|
|
|
|
export interface SocialMediaLinkProps
|
2023-10-23 23:33:39 +02:00
|
|
|
extends React.ComponentPropsWithRef<"a">,
|
2022-01-07 21:21:38 +01:00
|
|
|
SocialMediaChildrenProps {}
|
|
|
|
|
|
|
|
export const SocialMediaLink: React.FC<SocialMediaLinkProps> = (props) => {
|
|
|
|
const { socialMedia, className: givenClassName, ...rest } = props
|
|
|
|
|
|
|
|
const socialMediaColor = useMemo(() => {
|
|
|
|
return socialMediaColors[socialMedia]
|
|
|
|
}, [socialMedia])
|
|
|
|
|
|
|
|
return (
|
2022-12-13 22:31:32 +01:00
|
|
|
<a
|
|
|
|
{...rest}
|
|
|
|
style={{ background: socialMediaColor }}
|
|
|
|
className={classNames(
|
|
|
|
className,
|
2023-10-23 23:33:39 +02:00
|
|
|
styles["button"],
|
2022-12-13 22:31:32 +01:00
|
|
|
{
|
2023-10-23 23:33:39 +02:00
|
|
|
[styles["buttonGoogle"] as string]: socialMedia === "Google",
|
|
|
|
[styles["buttonMedia"] as string]: socialMedia !== "Google",
|
2022-12-13 22:31:32 +01:00
|
|
|
},
|
2023-10-23 23:33:39 +02:00
|
|
|
givenClassName,
|
2022-12-13 22:31:32 +01:00
|
|
|
)}
|
|
|
|
>
|
|
|
|
<SocialMediaChildren socialMedia={socialMedia} />
|
|
|
|
</a>
|
2022-01-07 21:21:38 +01:00
|
|
|
)
|
|
|
|
}
|