-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make chromatic easier to opt-out of, update deps
- Loading branch information
1 parent
2d6ef77
commit 1a1fcbc
Showing
8 changed files
with
76 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import {addons} from '@storybook/preview-api'; | ||
import isChromatic from 'chromatic/isChromatic'; | ||
import {DARK_MODE_EVENT_NAME} from 'storybook-dark-mode'; | ||
import WrapDecorator from '../decorators/WrapDecorator'; | ||
import ChromaticDecorator from './decorator'; | ||
|
||
// render dark mode in chromatic snapshots | ||
export const isChromaticSnapshot = | ||
isChromatic() || | ||
(process.env.NODE_ENV === 'production' ? | ||
[...(window?.location.ancestorOrigins || {length: 0})].some((origin) => | ||
origin.includes('www.chromatic.com') | ||
) | ||
// @ts-ignore | ||
: false); | ||
|
||
if (!isChromaticSnapshot) { | ||
// listen for dark mode toggle changes | ||
const channel = addons.getChannel(); | ||
channel.on(DARK_MODE_EVENT_NAME, (isDark: boolean) => { | ||
// eslint-disable-next-line unicorn/prevent-abbreviations | ||
const docsStory = document.querySelector('.docs-story'); | ||
|
||
if (isDark) { | ||
document.documentElement.classList.add('dark'); | ||
docsStory?.classList.add('bg-grey-900'); | ||
docsStory?.classList.add('text-white'); | ||
} else { | ||
document.documentElement.classList.remove('dark'); | ||
docsStory?.classList.remove('bg-grey-900'); | ||
docsStory?.classList.remove('text-white'); | ||
} | ||
}); | ||
} | ||
|
||
export const decorators = | ||
isChromaticSnapshot ? [WrapDecorator, ChromaticDecorator] : [WrapDecorator]; |
7 changes: 5 additions & 2 deletions
7
.storybook/decorators/wrap.tsx → .storybook/decorators/WrapDecorator.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import type {ReactRenderer} from '@storybook/react'; | ||
import type {DecoratorFunction} from '@storybook/types'; | ||
|
||
const Wrap: DecoratorFunction<ReactRenderer> = (storyFn, {parameters}) => | ||
const WrapDecorator: DecoratorFunction<ReactRenderer> = ( | ||
storyFn, | ||
{parameters} | ||
) => | ||
parameters.wrap ? | ||
<div className={parameters.wrap}>{storyFn()}</div> | ||
: storyFn(); | ||
|
||
export default Wrap; | ||
export default WrapDecorator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters