@carbon/ibm-products
Version:
Carbon for IBM Products
56 lines (48 loc) • 1.81 kB
JavaScript
/**
* 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.
*/
;
var React = require('react');
var index = require('../../../_virtual/index.js');
var settings = require('../../../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__*/React.createContext({});
const componentName = 'WebTerminalProvider';
exports.WebTerminalProvider = _ref => {
let {
children
} = _ref;
const [open, setOpen] = React.useState(false);
const openWebTerminal = React.useCallback(() => setOpen(true), []);
const closeWebTerminal = React.useCallback(() => setOpen(false), []);
const toggleWebTerminal = React.useCallback(() => setOpen(!open), [open]);
return /*#__PURE__*/React.createElement(WebTerminalContext.Provider, {
value: {
open,
openWebTerminal,
closeWebTerminal,
toggleWebTerminal
}
}, children);
};
// Return a placeholder if not released and not enabled by feature flag
exports.WebTerminalProvider = settings.pkg.checkComponentEnabled(exports.WebTerminalProvider, componentName);
exports.WebTerminalProvider.propTypes = {
/**
* Provide your own terminal component as children to show up in the web terminal
*/
children: index.default.oneOfType([index.default.arrayOf(index.default.node), index.default.node]).isRequired
};
// Custom hook that exposes the provided value from context
const useWebTerminal = () => {
return React.useContext(WebTerminalContext);
};
exports.WebTerminalContext = WebTerminalContext;
exports.useWebTerminal = useWebTerminal;