Skip to content

Commit

Permalink
feat: initial social login buttons implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
naumovski-filip committed May 30, 2023
1 parent 9e1b8da commit 0dd1204
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/assets/icons/facebook.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/icons/google.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/icons/twitter.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions src/components/SocialButton/SocialButton.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.socialButtonContainer {
display: flex;
justify-content: center;
align-items: center;
width: fit-content;
height: fit-content;
}

.socialButtonContainer:hover {
transform: scale(1.05);
cursor: pointer;
}

.socialButtonContainer:active {
transform: scale(0.95);
}
30 changes: 30 additions & 0 deletions src/components/SocialButton/SocialButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useEffect, useState } from 'react';

import styles from './SocialButton.module.scss';

export type SocialButtonVariant = 'facebook' | 'google' | 'twitter';

interface SocialButtonProps {
variant: SocialButtonVariant;
onClick: () => void;
}

const SocialButton = ({ variant, onClick }: SocialButtonProps) => {
const [icon, setIcon] = useState<string | null>(null);

useEffect(() => {
const getIcon = async () => {
const iconSvg = await (import(`../../assets/icons/${variant}.svg`) as Promise<{ default: string }>);
setIcon(iconSvg.default);
};
getIcon();
}, [variant]);

return (
<div onClick={onClick} className={styles.socialButtonContainer}>
<img src={icon ?? ''} alt={`${variant} icon`} />
</div>
);
};

export default SocialButton;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.socialButtonsListContainer {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: 100%;
padding: 1rem;
gap: 1rem;
}
24 changes: 24 additions & 0 deletions src/components/SocialButtonsList/SocialButtonsList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import SocialButton, { SocialButtonVariant } from '../SocialButton/SocialButton';

import styles from './SocialButtonsList.module.scss';

type SocialButtonsListProps = {
buttonProps: {
[key in SocialButtonVariant]: {
onClick: () => void;
};
};
};

const SocialButtonsList = ({ buttonProps }: SocialButtonsListProps) => {
const variants: SocialButtonVariant[] = ['facebook', 'google', 'twitter'];
return (
<div className={styles.socialButtonsListContainer}>
{variants.map((variant) => (
<SocialButton key={variant} variant={variant} onClick={buttonProps[variant].onClick} />
))}
</div>
);
};

export default SocialButtonsList;

0 comments on commit 0dd1204

Please sign in to comment.