Socket
Socket
Sign inDemoInstall

storybook-addon-rem

Package Overview
Dependencies
60
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    storybook-addon-rem

A storybook addon which helps you to test how your REM sized components behave.


Version published
Weekly downloads
4K
increased by15.53%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Storybook Addon REM

Storybook REM preview

A storybook addon which helps you to test how your REM sized components behave.

Why and when to use REM

Aleksandr Hovhannisyan wrote an awesome article about rems for font size. Check it out if you want to learn more about this CSS unit.

Getting started

Install the addon:

npm i storybook-addon-rem --dev

Add following content to .storybook/main.(js|mjs|cjs):

module.exports = {
  addons: ['storybook-addon-rem']
};

Add some css rem declerations to your component styling, e.g.:

.your-component-button {
  font-size: 1rem;
}

Run your storybook instance. You should be able to see and use this addon in the toolbar 🚀

Configuration

Custom sizes

If you want to pass custom sizes you can do this by adding something like this in the .storybook/preview.(js|mjs|cjs) file:

export const parameters = {
  // ...
  rem: {
    // ...
    sizes: [
      { value: 6, title: 'Tiny' },
      { value: 12, title: 'Standard' },
      { value: 72, title: 'Huge' },
    ]
  },
}

Default paddings

By default storybook-rem-addon removes storybooks rem paddings on the canvas and docs pages. If you want to keep the rem padding you can configure this in the .storybook/preview.(js|mjs|cjs) file:

export const parameters = {
  // ...
  rem: {
    // ...
    canvasRemPadding: true,
    docsRemPadding: true,
  }
};

Events

You can listen for the rem-update event via the addons channel:

const channel = api.getChannel();

// On mount
useEffect(() => {
  channel.addListener( 'rem-update', onRemUpdate );

  return () => {

    // On unmount
    channel.removeListener( 'rem-update', onRemUpdate );
  };
});

const onRemUpdate = ( data ) => {
  console.log( data.title, data.value );
}

Storybook addon REM development

run the build:watch process:

npm build:watch

open a second terminal. Go to examples/basic:

cd example/basic/

this is a plain storybook setup where this addon has been integrated. Install dependencies with

npm i

then start storybook with

npm run storybook

Notice: This storybook instance requires a lower node version than 18. If needed: Install NVM and switch to a lower version of nodejs e.g. v16.19.0 also known as lts/gallium:

nvm i lts/gallium
nvm use lts/gallium

Roadmap

  • Integrate Storybook events
  • Update icon(s)

Notes

  • Code structure greatly inspired by storybook-dark-mode. I learned and adapted a lot ❤️
  • Kudos to @storybook/a11y repository for showing how to implement a storybook toolbar with a tooltip.

Keywords

FAQs

Last updated on 25 Feb 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc