Skip to content

Commit

Permalink
feat: Add Storybook CodeSandbox Addon for exporting stories to CodeSa…
Browse files Browse the repository at this point in the history
…ndbox with support for private dependencies and workspaces.
  • Loading branch information
danilowoz committed Mar 20, 2024
1 parent cacc034 commit bf55abc
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 11 deletions.
11 changes: 0 additions & 11 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@ import { Theme } from "@radix-ui/themes";

const preview: Preview = {
parameters: {
backgrounds: {
default: "light",
},
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},

codesandbox: {
/**
* CodeSandbox workspace id where sandbox will be created.
Expand Down
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
![Storybook CodeSandbox Addon](https://github.com/codesandbox/sandpack/assets/4838076/96c444fa-dcb0-4501-9024-6986b39f1455)

# Storybook CodeSandbox Addon

The `@codesandbox/storybook-addon` is a Storybook addon that facilitates exporting the current story to CodeSandbox. It offers support for private dependencies, workspaces, and more.

## Configuration

To run the addon, you'll need to configure it in your Storybook's `.storybook/preview.js` file.

```js
// .storybook/preview.js

codesandbox: {
/**
* CodeSandbox workspace id where the sandbox will be created.
* @required
*/
workspaceId: CUSTOM_WORKSPACE_ID,

/**
* List of dependencies to install in the sandbox
* @optional
*
* Example:
*/
dependencies: {
"@radix-ui/themes": "latest",
},

/**
* All required providers to run the sandbox properly, such as
* themes, i18n, store, and so on.
* @optional
*
* Example:
*/
provider: `import { Theme } from "@radix-ui/themes";
import '@radix-ui/themes/styles.css';
export default ThemeProvider = ({ children }) => {
return (
<Theme>
{children}
</Theme>
)
}`,
},
```

Make sure to provide the necessary values for workspaceId and any additional dependencies or providers required for your specific setup.

## Usage
Once configured, you can use the addon within your Storybook environment to export stories to CodeSandbox effortlessly.

## Additional Notes
- Ensure that you have proper permissions and access rights to the CodeSandbox workspace specified in the configuration.
- Verify the correctness of the dependencies and providers listed in the configuration to ensure the sandbox runs smoothly.

0 comments on commit bf55abc

Please sign in to comment.