
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
storybook-source-code-addon
Advanced tools
This is an addon for Storybook. It purpose is to allow anyone navigating your storybook to access the source code. It was implemented as an alternative to regular libraries, and to allow the end user to copy and paste your code instead of using it as a library.
It's pretty simple actually:
$ yarn add -D @storybook-source-code-addon
.storybook/main.js
module.exports = {
addons: ['storybook-source-code-addon']
}
If you happen to have your source code in a string, all you need is to add it to your story:
export default {
title: 'Your story',
parameters: {
componentSource: {
code: 'export default "This is my code"',
language: 'javascript',
}
},
};
With this approach, we recommend using a code file:
// MyComponent.code.js
export default `
const MyComponent = () => "Hello World"
`
import MyComponentCode from './MyComponent.code'
export default {
title: 'Your story',
parameters: {
componentSource: {
code: MyComponentCode,
language: 'javascript',
}
},
};
If your repository is publicly hosted, you can provide a url to your file to the addon:
export default {
title: 'Your story',
parameters: {
componentSource: {
url: 'https://path.to.your.repository/file%2Etsx',
language: 'javascript',
}
},
};
Common providers API include
https://gitlab.com/api/v4/projects/<ProjectID>/repository/files/<file path URL encoded>/raw?ref=master
for GitLabIf you want to expose multiple files, you can do as follow:
export default {
title: 'Your story',
parameters: {
componentSource: {
url: [
'https://path.to.your.repository/file%2Etsx',
'https://path.to.your.repository/file2%2Etsx',
],
language: 'javascript',
}
},
};
or
export default {
title: 'Your story',
parameters: {
componentSource: {
code: [
'export default "This is my code"',
'export default "This is also my code"',
],
language: 'javascript',
}
},
};
FAQs
## What is it?
The npm package storybook-source-code-addon receives a total of 1,464 weekly downloads. As such, storybook-source-code-addon popularity was classified as popular.
We found that storybook-source-code-addon demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.