Add src/components/cardStack/CardStackContext.tsx
This commit is contained in:
31
src/components/cardStack/CardStackContext.tsx
Normal file
31
src/components/cardStack/CardStackContext.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import { createContext, useContext, ReactNode } from 'react';
|
||||
|
||||
export interface CardStackContextType {
|
||||
isVisible: boolean;
|
||||
getAnimationProps: () => { isVisible: boolean };
|
||||
itemRefs?: Record<string, HTMLElement | null>;
|
||||
}
|
||||
|
||||
const CardStackContext = createContext<CardStackContextType | undefined>(undefined);
|
||||
|
||||
export function useCardStack() {
|
||||
const context = useContext(CardStackContext);
|
||||
if (!context) {
|
||||
return {
|
||||
isVisible: false,
|
||||
getAnimationProps: () => ({ isVisible: false }),
|
||||
itemRefs: {}
|
||||
};
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
export function CardStackProvider({ children, value }: { children: ReactNode; value: CardStackContextType }) {
|
||||
return (
|
||||
<CardStackContext.Provider value={value}>
|
||||
{children}
|
||||
</CardStackContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export default CardStackContext;
|
||||
Reference in New Issue
Block a user