-
Notifications
You must be signed in to change notification settings - Fork 89
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
Showing
8 changed files
with
170 additions
and
12 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
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,68 @@ | ||
import { AnimatePresence, motion } from "framer-motion"; | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
import { BannerContext } from "../contexts/BannerContext"; | ||
import Icon from "./Icon"; | ||
import IconButton from "./IconButton"; | ||
|
||
const Container = styled(motion.div)` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
`; | ||
|
||
const CloseWrapper = styled(IconButton)` | ||
position: absolute; | ||
right: 1%; | ||
`; | ||
|
||
function Banner() { | ||
const bannerContext = React.useContext(BannerContext); | ||
|
||
return ( | ||
<AnimatePresence> | ||
{bannerContext.content && ( | ||
<Container | ||
variants={{ | ||
show: { | ||
// slide down | ||
y: 0, | ||
transition: { | ||
delayChildren: 0.3, | ||
staggerChildren: 0.2, | ||
}, | ||
}, | ||
hide: { | ||
// slide up | ||
y: "-100%", | ||
transition: { | ||
delayChildren: 0.3, | ||
staggerChildren: 0.2, | ||
}, | ||
}, | ||
}} | ||
initial="hide" | ||
animate="show" | ||
exit="hide" | ||
onAnimationComplete={() => { | ||
console.log("animation complete"); | ||
}} | ||
style={bannerContext.content.style} | ||
> | ||
{bannerContext.content.element} | ||
{!bannerContext.content.forced && ( | ||
<CloseWrapper | ||
onClick={() => { | ||
bannerContext.close(); | ||
}} | ||
> | ||
<Icon icon="mdiClose" color="var(--text)" size="24px" /> | ||
</CloseWrapper> | ||
)} | ||
</Container> | ||
)} | ||
</AnimatePresence> | ||
); | ||
} | ||
|
||
export default Banner; |
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,24 @@ | ||
import styled from "styled-components"; | ||
import Icon from "../Icon"; | ||
|
||
const Wrapper = styled.div` | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
`; | ||
|
||
const Text = styled.span` | ||
padding: 10px; | ||
color: var(--warning); | ||
`; | ||
|
||
function OfflineBanner() { | ||
return ( | ||
<Wrapper> | ||
<Text>You are offline</Text> | ||
<Icon icon="mdiWifiStrengthOff" color="var(--warning)" size="24px" /> | ||
</Wrapper> | ||
); | ||
} | ||
|
||
export default OfflineBanner; |
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,31 @@ | ||
// context to handle banner open/close state | ||
|
||
import { MotionStyle } from "framer-motion"; | ||
import React from "react"; | ||
|
||
export interface BannerContent { | ||
element: React.ReactNode; | ||
style?: MotionStyle; | ||
forced?: boolean; | ||
} | ||
|
||
export type BannerContextType = { | ||
content?: BannerContent; | ||
setContent: React.Dispatch<React.SetStateAction<BannerContent | undefined>>; | ||
close: () => void; | ||
}; | ||
|
||
// @ts-expect-error not specifying a default value here | ||
export const BannerContext = React.createContext<BannerContextType>(); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export const BannerContextProvider: React.FC<any> = ({ children }) => { | ||
const [content, setContent] = React.useState<BannerContent>(); | ||
|
||
const close = () => { | ||
// clear content | ||
setContent(undefined); | ||
}; | ||
|
||
return <BannerContext.Provider value={{ content, setContent, close }}>{children}</BannerContext.Provider>; | ||
}; |
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 |
---|---|---|
|
@@ -6,7 +6,6 @@ h5, | |
h6, | ||
p, | ||
span { | ||
color: var(--text); | ||
padding: 0; | ||
margin: 0; | ||
} | ||
|
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