-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from meza/colormode
Color mode
- Loading branch information
Showing
38 changed files
with
969 additions
and
139 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
import { addons } from '@storybook/manager-api'; | ||
import { theme } from './theme'; | ||
import theme from './theme'; | ||
|
||
addons.setConfig({ | ||
theme: theme, | ||
theme: theme | ||
}); | ||
|
||
export default theme; |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import i18n from '../testUtils/i18nextForStorybook'; | ||
import React, { useEffect } from 'react'; | ||
import { ColorMode, ColorModeContext } from '~/components/ColorModeSwitcher'; | ||
import { StoryContext, StoryFn } from '@storybook/react'; | ||
import '../src/styles/app.css'; | ||
import './storybook.css'; | ||
import { I18nextProvider } from 'react-i18next'; | ||
import theme from './theme'; | ||
import { useGlobals } from '@storybook/addons'; | ||
import { createRemixStub } from '@remix-run/testing/dist/create-remix-stub'; | ||
|
||
const createRemixStoryDecorator = (Story: StoryFn) => { | ||
const RemixStub = createRemixStub([ | ||
{ | ||
path: '/*', | ||
element: <Story/>, | ||
action: () => ({ redirect: '/' }), | ||
loader: () => ({ redirect: '/' }) | ||
} | ||
]); | ||
return <RemixStub/>; | ||
}; | ||
|
||
const withAllTheThings = (Story: StoryFn, context: StoryContext) => { | ||
const [globals, updateGlobals] = useGlobals(); | ||
const colorMode = globals.colorMode || ColorMode.LIGHT; | ||
|
||
const setStoryColorMode = (mode: ColorMode, force = true) => { | ||
const cl = document.firstElementChild?.classList; | ||
document.body.classList.remove(ColorMode.LIGHT, ColorMode.DARK); | ||
if (cl) { | ||
cl.remove(ColorMode.LIGHT, ColorMode.DARK); | ||
cl.add(mode); | ||
if (force) { | ||
updateGlobals({ colorMode: mode }); | ||
} | ||
} | ||
}; | ||
|
||
const RemixStub = createRemixStub([ | ||
{ | ||
path: '/*', | ||
element: <Story/>, | ||
action: () => ({ redirect: '/' }), | ||
loader: () => ({ redirect: '/' }) | ||
} | ||
]); | ||
|
||
useEffect(() => { | ||
setStoryColorMode(colorMode, false); | ||
}, [colorMode]); | ||
|
||
return ( | ||
<I18nextProvider i18n={i18n}> | ||
<ColorModeContext.Provider | ||
value={{ | ||
colorMode: colorMode, | ||
setColorMode: setStoryColorMode | ||
}}> | ||
<RemixStub/> | ||
</ColorModeContext.Provider> | ||
</I18nextProvider> | ||
); | ||
}; | ||
|
||
export const decorators = [ | ||
withAllTheThings | ||
]; | ||
|
||
/** @type { import('@storybook/react').Preview } */ | ||
export const parameters = { | ||
docs: { | ||
theme: theme, | ||
canvas: { | ||
background: false, | ||
className: 'storybook-canvas' | ||
}, | ||
story: { | ||
inline: true | ||
} | ||
}, | ||
actions: { argTypesRegex: '^on[A-Z].*' }, | ||
controls: { | ||
matchers: { | ||
color: /(background|color)$/i, | ||
date: /Date$/ | ||
} | ||
}, | ||
dependencies: { | ||
// display only dependencies/dependents that have a story in storybook | ||
// by default this is false | ||
withStoriesOnly: true, | ||
|
||
// completely hide a dependency/dependents block if it has no elements | ||
// by default this is false | ||
hideEmpty: true | ||
}, | ||
backgrounds: { disable: true }, | ||
locale: 'en', | ||
locales: { | ||
en: 'English' | ||
} | ||
}; | ||
|
||
export const globalTypes = { | ||
colorMode: { | ||
name: 'ColorMode', | ||
description: 'Color Mode', | ||
defaultValue: 'dark', | ||
toolbar: { | ||
items: [ | ||
{ value: 'dark', title: 'Dark', icon: 'moon' }, | ||
{ value: 'light', title: 'Light', icon: 'sun' } | ||
], | ||
showName: true, | ||
dynamicTitle: true | ||
} | ||
} | ||
}; | ||
|
||
|
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,6 @@ | ||
/** This is necessary to override the default canvas styles */ | ||
.storybook-canvas { | ||
background-color: var(--color-secondary) !important; | ||
color: var(--color-primary) !important; | ||
@custom-media --motion-ok true; | ||
} |
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,12 +1,9 @@ | ||
import { create } from '@storybook/theming/create'; | ||
|
||
export const theme = create({ | ||
export default create({ | ||
base: 'dark', | ||
brandTitle: 'Storybook', | ||
brandUrl: 'https://storybook.com', | ||
brandImage: 'https://placekitten.com/350/150', | ||
brandTarget: '_self', | ||
colorPrimary: '#ED117D', | ||
brandTarget: '_self' | ||
}); | ||
|
||
export default theme; |
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.