-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(themes): add scale and shadow, storybook settings
- Loading branch information
Showing
112 changed files
with
1,142 additions
and
727 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 was deleted.
Oops, something went wrong.
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
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,41 @@ | ||
import { useAddonState } from '@storybook/client-api'; | ||
import { DecoratorFn } from '@storybook/react'; | ||
import React from 'react'; | ||
import { createGlobalStyle, ThemeProvider } from 'styled-components'; | ||
|
||
import themes from '../../src/common/themes/index'; | ||
import { SCALE } from '../../src/common/constants'; | ||
import { Theme } from '../../src/common/themes/types'; | ||
import { THEMES_ID } from './constants'; | ||
|
||
const GlobalScaledFont = createGlobalStyle` | ||
html { | ||
font-size: ${({ theme }: { theme: Theme }) => | ||
(theme?.scale ?? SCALE) * 2 + 12}px; | ||
} | ||
`; | ||
|
||
export const withThemeSettings: DecoratorFn = story => { | ||
const [themeName] = useAddonState(`${THEMES_ID}/themeName`, 'original'); | ||
const [themeScale] = useAddonState( | ||
`${THEMES_ID}/themeScale`, | ||
themes.original.scale | ||
); | ||
const [themeShadow] = useAddonState( | ||
`${THEMES_ID}/themeShadow`, | ||
themes.original.shadow | ||
); | ||
|
||
const theme: Theme = { | ||
...themes[themeName], | ||
scale: themeScale, | ||
shadow: themeShadow | ||
}; | ||
|
||
return ( | ||
<ThemeProvider theme={theme}> | ||
<GlobalScaledFont /> | ||
{story()} | ||
</ThemeProvider> | ||
); | ||
}; |
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,135 @@ | ||
import { useAddonState } from '@storybook/api'; | ||
import React, { useCallback } from 'react'; | ||
import styled, { ThemeProvider } from 'styled-components'; | ||
import { SCALE } from '../../src/common/constants'; | ||
|
||
import themes from '../../src/common/themes'; | ||
import { Checkbox, GroupBox, Slider } from '../../src/index'; | ||
import { Theme } from '../../src/types'; | ||
import { THEMES_ID } from './constants'; | ||
import { ThemeButton } from './ThemeButton'; | ||
|
||
const { | ||
original, | ||
rainyDay, | ||
vaporTeal, | ||
theSixtiesUSA, | ||
olive, | ||
tokyoDark, | ||
rose, | ||
plum, | ||
matrix, | ||
travel, | ||
...otherThemes | ||
} = themes; | ||
|
||
const themeList = [ | ||
original, | ||
rainyDay, | ||
vaporTeal, | ||
theSixtiesUSA, | ||
olive, | ||
tokyoDark, | ||
rose, | ||
plum, | ||
matrix, | ||
travel, | ||
...Object.values(otherThemes) | ||
]; | ||
|
||
type ThemesProps = { | ||
active?: boolean; | ||
}; | ||
|
||
const Wrapper = styled.div<{ theme: Theme }>` | ||
padding: 1em; | ||
background-color: ${({ theme }) => theme.material}; | ||
`; | ||
|
||
const ThemesGrid = styled.div` | ||
display: grid; | ||
grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); | ||
grid-template-rows: repeat(auto-fill, 40px); | ||
gap: 1em; | ||
margin-bottom: 1em; | ||
`; | ||
|
||
const marks = [ | ||
{ label: '1', value: 1 }, | ||
{ label: '2', value: 2 }, | ||
{ label: '3', value: 3 }, | ||
{ label: '4', value: 4 }, | ||
{ label: '5', value: 5 } | ||
]; | ||
|
||
export function ThemeSettings({ active }: ThemesProps) { | ||
const [themeName, setThemeName] = useAddonState( | ||
`${THEMES_ID}/themeName`, | ||
'original' | ||
); | ||
const [themeScale, setThemeScale] = useAddonState( | ||
`${THEMES_ID}/themeScale`, | ||
themes.original.scale | ||
); | ||
const [themeShadow, setThemeShadow] = useAddonState( | ||
`${THEMES_ID}/themeShadow`, | ||
themes.original.shadow | ||
); | ||
|
||
const handleChoose = useCallback( | ||
(newTheme: Theme) => { | ||
setThemeName(newTheme.name); | ||
}, | ||
[setThemeName] | ||
); | ||
|
||
const handleShadowChange = useCallback( | ||
(event: React.ChangeEvent<HTMLInputElement>) => { | ||
const checked = (event.target as HTMLInputElement).checked; | ||
setThemeShadow(checked); | ||
}, | ||
[] | ||
); | ||
|
||
const handleScaleChange = useCallback( | ||
(_: Event | React.SyntheticEvent, value: number) => { | ||
setThemeScale(value); | ||
}, | ||
[] | ||
); | ||
|
||
if (!active) { | ||
return <></>; | ||
} | ||
|
||
return ( | ||
<Wrapper key={THEMES_ID} theme={themes.original}> | ||
<ThemesGrid> | ||
{themeList.map(theme => ( | ||
<ThemeButton | ||
active={themeName === theme.name} | ||
key={theme.name} | ||
onChoose={handleChoose} | ||
theme={theme} | ||
/> | ||
))} | ||
</ThemesGrid> | ||
<ThemeProvider theme={themes.original}> | ||
<GroupBox label='Options'> | ||
<Checkbox | ||
checked={themeShadow} | ||
onChange={handleShadowChange} | ||
label='Modern Shadows' | ||
/> | ||
<Slider | ||
onChange={handleScaleChange} | ||
min={1} | ||
max={5} | ||
marks={marks} | ||
value={themeScale ?? SCALE} | ||
/> | ||
</GroupBox> | ||
</ThemeProvider> | ||
</Wrapper> | ||
); | ||
} |
File renamed without changes.
8 changes: 4 additions & 4 deletions
8
.storybook/theme-picker/register.ts → .storybook/theme-settings/register.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 |
---|---|---|
@@ -1,17 +1,17 @@ | ||
import addons, { makeDecorator, types } from '@storybook/addons'; | ||
import { THEMES_ID } from './constants'; | ||
import { ThemeList } from './ThemeList'; | ||
import { ThemeSettings } from './ThemeSettings'; | ||
|
||
addons.register(THEMES_ID, () => { | ||
addons.addPanel(`${THEMES_ID}/panel`, { | ||
title: 'Themes', | ||
title: 'Theme Settings', | ||
type: types.PANEL, | ||
render: ThemeList | ||
render: ThemeSettings | ||
}); | ||
}); | ||
|
||
export default makeDecorator({ | ||
name: 'withThemesProvider', | ||
name: 'withThemeSettingsProvider', | ||
parameterName: 'theme', | ||
wrapper: (getStory, context) => getStory(context) | ||
}); |
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.