Skip to content

Commit 18f5ac4

Browse files
committed
refactor the button component
1 parent 5b44bc8 commit 18f5ac4

6 files changed

Lines changed: 99 additions & 25 deletions

File tree

src/assets/variables.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ html.dark {
3131

3232
/** Buttons **/
3333
--button-background-color: #1c2026;
34+
--button-hover-background-color: #181c21;
3435
--button-text-color: #fff;
36+
--button-hover-text-color: #d0d0d0;
3537

3638
/**Card **/
3739
--card-background-color: #0d1116;
@@ -117,6 +119,8 @@ html.light {
117119

118120
--button-background-color: #d2deeb;
119121
--button-text-color: #3c5065;
122+
--button-hover-background-color: #b9cadc;
123+
--button-hover-text-color: #3c5065;
120124

121125
/**Card **/
122126
--card-background-color: #ffffff;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.button {
2+
background-color: var(--button-background-color);
3+
color: var(--button-text-color);
4+
font-size: 18px;
5+
text-align: center;
6+
border: 0;
7+
border-radius: 50px;
8+
cursor: pointer;
9+
position: relative;
10+
display: inline-flex;
11+
align-items: center;
12+
justify-content: center;
13+
gap: 0.5rem;
14+
&:hover {
15+
background-color: var(--button-hover-background-color);
16+
color: var(--button-hover-text-color);
17+
}
18+
}
19+
20+
button.small {
21+
padding: 0.5rem 1rem;
22+
font-size: 0.875rem;
23+
}
24+
button.medium {
25+
padding: 0.75rem 1.5rem;
26+
font-size: 1rem;
27+
}
28+
button.large {
29+
padding: 1rem 2rem;
30+
font-size: 1.25rem;
31+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import clsx from 'clsx'
2+
import React from 'react'
3+
import './Button.css'
4+
5+
const sizes = {
6+
small: 'small',
7+
medium: 'medium',
8+
large: 'large',
9+
}
10+
type ButtonProps = {
11+
children: React.ReactNode
12+
onClick: () => void
13+
className?: string
14+
size?: keyof typeof sizes
15+
startIcon?: React.ReactNode
16+
endIcon?: React.ReactNode
17+
}
18+
export const Button = ({
19+
size = 'medium',
20+
onClick,
21+
className,
22+
startIcon,
23+
endIcon,
24+
children,
25+
}: ButtonProps) => {
26+
return (
27+
<button className={clsx('button', sizes[size], className)} onClick={onClick}>
28+
{startIcon}
29+
{children}
30+
{endIcon}
31+
</button>
32+
)
33+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Button'

src/components/Elements/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './BottomNavigation'
2+
export * from './Button'
23
export * from './Card'
34
export * from './CardLink'
45
export * from './CardWithActions'

src/features/auth/components/AuthModal.tsx

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { FcGoogle } from 'react-icons/fc'
44
import { IoMdClose } from 'react-icons/io'
55
import ReactModal from 'react-modal'
66
import toast from 'react-simple-toasts'
7+
import { Button } from 'src/components/Elements'
78
import { useAuth } from 'src/features/auth'
89
import { trackUserConnect } from 'src/lib/analytics'
910
import { firebaseAuth, githubAuthProvider, googleAuthProvider } from 'src/lib/firebase'
@@ -59,32 +60,35 @@ export const AuthModal = ({ showAuth }: AuthModalProps) => {
5960
},
6061
}}
6162
overlayClassName="Overlay">
62-
<div className="titleAndCloseBtn">
63-
<h3>
64-
<FaHeart /> Join the community
65-
</h3>
66-
<button className="extraBtn" onClick={closeAuthModal}>
67-
<IoMdClose />
68-
</button>
69-
</div>
70-
<div className="buttons">
71-
<button
72-
className="extraTextWithIconBtn"
73-
onClick={() => signIn(githubAuthProvider, 'Github')}>
74-
<FaGithub />
75-
Connect with Github
76-
</button>
77-
<button
78-
className="extraTextWithIconBtn"
79-
onClick={() => signIn(googleAuthProvider, 'Google')}>
80-
<FcGoogle />
81-
Connect with Google
82-
</button>
63+
<div className="authModal">
64+
<div className="titleAndCloseBtn">
65+
<h3>
66+
<FaHeart /> Join the community
67+
</h3>
68+
<button className="extraBtn" onClick={closeAuthModal}>
69+
<IoMdClose />
70+
</button>
71+
</div>
72+
<div className="buttons">
73+
<Button
74+
startIcon={<FaGithub />}
75+
onClick={() => signIn(githubAuthProvider, 'Github')}
76+
size="large">
77+
Connect with Github
78+
</Button>
79+
80+
<Button
81+
startIcon={<FcGoogle />}
82+
onClick={() => signIn(googleAuthProvider, 'Google')}
83+
size="large">
84+
Connect with Google
85+
</Button>
86+
</div>
87+
<p className="description">
88+
We use your account to save your settings and track streaks for rowards 🎁 ... or risk
89+
losing them like unusaved code!
90+
</p>
8391
</div>
84-
<p className="description">
85-
We use your account to save your settings and track streaks for rowards 🎁 ... or risk
86-
losing them like unusaved code!
87-
</p>
8892
</ReactModal>
8993
)
9094
}

0 commit comments

Comments
 (0)