Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(useWebTerminal): add typescript types #5132

Merged
merged 5 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading