generated from agustinusnathaniel/nextarter-chakra
-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(storybook): configure storybook
- Loading branch information
1 parent
eaefd9a
commit 38850af
Showing
7 changed files
with
1,355 additions
and
2,598 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,32 @@ | ||
const { TsconfigPathsPlugin } = require("tsconfig-paths-webpack-plugin"); | ||
|
||
const path = require("path") | ||
const toPath = (_path) => path.join(process.cwd(), _path) | ||
|
||
/** @type {import('@storybook/react/types').StorybookConfig} */ | ||
module.exports = { | ||
stories: ["../src/**/*.stories.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"], | ||
addons: ["@storybook/addon-links", "@storybook/addon-essentials"], | ||
addons: [ | ||
"@storybook/addon-links", | ||
"@storybook/addon-essentials", | ||
"@storybook/addon-toolbars", | ||
"@storybook/addon-a11y", | ||
"@storybook/addon-storysource", | ||
"storybook-addon-performance/register", | ||
], | ||
framework: "@storybook/react", | ||
webpackFinal: async (config) => { | ||
return { | ||
...config, | ||
resolve: { | ||
...config.resolve, | ||
alias: { | ||
...config.resolve.alias, | ||
"@emotion/core": toPath("node_modules/@emotion/react"), | ||
"emotion-theming": toPath("node_modules/@emotion/react"), | ||
}, | ||
plugins: [...(config.resolve.plugins ?? []), new TsconfigPathsPlugin()], | ||
}, | ||
} | ||
}, | ||
}; |
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 @@ | ||
import { create } from "@storybook/theming"; | ||
|
||
export default create({ | ||
base: "dark", | ||
brandTitle: "Spoker Storybook", | ||
brandURL: "https://storybook.spoker.sznm.dev", | ||
}); |
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 @@ | ||
import { addons } from "@storybook/addons"; | ||
|
||
import mainTheme from "./mainTheme"; | ||
|
||
addons.setConfig({ | ||
theme: mainTheme, | ||
}); |
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,80 @@ | ||
import { | ||
ChakraProvider, | ||
Flex, | ||
IconButton, | ||
useColorMode, | ||
useColorModeValue, | ||
} from "@chakra-ui/react"; | ||
import { Parameters, StoryContext } from "@storybook/react"; | ||
import * as React from "react"; | ||
import { FaMoon, FaSun } from "react-icons/fa"; | ||
import { withPerformance } from "storybook-addon-performance"; | ||
|
||
import customTheme from "../src/lib/styles/theme"; | ||
|
||
/** | ||
* Add global context for RTL-LTR switching | ||
*/ | ||
export const globalTypes = { | ||
direction: { | ||
name: "Direction", | ||
description: "Direction for layout", | ||
defaultValue: "LTR", | ||
toolbar: { | ||
icon: "globe", | ||
items: ["LTR", "RTL"], | ||
}, | ||
}, | ||
}; | ||
|
||
const ColorModeToggleBar = () => { | ||
const { toggleColorMode } = useColorMode(); | ||
const SwitchIcon = useColorModeValue(FaMoon, FaSun); | ||
const nextMode = useColorModeValue("dark", "light"); | ||
|
||
return ( | ||
<Flex justify="flex-end" mb={4}> | ||
<IconButton | ||
size="md" | ||
fontSize="lg" | ||
aria-label={`Switch to ${nextMode} mode`} | ||
variant="ghost" | ||
color="current" | ||
marginLeft="2" | ||
onClick={toggleColorMode} | ||
icon={<SwitchIcon />} | ||
/> | ||
</Flex> | ||
); | ||
}; | ||
|
||
const withChakra = (StoryFn: Function, context: StoryContext) => { | ||
const { direction } = context.globals; | ||
const dir = direction.toLowerCase(); | ||
|
||
React.useEffect(() => { | ||
document.documentElement.dir = dir; | ||
}, [dir]); | ||
|
||
return ( | ||
<ChakraProvider theme={customTheme}> | ||
<div dir={dir} id="story-wrapper" style={{ minHeight: "100vh" }}> | ||
<ColorModeToggleBar /> | ||
<StoryFn /> | ||
</div> | ||
</ChakraProvider> | ||
); | ||
}; | ||
|
||
export const parameters: Parameters = { | ||
options: { | ||
storySort: (a, b) => | ||
a[1].kind === b[1].kind | ||
? 0 | ||
: a[1].id.localeCompare(b[1].id, undefined, { numeric: true }), | ||
}, | ||
actions: { argTypesRegex: "^on[A-Z].*" }, | ||
controls: { expanded: true }, | ||
}; | ||
|
||
export const decorators = [withChakra, withPerformance]; |
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.