Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Add storybook #99

Merged
merged 8 commits into from
Dec 4, 2017
Merged

Add storybook #99

merged 8 commits into from
Dec 4, 2017

Conversation

zhongyn
Copy link
Contributor

@zhongyn zhongyn commented Nov 3, 2017

Summary

Setup storybook as doc site, migrate nav/layout/icon examples to storybook

npm install
npm run storybook
visit localhost:8081

@alex-bezek alex-bezek temporarily deployed to terra-consumer-pr-99 November 3, 2017 16:20 Inactive
@terra-bot
Copy link

terra-bot commented Nov 3, 2017

Warnings
⚠️

❗ Big PR. Consider breaking this into smaller PRs if applicaple

Generated by 🚫 dangerJS

@mhemesath
Copy link
Contributor

mhemesath commented Nov 4, 2017

I prefer that the stories live in the package of each component. We can then use story discovery to pull all the stories into storybook.

e.g https://github.com/cerner/terra-core/blob/storybook/.storybook/config.js

@mhemesath
Copy link
Contributor

Can we update the the deployment to run storybook rather than site? I want to remove the site, but we can do that in a subsequent pull request when we switch everything to webdriver.io and storybook

@bjankord
Copy link
Contributor

bjankord commented Nov 5, 2017

@mhemesath Storybook just added a feature to autoload all files with /.story.js$/ in their name to their v3.3.0 release branch. v3.3.0 has not yet been released yet though, there are a few other issues in that milestone.

@zhongyn
Copy link
Contributor Author

zhongyn commented Nov 7, 2017

@mhemesath putting the stories in the package of each component works for most components except those with translations. In this PR, all stories and story configs are inside the storybook folder and isolate from the outside.

  • root
    • storybook
      • package.json
      • config.js
      • webpack.config.js
      • stories
    • packages
    • package.json

so it can install terra-consumer-nav and add terra-i18n-plugin in its own node_modules. terra-in8-plugin then aggregates the translations by searching the node_modules folder. i18n is required for component like NavHelp.

In the terra-badge example, the structure is:

  • root
    • .storybook
      • config.js
    • packages
      • terra-badge
        • stories
    • package.json

That works. In the case of terra-alert with translations, it requires adding webpack.config.js with terra-i18n-plugin inside .storybook, and it will try to search the root level node_modules for translations folder. That means terra-alert should be added as devDependency in the root level. Not sure if that's appropriate. Any idea for handling this case?

@zhongyn
Copy link
Contributor Author

zhongyn commented Nov 7, 2017

yes, will update the deployment to run storybook after this PR

@mhemesath
Copy link
Contributor

terra-i18n-plugin then aggregates the translations by searching the node_modules folder

That plugin is only needed for aggregation. Do we need aggregation with storybook? Why can't the component find the translations relative to its directory. If we do need i18n plugin, can the source folder be modified it uses to search for translations?

@mhemesath
Copy link
Contributor

I am really adamant about having the stories of the components live in each package if possible.

@zhongyn
Copy link
Contributor Author

zhongyn commented Nov 7, 2017

That plugin is only needed for aggregation. Do we need aggregation with storybook?

yes, terra-consumer-nav depends on terra-i18n, and i18n loads translation files from the aggregation folder. i18n-plugin generates the aggregation. Without the aggregation folder webpack compile will fail. One solution is creating the aggregation manually with empty message. If so terra-i18n will work but no message is pulled in the component.

Why can't the component find the translations relative to its directory.

terra-i18n at the root level pulls in the translations. The component itself doesn't load the translations.

If we do need i18n plugin, can the source folder be modified it uses to search for translations?

i18n plugin only checks the node_modules for translation files. We can update it to take a custom path param so that it can search any custom folder

@zhongyn
Copy link
Contributor Author

zhongyn commented Nov 7, 2017

I created an issue in terra-core for extending i18n plugin with custom search path: cerner/terra-core#998

package.json Outdated
"terra-i18n": "^1.4.0",
"terra-i18n-plugin": "file:../terra-core/packages/terra-i18n-plugin",
Copy link
Contributor Author

@zhongyn zhongyn Nov 9, 2017

Choose a reason for hiding this comment

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

just for local dev, after this PR is merged we can update it with the new version

@alex-bezek alex-bezek temporarily deployed to terra-consumer-pr-99 November 29, 2017 17:16 Inactive
@alex-bezek alex-bezek temporarily deployed to terra-consumer-pr-99 November 29, 2017 17:33 Inactive
@alex-bezek alex-bezek temporarily deployed to terra-consumer-pr-99 November 29, 2017 17:42 Inactive
package.json Outdated
"test": "npm run jest && npm run nightwatch"
},
"devDependencies": {
"@storybook/addon-actions": "^3.2.14",
Copy link
Contributor

Choose a reason for hiding this comment

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

You may want to update to 3.3.0-alpha.4. Version 3.2 had issues with loading JSONP which is needed for requiring translations. This issue was fixed in v3.3.0 alphas. More info: storybookjs/storybook#1411

@alex-bezek alex-bezek temporarily deployed to terra-consumer-pr-99 November 29, 2017 19:27 Inactive
@@ -0,0 +1,3 @@
<script>
document.documentElement.setAttribute("dir", "ltr");
Copy link
Contributor

Choose a reason for hiding this comment

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

you can probably just do this in your main decorator

addDecorator(story => <div dir="ltr"><Base locale="en-US">{story()}</Base></div>);

Terra might log a warning, but the attribute will still work even if its not on HTML tag

Copy link
Contributor Author

Choose a reason for hiding this comment

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

neat! will update

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just found that it doesn't work for popup/modal rendered outside the Base tree. NavHelp looks like this after the change:
screen shot 2017-12-04 at 9 55 07 am
So we still need to put it in html tag

const rtl = require('postcss-rtl');

const customProperties = CustomProperties({ preserve: true, warnings: false });
customProperties.setVariables({
Copy link
Contributor

Choose a reason for hiding this comment

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

is this duplicated from our other webpack?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's copied from terra-consumer-site webpack config. Probably it's not necessary, will remove it and test the code

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants