Skip to content

Commit

Permalink
fix(showOpenInCodeSandbox): pass prop to loading component (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
danilowoz committed Jun 1, 2022
1 parent 1478879 commit ba81506
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
7 changes: 5 additions & 2 deletions sandpack-react/src/common/Loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ const sidesClassNames = css({

export const Loading = ({
className,
showOpenInCodeSandbox,
...props
}: React.HTMLAttributes<HTMLDivElement>): JSX.Element => {
}: React.HTMLAttributes<HTMLDivElement> & {
showOpenInCodeSandbox: boolean;
}): JSX.Element => {
const c = useClasser(THEME_PREFIX);

return (
Expand All @@ -87,7 +90,7 @@ export const Loading = ({
title="Open in CodeSandbox"
{...props}
>
<OpenInCodeSandboxButton />
{showOpenInCodeSandbox && <OpenInCodeSandboxButton />}
<div className={classNames(c("cube"), cubeClassName)}>
<div className={classNames(c("sides"), sidesClassNames)}>
<div className="top" />
Expand Down
5 changes: 4 additions & 1 deletion sandpack-react/src/common/LoadingOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export interface LoadingOverlayProps {
* which is helpful for external loading states.
*/
loading?: boolean;

showOpenInCodeSandbox: boolean;
}

const loadingClassName = css({
Expand All @@ -40,6 +42,7 @@ export const LoadingOverlay = ({
loading,
className,
style,
showOpenInCodeSandbox,
...props
}: LoadingOverlayProps &
React.HTMLAttributes<HTMLDivElement>): JSX.Element | null => {
Expand Down Expand Up @@ -103,7 +106,7 @@ export const LoadingOverlay = ({
}}
{...props}
>
<Loading />
<Loading showOpenInCodeSandbox={showOpenInCodeSandbox} />
</div>
);
};
17 changes: 10 additions & 7 deletions sandpack-react/src/components/Preview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ export const SandpackPreview = React.forwardRef<
}}
{...props}
>
{showNavigator ? (
{showNavigator && (
<Navigator clientId={clientId.current} onURLChange={handleNewURL} />
) : null}
)}

<div className={classNames(c("preview-container"), previewClassName)}>
<iframe
Expand All @@ -183,7 +183,7 @@ export const SandpackPreview = React.forwardRef<
title="Sandpack Preview"
/>

{showSandpackErrorOverlay ? <ErrorOverlay /> : null}
{showSandpackErrorOverlay && <ErrorOverlay />}

<div
className={classNames(
Expand All @@ -192,14 +192,17 @@ export const SandpackPreview = React.forwardRef<
)}
>
{actionsChildren}
{!showNavigator && showRefreshButton && status === "running" ? (
{!showNavigator && showRefreshButton && status === "running" && (
<RefreshButton clientId={clientId.current} />
) : null}
)}

{showOpenInCodeSandbox ? <OpenInCodeSandboxButton /> : null}
{showOpenInCodeSandbox && <OpenInCodeSandboxButton />}
</div>

<LoadingOverlay clientId={clientId.current} />
<LoadingOverlay
clientId={clientId.current}
showOpenInCodeSandbox={showOpenInCodeSandbox}
/>

{children}
</div>
Expand Down
2 changes: 1 addition & 1 deletion sandpack-react/src/components/TranspiledCode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const SandpackTranspiledCode = ({
title="transpiled sandpack code"
/>
<ErrorOverlay />
<LoadingOverlay clientId="hidden" />
<LoadingOverlay clientId="hidden" showOpenInCodeSandbox={false} />
</div>
);
};

0 comments on commit ba81506

Please sign in to comment.