Skip to content

Commit

Permalink
add modal manager, animations, state management and hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
deveshidwivedi committed Jun 22, 2024
1 parent a5d2fba commit 9625c8a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
14 changes: 14 additions & 0 deletions common/components/modal/animations/ModalManagar.animations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { DEFAULT_EASE } from "@/common/constants/easings";

const transition= {ease: DEFAULT_EASE};

export const bgAnimation = {
closed: {opacity: 0, transition},
opened: {opacity: 1, transition},
};

export const modalAnimation = {
closed: {y:-100, transition},
opened: {y:0, transition},
exited: {y:100, transition},
};
1 change: 1 addition & 0 deletions common/constants/easings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DEFAULT_EASE= [0.6, 0.01, -0.05, 0.9];
5 changes: 5 additions & 0 deletions common/recoil/modal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { modalAtom } from "./modal.atom";
import useModal from "./modal.hooks";

export default modalAtom;
export {useModal};
12 changes: 12 additions & 0 deletions common/recoil/modal/modal.atom.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { atom } from "recoil";

export const modalAtom = atom <{
modal: JSX.Element | JSX.Element[];
opened: boolean;
}>({
key: "modal",
default: {
modal:<></>,
opened: false,
},
});
23 changes: 23 additions & 0 deletions common/recoil/modal/modal.hooks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useSetRecoilState } from "recoil";
import { modalAtom } from "./modal.atom";

const useModal = () => {
const setModal= useSetRecoilState(modalAtom);
const openModal = (modal: JSX.Element | JSX.Element[]) => {
setModal({
modal,
opened: true,
});
};

const closeModal = () =>
setModal({
modal: <></>,
opened: false,
});

return {openModal, closeModal};

};

export default useModal;

0 comments on commit 9625c8a

Please sign in to comment.