This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3fefbdf
commit 4a09ea0
Showing
46 changed files
with
1,122 additions
and
1,323 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
41 changes: 0 additions & 41 deletions
41
client/storybook/src/chromatic-story/create-chromatic-story.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
client/storybook/src/decorators/withChromaticThemes/ChromaticRoot/ChromaticRoot.module.scss
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,7 @@ | ||
.theme-wrapper { | ||
padding: 1rem; | ||
color: var(--body-color); | ||
background-color: var(--body-bg); | ||
position: relative; | ||
min-height: 50vh; | ||
} |
31 changes: 31 additions & 0 deletions
31
client/storybook/src/decorators/withChromaticThemes/ChromaticRoot/ChromaticRoot.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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { FunctionComponent, PropsWithChildren, useState } from 'react' | ||
|
||
import classNames from 'classnames' | ||
|
||
import { PopoverRoot } from '@sourcegraph/wildcard' | ||
|
||
import { ChromaticThemeContext, ChromaticTheme } from '../../../hooks/useChromaticTheme' | ||
|
||
import styles from './ChromaticRoot.module.scss' | ||
|
||
interface ChromaticRootProps extends ChromaticTheme {} | ||
|
||
export const ChromaticRoot: FunctionComponent<PropsWithChildren<ChromaticRootProps>> = props => { | ||
const { theme, children } = props | ||
|
||
const [rootReference, setElement] = useState<HTMLDivElement | null>(null) | ||
const themeClass = theme === 'light' ? 'theme-light' : 'theme-dark' | ||
|
||
return ( | ||
<ChromaticThemeContext.Provider value={{ theme }}> | ||
{/* Required to render `Popover` inside of the `ChromaticRoot` component. */} | ||
<PopoverRoot.Provider value={{ renderRoot: rootReference }}> | ||
<div className={classNames(themeClass, styles.themeWrapper)}> | ||
{children} | ||
|
||
<div ref={setElement} /> | ||
</div> | ||
</PopoverRoot.Provider> | ||
</ChromaticThemeContext.Provider> | ||
) | ||
} |
1 change: 1 addition & 0 deletions
1
client/storybook/src/decorators/withChromaticThemes/ChromaticRoot/index.ts
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 @@ | ||
export * from './ChromaticRoot' |
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 @@ | ||
export * from './withChromaticThemes' |
32 changes: 32 additions & 0 deletions
32
client/storybook/src/decorators/withChromaticThemes/withChromaticThemes.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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { ReactElement } from 'react' | ||
|
||
import { DecoratorFunction } from '@storybook/addons' | ||
|
||
import { ChromaticRoot } from './ChromaticRoot' | ||
|
||
/** | ||
* The global Storybook decorator used to snapshot stories with multiple themes in Chromatic. | ||
* | ||
* It's a recommended way of achieving this goal: | ||
* https://www.chromatic.com/docs/faq#do-you-support-taking-snapshots-of-a-component-with-multiple-the | ||
* | ||
* If the `chromatic.enableDarkMode` story parameter is set to `true`, the story will | ||
* be rendered twice in Chromatic — in light and dark modes. | ||
*/ | ||
export const withChromaticThemes: DecoratorFunction<ReactElement> = (StoryFunc, { parameters }) => { | ||
if (parameters?.chromatic?.enableDarkMode) { | ||
return ( | ||
<> | ||
<ChromaticRoot theme="light"> | ||
<StoryFunc /> | ||
</ChromaticRoot> | ||
|
||
<ChromaticRoot theme="dark"> | ||
<StoryFunc /> | ||
</ChromaticRoot> | ||
</> | ||
) | ||
} | ||
|
||
return <StoryFunc /> | ||
} |
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,13 @@ | ||
import { createContext, useContext } from 'react' | ||
|
||
export interface ChromaticTheme { | ||
theme: 'light' | 'dark' | ||
} | ||
|
||
export const ChromaticThemeContext = createContext<ChromaticTheme>({ | ||
theme: 'light', | ||
}) | ||
|
||
export function useChromaticDarkMode(): boolean { | ||
return useContext(ChromaticThemeContext).theme === 'dark' | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './apollo/MockedStoryProvider' | ||
export * from './hooks/usePrependStyles' | ||
export * from './hooks/useTheme' | ||
export * from './utils/isChromatic' |
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
Oops, something went wrong.