Skip to content

Commit

Permalink
move storybook configs to configs/storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
sndrs committed May 20, 2024
1 parent ff58a2a commit 8c92d77
Show file tree
Hide file tree
Showing 42 changed files with 510 additions and 2,137 deletions.
2 changes: 1 addition & 1 deletion apps/storybooks/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const rootMain = require('../../../.storybook/main');
const rootMain = require('../../../configs/storybook/main');

module.exports = {
...rootMain,
Expand Down
1 change: 1 addition & 0 deletions apps/storybooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dev": "wireit"
},
"devDependencies": {
"storybook": "8.0.5",
"wireit": "0.14.4"
},
"wireit": {
Expand Down
11 changes: 10 additions & 1 deletion .storybook/main.js → configs/storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const path = require('path');
const fs = require('node:fs');

const nodeModulesExclude = {
and: [/node_modules/],
not: [/@guardian\//],
};

module.exports = {
stories: [],
addons: [
Expand Down Expand Up @@ -42,6 +44,11 @@ module.exports = {
],
});

config.module.rules.push({
test: /\.html$/i,
loader: 'html-loader',
});

// update storybook webpack config to transpile *all* JS
config.module.rules.find(
(rule) => String(rule.test) === String(/\.(cjs|mjs|tsx?|jsx?)$/),
Expand All @@ -57,4 +64,6 @@ module.exports = {
docs: {
autodocs: true,
},
previewHead: (head) =>
head + fs.readFileSync(require.resolve('./preview-head.html'), 'utf8'),
};
29 changes: 29 additions & 0 deletions configs/storybook/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "@configs/storybook",
"version": "0.1.0",
"private": true,
"type": "module",
"dependencies": {
"@babel/core": "7.24.0",
"@babel/plugin-transform-typescript": "7.24.5",
"@babel/preset-env": "7.24.0",
"@babel/preset-react": "7.24.1",
"@babel/preset-typescript": "7.24.1",
"@emotion/babel-plugin": "11.11.0",
"@emotion/react": "11.11.1",
"@guardian/source-foundations": "workspace:*",
"@storybook/addon-a11y": "8.0.5",
"@storybook/addon-docs": "8.0.5",
"@storybook/addon-essentials": "8.0.5",
"@storybook/addon-links": "8.0.5",
"@storybook/addon-viewport": "8.0.5",
"@storybook/manager-api": "8.0.5",
"@storybook/react": "8.0.5",
"@storybook/react-webpack5": "8.0.5",
"@storybook/theming": "8.0.5",
"@types/babel__core": "7.20.5",
"@types/react": "18.2.11",
"babel-loader": "9.1.3",
"react": "18.2.0"
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FocusStyleManager } from '@guardian/source-foundations';
import type { Decorator } from '@storybook/react';
import { useEffect } from 'react';
import { FocusStyleManager } from '@guardian/source-foundations';

export const FocusManagerDecorator: Decorator = (storyFn) => {
useEffect(() => {
Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions configs/storybook/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { create } from '@storybook/theming';

export const createTheme = (pkgName: string) =>
create({
base: 'light',
brandTitle: pkgName,
brandUrl: `https://www.npmjs.com/package/${pkgName}`,
brandImage:
'https://raw.githubusercontent.com/guardian/source/main/assets/logo.png',
});
2 changes: 1 addition & 1 deletion libs/@guardian/source-foundations/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const rootMain = require('../../../../.storybook/main');
const rootMain = require('../../../../configs/storybook/main');

// To customise your Storybook config for this project, update this file

Expand Down
3 changes: 3 additions & 0 deletions libs/@guardian/source-foundations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"rollup": "4.17.2",
"storybook": "8.0.5",
"tslib": "2.6.2",
"tsx": "4.7.1",
"typescript": "5.3.3",
Expand Down Expand Up @@ -79,6 +80,8 @@
"build"
],
"files": [
"../../../../configs/storybook/**",
"./.storybook/**",
"**/*.{ts,tsx,js,json,mdx,md}",
"!storybook-static/**",
"!(jest*)"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const rootMain = require('../../../../.storybook/main');
const rootMain = require('../../../../configs/storybook/main');

// To customise your Storybook config for this project, update this file

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { addons } from '@storybook/manager-api';
import { theme } from './theme';
import { createTheme } from '../../../../configs/storybook/theme';

addons.setConfig({
theme,
theme: createTheme('@guardian/source-react-components-development-kitchen'),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { decorators, parameters } from '../../../../configs/storybook/preview';

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
"@guardian/libs": "16.0.0",
"@guardian/source-foundations": "16.0.0",
"@guardian/source-react-components": "25.0.0",
"@storybook/manager-api": "8.0.5",
"@types/react": "18.2.11",
"react": "18.2.0",
"rollup": "4.17.2",
"storybook": "8.0.5",
"tslib": "2.6.2",
"typescript": "5.3.3",
"wireit": "0.14.4"
Expand Down Expand Up @@ -83,6 +85,8 @@
"_deps"
],
"files": [
"../../../../configs/storybook/**",
"./.storybook/**",
"**/*.{ts,tsx,js,json,mdx,md}",
"!storybook-static/**",
"!(jest*)"
Expand Down
2 changes: 1 addition & 1 deletion libs/@guardian/source-react-components/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const rootMain = require('../../../../.storybook/main');
const rootMain = require('../../../../configs/storybook/main');

// To customise your Storybook config for this project, update this file

Expand Down
4 changes: 2 additions & 2 deletions libs/@guardian/source-react-components/.storybook/manager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { addons } from '@storybook/manager-api';
import { theme } from './theme';
import { createTheme } from '../../../../configs/storybook/theme';

addons.setConfig({
theme,
theme: createTheme('@guardian/source-react-components'),
});

0 comments on commit 8c92d77

Please sign in to comment.