How PhoenixStorybook styling and sandboxing works
mainStyling Isolation
PhoenixStorybook uses TailwindCSS 4.x with preflight and a custom prefix psb:. To prevent styling leaks, only elements with the .psb class are preflighted. This ensures that unless your components use psb or psb: prefixed classes, the storybook's base styles won't affect them.
Component Styling via Scoped Styles
To provide your component's styles to the storybook without affecting the storybook UI, you should use scoped styles via a custom sandbox class:
- Define a
sandbox_class: In yourstorybook.exconfiguration, specify a custom class name (e.g.,sandbox_class: "my-app"). - Inject Stylesheets: Set the
css_pathoption instorybook.exto a remote path (e.g.,"/assets/css/storybook.css"). These are loaded within theappCSS layer, giving them priority over storybook styles. - Scope CSS: In your stylesheet, nest your component-specific CSS under your chosen sandbox class.
- Apply to Application: Add the sandbox class to the
<body>element of your main application layout.