Skip to content

Commit

Permalink
refactor(useWebTerminal): add typescript types (#5132)
Browse files Browse the repository at this point in the history
* refactor(useWebTerminal): add typescript types

* refactor(useWebTerminal): resolve error in WebTerminal.tsx
  • Loading branch information
anamikaanu96 authored May 13, 2024
1 parent af22157 commit 351f095
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export let WebTerminal = React.forwardRef(
*/
useEffect(() => {
if (isInitiallyOpen) {
openWebTerminal();
openWebTerminal?.();
}
}, []); // eslint-disable-line

Expand All @@ -152,7 +152,7 @@ export let WebTerminal = React.forwardRef(
if (prefersReducedMotion) {
setRender(false);
}
closeWebTerminal();
closeWebTerminal?.();
};

return shouldRender ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,32 @@
// LICENSE file in the root directory of this source tree.
//

import React, { useState, useCallback, createContext } from 'react';
import React, { useState, useCallback, createContext, ReactNode } from 'react';
import { useContext } from 'react';
import PropTypes from 'prop-types';
import { pkg } from '../../../settings';

export const WebTerminalContext = createContext();
export interface WebTerminalContextType {
open?: boolean;
openWebTerminal?: () => void;
closeWebTerminal?: () => void;
toggleWebTerminal?: () => void;
}

export const WebTerminalContext = createContext<WebTerminalContextType>({});

const componentName = 'WebTerminalProvider';
export let WebTerminalProvider = ({ children }) => {

interface WebTerminalProviderProps {
/**
* Provide your own terminal component as children to show up in the web terminal
*/
children: ReactNode | ReactNode[];
}

export let WebTerminalProvider: React.FC<WebTerminalProviderProps> = ({
children,
}) => {
const [open, setOpen] = useState(false);

const openWebTerminal = useCallback(() => setOpen(true), []);
Expand Down

0 comments on commit 351f095

Please sign in to comment.