-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(docs): introduce storybook and migrate react-tabs examples (#873)
- Loading branch information
Austin Green
authored
Sep 11, 2020
1 parent
8db5419
commit 4e57981
Showing
25 changed files
with
3,876 additions
and
359 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
This file was deleted.
Oops, something went wrong.
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,39 @@ | ||
/** | ||
* 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 storybookBabelConfig = require('@storybook/core/dist/server/common/babel'); | ||
|
||
const PACKAGE_NAMES = readdirSync(path.resolve(__dirname, '../packages')).filter( | ||
name => name !== '.template' | ||
); | ||
|
||
module.exports = { | ||
sourceType: 'unambiguous', | ||
presets: [...storybookBabelConfig.presets], | ||
plugins: [ | ||
...storybookBabelConfig.plugins, | ||
'babel-plugin-styled-components', | ||
[ | ||
'module-resolver', | ||
{ | ||
root: ['../'], | ||
alias: PACKAGE_NAMES.reduce((previousValue, packageName) => { | ||
previousValue[`@zendeskgarden/react-${packageName}`] = `./packages/${packageName}/src`; | ||
|
||
return previousValue; | ||
}, {}) | ||
} | ||
] | ||
], | ||
env: { | ||
production: { | ||
plugins: [['react-remove-properties', { properties: [/data-test/u] }]] | ||
} | ||
} | ||
}; |
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 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
import { create } from '@storybook/theming/create'; | ||
import { DEFAULT_THEME } from '../packages/theming/src'; | ||
|
||
export const managerTheme = create({ | ||
base: 'dark', | ||
fontBase: DEFAULT_THEME.fonts.system, | ||
fontCode: DEFAULT_THEME.fonts.mono, | ||
brandTitle: 'React Components / Zendesk Garden', | ||
brandUrl: 'https://zendeskgarden.github.io/react-components/storybook', | ||
brandImage: './images/garden.svg' | ||
}); | ||
|
||
export const previewTheme = create({ | ||
base: 'light', | ||
fontBase: DEFAULT_THEME.fonts.system, | ||
fontCode: DEFAULT_THEME.fonts.mono | ||
}); |
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,66 @@ | ||
/** | ||
* 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 webpack = require('webpack'); | ||
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin'); | ||
const TS_CONFIG_PATH = path.resolve(__dirname, '../tsconfig.json'); | ||
|
||
module.exports = { | ||
stories: ['../packages/*/stories/**/*.stories.@(js|jsx|ts|tsx|mdx)'], | ||
addons: ['@storybook/addon-links', '@storybook/addon-essentials', '@storybook/addon-a11y'], | ||
typescript: { | ||
check: true, | ||
checkOptions: { | ||
configFile: TS_CONFIG_PATH | ||
}, | ||
reactDocgen: 'react-docgen-typescript', | ||
reactDocgenTypescriptOptions: { | ||
shouldExtractLiteralValuesFromEnum: true, | ||
/** | ||
* Ensure that HTMLAttributes are not included in prop-sheets | ||
*/ | ||
propFilter: prop => (prop.parent ? !/node_modules/u.test(prop.parent.fileName) : true) | ||
} | ||
}, | ||
webpackFinal: config => { | ||
config.module.rules.push({ | ||
test: /\.tsx?$/u, | ||
loaders: [ | ||
{ | ||
loader: 'eslint-loader', | ||
options: { | ||
emitWarning: true | ||
} | ||
} | ||
], | ||
enforce: 'pre' | ||
}); | ||
|
||
config.module.rules.push({ | ||
test: /\.svg$/u, | ||
use: [ | ||
{ | ||
loader: '@svgr/webpack', | ||
options: { | ||
externalConfig: path.resolve('../.svgo.yml') | ||
} | ||
} | ||
] | ||
}); | ||
|
||
config.plugins.push( | ||
new webpack.DefinePlugin({ | ||
PACKAGE_VERSION: JSON.stringify('storybook') | ||
}) | ||
); | ||
|
||
config.resolve.plugins.push(new TsconfigPathsPlugin({ configFile: TS_CONFIG_PATH })); | ||
|
||
return config; | ||
} | ||
}; |
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" href="https://zendeskgarden.github.io/favicon.ico" /> |
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,17 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
import { addons } from '@storybook/addons'; | ||
import { managerTheme } from './gardenTheme'; | ||
|
||
addons.setConfig({ | ||
theme: managerTheme, | ||
/** | ||
* Show the controls addon by default | ||
*/ | ||
selectedPanel: 'controls' | ||
}); |
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 href="https://zendeskgarden.github.io/css-components/bedrock/index.css" rel="stylesheet" disabled /> |
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,81 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
import React from 'react'; | ||
import styled, { createGlobalStyle } from 'styled-components'; | ||
import { previewTheme } from './gardenTheme'; | ||
import { ThemeProvider, DEFAULT_THEME } from '../packages/theming/src'; | ||
|
||
export const parameters = { | ||
actions: { argTypesRegex: '^on[A-Z].*', layout: 'centered' }, | ||
backgrounds: { disable: true }, | ||
docs: { | ||
theme: previewTheme | ||
} | ||
}; | ||
|
||
const GlobalPreviewStyling = createGlobalStyle` | ||
body { | ||
background-color: ${p => p.theme.colors.background}; | ||
color: ${p => p.theme.colors.foreground}; | ||
font-family: ${p => p.theme.fonts.system}; | ||
font-size: ${p => p.theme.fontSizes.md}; | ||
} | ||
`; | ||
|
||
const StyledExampleWrapper = styled.div` | ||
direction: ${p => (p.theme.rtl ? 'rtl' : 'ltr')}; | ||
padding: ${p => p.theme.space.xl}; | ||
`; | ||
|
||
const withThemeProvider = (Story, context) => { | ||
const rtl = context.globals.locale === 'rtl'; | ||
|
||
if (context.globals.bedrock === 'enabled') { | ||
document.querySelector('link[href$="bedrock/index.css"]').removeAttribute('disabled'); | ||
} else { | ||
document.querySelector('link[href$="bedrock/index.css"]').setAttribute('disabled', true); | ||
} | ||
|
||
return ( | ||
<ThemeProvider theme={{ ...DEFAULT_THEME, rtl }}> | ||
<GlobalPreviewStyling /> | ||
<StyledExampleWrapper> | ||
<Story /> | ||
</StyledExampleWrapper> | ||
</ThemeProvider> | ||
); | ||
}; | ||
|
||
export const decorators = [withThemeProvider]; | ||
|
||
export const globalTypes = { | ||
locale: { | ||
name: 'direction', | ||
description: 'Locale direction', | ||
defaultValue: 'ltr', | ||
toolbar: { | ||
icon: 'globe', | ||
items: [ | ||
{ value: 'ltr', title: 'LTR' }, | ||
{ value: 'rtl', title: 'RTL' } | ||
] | ||
} | ||
}, | ||
bedrock: { | ||
name: 'bedrock', | ||
description: 'CSS Bedrock', | ||
defaultValue: 'disabled', | ||
toolbar: { | ||
icon: 'paintbrush', | ||
items: [ | ||
{ value: 'disabled', title: 'Bedrock disabled' }, | ||
{ value: 'enabled', title: 'Bedrock enabled' } | ||
] | ||
} | ||
} | ||
}; |
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
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
Oops, something went wrong.