Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@ergosign/storybook-addon-pseudo-states-react
Advanced tools
Storybook decorator to enable automatic generation and displaying of CSS pseudo states for components.
Storybook Addon Pseudo States allows you to automatically display pseudo states (and attribute states) of a component in Storybook's preview area.
Framework | Display States | Tool-Button to show/hide |
---|---|---|
Angular | + | + |
React | + | + |
Lit | + | + |
HTML | + | + |
Vue | + | + |
First of all, you need to install Pseudo States into your project as a dev dependency.
npm install @ergosign/storybook-addon-pseudo-states-react --save-dev
Then, configure it as an addon by adding it to your addons.js file (located in the Storybook config directory).
To display the pseudo states, you have to add specific css classes to your styling, see Styling
Then, you can set the decorator locally, see Usage.
Preset-Postcss adds postcss-loader to Storybook's custom webpack config.
You must also install postcss-pseudo-classes. Unfortunately, latest version is only tagged and not released. Please use at least tagged version 0.3.0
npm install postcss-pseudo-classes@0.3.0 --save-dev
Then add the preset preset-postcss
to your configuration in main.js
(located in the Storybook config directory):
main.js;
module.exports = {
presets: ['@ergosign/storybook-addon-pseudo-states-react/preset-postcss'],
};
This creates for each css pseudo class an equivalent as normal css class (for instance :hover
to \:hover
), so that
you can use it in element's class attribute (<div class=":hover">Element in hover state</div>
).
You can modify post css loader options:
module.exports = {
presets: [
{
name:"@ergosign/storybook-addon-pseudo-states-react/preset-postcss",
options: {
postCssLoaderOptions: {
//prefix: '\:hover', // default for react
blacklist: [':nth-child', ':nth-of-type']
}
}
}
]
}
If you set another prefix you have to set the same for the addon, too.
Therefore, add the following to your .storybook/preview.js
:
addParameters({
withPseudo: {
prefix: "still-pseudo-states--",
},
});
Add postcss-loader to a Storybook custom webpack config
module.exports = {
module: {
rules: [
{
test: /\.(scss|css)$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
// ATTENTION when using css modules
modules: {
// !!! must not use [hash]'
localIdentName: '[path][name]__[local]',
},
},
},
// Add loader here
{
loader: 'postcss-loader',
},
{
loader: 'sass-loader',
},
],
},
],
},
};
npm install postcss-pseudo-classes --save-dev
And enable it in postcss.config.js
module.exports = {
plugins: {
'postcss-pseudo-classes': {
// prefix: 'pseudoclass--',
},
},
};
module.exports = {
plugins: {
'postcss-pseudo-classes': {
prefix: 'pseudoclass-example-prefix',
},
},
};
In addition to the standard pseudo state styling, you have to add fake classes consisting of prefix
+ pseudostate
(\:hover
, \:focus
, \:active
, \:yourOwnState
) by yourself.
Be aware that default prefix is \:
. When using your own prefix, update your styling accordingly.
.element {
//element styling
&:hover,
&\:hover {
// hover styling
}
}
custom prefix: .pseudoclass--
// in your story
parameters: {
withPseudo: {
selector: "element",
prefix: "pseudoclass--"
}
}
.element {
//element styling
&:hover,
&.pseudoclass--hover {
// hover styling
}
}
You can enable a toolbar button that toggles the Pseudo States in the Preview area.
See Framework Support which Frameworks support this feature.
Enable the button by adding it to your main.js
file (located in the Storybook config directory):
// main.js
module.exports = {
addons: ['@ergosign/storybook-addon-pseudo-states-react/register'],
};
WARNING:
withPseudo
should always the first element in yourdecorators
array because it alters the template of the story.
import { withPseudo } from '@ergosign/storybook-addon-pseudo-states-react';
const section = {
title: 'Button',
decorators: [withPseudo],
parameters: {
withPseudo: { selector: 'button' },
},
};
export default section;
export const Story = () => {
return {
component: ButtonComponent,
};
};
import { withPseudo } from '@ergosign/storybook-addon-pseudo-states-react';
storiesOf('Button', module)
.addDecorator(withPseudo)
.addParameters({
withPseudo: {
selector: 'button', // css selector of pseudo state's host element
pseudo: ['focus', 'hover', 'hover & focus', 'active'],
attributes: ['disabled', 'readonly', 'error'],
},
})
.add('Icon Button', () => <Button />);
There is a default configuration for selector
, pseudos
and attributes
. Thus, you can leave withPseudo
options it empty.
When using CSS Modules, you must use automatically styling generation via postcss-loader
(see Styling section).
attributes
enable component's props.
import { withPseudo } from '@ergosign/storybook-addon-pseudo-states-react';
storiesOf('Button', module)
.addDecorator(withPseudo)
.addParameters({
withPseudo: {
attribtues: [], // no attributes to show --> overwrite default [DISABLE]
},
})
.add('Button', () => <Button label="I'm a normal button" />)
.addParameters({
withPseudo: {
pseudo: [...PseudoStatesDefault, 'hover & focus'],
attributes: [
...AttributesStatesDefault,
'selected',
'error',
'isLoading',
'isReady',
]
},
})
.add('Button', () => <Button label="I'm a normal button" />);
See Types
0.0.1-alpha.29 (2020-04-07)
FAQs
Storybook decorator to enable automatic generation and displaying of CSS pseudo states for components.
The npm package @ergosign/storybook-addon-pseudo-states-react receives a total of 150 weekly downloads. As such, @ergosign/storybook-addon-pseudo-states-react popularity was classified as not popular.
We found that @ergosign/storybook-addon-pseudo-states-react demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.