-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(storybook): update storybook config and convert stories to work…
… 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
Showing
210 changed files
with
1,929 additions
and
397 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+7.9 KB
.yarn/offline-mirror/@babel-helper-builder-react-jsx-experimental-7.10.5.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+4.85 KB
.yarn/offline-mirror/@babel-plugin-proposal-object-rest-spread-7.10.4.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 not shown.
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 not shown.
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 not shown.
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 not shown.
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 not shown.
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 not shown.
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 not shown.
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 not shown.
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 not shown.
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 not shown.
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 not shown.
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 not shown.
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 not shown.
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 not shown.
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 not shown.
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 not shown.
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 not shown.
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 not shown.
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 not shown.
Binary file not shown.
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
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'], | ||
}; |
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,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) | ||
); | ||
}); |
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.