Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
storybook-addon-prettier-source
Advanced tools
Storybook addon to show inline story source formatted using prettier and a syntax highlighter
Storybook addon to show inline story source code formatted using prettier and syntax highlighting
# yarn
yarn add --dev storybook-addon-prettier-source
# npm
npm install --save-dev storybook-addon-prettier-source
Apply to all your stories by adding a decorator in your .storybook/config.js
file:
import { withPrettierSource } from 'storybook-addon-prettier-source';
addDecorator((story, context) => withPrettierSource()(story)(context);
Or use per story
import { withPrettierSource } from 'storybook-addon-prettier-source';
storiesOf('Button', module)
.add(
'text',
withPrettierSource()(() => (
<Button text="Default" onClick={action('click')} />
))
)
You can easily combine this with the @storybook/addon-info addon, just disable the source code option in addon-info and exclude the PrettierSource
component from the prop tables
import { withPrettierSource, PrettierSource } from 'storybook-addon-prettier-source';
import { withInfo } from '@storybook/addon-info';
addDecorator((story, context) => withPrettierSource()(story)(context);
addDecorator((story, context) => withInfo({
source: false,
propTablesExclude: [PrettierSource]
})(story)(context);
withPrettierSource
takes an optional parameter for configuring options
Defaults shown are merged with any options provided
{
prettier: {
/* prettier options */
parser: 'babylon',
plugins: [require('prettier/parser-babylon')]
},
syntaxHighlighter: {
/* react-syntax-highlighter options */
language: 'javascript',
style: require('react-syntax-highlighter/styles/prism/tomorrow')
},
reactElToString: {
/* react-element-to-jsx-string options */
sortProps: false
}
}
We are using the standalone UMD bundle that runs in the browser, you can customise the options passed to prettier.format()
addDecorator((story, context) => withPrettierSource({
prettier: {
parser: 'graphql',
plugin: [require("prettier/parser-graphql")]
}
})(story)(context);
Customise any of the react-syntax-highlighter options to control how your source code looks
To change the style, provide one of the prism styles - you will need to install react-syntax-highlighter
in your project
import dark from 'react-syntax-highlighter/styles/prism/dark'
addDecorator((story, context) => withPrettierSource({
syntaxHighlighter: {
showLineNumbers: true,
style: dark
}
})(story)(context);
Provide options for the react-element-to-jsx-string library to control how your story component is turned into source code (keep in mind that the formatting is handled by prettier, so changing any of the format-related options may not do anything)
addDecorator((story, context) => withPrettierSource({
reactElToString: {
filterProps: ['wrapper']
}
})(story)(context);
FAQs
Storybook addon to show inline story source code formatted using prettier and a syntax highlighter
The npm package storybook-addon-prettier-source receives a total of 44 weekly downloads. As such, storybook-addon-prettier-source popularity was classified as not popular.
We found that storybook-addon-prettier-source 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
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.