Skip to content

Commit

Permalink
Merge pull request #24575 from storybookjs/22029-bug-preview-always-h…
Browse files Browse the repository at this point in the history
…as-a-white-background

Theming: Add theme variable to set the preview background color
  • Loading branch information
JReinhold authored Oct 31, 2023
2 parents e437742 + 94eee1f commit 8fdd30a
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions code/lib/theming/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const background = {
app: '#F6F9FC',
bar: color.lightest,
content: color.lightest,
preview: color.lightest,
gridCellSize: 10,
hoverable: transparentize(0.9, color.secondary), // hover state for items in a list

Expand Down
2 changes: 2 additions & 0 deletions code/lib/theming/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const convert = (inherit: ThemeVars = themes[getPreferredColorScheme()]):
colorSecondary,
appBg,
appContentBg,
appPreviewBg,
appBorderColor,
appBorderRadius,
fontBase,
Expand Down Expand Up @@ -116,6 +117,7 @@ export const convert = (inherit: ThemeVars = themes[getPreferredColorScheme()]):
app: appBg,
bar: barBg,
content: appContentBg,
preview: appPreviewBg,
gridCellSize: gridCellSize || background.gridCellSize,
hoverable: background.hoverable,
positive: background.positive,
Expand Down
1 change: 1 addition & 0 deletions code/lib/theming/src/themes/dark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const theme: ThemeVars = {
// UI
appBg: '#222425',
appContentBg: '#1B1C1D',
appPreviewBg: color.lightest,
appBorderColor: 'rgba(255,255,255,.1)',
appBorderRadius: 4,

Expand Down
1 change: 1 addition & 0 deletions code/lib/theming/src/themes/light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const theme: ThemeVars = {
// UI
appBg: background.app,
appContentBg: color.lightest,
appPreviewBg: color.lightest,
appBorderColor: color.border,
appBorderRadius: 4,

Expand Down
1 change: 1 addition & 0 deletions code/lib/theming/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface ThemeVarsColors {
// UI
appBg: string;
appContentBg: string;
appPreviewBg: string;
appBorderColor: string;
appBorderRadius: number;

Expand Down
6 changes: 3 additions & 3 deletions code/ui/manager/src/components/preview/iframe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import React from 'react';
import { styled } from '@storybook/theming';
import { Zoom } from '@storybook/components';

const StyledIframe = styled.iframe({
backgroundColor: 'white',
const StyledIframe = styled.iframe(({ theme }) => ({
backgroundColor: theme.background.preview,
position: 'absolute',
display: 'block',
boxSizing: 'content-box',
Expand All @@ -13,7 +13,7 @@ const StyledIframe = styled.iframe({
border: '0 none',
transition: 'background-position 0s, visibility 0s',
backgroundPosition: '-1px -1px, -1px -1px, -1px -1px, -1px -1px',
});
}));

export interface IFrameProps {
id: string;
Expand Down
3 changes: 1 addition & 2 deletions code/ui/manager/src/components/preview/utils/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const IframeWrapper = styled.div(({ theme }) => ({
right: 0,
width: '100%',
height: '100%',
background: theme.background.content,
}));

export const LoaderWrapper = styled.div(({ theme }) => ({
Expand All @@ -44,6 +43,6 @@ export const LoaderWrapper = styled.div(({ theme }) => ({
left: 0,
bottom: 0,
right: 0,
background: theme.background.content,
background: theme.background.preview,
zIndex: 1,
}));
1 change: 1 addition & 0 deletions docs/snippets/common/your-theme.js.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default create({
// UI
appBg: '#ffffff',
appContentBg: '#ffffff',
appPreviewBg: '#ffffff',
appBorderColor: '#585C6D',
appBorderRadius: 4,

Expand Down

0 comments on commit 8fdd30a

Please sign in to comment.