Skip to content

Commit

Permalink
[Design System] Storybook & Vitest (#5569)
Browse files Browse the repository at this point in the history
* refactor: Setup storybook & vitest
  • Loading branch information
Joel Anton authored May 17, 2024
1 parent 296d61f commit d7af8af
Show file tree
Hide file tree
Showing 16 changed files with 2,512 additions and 191 deletions.
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',
});
19 changes: 19 additions & 0 deletions libs/novui/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { StorybookConfig } from '@storybook/react-vite';

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

addons: ['storybook-dark-mode', '@storybook/addon-controls'],

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

docs: {
// TODO: re-enable docs when we decide how to incorporate them
autodocs: false,
},

staticDirs: ['./public'],
} satisfies StorybookConfig;
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>
40 changes: 40 additions & 0 deletions libs/novui/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';
import { lightTheme, darkTheme } from './NovuTheme';
import { Parameters, Decorator } from '@storybook/react';
import { css } from '../styled-system/css';

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

export const parameters: Parameters = {
layout: 'fullscreen',
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,
darkClass: 'dark',
stylePreview: true,
},
};

// const channel = addons.getChannel();
function ColorSchemeThemeWrapper({ children }) {
// wraps the component preview in a full-page container with proper bg color
return <section className={css({ padding: '250', bg: 'surface.page', height: '[100dvh]' })}>{children}</section>;
}

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.
49 changes: 44 additions & 5 deletions libs/novui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"description": "Novu's Design System & Component Library",
"types": "./dist/index.d.ts",
"main": "./dist/index.js",
"files": ["dist", "styled-system"],
"files": [
"dist",
"styled-system"
],
"exports": {
".": {
"source": "./src/index.ts",
Expand Down Expand Up @@ -49,7 +52,9 @@
"prebuild": "rimraf dist styled-system",
"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: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 @@ -60,17 +65,51 @@
"@pandacss/dev": "^0.38.0",
"@pandacss/eslint-plugin": "^0.1.2",
"@pandacss/studio": "^0.38.0",
"@storybook/addon-actions": "8.1.0",
"@storybook/addon-controls": "^8.1.0",
"@storybook/addon-docs": "^8.1.0",
"@storybook/react": "^8.1.0",
"@storybook/react-vite": "^8.1.0",
"@storybook/theming": "^8.1.0",
"@storybook/types": "^8.1.0",
"@testing-library/jest-dom": "^6.4.1",
"@testing-library/react": "^12.1.5",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/user-event": "^14.5.2",
"@types/node": "^18.11.12",
"@types/react": "^17.0.1",
"@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",
"typescript": "^4.9.5"
"storybook": "^8.1.0",
"storybook-dark-mode": "^4.0.1",
"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();
});
13 changes: 13 additions & 0 deletions libs/novui/src/components/Test.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import { StoryFn, Meta } from '@storybook/react';
import { Test } from './Test';

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

const Template: StoryFn<typeof Test> = ({ ...args }) => <Test {...args}>Example Text</Test>;

export const all = () => <Test />;
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;
24 changes: 24 additions & 0 deletions libs/novui/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import react from '@vitejs/plugin-react';
import { resolve } from 'path';
import tsconfigPaths from 'vite-tsconfig-paths';
import { defineConfig } from 'vite';

export default defineConfig({
plugins: [
// leverages tsconfig to work with panda styled-system
tsconfigPaths(),
react(),
],
build: {
lib: {
entry: resolve(__dirname, 'src/index.ts'),
formats: ['es'],
},
rollupOptions: {
external: ['react', 'react/jsx-runtime'],
},
},
resolve: {
extensions: ['.tsx', '.ts', '.jsx', '.js'],
},
});
11 changes: 11 additions & 0 deletions libs/novui/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// <reference types="vitest" />

import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
environment: 'jsdom',
globals: true,
setupFiles: './setup-tests.ts',
},
});
Loading

0 comments on commit d7af8af

Please sign in to comment.