UNPKG

786 BJavaScriptView Raw
1import { DropdownActionTypes } from './useDropdown.types';
2export function dropdownReducer(state, action) {
3 switch (action.type) {
4 case DropdownActionTypes.blur:
5 return {
6 open: false,
7 changeReason: action.event
8 };
9 case DropdownActionTypes.escapeKeyDown:
10 return {
11 open: false,
12 changeReason: action.event
13 };
14 case DropdownActionTypes.toggle:
15 return {
16 open: !state.open,
17 changeReason: action.event
18 };
19 case DropdownActionTypes.open:
20 return {
21 open: true,
22 changeReason: action.event
23 };
24 case DropdownActionTypes.close:
25 return {
26 open: false,
27 changeReason: action.event
28 };
29 default:
30 throw new Error(`Unhandled action`);
31 }
32}
\No newline at end of file