-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added theme, components for PageContainer
- Loading branch information
1 parent
9f2acfa
commit ae6f7c1
Showing
36 changed files
with
391 additions
and
196 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
7 changes: 4 additions & 3 deletions
7
...es/src/stories/smart-controls.stories.mdx → ...o-docs/stories/smart-controls.stories.mdx
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 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,45 @@ | ||
import { Meta, PropsTable, Playground as Preview, Story, BlockContextProvider, ControlsTable, ComponentSource, StorySource } from '@component-controls/storybook'; | ||
import { Button } from '../../stories/src/components/Button'; | ||
|
||
<Meta title="Storybook/MDX" parameters={{component: Button}} /> | ||
|
||
|
||
# Smart controls | ||
<ComponentSource of={Button} title='Component source' /> | ||
|
||
<PropsTable of={Button} /> | ||
|
||
|
||
<Preview> | ||
<Story name="smart story"> | ||
{(props) => ( | ||
<Button label="default" {...props}/> | ||
)} | ||
</Story> | ||
</Preview> | ||
|
||
|
||
# Small story with custom controls | ||
|
||
<Preview> | ||
<Story name="small story" | ||
controls={{ | ||
text: {type: 'text', value: 'Hello'}, | ||
}} | ||
> | ||
{({ text }) => ( | ||
<Button label={text}/> | ||
)} | ||
</Story> | ||
</Preview> | ||
|
||
|
||
<ControlsTable name="small story" /> | ||
# Story with no parameters == no smart controls | ||
|
||
<Preview> | ||
<Story name="no controls"> | ||
<Button label="Hello"/> | ||
<Button label="Second button"/> | ||
</Story> | ||
</Preview> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
import React from 'react'; | ||
import { getLuminance } from 'polished'; | ||
import { ThemeContext, Theme } from '@storybook/theming'; | ||
import { ThemeProvider as ThemeUIProvider } from '@component-controls/components'; | ||
import { BlockContextProvider } from './BlockContext'; | ||
import { useIsDark } from './useIsDark'; | ||
|
||
export const ThemeProvider: React.FC = ({ children }) => { | ||
const { background: { content = '#ffffff' } = {} } = React.useContext<Theme>( | ||
ThemeContext as any, | ||
); | ||
const isDark = useIsDark(); | ||
return ( | ||
<ThemeUIProvider dark={getLuminance(content) < 0.5}> | ||
{children} | ||
<ThemeUIProvider dark={isDark}> | ||
<BlockContextProvider>{children}</BlockContextProvider> | ||
</ThemeUIProvider> | ||
); | ||
}; |
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,2 +1,3 @@ | ||
export * from './BlockContext'; | ||
export * from './ThemeProvider'; | ||
export * from './useIsDark'; |
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,19 @@ | ||
import React from 'react'; | ||
|
||
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)'); | ||
|
||
export const useIsDark = (): boolean => { | ||
const [isDark, setIsDark] = React.useState(prefersDark.matches); | ||
React.useEffect(() => { | ||
//inspired from: https://github.com/hipstersmoothie/storybook-dark-mode/blob/46476b4e96a5b310f13e7dccc69e2baa5e477814/src/Tool.tsx#L111 | ||
const prefersDarkUpdate = (event: MediaQueryListEvent) => { | ||
setIsDark(event.matches); | ||
}; | ||
prefersDark.addListener(prefersDarkUpdate); | ||
|
||
return () => { | ||
prefersDark.removeListener(prefersDarkUpdate); | ||
}; | ||
}); | ||
return isDark; | ||
}; |
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
Oops, something went wrong.