UNPKG

koval-ui

Version:

React components collection with minimalistic design. Supports theming, layout, and input validation.

1 lines 1.88 kB
{"version":3,"file":"DrawerReducer.cjs","sources":["../../../../src/lib/Drawer/DrawerReducer.ts"],"sourcesContent":["/**\n * Action names collection\n * @example\n * import { Actions } from './DrawerReducer';\n * dispatch({ type: Drawer.DRAWER_CLOSE})\n * dispatch({ type: Drawer.DRAWER_OPEN})\n * */\nexport enum Actions {\n DRAWER_CLOSE = 'DRAWER_CLOSE',\n DRAWER_OPEN = 'DRAWER_OPEN',\n}\n\n/** Drawer ID type */\nexport type Id = string;\n\n/** Drawer state type */\nexport type DrawerState = {\n /** List of open Drawer IDs */\n open?: Id;\n};\n\nexport const initialState = {\n open: undefined,\n} as DrawerState;\n\nexport type DrawerAction = {\n /** ID of target Drawer */\n id: Id;\n /** Action name */\n type: Actions;\n};\n\nexport const DrawerReducer = (state = initialState, action: DrawerAction): DrawerState => {\n switch (action.type) {\n case Actions.DRAWER_CLOSE: {\n const {id} = action;\n const nextOpen = id === state.open ? undefined : state.open;\n return {\n ...state,\n open: nextOpen,\n };\n }\n case Actions.DRAWER_OPEN: {\n const {id} = action;\n return {\n ...state,\n open: id,\n };\n }\n default:\n return state;\n }\n};\n"],"names":["Actions","initialState","DrawerReducer","state","action","id","nextOpen"],"mappings":"6FAOY,IAAAA,GAAAA,IACRA,EAAA,aAAe,eACfA,EAAA,YAAc,cAFNA,IAAAA,GAAA,CAAA,CAAA,EAcL,MAAMC,EAAe,CACxB,KAAM,MACV,EASaC,EAAgB,CAACC,EAAQF,EAAcG,IAAsC,CACtF,OAAQA,EAAO,KAAM,CACjB,IAAK,eAAsB,CACjB,KAAA,CAAC,GAAAC,GAAMD,EACPE,EAAWD,IAAOF,EAAM,KAAO,OAAYA,EAAM,KAChD,MAAA,CACH,GAAGA,EACH,KAAMG,CACV,CAAA,CAEJ,IAAK,cAAqB,CAChB,KAAA,CAAC,GAAAD,GAAMD,EACN,MAAA,CACH,GAAGD,EACH,KAAME,CACV,CAAA,CAEJ,QACW,OAAAF,CAAA,CAEnB"}