Skip to content

Commit

Permalink
feat: Working setup for Storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Anton committed May 14, 2024
1 parent f5a79d2 commit 8af5b56
Show file tree
Hide file tree
Showing 17 changed files with 1,309 additions and 167 deletions.
27 changes: 27 additions & 0 deletions libs/novui/.storybook/Doc.container.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import { DocsContainer as BaseContainer } from '@storybook/addon-docs';
import { themes } from '@storybook/theming';

export const DocsContainer = ({ children, context }) => {
return (
<BaseContainer
context={{
...context,
storyById: (id) => {
const storyContext = context.storyById(id);
return {
...storyContext,
parameters: {
...storyContext?.parameters,
docs: {
// theme: dark ? themes.dark : themes.light,
},
},
};
},
}}
>
{children}
</BaseContainer>
);
};
23 changes: 23 additions & 0 deletions libs/novui/.storybook/NovuTheme.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ThemeVarsPartial } from '@storybook/theming';
import { create } from '@storybook/theming/create';

const themeBase: ThemeVarsPartial = {
base: 'light',
brandTitle: 'Novu Design System',
brandTarget: '_self',
}
/**
* Novu Design System theme for Storybook
*
* @see https://storybook.js.org/docs/configure/theming
*/
export const lightTheme = create({
...themeBase,
brandImage: './novu-logo-light.svg',
});

export const darkTheme = create({
...themeBase,
base: 'dark',
brandImage: './novu-logo-dark.svg',
});
23 changes: 23 additions & 0 deletions libs/novui/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { dirname, join } from 'path';
import { StorybookConfig } from '@storybook/react-vite';

export default {
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],

addons: [getAbsolutePath('storybook-dark-mode'), getAbsolutePath('@storybook/addon-mdx-gfm')],

framework: {
name: '@storybook/react-vite',
options: {},
},

docs: {
autodocs: true,
},

staticDirs: ['./public'],
} satisfies StorybookConfig;

function getAbsolutePath(value) {
return dirname(require.resolve(join(value, 'package.json')));
}
1 change: 1 addition & 0 deletions libs/novui/.storybook/manager-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<link rel="icon" type="image/svg+xml" href="./favicon.svg">
7 changes: 7 additions & 0 deletions libs/novui/.storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<script>
window._env_ = {
SKIP_PREFLIGHT_CHECK: 'true',
};
</script>
53 changes: 53 additions & 0 deletions libs/novui/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
// import { addons } from '@storybook/preview-api';
// import { DARK_MODE_EVENT_NAME } from 'storybook-dark-mode';
// import { ColorSchemePreferenceEnum, useLocalThemePreference } from '@novu/shared-web';
import { lightTheme, darkTheme } from './NovuTheme';
import { Parameters, Decorator } from '@storybook/react';

// Bring in the Panda-generated stylesheets
import '../src/index.css';

// import '../styled-system/styles.css';

export const parameters: Parameters = {
layout: 'fullscreen',
viewMode: 'docs',
docs: {
// @TODO: fix the container context
// container: DocsContainer,
},
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
darkMode: {
// Override the default dark theme
dark: darkTheme,
// Override the default light theme
light: lightTheme,
},
};

// const channel = addons.getChannel();
function ColorSchemeThemeWrapper({ children }) {
// const { setThemeStatus } = useLocalThemePreference();

// const handleColorScheme = (value) => {
// setThemeStatus(value ? ColorSchemePreferenceEnum.DARK : ColorSchemePreferenceEnum.LIGHT);
// };

// useEffect(() => {
// channel.on(DARK_MODE_EVENT_NAME, handleColorScheme);
// return () => channel.off(DARK_MODE_EVENT_NAME, handleColorScheme);
// }, [channel]);

return <div style={{ margin: '3em' }}>{children}</div>;
}

export const decorators: Decorator[] = [
(renderStory) => <ColorSchemeThemeWrapper>{renderStory()}</ColorSchemeThemeWrapper>,
];
3 changes: 3 additions & 0 deletions libs/novui/.storybook/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions libs/novui/.storybook/public/novu-logo-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions libs/novui/.storybook/public/novu-logo-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 27 additions & 6 deletions libs/novui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
"lint": "eslint --ext .ts,.tsx src",
"build": "cross-env node_modules/.bin/tsc",
"build:watch": "pnpm panda & cross-env node_modules/.bin/tsc -w --preserveWatchOutput",
"build:storybook": "pnpm panda && storybook build",
"storybook": "pnpm panda --watch & storybook dev -p 6006",
"studio": "pnpm panda studio"
},
"keywords": [],
Expand All @@ -64,11 +66,11 @@
"@pandacss/eslint-plugin": "^0.1.2",
"@pandacss/studio": "^0.38.0",
"@storybook/addon-actions": "^7.5.0",
"@storybook/addon-docs": "^7.4.2",
"@storybook/addon-docs": "^8.0.10",
"@storybook/client-api": "^7.6.10",
"@storybook/react": "^7.4.2",
"@storybook/react-webpack5": "^7.4.2",
"@storybook/theming": "^7.4.2",
"@storybook/react": "^8.0.10",
"@storybook/react-vite": "^8.0.10",
"@storybook/theming": "^8.0.10",
"@testing-library/jest-dom": "^6.4.1",
"@testing-library/react": "^12.1.5",
"@testing-library/react-hooks": "^8.0.1",
Expand All @@ -78,15 +80,34 @@
"@types/react-dom": "^17.0.1",
"@vitejs/plugin-react": "^4.0.3",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-storybook": "^0.6.13",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"rimraf": "^3.0.2",
"storybook": "^8.0.10",
"typescript": "^4.9.5",
"vite": "^4.5.2",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^1.2.1"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0",
"react-dom": "^16.8.0 || ^17.0.0"
"react": ">=17.0.0",
"react-dom": ">=17.0.0"
},
"nx": {
"targets": {
"build-storybook": {
"dependsOn": [
"^build"
],
"outputs": [
"{projectRoot}/storybook-static"
],
"inputs": [
"{projectRoot}/.storybook",
"{projectRoot}/src"
]
}
}
}
}
7 changes: 7 additions & 0 deletions libs/novui/postcss.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
/**
* must use this syntax for vite + panda
* https://panda-css.com/docs/installation/storybook#install-panda
*/
plugins: [require('@pandacss/dev/postcss')()],
};
8 changes: 8 additions & 0 deletions libs/novui/setup-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { afterEach } from 'vitest';
import { cleanup } from '@testing-library/react';
import '@testing-library/jest-dom/vitest';

// runs a clean after each test case (e.g. clearing jsdom)
afterEach(() => {
cleanup();
});
1 change: 1 addition & 0 deletions libs/novui/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@layer reset, base, tokens, recipes, utilities;
44 changes: 26 additions & 18 deletions libs/novui/src/tokens/typography/typography.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
import { Meta } from '@storybook/react';
import React from 'react';
import { Divider, Flex, styled } from '../../../styled-system/jsx';
import { text, title } from '../../../styled-system/recipes';
/*
* import { Divider, Flex, styled } from '../../../styled-system/jsx';
* import { text, title } from '../../../styled-system/recipes';
*/

const Text = styled('p', text);
const Title = styled('h2', title);
/*
* const Text = styled('p', text);
* const Title = styled('h2', title);
*/

export default {
title: 'Panda/Components/Typography',
component: Text,
// component: Text,
argTypes: {},
} as Meta<typeof Text>;
};
// } as Meta<typeof Text>;

export const all = () => (
<Flex direction="column" gap="100">
<Text>Default Body</Text>
<Text variant="main">Main text</Text>
<Text variant="secondary">Secondary text</Text>
<Text variant="strong">Strong text</Text>
<Text variant="mono">Mono text</Text>
<Divider />
<Title>Default title</Title>
<Title variant="page">Page title</Title>
<Title variant="section">Section title</Title>
<Title variant="subsection">Subsection title</Title>
</Flex>
/*
* <Flex direction="column" gap="100">
* <Text>Default Body</Text>
* <Text variant="main">Main text</Text>
* <Text variant="secondary">Secondary text</Text>
* <Text variant="strong">Strong text</Text>
* <Text variant="mono">Mono text</Text>
* <Divider />
* <Title>Default title</Title>
* <Title variant="page">Page title</Title>
* <Title variant="section">Section title</Title>
* <Title variant="subsection">Subsection title</Title>
* </Flex>
*/
<div>Hello</div>
);
Loading

0 comments on commit 8af5b56

Please sign in to comment.