Skip to content
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

Change Style guide to Storybook #39

Merged
merged 5 commits into from
Jan 17, 2020
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: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ typings/
# build directory
build

# styleguide build directory
styleguide
# storybook build directory
storybook

# Intellij IDE specific settings
.idea/
21 changes: 11 additions & 10 deletions .neutrinorc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@ module.exports = {
use: [
reactLint({
rules: {
/**
* Ignores reference to functions used before the function declaration.
* Since function declarations are hoisted, this is considered safe.
*/
'no-use-before-define': ['error', {
/**
* Ignores reference to functions used before the function declaration.
* Since function declarations are hoisted, this is considered safe.
*/
functions: false,
}],
'import/prefer-default-export': ['off'],
/**
* Allow both '.jsx' and '.js' file extensions to contain JSX
* ('.js' files are necessary for stories)
*/
'react/jsx-filename-extension': ['error', {
'extensions': ['.js', '.jsx']
}],
},
}),
reactComponents(),
jest(),
(neutrino) => {
neutrino.register('styleguide', () => ({
webpackConfig: neutrino.config.toConfig(),
skipComponentsWithoutExample: true,
}));
},
]
};
3 changes: 3 additions & 0 deletions .storybook/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { configure } from '@storybook/react';

configure(require.context('../src', true, /\.stories\.js$/), module);
Comment on lines +1 to +3
Copy link
Collaborator Author

@JiwoonKim JiwoonKim Dec 26, 2019

Choose a reason for hiding this comment

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

Storybook utilizes configs in .storybook/ folder (see #15 (comment)).
Overall, this config.js file helps Storybook to work 🌈 .

ℹ️ I've also tried customizing Storybook's webpack config to utilize Neutrino's webpack config, however, had come across some undesirable results.

Since Storybook works fine even without hooking Neutrino's webpack config (and hooking Neutrino's webpack config would rather produce undesirable consequences), I think it's best we leave Storybook's config as-is.
Maybe if Storybook implements changes to use storybook.config.js to export a preset, we may be able to consider hooking webpack in the future, if necessary :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting! Thank you for the explanation, very helpful. I'll try to look into it soon and get back to you.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,23 @@
"lint": "eslint --cache --format codeframe --ext mjs,jsx,js src",
"test": "jest",
"test:watch": "jest --watch",
"styleguide": "styleguidist server",
"deploy": "styleguidist build && gh-pages --remote upstream -d styleguide"
"storybook": "start-storybook",
"deploy": "build-storybook -c .storybook -o storybook && gh-pages --remote upstream -d storybook"
},
"devDependencies": {
"@material-ui/core": "^4.7.1",
"@material-ui/icons": "^4.5.1",
"@mozilla-frontend-infra/react-lint": "^2.0.1",
"@neutrinojs/jest": "9.0.0-rc.5",
"@neutrinojs/react-components": "9.0.0-rc.5",
"@storybook/react": "^5.2.8",
"babel-loader": "^8.0.6",
"eslint": "^6.7.2",
"gh-pages": "^2.1.1",
"jest": "^24.9.0",
"neutrino": "9.0.0-rc.5",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-styleguidist": "^10.2.1",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.9.0"
Expand Down
3 changes: 0 additions & 3 deletions schemas/basicDataTypes/array/tupleValidation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
{
"type": "number"
},
{
"type": "string"
},
{
"type": "string",
"enum": ["Street", "Avenue", "Boulevard"]
Expand Down
77 changes: 77 additions & 0 deletions src/components/SchemaTable/index.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React, { Fragment } from 'react';
import SchemaTable from './index';

export default {
title: 'Schema Table',
component: SchemaTable,
};

/**
* Schema examples to use for displaying stories
*/
const defaultSchemas = {};

defaultSchemas.boolean = require('../../../schemas/basicDataTypes/boolean/boolean.json');
defaultSchemas.null = require('../../../schemas/basicDataTypes/null/null.json');
defaultSchemas.integer = require('../../../schemas/basicDataTypes/numeric/integer.json');
defaultSchemas.numberMultiples = require('../../../schemas/basicDataTypes/numeric/numberMultiples.json');
defaultSchemas.numberRange = require('../../../schemas/basicDataTypes/numeric/numberRange.json');
defaultSchemas.stringPattern = require('../../../schemas/basicDataTypes/string/stringPattern.json');
defaultSchemas.stringFormat = require('../../../schemas/basicDataTypes/string/stringFormat.json');

const arraySchemas = {};

arraySchemas.emptyArray = require('../../../schemas/basicDataTypes/array/emptyArray.json');
arraySchemas.listValidation = require('../../../schemas/basicDataTypes/array/listValidation.json');
arraySchemas.tupleValidation = require('../../../schemas/basicDataTypes/array/tupleValidation.json');
arraySchemas.containsValidations = require('../../../schemas/basicDataTypes/array/containsValidation.json');
arraySchemas.additionalItems = require('../../../schemas/basicDataTypes/array/additionalItems.json');

const objectSchemas = {};

objectSchemas.emptyObject = require('../../../schemas/basicDataTypes/object/emptyObject.json');
objectSchemas.simpleObject = require('../../../schemas/basicDataTypes/object/simpleObject.json');
objectSchemas.propertySpecification = require('../../../schemas/basicDataTypes/object/propertySpecifications.json');
objectSchemas.propertyDependency = require('../../../schemas/basicDataTypes/object/propertyDependencies.json');
objectSchemas.requiredProperties = require('../../../schemas/basicDataTypes/object/requiredProperties.json');

export const defaultType = () => (
<Fragment>
<h3>Boolean</h3>
<SchemaTable schema={defaultSchemas.boolean} />
<h3>Null</h3>
<SchemaTable schema={defaultSchemas.null} />
<h3>Integer</h3>
<SchemaTable schema={defaultSchemas.integer} />
<h3>Number</h3>
<SchemaTable schema={defaultSchemas.numberRange} />
<h3>String</h3>
<SchemaTable schema={defaultSchemas.stringPattern} />
</Fragment>
);
export const arrayType = () => (
<Fragment>
<h3>List Validation</h3>
<SchemaTable schema={arraySchemas.listValidation} />
<h3>Tuple Validation</h3>
<SchemaTable schema={arraySchemas.tupleValidation} />
<h3>Contains Validation</h3>
<SchemaTable schema={arraySchemas.containsValidations} />
<h3>Additional Items Specification</h3>
<SchemaTable schema={arraySchemas.additionalItems} />
<h3>Empty Array</h3>
<SchemaTable schema={arraySchemas.emptyArray} />
</Fragment>
);
export const objectType = () => (
<Fragment>
<h3>Simple Object</h3>
<SchemaTable schema={objectSchemas.simpleObject} />
<h3>Property Specification</h3>
<SchemaTable schema={objectSchemas.propertySpecification} />
<h3>Required Properties Specification</h3>
<SchemaTable schema={objectSchemas.requiredProperties} />
<h3>Empty Object</h3>
<SchemaTable schema={objectSchemas.emptyObject} />
</Fragment>
);
3 changes: 0 additions & 3 deletions styleguide.config.js

This file was deleted.

Loading