-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5dd722a
commit 6902db3
Showing
8 changed files
with
246 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import React, { useState } from "react"; | ||
import { LoginForm } from "./loginForm"; | ||
import { AccountContext } from "./accountContext"; | ||
import { SignupForm } from "./signupForm"; | ||
import {BoxContainer, TopContainer, HeaderContainer, | ||
BackDrop, InnerContainer, HeaderText, SmallText} from "../../../Layout/Auth/styledAuth"; | ||
|
||
const backdropVariants = { | ||
expanded: { | ||
width: "233%", | ||
height: "1050px", | ||
borderRadius: "20%", | ||
transform: "rotate(60deg)", | ||
}, | ||
collapsed: { | ||
width: "160%", | ||
height: "550px", | ||
borderRadius: "50%", | ||
transform: "rotate(60deg)", | ||
}, | ||
}; | ||
|
||
const expandingTransition = { | ||
type: "spring", | ||
duration: 2.3, | ||
stiffness: 30, | ||
}; | ||
|
||
const AccountBox = () => { | ||
const [isExpanded, setExpanded] = useState(false); | ||
const [active, setActive] = useState("signin"); | ||
|
||
const playExpandingAnimation = () => { | ||
setExpanded(true); | ||
setTimeout(() => { | ||
setExpanded(false); | ||
}, expandingTransition.duration * 1000 - 1500); | ||
}; | ||
|
||
const switchToSignup = () => { | ||
playExpandingAnimation(); | ||
setTimeout(() => { | ||
setActive("signup"); | ||
}, 400); | ||
}; | ||
|
||
const switchToSignin = () => { | ||
playExpandingAnimation(); | ||
setTimeout(() => { | ||
setActive("signin"); | ||
}, 400); | ||
}; | ||
|
||
const contextValue = { switchToSignup, switchToSignin }; | ||
|
||
return ( | ||
<AccountContext.Provider value={contextValue}> | ||
<BoxContainer> | ||
<TopContainer> | ||
<BackDrop | ||
initial={false} | ||
animate={isExpanded ? "expanded" : "collapsed"} | ||
variants={backdropVariants} | ||
transition={expandingTransition} | ||
/> | ||
{active === "signin" && ( | ||
<HeaderContainer> | ||
<HeaderText>Welcome</HeaderText> | ||
<HeaderText>Back</HeaderText> | ||
<SmallText>Please sign-in to continue!</SmallText> | ||
</HeaderContainer> | ||
)} | ||
{active === "signup" && ( | ||
<HeaderContainer> | ||
<HeaderText>Create</HeaderText> | ||
<HeaderText>Account</HeaderText> | ||
<SmallText>Please sign-up to continue!</SmallText> | ||
</HeaderContainer> | ||
)} | ||
</TopContainer> | ||
<InnerContainer> | ||
{active === "signin" && <LoginForm />} | ||
{active === "signup" && <SignupForm />} | ||
</InnerContainer> | ||
</BoxContainer> | ||
</AccountContext.Provider> | ||
); | ||
} | ||
|
||
export default AccountBox; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { createContext } from "react"; | ||
|
||
export const AccountContext = createContext(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React, { useContext } from "react"; | ||
import { | ||
BoldLink, | ||
BoxContainer, | ||
FormContainer, | ||
Input, | ||
MutedLink, | ||
SubmitButton, | ||
} from "../../../Layout/Auth/styledCommon"; | ||
import { Marginer } from "./marginer"; | ||
import { AccountContext } from "./accountContext"; | ||
|
||
export function LoginForm() { | ||
const { switchToSignup } = useContext(AccountContext); | ||
|
||
return ( | ||
<BoxContainer> | ||
<FormContainer> | ||
<Input type="email" placeholder="Email" /> | ||
<Input type="password" placeholder="Password" /> | ||
</FormContainer> | ||
<Marginer direction="vertical" margin={10} /> | ||
<MutedLink href="#">Forget your password?</MutedLink> | ||
<Marginer direction="vertical" margin="1.6em" /> | ||
<SubmitButton type="submit">Signin</SubmitButton> | ||
<Marginer direction="vertical" margin="1em" /> | ||
<MutedLink href="#"> | ||
Don't have an accoun?{" "} | ||
<BoldLink href="#" onClick={switchToSignup}> | ||
Signup | ||
</BoldLink> | ||
</MutedLink> | ||
</BoxContainer> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
|
||
const HorizontalMargin = styled.span` | ||
display: flex; | ||
width: ${({ margin }) => | ||
typeof margin === "string" ? margin : `${margin}px`}; | ||
`; | ||
|
||
const VerticalMargin = styled.span` | ||
display: flex; | ||
height: ${({ margin }) => | ||
typeof margin === "string" ? margin : `${margin}px`}; | ||
`; | ||
|
||
function Marginer(props) { | ||
const { direction } = props; | ||
|
||
if (direction === "horizontal") return <HorizontalMargin {...props} />; | ||
else { | ||
return <VerticalMargin {...props} />; | ||
} | ||
} | ||
|
||
Marginer.defaultProps = { | ||
direction: "horizontal", | ||
}; | ||
|
||
export { Marginer }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React, { useContext } from "react"; | ||
import { | ||
BoldLink, | ||
BoxContainer, | ||
FormContainer, | ||
Input, | ||
MutedLink, | ||
SubmitButton, | ||
} from "../../../Layout/Auth/styledCommon"; | ||
import { Marginer } from "./marginer"; | ||
import { AccountContext } from "./accountContext"; | ||
|
||
export function SignupForm() { | ||
const { switchToSignin } = useContext(AccountContext); | ||
|
||
return ( | ||
<BoxContainer> | ||
<FormContainer> | ||
<Input type="text" placeholder="Full Name" /> | ||
<Input type="email" placeholder="Email" /> | ||
<Input type="password" placeholder="Password" /> | ||
<Input type="password" placeholder="Confirm Password" /> | ||
</FormContainer> | ||
<Marginer direction="vertical" margin={10} /> | ||
<SubmitButton type="submit">Signup</SubmitButton> | ||
<Marginer direction="vertical" margin="1em" /> | ||
<MutedLink href="#"> | ||
Already have an account? | ||
<BoldLink href="#" onClick={switchToSignin}> | ||
Signin | ||
</BoldLink> | ||
</MutedLink> | ||
</BoxContainer> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters