Storybook: Make grid cell size customizeable

Created on 4 Mar 2019  路  2Comments  路  Source: storybookjs/storybook

Right now it's hardcoded to be 10px. Our designer uses 8px grid, so I'd like to have it in storybook as well

feature request has workaround theming

Most helpful comment

@Hypnosphi I had the same issue. In my case I need a 12px grid.

To work around I did this:

  • Add Storybook Background Addon
  • Use custom SVG (You can take this, modify and encode it https://codepen.io/pigabo/pen/eAiLF) or just copy and modify the one from node_modules/@storybook/ui/src/components/preview/background.js
// config.js
import { addParameters } from "@storybook/react" // <- or your storybook framework

addParameters({
  backgrounds: [
    {
      name: "grid",
      value: `url("data:image/svg+xml,%3Csvg  xmlns='http://www.w3.org/2000/svg'%3E%3Cdefs%3E%3Cpattern id='smallGrid' width='12' height='12' patternUnits='userSpaceOnUse'%3E%3Cpath d='M 12 0 L 0 0 0 12' fill='none' stroke='gray' stroke-width='0.5'/%3E%3C/pattern%3E%3Cpattern id='grid' width='144' height='144' patternUnits='userSpaceOnUse'%3E%3Crect width='144' height='144' fill='url(%23smallGrid)'/%3E%3Cpath d='M 144 0 L 0 0 0 144' fill='none' stroke='gray' stroke-width='1'/%3E%3C/pattern%3E%3C/defs%3E%3Crect width='144%25' height='144%25' fill='url(%23grid)' /%3E%3C/svg%3E")`,
      default: true,
    },
  ],
})

Additionally there was a 8px margin in the preview area. Just add a preview-head.html and set whatever you need in a style tag.

Result:

Screen Shot 2019-03-22 at 2 56 42 AM

It's ugly but it works.

All 2 comments

@Hypnosphi I had the same issue. In my case I need a 12px grid.

To work around I did this:

  • Add Storybook Background Addon
  • Use custom SVG (You can take this, modify and encode it https://codepen.io/pigabo/pen/eAiLF) or just copy and modify the one from node_modules/@storybook/ui/src/components/preview/background.js
// config.js
import { addParameters } from "@storybook/react" // <- or your storybook framework

addParameters({
  backgrounds: [
    {
      name: "grid",
      value: `url("data:image/svg+xml,%3Csvg  xmlns='http://www.w3.org/2000/svg'%3E%3Cdefs%3E%3Cpattern id='smallGrid' width='12' height='12' patternUnits='userSpaceOnUse'%3E%3Cpath d='M 12 0 L 0 0 0 12' fill='none' stroke='gray' stroke-width='0.5'/%3E%3C/pattern%3E%3Cpattern id='grid' width='144' height='144' patternUnits='userSpaceOnUse'%3E%3Crect width='144' height='144' fill='url(%23smallGrid)'/%3E%3Cpath d='M 144 0 L 0 0 0 144' fill='none' stroke='gray' stroke-width='1'/%3E%3C/pattern%3E%3C/defs%3E%3Crect width='144%25' height='144%25' fill='url(%23grid)' /%3E%3C/svg%3E")`,
      default: true,
    },
  ],
})

Additionally there was a 8px margin in the preview area. Just add a preview-head.html and set whatever you need in a style tag.

Result:

Screen Shot 2019-03-22 at 2 56 42 AM

It's ugly but it works.

Boo-yah!! I just released https://github.com/storybooks/storybook/releases/tag/v5.1.0-alpha.14 containing PR #6252 that references this issue. Upgrade today to try it out!

Because it's a pre-release you can find it on the @next NPM tag.

Closing this issue. Please re-open if you think there's still more to do.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dnlsandiego picture dnlsandiego  路  3Comments

purplecones picture purplecones  路  3Comments

oriSomething picture oriSomething  路  3Comments

rpersaud picture rpersaud  路  3Comments

levithomason picture levithomason  路  3Comments