diff options
| -rw-r--r-- | desktop/packages/mullvad-vpn/src/renderer/lib/components/animate/AnimateContext.tsx | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/desktop/packages/mullvad-vpn/src/renderer/lib/components/animate/AnimateContext.tsx b/desktop/packages/mullvad-vpn/src/renderer/lib/components/animate/AnimateContext.tsx new file mode 100644 index 0000000000..e9a41e8079 --- /dev/null +++ b/desktop/packages/mullvad-vpn/src/renderer/lib/components/animate/AnimateContext.tsx @@ -0,0 +1,33 @@ +import React from 'react'; + +interface AnimateContextProps { + present?: boolean; + initial?: boolean; + show: boolean; + setShow: React.Dispatch<React.SetStateAction<boolean>>; +} + +const AnimateContext = React.createContext<AnimateContextProps | undefined>(undefined); + +export const useAnimateContext = (): AnimateContextProps => { + const context = React.useContext(AnimateContext); + if (!context) { + throw new Error('useButtonContext must be used within a ButtonProvider'); + } + return context; +}; + +interface AnimateProviderProps { + present?: boolean; + initial?: boolean; + children: React.ReactNode; +} + +export const AnimateProvider = ({ present, initial, children }: AnimateProviderProps) => { + const [show, setShow] = React.useState<boolean>(present || false); + return ( + <AnimateContext.Provider value={{ present, initial, show, setShow }}> + {children} + </AnimateContext.Provider> + ); +}; |
