This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
website/components/design/SocialMediaButton/SocialMediaButton.tsx

103 lines
2.5 KiB
TypeScript
Raw Normal View History

2021-10-24 05:48:06 +02:00
import { useMemo } from 'react'
import Image from 'next/image'
import classNames from 'clsx'
2021-10-24 05:48:06 +02:00
2022-08-31 21:44:33 +02:00
import type { ProviderOAuth } from '../../../models/OAuth'
2022-12-13 22:31:32 +01:00
import styles from './SocialMediaButton.module.css'
export type SocialMedia = ProviderOAuth
2021-10-24 05:48:06 +02:00
type SocialMediaColors = {
[key in SocialMedia]: string
}
const socialMediaColors: SocialMediaColors = {
Discord: '#404EED',
GitHub: '#24292E',
Google: '#FCFCFC'
}
const className =
'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'
interface SocialMediaChildrenProps {
socialMedia: SocialMedia
}
const SocialMediaChildren: React.FC<SocialMediaChildrenProps> = (props) => {
const { socialMedia } = props
return (
<>
<Image
quality={100}
width={20}
height={20}
src={`/images/svg/web/${socialMedia}.svg`}
alt={socialMedia}
/>
<span className='ml-2'>{socialMedia}</span>
</>
)
}
export interface SocialMediaButtonProps
extends React.ComponentPropsWithRef<'button'>,
SocialMediaChildrenProps {}
2021-10-24 05:48:06 +02:00
export const SocialMediaButton: React.FC<SocialMediaButtonProps> = (props) => {
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,
styles.button,
{
[styles.buttonGoogle]: socialMedia === 'Google',
[styles.buttonMedia]: socialMedia !== 'Google'
},
givenClassName
)}
>
<SocialMediaChildren socialMedia={socialMedia} />
</button>
2021-10-24 05:48:06 +02:00
)
}
export interface SocialMediaLinkProps
extends React.ComponentPropsWithRef<'a'>,
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,
styles.button,
{
[styles.buttonGoogle]: socialMedia === 'Google',
[styles.buttonMedia]: socialMedia !== 'Google'
},
givenClassName
)}
>
<SocialMediaChildren socialMedia={socialMedia} />
</a>
)
}