[RFC] Allow styles targeted at individual viewports #25915
jasonsperske
started this conversation in
RFC
Replies: 1 comment 5 replies
-
Thank you so much for elaborating this RFC. We are currently working hard on the Storybook 8 beta, so it might take some time to check this in detail, so we appreciate your patience! @cdedreuille would you be interested in leading this since you had ideas regarding the viewports addon? |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
A proposal to add an attribute allowing style properties beyond height/width to be defined on a per-viewport basis.
Problem Statement
In my application, I use Storybook to test components for four different clients. Each client has its own dimensions and global style (in our case, padding and font size impact layout). Currently, Storybook doesn't provide a way to define these viewport styles without targeting all viewports.
Non-goals
This proposal is not seeking to provide a more extensive API to the addon-viewport (this might cover our specific use case but wouldn't scale to others).
Implementation
We would introduce a small bit of code that adds the
viewport.id
to the outerbody
element inside the previewiframe
with a data attribute nameddata-storybook-viewport-id
. This would allow people to write CSS that targets a specific viewport. Using the viewports that come with Storybook by default, this might look like this:By using the viewport ID we maintain consistency with configuration of viewports.
Prior Art
Projects already target the preview viewport in CSS, so this solution feels consistent with that approach (adding just an extra layer of information). Also, the approach is similar to how the addon-viewport implements the height/width settings in
https://github.com/storybookjs/storybook/blob/next/code/addons/viewport/src/Tool.tsx#L203-L210.
Deliverables
Risks
peramaters.viewports
Unresolved Questions
Alternatives considered / Abandoned Ideas
It is also possible to define the interface of
ViewportStyles
(found in code/addons/viewport/src/models/Viewport.ts) as like this:This would allow all CSS styles to be defined in the parameters. However this would require more downstream changes to support.
Beta Was this translation helpful? Give feedback.
All reactions