UNPKG

@carbon/ibm-products

Version:

Carbon for IBM Products

53 lines (46 loc) 1.75 kB
/** * Copyright IBM Corp. 2020, 2025 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ import React__default, { useState, useCallback, createContext, useContext } from 'react'; import PropTypes from '../../../_virtual/index.js'; import { pkg } from '../../../settings.js'; // Copyright IBM Corp. 2022, 2022 // // This source code is licensed under the Apache-2.0 license found in the // LICENSE file in the root directory of this source tree. // const WebTerminalContext = /*#__PURE__*/createContext({}); const componentName = 'WebTerminalProvider'; let WebTerminalProvider = _ref => { let { children } = _ref; const [open, setOpen] = useState(false); const openWebTerminal = useCallback(() => setOpen(true), []); const closeWebTerminal = useCallback(() => setOpen(false), []); const toggleWebTerminal = useCallback(() => setOpen(!open), [open]); return /*#__PURE__*/React__default.createElement(WebTerminalContext.Provider, { value: { open, openWebTerminal, closeWebTerminal, toggleWebTerminal } }, children); }; // Return a placeholder if not released and not enabled by feature flag WebTerminalProvider = pkg.checkComponentEnabled(WebTerminalProvider, componentName); WebTerminalProvider.propTypes = { /** * Provide your own terminal component as children to show up in the web terminal */ children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired }; // Custom hook that exposes the provided value from context const useWebTerminal = () => { return useContext(WebTerminalContext); }; export { WebTerminalContext, WebTerminalProvider, useWebTerminal };