UNPKG

@carbon/react

Version:

React components for the Carbon Design System

49 lines (43 loc) 1.09 kB
/** * Copyright IBM Corp. 2016, 2023 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var React = require('react'); const menuDefaultState = { isRoot: true, hasIcons: false, hasSelectableItems: false, size: null, items: [], requestCloseRoot: () => {} }; function menuReducer(state, action) { switch (action.type) { case 'enableIcons': return { ...state, hasIcons: true }; case 'enableSelectableItems': return { ...state, hasSelectableItems: true }; case 'registerItem': return { ...state, items: [...state.items, action.payload].filter(item => item.ref.current !== null) }; } } const MenuContext = /*#__PURE__*/React.createContext({ state: menuDefaultState, // 'dispatch' is populated by the root menu dispatch: _ => {} }); exports.MenuContext = MenuContext; exports.menuReducer = menuReducer;