Socket
Socket
Sign inDemoInstall

@storybook/addon-viewport

Package Overview
Dependencies
2
Maintainers
9
Versions
1639
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @storybook/addon-viewport

Build responsive components by adjusting Storybook’s viewport size and orientation


Version published
Weekly downloads
4.9M
decreased by-1.28%
Maintainers
9
Created
Weekly downloads
 

Package description

What is @storybook/addon-viewport?

The @storybook/addon-viewport package allows developers to customize the viewport size to simulate different screen sizes in Storybook's UI. This is particularly useful for ensuring that components and layouts are responsive and look good on various devices, from mobile phones to desktop monitors.

What are @storybook/addon-viewport's main functionalities?

Custom Viewport Configuration

This code configures Storybook to use a set of predefined viewports. The INITIAL_VIEWPORTS constant provides a list of common device resolutions that can be used to test the responsiveness of components.

import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';

export const parameters = {
  viewport: {
    viewports: INITIAL_VIEWPORTS,
  },
};

Adding New Viewports

Developers can add custom viewports to the Storybook configuration. This code sample demonstrates how to add new devices, such as Kindle Fire 2 and Kindle Fire HD, with specific resolutions to the viewport addon.

export const parameters = {
  viewport: {
    viewports: {
      kindleFire2: {
        name: 'Kindle Fire 2',
        styles: {
          width: '600px',
          height: '963px',
        },
      },
      kindleFireHD: {
        name: 'Kindle Fire HD',
        styles: {
          width: '533px',
          height: '801px',
        },
      },
    },
  },
};

Other packages similar to @storybook/addon-viewport

Changelog

Source

8.0.9

  • Addon-docs: Fix MDX compilation when using @vitejs/plugin-react-swc with plugins - #26837, thanks @JReinhold!
  • CSF: Fix typings for control and other properties of argTypes - #26824, thanks @kasperpeulen!
  • Controls: Fix crashing when docgen extraction partially fails - #26862, thanks @yannbf!
  • Doc Tools: Signature Type Error Handling - #26774, thanks @ethriel3695!
  • Next.js: Move sharp into optional deps - #26787, thanks @shuta13!
  • Nextjs: Support next 14.2 useParams functionality - #26874, thanks @yannbf!
  • Test: Remove chai as dependency of @storybook/test - #26852, thanks @kasperpeulen!
  • UI: Fix sidebar search hanging when selecting a story in touch mode - #26807, thanks @JReinhold!

Readme

Source

Storybook Viewport Addon

Storybook Viewport Addon allows your stories to be displayed in different sizes and layouts in Storybook. This helps build responsive components inside of Storybook.

Framework Support

Screenshot

Installation

Viewport is part of essentials and so is installed in all new Storybooks by default. If you need to add it to your Storybook, you can run:

npm i -D @storybook/addon-viewport

Then, add following content to .storybook/main.js:

export default {
  addons: ['@storybook/addon-viewport'],
};

You should now be able to see the viewport addon icon in the toolbar at the top of the screen.

Usage

The usage is documented in the documentation.

Keywords

FAQs

Last updated on 22 Apr 2024

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