-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Design System] Storybook & Vitest (#5569)
* refactor: Setup storybook & vitest
- Loading branch information
Joel Anton
authored
May 17, 2024
1 parent
296d61f
commit d7af8af
Showing
16 changed files
with
2,512 additions
and
191 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 |
---|---|---|
@@ -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', | ||
}); |
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 { 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; |
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 @@ | ||
<link rel="icon" type="image/svg+xml" href="./favicon.svg"> |
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 @@ | ||
<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> |
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,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>, | ||
]; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,7 @@ | ||
module.exports = { | ||
/** | ||
* must use this syntax for vite + panda | ||
* https://panda-css.com/docs/installation/storybook#install-panda | ||
*/ | ||
plugins: [require('@pandacss/dev/postcss')()], | ||
}; |
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,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(); | ||
}); |
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,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 />; |
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 @@ | ||
@layer reset, base, tokens, recipes, utilities; |
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,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'], | ||
}, | ||
}); |
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,11 @@ | ||
/// <reference types="vitest" /> | ||
|
||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
environment: 'jsdom', | ||
globals: true, | ||
setupFiles: './setup-tests.ts', | ||
}, | ||
}); |
Oops, something went wrong.