Skip to content

Commit

Permalink
chore(storybook): update storybook config and convert stories to work…
Browse files Browse the repository at this point in the history
… with addon-docs (#6532)

* chore(storybook): rename config to preview and addons to manager

* chore(storybook): add main.js for defining stories

* chore(storybook): move addons to main.js

* chore(storybook): add docs and notes addons

* docs(accordion): update accordion story to CSF

* chore(storybook): update sorting and remove unused addons

* chore(storybook): update stories to include component parameters

* chore(storybook): update sort order to include story title

* chore(react): revert changes for storybook and update snapshots

* docs(storybook): update container to include missing markup

Co-authored-by: TJ Egan <[email protected]>
  • Loading branch information
joshblack and tw15egan authored Jul 27, 2020
1 parent f2f702b commit 8a99fc6
Show file tree
Hide file tree
Showing 210 changed files with 1,929 additions and 397 deletions.
Binary file added .yarn/offline-mirror/@babel-core-7.10.5.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/@babel-generator-7.10.5.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/@babel-parser-7.10.5.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/offline-mirror/@babel-standalone-7.8.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/@babel-traverse-7.10.5.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/@babel-types-7.10.5.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/@jest-console-24.9.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/@jest-fake-timers-24.9.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/@jest-source-map-24.9.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/@jest-test-result-24.9.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/@jest-transform-24.9.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/@mdx-js-loader-1.6.14.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/@mdx-js-mdx-1.6.14.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/@mdx-js-react-1.6.14.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/@mdx-js-util-1.6.14.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/@types-babel-types-7.0.8.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/@types-babylon-6.16.5.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/@types-hast-2.3.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/@types-mdast-3.0.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/@types-parse5-5.0.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/acorn-4.0.13.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/acorn-globals-3.1.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/acorn-walk-7.2.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/align-text-0.1.4.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/ast-types-0.12.4.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/ast-types-0.13.3.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/babel-types-6.26.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/babylon-6.18.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/camelcase-1.2.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/camelcase-css-2.0.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/center-align-0.1.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/character-parser-2.2.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/clean-css-4.2.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/cliui-2.1.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/constantinople-3.1.2.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/de-indent-1.0.2.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/detab-2.0.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/doctypes-1.1.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/emoji-regex-6.1.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/escodegen-1.14.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/github-slugger-1.3.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/hash-sum-1.0.2.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/hast-util-raw-6.0.0.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/html-void-elements-1.0.5.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/is-absolute-url-3.0.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/is-expression-3.0.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/is-promise-2.2.2.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/is-regex-1.1.0.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/jest-haste-map-24.9.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/jest-message-util-24.9.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/jest-mock-24.9.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/jest-regex-util-24.9.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/jest-serializer-24.9.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/jest-util-24.9.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/js-string-escape-1.0.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/js-stringify-1.0.2.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/jscodeshift-0.7.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/jstransformer-1.0.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/loader-utils-2.0.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/longest-1.0.1.tgz
Binary file not shown.
Binary file removed .yarn/offline-mirror/marked-0.3.19.tgz
Binary file not shown.
Binary file removed .yarn/offline-mirror/marksy-8.0.0.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/mdast-util-to-hast-9.1.0.tgz
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/offline-mirror/nested-object-assign-1.0.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/parse5-6.0.0.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/pug-2.0.4.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/pug-attrs-2.0.4.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/pug-code-gen-2.0.2.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/pug-error-1.3.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/pug-filters-3.1.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/pug-lexer-4.1.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/pug-linker-3.0.6.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/pug-load-2.0.12.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/pug-parser-5.0.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/pug-runtime-2.0.5.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/pug-strip-comments-1.0.4.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/pug-walk-1.1.8.tgz
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/offline-mirror/react-redux-7.1.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/read-pkg-up-4.0.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/realpath-native-1.1.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/recast-0.17.6.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/recast-0.18.10.tgz
Binary file not shown.
Binary file removed .yarn/offline-mirror/redux-4.0.5.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/remark-footnotes-1.0.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/remark-mdx-1.6.14.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/remark-parse-8.0.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/remark-slug-5.1.2.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/right-align-0.1.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/stack-utils-1.0.2.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/style-to-object-0.3.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/test-exclude-5.2.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/to-fast-properties-1.0.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/token-stream-0.0.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/trim-lines-1.1.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/ts-map-1.0.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/uglify-js-2.8.29.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/unist-builder-2.0.3.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/unist-util-remove-2.0.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/unist-util-visit-2.0.3.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/vue-docgen-api-4.28.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/vue-docgen-loader-1.5.0.tgz
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/window-size-0.1.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/with-5.1.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/wordwrap-0.0.2.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/write-file-atomic-2.4.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/yargs-3.10.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/zwitch-1.0.5.tgz
Binary file not shown.
4 changes: 3 additions & 1 deletion packages/react/.storybook/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ function Container({ story }) {
flexDirection: 'column',
alignItems: 'center',
}}>
{story()}
<div style={{ position: 'relative', width: '100%', zIndex: 0 }}>
{story()}
</div>
</div>
</React.StrictMode>
);
Expand Down
75 changes: 0 additions & 75 deletions packages/react/.storybook/config.js

This file was deleted.

22 changes: 22 additions & 0 deletions packages/react/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright IBM Corp. 2016, 2018
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

module.exports = {
addons: [
'@storybook/addon-storysource',
'@storybook/addon-knobs',
'@storybook/addon-actions',
'@storybook/addon-links',
'@storybook/addon-docs',
'@storybook/addon-notes/register',
'storybook-readme/register',
require.resolve('./addon-carbon-theme/register'),
],
stories: ['../src/**/*-story.js', '../src/**/*.stories.mdx'],
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

import '@storybook/addon-storysource/register';
import '@storybook/addon-knobs/register';
import '@storybook/addon-actions/register';
import '@storybook/addon-links/register';
import '@storybook/addon-a11y/register';

// Community addons
import 'storybook-readme/register';

// Custom addons
import './addon-carbon-theme/register';

// These options used by storybook often conflict with developer tools,
// conditional panels, or other things that get in the way of our workflow
localStorage.removeItem('@storybook/ui/store');
Expand Down
124 changes: 124 additions & 0 deletions packages/react/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/**
* Copyright IBM Corp. 2016, 2018
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import { addDecorator, addParameters } from '@storybook/react';
import addons from '@storybook/addons';
import { themes } from '@storybook/theming';
import { configureActions } from '@storybook/addon-actions';
import {
CARBON_CURRENT_THEME,
CARBON_TYPE_TOKEN,
} from './addon-carbon-theme/shared';
import Container from './Container';
import PackageInfo from './../package.json';

const customPropertyPrefix = 'cds';

addParameters({
options: {
/**
* We sort our stories by default alphabetically, however there are specific
* keywords that will be sorted further down the sidebar, including
* "playground" and "unstable" stories.
*/
storySort: (storyA, storyB) => {
// By default, sort by the story "kind". The "kind" refers to the
// top-level title of the story, either through Component Story Format
// with the default export, or the `storiesOf('kind', module)` format
if (storyA[1].kind !== storyB[1].kind) {
return storyA[1].kind.localeCompare(storyB[1].kind);
}

const idA = storyA[0];
const idB = storyB[0];

// To story the stories, we first build up a list of matches based on
// keywords. Each keyword has a specific weight that will be used to
// determine order later on.
const UNKNOWN_KEYWORD = 2;
const keywords = new Map([
['default', 1],
['playground', 3],
['deprecated', 4],
['unstable', 5],
]);
const matches = new Map();

// We use this list of keywords to determine a collection of matches. By
// default, we will look for the greatest valued matched
for (const [keyword, weight] of keywords) {
// If we already have a match for a given id that is greater than the
// specific keyword we're looking for, break early
if (matches.get(idA) > weight || matches.get(idB) > weight) {
break;
}

// If we don't have a match already for either id, we check to see if
// the id includes the keyword and assigns the relevant weight, if so
if (idA.includes(keyword)) {
matches.set(idA, weight);
}

if (idB.includes(keyword)) {
matches.set(idB, weight);
}
}

// If we have matches for either id, then we will compare the ids based on
// the weight assigned to the matching keyword
if (matches.size > 0) {
const weightA = matches.get(idA) ?? UNKNOWN_KEYWORD;
const weightB = matches.get(idB) ?? UNKNOWN_KEYWORD;
// If we have the same weight for the ids, then we should compare them
// using locale compare instead of by weight
if (weightA === weightB) {
return idA.localeCompare(idB);
}
return weightA - weightB;
}

// By default, if we have no matches we'll do a locale compare between the
// two ids
return idA.localeCompare(idB);
},
theme: {
...themes.light,
brandTitle: `Carbon Components React v${PackageInfo.version}`,
brandUrl:
'https://github.com/carbon-design-system/carbon/tree/master/packages/react',
},
},
});

configureActions({
depth: 3,
limit: 10,
});

addDecorator((story) => <Container story={story} />);

addons.getChannel().on(CARBON_CURRENT_THEME, (theme) => {
document.documentElement.setAttribute('storybook-carbon-theme', theme);
});

addons.getChannel().on(CARBON_TYPE_TOKEN, ({ tokenName, tokenValue }) => {
const root = document.documentElement;
const [fontSize, lineHeight] = tokenValue.split('-');
const rem = (px) =>
`${
px / parseFloat(getComputedStyle(document.documentElement).fontSize)
}rem`;
root.style.setProperty(
`--${customPropertyPrefix}-${tokenName}-font-size`,
rem(fontSize)
);
root.style.setProperty(
`--${customPropertyPrefix}-${tokenName}-line-height`,
rem(lineHeight)
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Map {
"tabIndex": 0,
"type": "button",
},
"displayName": "Button",
"propTypes": Object {
"as": Object {
"args": Array [
Expand Down
5 changes: 3 additions & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,16 @@
"@babel/preset-react": "^7.10.0",
"@carbon/test-utils": "^10.10.0",
"@percy/storybook": "^3.3.0",
"@storybook/addon-a11y": "^5.3.19",
"@storybook/addon-actions": "^5.3.19",
"@storybook/addon-info": "^5.3.19",
"@storybook/addon-docs": "^5.3.19",
"@storybook/addon-knobs": "^5.3.19",
"@storybook/addon-links": "^5.3.19",
"@storybook/addon-notes": "^5.3.19",
"@storybook/addon-storysource": "^5.3.19",
"@storybook/addons": "^5.3.19",
"@storybook/react": "^5.3.19",
"@storybook/source-loader": "^5.3.19",
"@storybook/theming": "^5.3.19",
"babel-core": "^7.0.0-bridge.0",
"babel-loader": "^8.1.0",
"babel-plugin-dev-expression": "^0.2.2",
Expand Down
Loading

0 comments on commit 8a99fc6

Please sign in to comment.