UNPKG

@carbon/ibm-products

Version:
34 lines (32 loc) 1.21 kB
/** * Copyright IBM Corp. 2020, 2026 * * 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, { createContext, useCallback, useContext, useState } from "react"; import PropTypes from "prop-types"; //#region src/components/WebTerminal/hooks/index.tsx const WebTerminalContext = createContext({}); const WebTerminalProvider = ({ children }) => { const [open, setOpen] = useState(false); const openWebTerminal = useCallback(() => setOpen(true), []); const closeWebTerminal = useCallback(() => setOpen(false), []); const toggleWebTerminal = useCallback(() => setOpen(!open), [open]); return /* @__PURE__ */ React.createElement(WebTerminalContext.Provider, { value: { open, openWebTerminal, closeWebTerminal, toggleWebTerminal } }, children); }; 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 }; const useWebTerminal = () => { return useContext(WebTerminalContext); }; //#endregion export { WebTerminalProvider, useWebTerminal };