mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-26 05:16:41 +07:00
Modal
This commit is contained in:
parent
132fe872b6
commit
e5bc0d258f
17 changed files with 301 additions and 65 deletions
17
src/redux/modal/actions.ts
Normal file
17
src/redux/modal/actions.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { IModalState } from '~/redux/modal/reducer';
|
||||
import { MODAL_ACTIONS } from '~/redux/modal/constants';
|
||||
|
||||
export const modalSetShown = (is_shown: IModalState['is_shown']) => ({
|
||||
is_shown,
|
||||
type: MODAL_ACTIONS.SET_SHOWN,
|
||||
});
|
||||
|
||||
export const modalSetDialog = (dialog: IModalState['dialog']) => ({
|
||||
dialog,
|
||||
type: MODAL_ACTIONS.SET_DIALOG,
|
||||
});
|
||||
|
||||
export const modalShowDialog = (dialog: IModalState['dialog']) => ({
|
||||
dialog,
|
||||
type: MODAL_ACTIONS.SHOW_DIALOG,
|
||||
});
|
21
src/redux/modal/constants.ts
Normal file
21
src/redux/modal/constants.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { ValueOf } from "~/redux/types";
|
||||
import { HorizontalExample } from "~/containers/examples/HorizontalExample";
|
||||
|
||||
export const MODAL_ACTIONS = {
|
||||
SET_SHOWN: "MODAL.SET_SHOWN",
|
||||
SET_DIALOG: "SET_DIALOG",
|
||||
SHOW_DIALOG: "SHOW_DIALOG"
|
||||
};
|
||||
|
||||
export const DIALOGS = {
|
||||
TEST: "TEST"
|
||||
};
|
||||
|
||||
export const DIALOG_CONTENT = {
|
||||
[DIALOGS.TEST]: HorizontalExample
|
||||
};
|
||||
|
||||
export interface IDialogProps {
|
||||
onRequestClose: () => void;
|
||||
onDialogChange: (dialog: ValueOf<typeof DIALOGS>) => void;
|
||||
}
|
11
src/redux/modal/handlers.ts
Normal file
11
src/redux/modal/handlers.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
import { MODAL_ACTIONS } from '~/redux/modal/constants';
|
||||
|
||||
const setShown = (state, { is_shown }) => ({ ...state, is_shown });
|
||||
const showDialog = (state, { dialog }) => ({ ...state, dialog, is_shown: true });
|
||||
const setDialog = (state, { dialog }) => ({ ...state, dialog });
|
||||
|
||||
export const MODAL_HANDLERS = {
|
||||
[MODAL_ACTIONS.SET_SHOWN]: setShown,
|
||||
[MODAL_ACTIONS.SHOW_DIALOG]: showDialog,
|
||||
[MODAL_ACTIONS.SET_DIALOG]: setDialog,
|
||||
};
|
16
src/redux/modal/reducer.ts
Normal file
16
src/redux/modal/reducer.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { MODAL_HANDLERS } from "~/redux/modal/handlers";
|
||||
import { createReducer } from "~/utils/reducer";
|
||||
import { DIALOGS } from "~/redux/modal/constants";
|
||||
import { ValueOf } from "~/redux/types";
|
||||
|
||||
export interface IModalState {
|
||||
is_shown: boolean;
|
||||
dialog: ValueOf<typeof DIALOGS>;
|
||||
}
|
||||
|
||||
const INITIAL_STATE: IModalState = {
|
||||
is_shown: true,
|
||||
dialog: DIALOGS.TEST
|
||||
};
|
||||
|
||||
export default createReducer(INITIAL_STATE, MODAL_HANDLERS);
|
3
src/redux/modal/selectors.ts
Normal file
3
src/redux/modal/selectors.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
import { IState } from "~/redux/store";
|
||||
|
||||
export const selectModal = (state: IState) => state.modal;
|
Loading…
Add table
Add a link
Reference in a new issue