From 62ba6720fd0c8cef46f0cbe8bdad4083a29cdf9f Mon Sep 17 00:00:00 2001 From: Danilo Woznica Date: Wed, 5 Jun 2024 15:21:57 +0100 Subject: [PATCH] fix(openCSB): pass children to buttons (#1144) * fix(open in CSB): pass children to buttons * format --- sandpack-react/src/PrivatePackage.stories.tsx | 22 ++++++------- .../UnstyledOpenInCodeSandboxButton.tsx | 2 +- .../src/contexts/utils/useFiles.test.ts | 32 ++++++++++--------- sandpack-react/src/contexts/utils/useFiles.ts | 2 +- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/sandpack-react/src/PrivatePackage.stories.tsx b/sandpack-react/src/PrivatePackage.stories.tsx index be40526ec..dc490c046 100644 --- a/sandpack-react/src/PrivatePackage.stories.tsx +++ b/sandpack-react/src/PrivatePackage.stories.tsx @@ -10,19 +10,19 @@ export const Basic: React.FC = () => { return (
Hello World - // }`, - // }} +export default function App() { + return +}`, + }} // options={{ bundlerURL: `http://localhost:3000` }} - options={{ bundlerURL: `https://2-1-0-sandpack.codesandbox.stream/` }} - teamId="6756547b-12fb-465e-82c8-b38a981f1f67" + // options={{ bundlerURL: `https://2-1-0-sandpack.codesandbox.stream/` }} + teamId="642af90c-4717-4730-bad3-e4c1e37ca5e2" template="react" />
diff --git a/sandpack-react/src/components/common/OpenInCodeSandboxButton/UnstyledOpenInCodeSandboxButton.tsx b/sandpack-react/src/components/common/OpenInCodeSandboxButton/UnstyledOpenInCodeSandboxButton.tsx index 2c25d037a..79e62d8e7 100644 --- a/sandpack-react/src/components/common/OpenInCodeSandboxButton/UnstyledOpenInCodeSandboxButton.tsx +++ b/sandpack-react/src/components/common/OpenInCodeSandboxButton/UnstyledOpenInCodeSandboxButton.tsx @@ -45,7 +45,7 @@ const getFileParameters = ( export const UnstyledOpenInCodeSandboxButton: React.FC< React.HtmlHTMLAttributes -> = ({ children, ...props }) => { +> = (props) => { const { sandpack } = useSandpack(); if (sandpack.exportOptions) { diff --git a/sandpack-react/src/contexts/utils/useFiles.test.ts b/sandpack-react/src/contexts/utils/useFiles.test.ts index d738f554c..95a16be4d 100644 --- a/sandpack-react/src/contexts/utils/useFiles.test.ts +++ b/sandpack-react/src/contexts/utils/useFiles.test.ts @@ -7,7 +7,7 @@ import { VANILLA_TEMPLATE } from "../../templates"; import { getSandpackStateFromProps } from "../../utils/sandpackUtils"; import { useFiles } from "./useFiles"; -import {SandpackBundlerFile} from "@codesandbox/sandpack-client/src"; +import { SandpackBundlerFile } from "@codesandbox/sandpack-client/src"; describe(useFiles, () => { it("should returns an initial state, which is the default template", () => { @@ -127,24 +127,26 @@ describe(useFiles, () => { expect(result.current[0].files["/index.js"]).toEqual({ code: `Baz` }); }); it("doesn't override the activeFile's metadata", () => { - const {result} = renderHook(() => useFiles({ - template: "react", - files: { - "/App.js": { - code: "export default function App() { return

Hello world

}", - readOnly: true, - someOtherMetadata: "foo" - } as SandpackBundlerFile - } - })); + const { result } = renderHook(() => + useFiles({ + template: "react", + files: { + "/App.js": { + code: "export default function App() { return

Hello world

}", + readOnly: true, + someOtherMetadata: "foo", + } as SandpackBundlerFile, + }, + }) + ); act(() => { result.current[1].updateFile("/App.js", "console.log(10)"); }); expect(result.current[0].files["/App.js"]).toEqual({ - code: "console.log(10)", - readOnly: true, - someOtherMetadata: "foo" + code: "console.log(10)", + readOnly: true, + someOtherMetadata: "foo", }); - }) + }); }); diff --git a/sandpack-react/src/contexts/utils/useFiles.ts b/sandpack-react/src/contexts/utils/useFiles.ts index faf168295..97752c3a0 100644 --- a/sandpack-react/src/contexts/utils/useFiles.ts +++ b/sandpack-react/src/contexts/utils/useFiles.ts @@ -78,7 +78,7 @@ export const useFiles: UseFiles = (props) => { ...files, [pathOrFiles]: { ...files[pathOrFiles], - code + code, }, }; } else if (typeof pathOrFiles === "object") {