Skip to content

chore: update storybook configuration #418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# General ignores
.env
demo
node_modules
utils/storybook/coverage
*.log

# Package specific
packages/**/dist
package-lock.json

# Demo specific
demo/**/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has there been any changes to add demo folder yet?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet. TBD per PR description.

3 changes: 1 addition & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
yarn lerna run build --since main
yarn lint-staged && yarn build --since HEAD --exclude-dependents && git add packages/**/.size-snapshot.json
38 changes: 38 additions & 0 deletions .storybook/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright Zendesk, Inc.
*
* Use of this source code is governed under the Apache License, Version 2.0
* found at http://www.apache.org/licenses/LICENSE-2.0.
*/

const path = require('path');
const { readdirSync } = require('fs');
const { getStorybookBabelConfig } = require('@storybook/core-common');

const config = getStorybookBabelConfig();

const PACKAGE_NAMES = readdirSync(path.resolve(__dirname, '../packages')).filter(
name => name !== '.template'
);

module.exports = {
sourceType: 'unambiguous',
presets: [...config.presets],
plugins: [
...config.plugins,
'babel-plugin-styled-components',
[
'module-resolver',
{
root: ['../'],
alias: PACKAGE_NAMES.reduce((previousValue, packageName) => {
previousValue[
`@zendeskgarden/container-${packageName}`
] = `./packages/${packageName}/src`;

return previousValue;
}, {})
}
]
]
};
3 changes: 3 additions & 0 deletions .storybook/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
45 changes: 40 additions & 5 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,39 @@
* found at http://www.apache.org/licenses/LICENSE-2.0.
*/

const path = require('path');
const { DefinePlugin } = require('webpack');
const postcss = require('postcss');
const tailwindcss = require('tailwindcss');
const autoprefixer = require('autoprefixer');

const options = {
backgrounds: false,
docs: process.env.BROWSER ? process.env.BROWSER.toUpperCase() !== 'IE11' : true,
measure: false,
outline: false,
viewport: false
};

module.exports = {
stories: ['../packages/**/*.stories.@(tsx|mdx)'],
stories: [
'../packages/*/demo/**/*.stories.@(js|jsx|ts|tsx|mdx)',
'../packages/*/*.stories.@(tsx|mdx)'
],
addons: [
{ name: '@storybook/addon-essentials', options: { viewport: false } },
'@storybook/addon-a11y',
'@storybook/addon-storysource',
'@storybook/addon-postcss'
{ name: '@storybook/addon-essentials', options },
{
name: '@storybook/addon-postcss',
options: {
postcssLoaderOptions: {
implementation: postcss,
postcssOptions: {
plugins: [tailwindcss(path.resolve(__dirname, 'tailwind.config.js')), autoprefixer()]
}
}
}
},
'@storybook/addon-a11y'
],
core: {
builder: 'webpack5'
Expand All @@ -21,6 +47,15 @@ module.exports = {
// to support IE11, we need to ensure the manager UI bundle is ES5 compatible
config.target = ['web', 'es5'];

return config;
},
webpackFinal: config => {
config.plugins.push(
new DefinePlugin({
PACKAGE_VERSION: JSON.stringify('storybook')
})
);

return config;
}
};
1 change: 1 addition & 0 deletions .storybook/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { create } from '@storybook/theming';
import { DEFAULT_THEME } from '@zendeskgarden/react-theming';

addons.setConfig({
panelPosition: 'right',
theme: create({
brandTitle: 'Zendesk Garden React Containers',
brandUrl: 'https://github.com/zendeskgarden/react-containers',
Expand Down
1 change: 0 additions & 1 deletion .storybook/preview-head.html

This file was deleted.

46 changes: 25 additions & 21 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,41 @@
*/

import React from 'react';
import { createGlobalStyle } from 'styled-components';
import { create } from '@storybook/theming/create';
import { DEFAULT_THEME } from '@zendeskgarden/react-theming';
import { DEFAULT_THEME, getColor } from '@zendeskgarden/react-theming';

/**
* Center "Docs" previews
* See: https://github.com/storybookjs/storybook/issues/7227#issuecomment-680332161
*/
export const decorators = [
Story => (
<div
style={{
display: 'flex',
alignItems: 'center',
overflow: 'auto'
}}
>
<div style={{ margin: 'auto', maxHeight: '100%' }}>
<Story />
</div>
</div>
)
];
import './index.css';

export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
backgrounds: {
default: DEFAULT_THEME.colors.base,
grid: { disable: true }
},
controls: {
hideNoControlsWarning: true,
sort: 'alpha'
},
docs: {
theme: create({
base: DEFAULT_THEME.colors.base
})
}
},
layout: 'centered'
};

const GlobalStyle = createGlobalStyle`
:focus {
outline-color: ${p => getColor('primaryHue', 600, p.theme)};
}
`;

export const decorators = [
Story => (
<>
<GlobalStyle />
<Story />
</>
)
];
15 changes: 15 additions & 0 deletions .storybook/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright Zendesk, Inc.
*
* Use of this source code is governed under the Apache License, Version 2.0
* found at http://www.apache.org/licenses/LICENSE-2.0.
*/

const path = require('path');
const gardenTailwindCss = require('@zendeskgarden/tailwindcss');

module.exports = {
content: [`${path.resolve(__dirname, '../packages')}/*/demo/**/*.{mdx,tsx}`],
plugins: [gardenTailwindCss],
safelist: process.env.NODE_ENV === 'development' ? [{ pattern: /.*/u }] : []
};
7 changes: 0 additions & 7 deletions .storybook/tsconfig.storybook.json

This file was deleted.

49 changes: 0 additions & 49 deletions .storybook/webpack.config.js

This file was deleted.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"lint:md": "markdownlint README.md packages/*/src/**/*.md packages/*/src/*.md packages/*/README.md",
"new": "utils/scripts/new.js",
"prepare": "yarn build",
"start": "start-storybook -p 6006",
"start": "start-storybook --no-version-updates -p 6006",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find --no-version-updates in their CLI docs. https://storybook.js.org/docs/react/api/cli-options Is this an undocumented flag?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's documented with yarn start-storybook --help. Also see storybookjs/storybook#8488

"start:demo": "yarn build:demo && live-server demo",
"tag": "lerna version --conventional-commits --force-git-tag",
"test": "yarn test:all --watch",
Expand All @@ -40,7 +40,6 @@
"@storybook/addon-a11y": "6.4.13",
"@storybook/addon-essentials": "6.4.13",
"@storybook/addon-postcss": "2.0.0",
"@storybook/addon-storysource": "6.4.13",
"@storybook/builder-webpack5": "6.4.13",
"@storybook/manager-webpack5": "6.4.13",
"@storybook/react": "6.4.13",
Expand All @@ -61,10 +60,13 @@
"@zendeskgarden/eslint-config": "27.0.0",
"@zendeskgarden/react-theming": "8.47.2",
"@zendeskgarden/scripts": "1.4.0",
"@zendeskgarden/tailwindcss": "3.0.1",
"acorn-jsx": "5.3.2",
"autoprefixer": "10.4.2",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "27.4.6",
"babel-loader": "8.2.3",
"babel-plugin-module-resolver": "4.1.0",
"babel-plugin-styled-components": "2.0.2",
"commander": "8.3.0",
"core-js": "3.20.3",
Expand All @@ -87,6 +89,7 @@
"markdownlint-cli": "0.30.0",
"ora": "5.4.1",
"popper.js": "1.16.1",
"postcss": "8.4.6",
"prettier": "2.5.1",
"prettier-package-json": "2.6.0",
"react": "17.0.2",
Expand All @@ -101,6 +104,7 @@
"rollup-plugin-size-snapshot": "0.12.0",
"rollup-plugin-typescript2": "0.31.1",
"styled-components": "5.3.3",
"tailwindcss": "3.0.19",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reason for adding tailwindcss and @zendeskgarden/tailwindcss?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like tailwindcss is the library and @zendeskgarden/tailwindcss is the plugin.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mtomcal if you haven't yet, please see the PR description.

"ts-jest": "27.1.3",
"ts-loader": "8.3.0",
"typescript": "4.5.4",
Expand Down
4 changes: 3 additions & 1 deletion packages/.template/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"declarationDir": "dist/typings",
"declaration": true,
"sourceMap": false,
"noEmit": false
"noEmit": false,
"paths": {}

},
"include": ["src/**/*"],
"exclude": ["**/*.spec.tsx", "**/*.spec.ts"]
Expand Down
3 changes: 2 additions & 1 deletion packages/accordion/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"declarationDir": "dist/typings",
"declaration": true,
"sourceMap": false,
"noEmit": false
"noEmit": false,
"paths": {}
},
"include": ["src/**/*"],
"exclude": ["**/*.spec.tsx", "**/*.spec.ts"]
Expand Down
4 changes: 3 additions & 1 deletion packages/breadcrumb/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"declarationDir": "dist/typings",
"declaration": true,
"sourceMap": false,
"noEmit": false
"noEmit": false,
"paths": {}

},
"include": ["src/**/*"],
"exclude": ["**/*.spec.tsx", "**/*.spec.ts"]
Expand Down
4 changes: 3 additions & 1 deletion packages/buttongroup/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"declarationDir": "dist/typings",
"declaration": true,
"sourceMap": false,
"noEmit": false
"noEmit": false,
"paths": {}

},
"include": ["src/**/*"],
"exclude": ["**/*.spec.tsx", "**/*.spec.ts"]
Expand Down
4 changes: 3 additions & 1 deletion packages/field/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"declarationDir": "dist/typings",
"declaration": true,
"sourceMap": false,
"noEmit": false
"noEmit": false,
"paths": {}

},
"include": ["src/**/*"],
"exclude": ["**/*.spec.tsx", "**/*.spec.ts"]
Expand Down
4 changes: 3 additions & 1 deletion packages/focusjail/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"declarationDir": "dist/typings",
"declaration": true,
"sourceMap": false,
"noEmit": false
"noEmit": false,
"paths": {}

},
"include": ["src/**/*"],
"exclude": ["**/*.spec.tsx", "**/*.spec.ts"]
Expand Down
4 changes: 3 additions & 1 deletion packages/grid/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"declarationDir": "dist/typings",
"declaration": true,
"sourceMap": false,
"noEmit": false
"noEmit": false,
"paths": {}

},
"include": ["src/**/*"],
"exclude": ["**/*.spec.tsx", "**/*.spec.ts"]
Expand Down
Loading