npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ergosign/storybook-addon-pseudo-states-vue

v0.0.1-alpha.61

Published

Storybook decorator to enable automatic generation and displaying of CSS pseudo states for components.

Downloads

82

Readme

Storybook Addon Pseudo States for Vue

This storybook addon allows you to automatically display pseudo states (and attribute states) of a component in Storybook's preview area.

Framework support

| Framework | Display States | Tool-Button to show/hide | | --------- | :------------: | :----------------------: | | Angular | + | + | | React | + | + | | Lit | + | + | | HTML | + | + | | Vue | + | + |

Getting started

First, add the addon to your project as a dev dependency:

npm install @ergosign/storybook-addon-pseudo-states-vue --save-dev

Next, enable it by adding it as an addon to .storybook/main.js, e.g.

module.exports = {
  stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
  addons: [
    '@storybook/addon-links',
    '@storybook/addon-essentials',
    '@ergosign/storybook-addon-pseudo-states-vue',
  ],
};

Since there's no way to force an element to appear with a specific pseudo state, the addon relies on specific classes to simulate the state. The Styling section explains how to generate them.

Once that's done, you can add the decorator to a story, as explained in Usage.

Styling

The recommended approach is to generate classes from your pseudo state CSS rules automatically. The easiest way is to use the postcss-pseudo-classes PostCSS plugin.

npm i -D postcss-pseudo-classes

Then add it to your postcss.config.js:

module.exports = {
  plugins: [require('postcss-pseudo-classes')],
};

postcss-pseudo-classes extracts all pseudo states from your styling and creates a class for each of them by adding a prefix, e.g. button:hover {} becomes button.\:hover {}. The default prefix is \:, and storybook-addon-pseudo-states-vue is configured to work with that configuration. If you need a different prefix, pass it to the plugin options:

module.exports = {
  plugins: {
    'postcss-pseudo-classes': {
      prefix: 'pseudoclass--',
    },
  },
};

And update your story config accordingly (more on configuring stories below):

{
  parameters: {
    withPseudo: {
      selector: "element",
      prefix: "pseudoclass--"
    },
  },
};

If you're unsure about how to set up PostCSS, you can check out the Vue CLI or PostCSS docs.

Manually

Alternatively, you can code the pseudo state classes manually. The naming pattern is prefix + pseudostate. With the default \: prefix, it would look something like this:

.element {
  // ...

  &:hover,
  &\:hover {
    // hover styling
  }

  &:focus,
  &\:focus {
    // focus styling
  }
}

Show/hide toolbar button

You can enable a toolbar button that toggles the pseudo states in the preview area. See framework support for information on which frameworks support this feature.

Enable the button by adding it to your .storybook/main.js file:

module.exports = {
  addons: ['@ergosign/storybook-addon-pseudo-states-vue'],
};

Usage

⚠️ withPseudo should always come first in your decorators array because it alters the template of the story.

General

Component Story Format (CSF, recommended)

import { withPseudo } from '@ergosign/storybook-addon-pseudo-states-vue';

const section = {
  title: 'Button',
  decorators: [withPseudo],
  parameters: {
    withPseudo: { selector: 'button' },
  },
};
export default section;

export const Story = () => {
  return {
    component: ButtonComponent,
  };
};

storyOf Format

import { withPseudo } from '@ergosign/storybook-addon-pseudo-states-vue';

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 empty.

With Vue

import { withPseudo } from '@ergosign/storybook-addon-pseudo-states-vue';
import { PseudoStateOrderDefault } from '@ergosign/storybook-addon-pseudo-states-vue/dist/share/types';
import SimpleButton from '../components/SimpleButton.vue';

export default {
  title: 'Simple Button',
  decorators: [withPseudo],
  parameters: {
    withPseudo: {
      pseudo: PseudoStateOrderDefault,
      attributes: ['disabled', { attr: 'appearance', value: 'primary' }],
    },
  },
  argTypes: {
    appearance: {
      control: false,
    },
  },
};

const template = (args, { argTypes }) => ({
  components: { SimpleButton },
  props: Object.keys(argTypes),
  template: '<simple-button :label="label" :disabled="disabled" />',
});

export const PseudoStates = template.bind({});
PseudoStates.args = {
  label: 'Hello World',
  disabled: false,
  appearance: false,
};

Parameters & Types

See types.ts

Known limitations

  • Vue 2.x support/not tested with Vue 3
  • Broken in docs view