Skip to content

Commit

Permalink
build(design-system): Add scripts for storybook build using nx (novuh…
Browse files Browse the repository at this point in the history
…q#5333)

* build(design-system): Add scripts for storybook build using nx

* feat(design-system): Add brand logos

* refactor(design-system): Use typescript for Storybook configuration

* feat(design-system): Add novu favicon
  • Loading branch information
rifont authored Mar 26, 2024
1 parent db7318f commit 7f15050
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 9 deletions.
23 changes: 23 additions & 0 deletions libs/design-system/.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',
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { dirname, join } from 'path';
module.exports = {
import { StorybookConfig } from '@storybook/react-webpack5';

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

addons: [
Expand All @@ -10,7 +12,7 @@ module.exports = {
],

framework: {
name: getAbsolutePath('@storybook/react-webpack5'),
name: '@storybook/react-webpack5',
options: {},
},

Expand All @@ -21,7 +23,9 @@ module.exports = {
docs: {
autodocs: true,
},
};

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

function getAbsolutePath(value) {
return dirname(require.resolve(join(value, 'package.json')));
Expand Down
1 change: 1 addition & 0 deletions libs/design-system/.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">
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import { DARK_MODE_EVENT_NAME } from 'storybook-dark-mode';
import { ThemeProvider } from '../src/ThemeProvider';
import { DocsContainer } from './Doc.container';
import { useLocalThemePreference } from '@novu/shared-web';
import { lightTheme, darkTheme } from './NovuTheme';
import { Parameters, Decorator } from '@storybook/react'

// Bring in the Panda-generated stylesheets
import '../styled-system/styles.css';

export const parameters = {
export const parameters: Parameters = {
layout: 'fullscreen',
viewMode: 'docs',
docs: {
container: DocsContainer,
// @TODO: fix the container context
// container: DocsContainer,
},
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
Expand All @@ -21,6 +24,12 @@ export const parameters = {
date: /Date$/,
},
},
darkMode: {
// Override the default dark theme
dark: darkTheme,
// Override the default light theme
light: lightTheme
}
};

const channel = addons.getChannel();
Expand All @@ -43,4 +52,4 @@ function ColorSchemeThemeWrapper({ children }) {
);
}

export const decorators = [(renderStory) => <ColorSchemeThemeWrapper>{renderStory()}</ColorSchemeThemeWrapper>];
export const decorators: Decorator[] = [(renderStory) => <ColorSchemeThemeWrapper>{renderStory()}</ColorSchemeThemeWrapper>];
3 changes: 3 additions & 0 deletions libs/design-system/.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/design-system/.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/design-system/.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.
15 changes: 13 additions & 2 deletions libs/design-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"dist/types"
],
"scripts": {
"prepare": "panda codegen --clean",
"prepare": "pnpm prepare:panda && pnpm prepare:audit",
"prepare:panda": "panda codegen --clean",
"prepare:audit": "pnpm audit-components",
"start": "npm run build:watch",
"prebuild": "rimraf dist",
"lint": "eslint --ext .ts,.tsx src",
Expand All @@ -28,7 +30,7 @@
"build:esm:watch": "cross-env node_modules/.bin/tsc -p tsconfig.esm.json -w --preserveWatchOutput",
"build:types": "tsc --declaration --emitDeclarationOnly --declarationMap --declarationDir dist/types -p tsconfig.json",
"storybook": "pnpm panda --watch & storybook dev -p 6006",
"build-storybook": "storybook build",
"build-storybook": "pnpm panda && storybook build",
"cypress:install": "cypress install",
"cypress:open": "cross-env NODE_ENV=test cypress open",
"cypress:run": "cross-env NODE_OPTIONS=--max_old_space_size=4096 NODE_ENV=test cypress run --component",
Expand Down Expand Up @@ -95,5 +97,14 @@
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0",
"react-dom": "^16.8.0 || ^17.0.0"
},
"nx": {
"targets": {
"build-storybook": {
"dependsOn": ["^build"],
"outputs": ["{projectRoot}/storybook-static"],
"inputs": ["{projectRoot}/.storybook", "{projectRoot}/src"]
}
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"build:web": "nx build @novu/web",
"build:widget": "nx build @novu/widget",
"build:embed": "nx build @novu/embed",
"build:storybook": "nx run @novu/web:build-storybook",
"build:storybook": "nx run @novu/design-system:build-storybook",
"test:providers": "cross-env pnpm --filter './providers/**' test",
"release:patch": "lerna version patch --no-push",
"release:minor": "lerna version minor --no-push",
Expand Down

0 comments on commit 7f15050

Please sign in to comment.