├── .npmignore
├── .gitignore
├── .babelrc
├── .scripts
├── user
│ ├── pretest.js
│ └── prepublish.sh
├── get_gh_pages_url.js
├── prepublish.sh
├── mocha_runner.js
└── publish_storybook.sh
├── .storybook
├── addons.js
├── user
│ └── modify_webpack_config.js
├── config.js
└── webpack.config.js
├── docs
└── home-screenshot.png
├── src
├── components
│ ├── markdown
│ │ ├── index.js
│ │ ├── text.js
│ │ ├── code.js
│ │ └── htags.js
│ ├── theme.js
│ ├── Props.js
│ ├── Node.js
│ ├── PropVal.js
│ ├── PropTable.js
│ └── Story.js
├── tests
│ └── index.js
└── index.js
├── dist
├── components
│ ├── theme.js
│ ├── markdown
│ │ ├── index.js
│ │ ├── text.js
│ │ ├── code.js
│ │ └── htags.js
│ ├── Props.js
│ ├── Node.js
│ ├── PropVal.js
│ ├── PropTable.js
│ └── Story.js
└── index.js
├── .eslintrc
├── CONTRIBUTING.md
├── README.md
├── example
├── Button.js
└── story.js
├── LICENSE
├── package.json
└── CHANGELOG.md
/.npmignore:
--------------------------------------------------------------------------------
1 | .babelrc
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | npm-debug.log
3 |
--------------------------------------------------------------------------------
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["es2015", "stage-2", "react"]
3 | }
4 |
--------------------------------------------------------------------------------
/.scripts/user/pretest.js:
--------------------------------------------------------------------------------
1 | // Use this file to setup any test utilities.
2 |
--------------------------------------------------------------------------------
/.scripts/user/prepublish.sh:
--------------------------------------------------------------------------------
1 | # Use this file to your own code to run at NPM `prepublish` event.
2 |
--------------------------------------------------------------------------------
/.storybook/addons.js:
--------------------------------------------------------------------------------
1 | import '@kadira/storybook/addons';
2 | import 'react-storybook-addon-backgrounds/register';
3 |
--------------------------------------------------------------------------------
/docs/home-screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/storybook-eol/react-storybook-addon-info/HEAD/docs/home-screenshot.png
--------------------------------------------------------------------------------
/src/components/markdown/index.js:
--------------------------------------------------------------------------------
1 | export { H1, H2, H3, H4, H5, H6 } from './htags';
2 | export { Code, Pre } from './code';
3 | export { P, Small, A, LI } from './text';
4 |
--------------------------------------------------------------------------------
/.storybook/user/modify_webpack_config.js:
--------------------------------------------------------------------------------
1 | module.exports = function (config) {
2 | // This is the default webpack config defined in the `../webpack.config.js`
3 | // modify as you need.
4 | };
5 |
--------------------------------------------------------------------------------
/src/components/theme.js:
--------------------------------------------------------------------------------
1 | export const baseFonts = {
2 | fontFamily: `
3 | -apple-system, ".SFNSText-Regular", "San Francisco", "Roboto",
4 | "Segoe UI", "Helvetica Neue", "Lucida Grande", sans-serif
5 | `,
6 | color: '#444',
7 | WebkitFontSmoothing: 'antialiased',
8 | };
9 |
--------------------------------------------------------------------------------
/src/tests/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { shallow, mount } from 'enzyme';
3 | import Story from '../index';
4 | import { expect } from 'chai';
5 | import sinon from 'sinon';
6 | const { describe, it } = global;
7 |
8 | describe('Story', () => {
9 | it('should show the info button');
10 | });
11 |
--------------------------------------------------------------------------------
/.scripts/get_gh_pages_url.js:
--------------------------------------------------------------------------------
1 | // IMPORTANT
2 | // ---------
3 | // This is an auto generated file with React CDK.
4 | // Do not modify this file.
5 |
6 | const parse = require('git-url-parse');
7 | var ghUrl = process.argv[2];
8 | const parsedUrl = parse(ghUrl);
9 |
10 | const ghPagesUrl = 'https://' + parsedUrl.owner + '.github.io/' + parsedUrl.name;
11 | console.log(ghPagesUrl);
12 |
--------------------------------------------------------------------------------
/dist/components/theme.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | Object.defineProperty(exports, "__esModule", {
4 | value: true
5 | });
6 | var baseFonts = exports.baseFonts = {
7 | fontFamily: '\n -apple-system, ".SFNSText-Regular", "San Francisco", "Roboto",\n "Segoe UI", "Helvetica Neue", "Lucida Grande", sans-serif\n ',
8 | color: '#444',
9 | WebkitFontSmoothing: 'antialiased'
10 | };
--------------------------------------------------------------------------------
/.storybook/config.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { configure, setAddon, addDecorator } from '@kadira/storybook';
3 | import InfoAddon from '../src/';
4 |
5 | addDecorator((story) => (
6 |
7 | {story()}
8 |
9 | ));
10 |
11 | setAddon(InfoAddon);
12 |
13 | configure(function () {
14 | require('../example/story');
15 | }, module);
16 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "airbnb",
3 | "rules": {
4 | "arrow-body-style": 0,
5 | "prefer-arrow-callback": 0,
6 | "func-names": 0,
7 | "react/jsx-no-bind": 0,
8 | "react/jsx-uses-react": 1,
9 | "react/prefer-stateless-function": 0
10 | },
11 | "parserOptions": {
12 | "ecmaVersion": 6,
13 | "ecmaFeatures": {
14 | "experimentalObjectRestSpread": true
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to React Storybook Story Component
2 |
3 | We welcome your help to make this component better. This document will help to streamline the contributing process and save everyone's precious time.
4 |
5 | ## Development Setup
6 |
7 | This component has been setup with [React CDK](https://github.com/kadirahq/react-cdk). Refer [React CDK documentation](https://github.com/kadirahq/react-cdk)) to get started with the development.
8 |
--------------------------------------------------------------------------------
/.scripts/prepublish.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # IMPORTANT
4 | # ---------
5 | # This is an auto generated file with React CDK.
6 | # Do not modify this file.
7 | # Use `.scripts/user/prepublish.sh instead`.
8 |
9 | echo "=> Transpiling 'src' into ES5 ..."
10 | echo ""
11 | rm -rf ./dist
12 | ./node_modules/.bin/babel --ignore tests,stories --plugins "transform-runtime" ./src --out-dir ./dist
13 | echo ""
14 | echo "=> Transpiling completed."
15 |
16 | . .scripts/user/prepublish.sh
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # React Storybook Info Addon
2 |
3 | This contents of this repo was moved to the [Storybook monorepo](https://github.com/storybooks/storybook/) and the NPM package name has been changed.
4 |
5 | - The old name of the package was: **@kadira/react-storybook-addon-info**
6 | - The new name of the package is: **@storybook/addon-info**
7 | - The location of the code is: https://github.com/storybooks/storybook/tree/master/addons/info
8 |
9 | The repo you're looking at now is out of date and no longer maintained.
10 |
--------------------------------------------------------------------------------
/example/Button.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | const Button = ({ disabled, label, style, onClick }) => (
4 |
5 | {label}
6 |
7 | );
8 |
9 | Object.assign(Button, {
10 | displayName: 'Button',
11 | propTypes: {
12 | /** Single line comment: This is label description */
13 | label: React.PropTypes.string.isRequired,
14 | /*
15 | * Multiple lines comment: This is style description
16 | * Must be in object
17 | */
18 | style: React.PropTypes.object,
19 | disabled: React.PropTypes.bool,
20 | onClick: React.PropTypes.func,
21 | },
22 | });
23 |
24 | export default Button;
25 |
--------------------------------------------------------------------------------
/.storybook/webpack.config.js:
--------------------------------------------------------------------------------
1 | // IMPORTANT
2 | // ---------
3 | // This is an auto generated file with React CDK.
4 | // Do not modify this file.
5 | // Use `.storybook/user/modify_webpack_config.js instead`.
6 |
7 | const path = require('path');
8 | const updateConfig = require('./user/modify_webpack_config');
9 |
10 | const config = {
11 | module: {
12 | loaders: [
13 | {
14 | test: /\.css?$/,
15 | loaders: ['style', 'raw'],
16 | include: path.resolve(__dirname, '../'),
17 | },
18 | {
19 | test: /\.json?$/,
20 | loaders: ['json'],
21 | include: path.resolve(__dirname, '../'),
22 | }
23 | ],
24 | },
25 | };
26 |
27 | updateConfig(config);
28 | module.exports = config;
29 |
--------------------------------------------------------------------------------
/.scripts/mocha_runner.js:
--------------------------------------------------------------------------------
1 | // IMPORTANT
2 | // ---------
3 | // This is an auto generated file with React CDK.
4 | // Do not modify this file.
5 | // Use `.scripts/user/pretest.js instead`.
6 |
7 | require('babel-core/register');
8 | require('babel-polyfill');
9 |
10 | // Add jsdom support, which is required for enzyme.
11 | var jsdom = require('jsdom').jsdom;
12 |
13 | var exposedProperties = ['window', 'navigator', 'document'];
14 |
15 | global.document = jsdom('');
16 | global.window = document.defaultView;
17 | Object.keys(document.defaultView).forEach((property) => {
18 | if (typeof global[property] === 'undefined') {
19 | exposedProperties.push(property);
20 | global[property] = document.defaultView[property];
21 | }
22 | });
23 |
24 | global.navigator = {
25 | userAgent: 'node.js'
26 | };
27 |
28 | process.on('unhandledRejection', function (error) {
29 | console.error('Unhandled Promise Rejection:');
30 | console.error(error && error.stack || error);
31 | });
32 |
33 | require('./user/pretest.js');
34 |
--------------------------------------------------------------------------------
/src/components/markdown/text.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { baseFonts } from '../theme';
3 |
4 | export class P extends React.Component {
5 | render() {
6 | const style = {
7 | ...baseFonts,
8 | fontSize: '15px',
9 | };
10 | return {this.props.children}
;
11 | }
12 | }
13 |
14 | export class LI extends React.Component {
15 | render() {
16 | const style = {
17 | ...baseFonts,
18 | fontSize: '15px',
19 | };
20 | return {this.props.children} ;
21 | }
22 | }
23 |
24 | export class UL extends React.Component {
25 | render() {
26 | const style = {
27 | ...baseFonts,
28 | fontSize: '15px',
29 | };
30 |
31 | return ;
32 | }
33 | }
34 |
35 | export class A extends React.Component {
36 | render() {
37 | const style = {
38 | color: '#3498db',
39 | };
40 |
41 | return {this.props.children} ;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Your Name.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/.scripts/publish_storybook.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # IMPORTANT
4 | # ---------
5 | # This is an auto generated file with React CDK.
6 | # Do not modify this file.
7 |
8 | set -e # exit with nonzero exit code if anything fails
9 |
10 | # get GIT url
11 |
12 | GIT_URL=`git config --get remote.origin.url`
13 | if [[ $GIT_URL == "" ]]; then
14 | echo "This project is not configured with a remote git repo".
15 | exit 1
16 | fi
17 |
18 | # clear and re-create the out directory
19 | rm -rf .out || exit 0;
20 | mkdir .out;
21 |
22 | # run our compile script, discussed above
23 | build-storybook -o .out
24 |
25 | # go to the out directory and create a *new* Git repo
26 | cd .out
27 | git init
28 |
29 | # inside this git repo we'll pretend to be a new user
30 | git config user.name "GH Pages Bot"
31 | git config user.email "hello@ghbot.com"
32 |
33 | # The first and only commit to this new Git repo contains all the
34 | # files present with the commit message "Deploy to GitHub Pages".
35 | git add .
36 | git commit -m "Deploy Storybook to GitHub Pages"
37 |
38 | # Force push from the current repo's master branch to the remote
39 | # repo's gh-pages branch. (All previous history on the gh-pages branch
40 | # will be lost, since we are overwriting it.) We redirect any output to
41 | # /dev/null to hide any sensitive credential data that might otherwise be exposed.
42 | git push --force --quiet $GIT_URL master:gh-pages > /dev/null 2>&1
43 | cd ..
44 | rm -rf .out
45 |
46 | echo ""
47 | echo "=> Storybook deployed to: `node .scripts/get_gh_pages_url.js $GIT_URL`"
48 |
--------------------------------------------------------------------------------
/src/components/Props.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import PropVal from './PropVal';
3 |
4 | const stylesheet = {
5 | propStyle: {
6 | },
7 | propNameStyle: {
8 | },
9 | propValueStyle: {
10 | }
11 | }
12 |
13 | export default class Props extends React.Component {
14 | render() {
15 | const props = this.props.node.props;
16 | const defaultProps = this.props.node.type.defaultProps;
17 | if (!props || typeof props !== 'object') {
18 | return ;
19 | }
20 |
21 | const {propStyle, propValueStyle, propNameStyle} = stylesheet;
22 |
23 | const names = Object.keys(props).filter(name => {
24 | return name[0] !== '_' && name !== 'children' && (!defaultProps || props[name] != defaultProps[name]);
25 | });
26 |
27 | const breakIntoNewLines = names.length > 3;
28 | const endingSpace = this.props.singleLine ? ' ' : '';
29 |
30 | const items = [];
31 | names.forEach((name, i) => {
32 | items.push(
33 |
34 | {breakIntoNewLines ? (
35 |
36 |
37 |
38 | ) : ' '}
39 | {name}
40 | {/* Use implicit true: */}
41 | {(!props[name] || typeof props[name] !== 'boolean') && (
42 |
43 | =
44 |
45 |
46 | )}
47 |
48 | {i === (names.length - 1) && (
49 | breakIntoNewLines ? : endingSpace
50 | )}
51 |
52 | );
53 | });
54 |
55 | return {items} ;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/components/markdown/code.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | export class Code extends React.Component {
4 |
5 | componentDidMount() {
6 | this.highlight()
7 | }
8 |
9 | componentDidUpdate() {
10 | this.highlight()
11 | }
12 |
13 | highlight() {
14 | if (typeof Prism !== 'undefined') {
15 | Prism.highlightAll()
16 | }
17 | }
18 |
19 | render() {
20 | const codeStyle = {
21 | fontFamily: 'Menlo, Monaco, "Courier New", monospace',
22 | backgroundColor: '#fafafa',
23 | };
24 |
25 | const preStyle = {
26 | fontFamily: 'Menlo, Monaco, "Courier New", monospace',
27 | backgroundColor: '#fafafa',
28 | padding: '.5rem',
29 | lineHeight: 1.5,
30 | overflowX: 'scroll',
31 | };
32 |
33 | const className = this.props.language ? `language-${this.props.language}` : '';
34 |
35 | return (
36 |
37 |
38 | { this.props.code }
39 |
40 |
41 | );
42 | }
43 | }
44 |
45 | export class Pre extends React.Component {
46 | render() {
47 | const style = {
48 | fontSize: '.88em',
49 | fontFamily: 'Menlo, Monaco, "Courier New", monospace',
50 | backgroundColor: '#fafafa',
51 | padding: '.5rem',
52 | lineHeight: 1.5,
53 | overflowX: 'scroll',
54 | };
55 |
56 | return {this.props.children} ;
57 | }
58 | }
59 |
60 | export class Blockquote extends React.Component {
61 | render() {
62 | const style = {
63 | fontSize: '1.88em',
64 | fontFamily: 'Menlo, Monaco, "Courier New", monospace',
65 | borderLeft: '8px solid #fafafa',
66 | padding: '1rem',
67 | };
68 |
69 | return {this.props.children} ;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/dist/components/markdown/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | Object.defineProperty(exports, "__esModule", {
4 | value: true
5 | });
6 |
7 | var _htags = require('./htags');
8 |
9 | Object.defineProperty(exports, 'H1', {
10 | enumerable: true,
11 | get: function get() {
12 | return _htags.H1;
13 | }
14 | });
15 | Object.defineProperty(exports, 'H2', {
16 | enumerable: true,
17 | get: function get() {
18 | return _htags.H2;
19 | }
20 | });
21 | Object.defineProperty(exports, 'H3', {
22 | enumerable: true,
23 | get: function get() {
24 | return _htags.H3;
25 | }
26 | });
27 | Object.defineProperty(exports, 'H4', {
28 | enumerable: true,
29 | get: function get() {
30 | return _htags.H4;
31 | }
32 | });
33 | Object.defineProperty(exports, 'H5', {
34 | enumerable: true,
35 | get: function get() {
36 | return _htags.H5;
37 | }
38 | });
39 | Object.defineProperty(exports, 'H6', {
40 | enumerable: true,
41 | get: function get() {
42 | return _htags.H6;
43 | }
44 | });
45 |
46 | var _code = require('./code');
47 |
48 | Object.defineProperty(exports, 'Code', {
49 | enumerable: true,
50 | get: function get() {
51 | return _code.Code;
52 | }
53 | });
54 | Object.defineProperty(exports, 'Pre', {
55 | enumerable: true,
56 | get: function get() {
57 | return _code.Pre;
58 | }
59 | });
60 |
61 | var _text = require('./text');
62 |
63 | Object.defineProperty(exports, 'P', {
64 | enumerable: true,
65 | get: function get() {
66 | return _text.P;
67 | }
68 | });
69 | Object.defineProperty(exports, 'Small', {
70 | enumerable: true,
71 | get: function get() {
72 | return _text.Small;
73 | }
74 | });
75 | Object.defineProperty(exports, 'A', {
76 | enumerable: true,
77 | get: function get() {
78 | return _text.A;
79 | }
80 | });
81 | Object.defineProperty(exports, 'LI', {
82 | enumerable: true,
83 | get: function get() {
84 | return _text.LI;
85 | }
86 | });
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@kadira/react-storybook-addon-info",
3 | "version": "3.4.0",
4 | "description": "A React Storybook addon to show additional information for your stories.",
5 | "repository": {
6 | "type": "git",
7 | "url": "https://github.com/kadirahq/react-storybook-addon-info.git"
8 | },
9 | "license": "MIT",
10 | "scripts": {
11 | "prepublish": ". ./.scripts/prepublish.sh",
12 | "lint": "eslint src",
13 | "lintfix": "eslint src --fix",
14 | "testonly": "mocha --require .scripts/mocha_runner src/**/tests/**/*.js",
15 | "test": "npm run lint && npm run testonly",
16 | "test-watch": "npm run testonly -- --watch --watch-extensions js",
17 | "storybook": "start-storybook -p 9010",
18 | "publish-storybook": "bash .scripts/publish_storybook.sh"
19 | },
20 | "devDependencies": {
21 | "@kadira/storybook": "^2.20.1",
22 | "babel-cli": "^6.5.0",
23 | "babel-core": "^6.5.0",
24 | "babel-eslint": "^7.0.0",
25 | "babel-plugin-transform-runtime": "^6.5.0",
26 | "babel-polyfill": "^6.5.0",
27 | "babel-preset-es2015": "^6.5.0",
28 | "babel-preset-react": "^6.5.0",
29 | "babel-preset-stage-2": "^6.5.0",
30 | "chai": "^3.5.0",
31 | "enzyme": "^2.2.0",
32 | "eslint": "^3.6.1",
33 | "eslint-config-airbnb": "^12.0.0",
34 | "eslint-plugin-babel": "^3.2.0",
35 | "eslint-plugin-jsx-a11y": "^2.2.2",
36 | "eslint-plugin-react": "^6.2.1",
37 | "git-url-parse": "^6.0.1",
38 | "jsdom": "^9.5.0",
39 | "mocha": "^3.0.2",
40 | "react": "^15.3.2",
41 | "react-addons-test-utils": "^15.3.1",
42 | "react-dom": "^0.14.7 || ^15.0.0",
43 | "react-storybook-addon-backgrounds": "0.0.7",
44 | "sinon": "^1.17.6"
45 | },
46 | "peerDependencies": {
47 | "react": "^0.14.7 || ^15.0.0"
48 | },
49 | "dependencies": {
50 | "babel-runtime": "^6.5.0",
51 | "markdown-to-react-components": "^0.2.1",
52 | "react-addons-create-fragment": "^15.3.2"
53 | },
54 | "main": "dist/index.js",
55 | "engines": {
56 | "npm": "^3.0.0"
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/components/markdown/htags.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { baseFonts } from '../theme';
3 |
4 | export class H1 extends React.Component {
5 | render() {
6 | const styles = {
7 | ...baseFonts,
8 | borderBottom: '1px solid #eee',
9 | fontWeight: 600,
10 | margin: 0,
11 | padding: 0,
12 | fontSize: '40px',
13 | };
14 |
15 | return {this.props.children} ;
16 | }
17 | }
18 |
19 | export class H2 extends React.Component {
20 | render() {
21 | const styles = {
22 | ...baseFonts,
23 | fontWeight: 600,
24 | margin: 0,
25 | padding: 0,
26 | fontSize: '30px',
27 | };
28 |
29 | return {this.props.children} ;
30 | }
31 | }
32 |
33 | export class H3 extends React.Component {
34 | render() {
35 | const styles = {
36 | ...baseFonts,
37 | fontWeight: 600,
38 | margin: 0,
39 | padding: 0,
40 | fontSize: '22px',
41 | textTransform: 'uppercase',
42 | };
43 |
44 | return {this.props.children} ;
45 | }
46 | }
47 |
48 | export class H4 extends React.Component {
49 | render() {
50 | const styles = {
51 | ...baseFonts,
52 | fontWeight: 600,
53 | margin: 0,
54 | padding: 0,
55 | fontSize: '20px',
56 | };
57 |
58 | return {this.props.children} ;
59 | }
60 | }
61 |
62 | export class H5 extends React.Component {
63 | render() {
64 | const styles = {
65 | ...baseFonts,
66 | fontWeight: 600,
67 | margin: 0,
68 | padding: 0,
69 | fontSize: '18px',
70 | };
71 |
72 | return {this.props.children} ;
73 | }
74 | }
75 |
76 | export class H6 extends React.Component {
77 | render() {
78 | const styles = {
79 | ...baseFonts,
80 | fontWeight: 400,
81 | margin: 0,
82 | padding: 0,
83 | fontSize: '18px',
84 | };
85 |
86 | return {this.props.children} ;
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import _Story from './components/Story';
3 | import { H1, H2, H3, H4, H5, H6, Code, P, UL, A, LI } from './components/markdown';
4 | export const Story = _Story;
5 |
6 | const defaultOptions = {
7 | inline: false,
8 | header: true,
9 | source: true,
10 | propTables: [],
11 | };
12 |
13 | const defaultMtrcConf = {
14 | h1: H1,
15 | h2: H2,
16 | h3: H3,
17 | h4: H4,
18 | h5: H5,
19 | h6: H6,
20 | code: Code,
21 | p: P,
22 | a: A,
23 | li: LI,
24 | ul: UL,
25 | };
26 |
27 | export default {
28 | addWithInfo(storyName, info, storyFn, _options) {
29 |
30 | if (typeof storyFn !== 'function') {
31 | if (typeof info === 'function') {
32 | _options = storyFn;
33 | storyFn = info;
34 | info = '';
35 | } else {
36 | throw new Error('No story defining function has been specified');
37 | }
38 | }
39 |
40 | const options = {
41 | ...defaultOptions,
42 | ..._options
43 | };
44 |
45 | // props.propTables can only be either an array of components or null
46 | // propTables option is allowed to be set to 'false' (a boolean)
47 | // if the option is false, replace it with null to avoid react warnings
48 | if (!options.propTables) {
49 | options.propTables = null;
50 | }
51 |
52 | const mtrcConf = { ...defaultMtrcConf };
53 | if (options && options.mtrcConf) {
54 | Object.assign(mtrcConf, options.mtrcConf);
55 | }
56 |
57 | return this.add(storyName, (context) => {
58 | const props = {
59 | info,
60 | context,
61 | showInline: Boolean(options.inline),
62 | showHeader: Boolean(options.header),
63 | showSource: Boolean(options.source),
64 | propTables: options.propTables,
65 | styles: typeof options.styles === 'function'
66 | ? options.styles
67 | : (s) => s,
68 | mtrcConf
69 | };
70 |
71 | return (
72 |
73 | {storyFn(context)}
74 |
75 | );
76 | });
77 | }
78 | };
79 |
80 | export function setDefaults(newDefaults) {
81 | return Object.assign(defaultOptions, newDefaults);
82 | };
83 |
--------------------------------------------------------------------------------
/src/components/Node.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import Props from './Props'
3 |
4 |
5 | const stylesheet = {
6 | containerStyle: {},
7 | tagStyle: {
8 | color: '#777',
9 | }
10 | }
11 |
12 | export default class Node extends React.Component {
13 | constructor(props){
14 | super(props);
15 | }
16 |
17 | render(){
18 | const {node, depth} = this.props;
19 | let {tagStyle, containerStyle} = stylesheet;
20 |
21 | var leftPad = {
22 | paddingLeft: 3 + (depth + 1) * 15,
23 | paddingRight: 3,
24 | };
25 |
26 | Object.assign(containerStyle, leftPad);
27 |
28 | const {name, text, children} = getData(node);
29 |
30 | // Just text
31 | if (!name) {
32 | return
33 | {text}
34 |
;
35 | }
36 |
37 | // Single-line tag
38 | if (!children) {
39 | return
40 |
<{name}
41 |
42 |
/>
43 |
;
44 | }
45 |
46 | // Keep a copy so that further mutations to containerStyle don't impact us:
47 | const containerStyleCopy = Object.assign({}, containerStyle);
48 |
49 | // tag with children
50 | return (
51 |
52 |
53 |
<{name}
54 |
55 |
>
56 |
57 | {React.Children.map(children, childElement => (
58 |
59 | ))}
60 |
61 | </{name}>
62 |
63 |
64 | );
65 | }
66 | }
67 |
68 | function getData(element) {
69 | const data = {
70 | name: null,
71 | text: null,
72 | children: null
73 | };
74 |
75 | if (typeof element == 'string') {
76 | data.text = element;
77 | return data;
78 | }
79 |
80 | if (typeof element === 'number') {
81 | data.text = String.toString(element);
82 | return data;
83 | }
84 |
85 | data.children = element.props.children;
86 | const type = element.type;
87 |
88 | if (typeof type === 'string') {
89 | data.name = type;
90 | } else {
91 | data.name = type.displayName || type.name || 'Unknown';
92 | }
93 |
94 | return data;
95 | }
96 |
--------------------------------------------------------------------------------
/dist/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | Object.defineProperty(exports, "__esModule", {
4 | value: true
5 | });
6 | exports.Story = undefined;
7 |
8 | var _assign = require('babel-runtime/core-js/object/assign');
9 |
10 | var _assign2 = _interopRequireDefault(_assign);
11 |
12 | var _extends2 = require('babel-runtime/helpers/extends');
13 |
14 | var _extends3 = _interopRequireDefault(_extends2);
15 |
16 | exports.setDefaults = setDefaults;
17 |
18 | var _react = require('react');
19 |
20 | var _react2 = _interopRequireDefault(_react);
21 |
22 | var _Story2 = require('./components/Story');
23 |
24 | var _Story3 = _interopRequireDefault(_Story2);
25 |
26 | var _markdown = require('./components/markdown');
27 |
28 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29 |
30 | var Story = exports.Story = _Story3.default;
31 |
32 | var defaultOptions = {
33 | inline: false,
34 | header: true,
35 | source: true,
36 | propTables: []
37 | };
38 |
39 | var defaultMtrcConf = {
40 | h1: _markdown.H1,
41 | h2: _markdown.H2,
42 | h3: _markdown.H3,
43 | h4: _markdown.H4,
44 | h5: _markdown.H5,
45 | h6: _markdown.H6,
46 | code: _markdown.Code,
47 | p: _markdown.P,
48 | a: _markdown.A,
49 | li: _markdown.LI,
50 | ul: _markdown.UL
51 | };
52 |
53 | exports.default = {
54 | addWithInfo: function addWithInfo(storyName, info, storyFn, _options) {
55 |
56 | if (typeof storyFn !== 'function') {
57 | if (typeof info === 'function') {
58 | _options = storyFn;
59 | storyFn = info;
60 | info = '';
61 | } else {
62 | throw new Error('No story defining function has been specified');
63 | }
64 | }
65 |
66 | var options = (0, _extends3.default)({}, defaultOptions, _options);
67 |
68 | // props.propTables can only be either an array of components or null
69 | // propTables option is allowed to be set to 'false' (a boolean)
70 | // if the option is false, replace it with null to avoid react warnings
71 | if (!options.propTables) {
72 | options.propTables = null;
73 | }
74 |
75 | var mtrcConf = (0, _extends3.default)({}, defaultMtrcConf);
76 | if (options && options.mtrcConf) {
77 | (0, _assign2.default)(mtrcConf, options.mtrcConf);
78 | }
79 |
80 | return this.add(storyName, function (context) {
81 | var props = {
82 | info: info,
83 | context: context,
84 | showInline: Boolean(options.inline),
85 | showHeader: Boolean(options.header),
86 | showSource: Boolean(options.source),
87 | propTables: options.propTables,
88 | styles: typeof options.styles === 'function' ? options.styles : function (s) {
89 | return s;
90 | },
91 | mtrcConf: mtrcConf
92 | };
93 |
94 | return _react2.default.createElement(
95 | Story,
96 | props,
97 | storyFn(context)
98 | );
99 | });
100 | }
101 | };
102 | function setDefaults(newDefaults) {
103 | return (0, _assign2.default)(defaultOptions, newDefaults);
104 | };
--------------------------------------------------------------------------------
/src/components/PropVal.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import createFragment from 'react-addons-create-fragment';
3 |
4 | const valueStyles = {
5 | func: {
6 | color: '#170',
7 | },
8 |
9 | attr: {
10 | color: '#666',
11 | },
12 |
13 | object: {
14 | color: '#666',
15 | },
16 |
17 | array: {
18 | color: '#666',
19 | },
20 |
21 | number: {
22 | color: '#a11',
23 | },
24 |
25 | string: {
26 | color: '#22a',
27 | wordBreak: 'break-word',
28 | },
29 |
30 | bool: {
31 | color: '#a11',
32 | },
33 |
34 | empty: {
35 | color: '#777',
36 | },
37 | };
38 |
39 | function previewArray(val) {
40 | const items = {};
41 | val.slice(0, 3).forEach((item, i) => {
42 | items[`n${i}`] = ;
43 | items[`c${i}`] = ', ';
44 | });
45 | if (val.length > 3) {
46 | items.last = '…';
47 | } else {
48 | delete items[`c${val.length - 1}`];
49 | }
50 | return (
51 |
52 | [{createFragment(items)}]
53 |
54 | );
55 | }
56 |
57 | function previewObject(val) {
58 | const names = Object.keys(val);
59 | const items = {};
60 | names.slice(0, 3).forEach((name, i) => {
61 | items[`k${i}`] = {name} ;
62 | items[`c${i}`] = ': ';
63 | items[`v${i}`] = ;
64 | items[`m${i}`] = ', ';
65 | });
66 | if (names.length > 3) {
67 | items.rest = '…';
68 | } else {
69 | delete items[`m${names.length - 1}`];
70 | }
71 | return (
72 |
73 | {'{'}{createFragment(items)}{'}'}
74 |
75 | );
76 | }
77 |
78 | function previewProp(val) {
79 | let braceWrap = true;
80 | let content = null;
81 | if (typeof val === 'number') {
82 | content = {val} ;
83 | } else if (typeof val === 'string') {
84 | if (val.length > 50) {
85 | val = val.slice(0, 50) + '…';
86 | }
87 | content = "{val}" ;
88 | braceWrap = false;
89 | } else if (typeof val === 'boolean') {
90 | content = {`${val}`} ;
91 | } else if (Array.isArray(val)) {
92 | content = previewArray(val);
93 | } else if (typeof val === 'function') {
94 | content = {val.name ? `${val.name}()` : 'anonymous()'} ;
95 | } else if (!val) {
96 | content = {`${val}`} ;
97 | } else if (typeof val !== 'object') {
98 | content = … ;
99 | } else if (React.isValidElement(val)) {
100 | content = (
101 |
102 | {`<${val.type.displayName || val.type.name || val.type} />`}
103 |
104 | );
105 | } else {
106 | content = previewObject(val);
107 | }
108 |
109 | if (!braceWrap) return content;
110 | return {{content}} ;
111 | }
112 |
113 | export default class PropVal extends React.Component {
114 | render() {
115 | return previewProp(this.props.val);
116 | }
117 | }
118 |
119 | module.exports = PropVal;
120 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | ### v3.3.0
4 |
5 | * Add setDefaults function [PR114](https://github.com/kadirahq/react-storybook-addon-info/pull/114)
6 |
7 | ### v3.2.4
8 |
9 | * Add missing dist files [PR113](https://github.com/kadirahq/react-storybook-addon-info/pull/113)
10 |
11 | ### v3.2.3
12 |
13 | * Handle number type nodes [PR110](https://github.com/kadirahq/react-storybook-addon-info/pull/110)
14 |
15 | ### v3.2.2
16 |
17 | * Use markdown-to-react-components npm package instead of our fork. Our PR to them is merged and published. [PR109](https://github.com/kadirahq/react-storybook-addon-info/pull/109)
18 |
19 | ### v3.2.1
20 |
21 | * Handle false values for types [PR54](https://github.com/kadirahq/react-storybook-addon-info/pull/54)
22 |
23 | ### v3.2.0
24 |
25 | * Support custom MTRC config [PR54](https://github.com/kadirahq/react-storybook-addon-info/pull/54)
26 | * Fix propTables prop validation with a default value [PR55](https://github.com/kadirahq/react-storybook-addon-info/pull/55)
27 |
28 | ### v3.1.4
29 |
30 | * Remove propTables prop validation warning [PR53](https://github.com/kadirahq/react-storybook-addon-info/pull/53)
31 | * Update example storybook [PR52](https://github.com/kadirahq/react-storybook-addon-info/pull/52)
32 |
33 | ### v3.1.3
34 |
35 | * Fix wrong detection of propType when isRequired is set [PR49](https://github.com/kadirahq/react-storybook-addon-info/pull/49)
36 | * Add displayName for Button [PR51](https://github.com/kadirahq/react-storybook-addon-info/pull/51)
37 |
38 | ### v3.1.2
39 |
40 | * Fixed a bug which made the `info` to not display and the `options` parameter to be ignored when `info` is not given.[PR45](https://github.com/kadirahq/react-storybook-addon-info/pull/45)
41 |
42 | ### v3.1.1
43 |
44 | * Add a z-index for rendered items to make the overlay always display on top [PR38](https://github.com/kadirahq/react-storybook-addon-info/pull/38)
45 |
46 | ### v3.1.0
47 |
48 | * Make the `info` argument optional [PR37](https://github.com/kadirahq/react-storybook-addon-info/pull/37)
49 |
50 | ### v3.0.10
51 |
52 | * Render the component inside a div element when on inline mode [PR34](https://github.com/kadirahq/react-storybook-addon-info/pull/34)
53 |
54 | ### v3.0.9
55 |
56 | * Add missing `@kadira/storybook` devDependencies [PR25](https://github.com/kadirahq/react-storybook-addon-info/pull/25)
57 | * Improve prop rendering in jsx source view [PR24](https://github.com/kadirahq/react-storybook-addon-info/pull/24)
58 | * Avoid warning message with "webkitFontSmoothing" [PR30](https://github.com/kadirahq/react-storybook-addon-info/pull/30)
59 | * Remove max-width style rule for wrapper [PR31](https://github.com/kadirahq/react-storybook-addon-info/pull/31) and [PR36](https://github.com/kadirahq/react-storybook-addon-info/pull/36)
60 | * Improve prop table rendering (handle css resets) [PR32](https://github.com/kadirahq/react-storybook-addon-info/pull/32)
61 |
62 | ### v3.0.8
63 |
64 | * Fixed unkeyed array iteration warning in React with: [PR23](https://github.com/kadirahq/react-storybook-addon-info/pull/23)
65 |
66 | ### v3.0.7
67 |
68 | * Improve default display in prop table. See [#16](https://github.com/kadirahq/react-storybook-addon-info/pull/16)
69 |
70 | ### v3.0.6
71 |
72 | * Improve function type and react element type props display. See [#14](https://github.com/kadirahq/react-storybook-addon-info/pull/14)
73 |
74 | ### v3.0.5
75 |
76 | * Over-indentation of ending tag in source code is fixed. See [#13](https://github.com/kadirahq/react-storybook-addon-info/pull/13)
77 |
78 | ### v3.0.4
79 |
80 | * Remove the need to use json-loader with webpack when using this package.
81 | See: [#12](https://github.com/kadirahq/react-storybook-addon-info/issues/12)
82 |
83 | ### v3.0.0
84 |
85 | * Add the version which works as an React Storybook addon.
86 |
--------------------------------------------------------------------------------
/dist/components/Props.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | Object.defineProperty(exports, "__esModule", {
4 | value: true
5 | });
6 |
7 | var _keys = require('babel-runtime/core-js/object/keys');
8 |
9 | var _keys2 = _interopRequireDefault(_keys);
10 |
11 | var _typeof2 = require('babel-runtime/helpers/typeof');
12 |
13 | var _typeof3 = _interopRequireDefault(_typeof2);
14 |
15 | var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
16 |
17 | var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
18 |
19 | var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
20 |
21 | var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
22 |
23 | var _createClass2 = require('babel-runtime/helpers/createClass');
24 |
25 | var _createClass3 = _interopRequireDefault(_createClass2);
26 |
27 | var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
28 |
29 | var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
30 |
31 | var _inherits2 = require('babel-runtime/helpers/inherits');
32 |
33 | var _inherits3 = _interopRequireDefault(_inherits2);
34 |
35 | var _react = require('react');
36 |
37 | var _react2 = _interopRequireDefault(_react);
38 |
39 | var _PropVal = require('./PropVal');
40 |
41 | var _PropVal2 = _interopRequireDefault(_PropVal);
42 |
43 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
44 |
45 | var stylesheet = {
46 | propStyle: {},
47 | propNameStyle: {},
48 | propValueStyle: {}
49 | };
50 |
51 | var Props = function (_React$Component) {
52 | (0, _inherits3.default)(Props, _React$Component);
53 |
54 | function Props() {
55 | (0, _classCallCheck3.default)(this, Props);
56 | return (0, _possibleConstructorReturn3.default)(this, (Props.__proto__ || (0, _getPrototypeOf2.default)(Props)).apply(this, arguments));
57 | }
58 |
59 | (0, _createClass3.default)(Props, [{
60 | key: 'render',
61 | value: function render() {
62 | var props = this.props.node.props;
63 | var defaultProps = this.props.node.type.defaultProps;
64 | if (!props || (typeof props === 'undefined' ? 'undefined' : (0, _typeof3.default)(props)) !== 'object') {
65 | return _react2.default.createElement('span', null);
66 | }
67 |
68 | var propStyle = stylesheet.propStyle,
69 | propValueStyle = stylesheet.propValueStyle,
70 | propNameStyle = stylesheet.propNameStyle;
71 |
72 |
73 | var names = (0, _keys2.default)(props).filter(function (name) {
74 | return name[0] !== '_' && name !== 'children' && (!defaultProps || props[name] != defaultProps[name]);
75 | });
76 |
77 | var breakIntoNewLines = names.length > 3;
78 | var endingSpace = this.props.singleLine ? ' ' : '';
79 |
80 | var items = [];
81 | names.forEach(function (name, i) {
82 | items.push(_react2.default.createElement(
83 | 'span',
84 | { key: name },
85 | breakIntoNewLines ? _react2.default.createElement(
86 | 'span',
87 | null,
88 | _react2.default.createElement('br', null),
89 | '\xA0\xA0'
90 | ) : ' ',
91 | _react2.default.createElement(
92 | 'span',
93 | { style: propNameStyle },
94 | name
95 | ),
96 | (!props[name] || typeof props[name] !== 'boolean') && _react2.default.createElement(
97 | 'span',
98 | null,
99 | '=',
100 | _react2.default.createElement(
101 | 'span',
102 | { style: propValueStyle },
103 | _react2.default.createElement(_PropVal2.default, { val: props[name] })
104 | )
105 | ),
106 | i === names.length - 1 && (breakIntoNewLines ? _react2.default.createElement('br', null) : endingSpace)
107 | ));
108 | });
109 |
110 | return _react2.default.createElement(
111 | 'span',
112 | null,
113 | items
114 | );
115 | }
116 | }]);
117 | return Props;
118 | }(_react2.default.Component);
119 |
120 | exports.default = Props;
--------------------------------------------------------------------------------
/dist/components/markdown/text.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | Object.defineProperty(exports, "__esModule", {
4 | value: true
5 | });
6 | exports.A = exports.UL = exports.LI = exports.P = undefined;
7 |
8 | var _extends2 = require('babel-runtime/helpers/extends');
9 |
10 | var _extends3 = _interopRequireDefault(_extends2);
11 |
12 | var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
13 |
14 | var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
15 |
16 | var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
17 |
18 | var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
19 |
20 | var _createClass2 = require('babel-runtime/helpers/createClass');
21 |
22 | var _createClass3 = _interopRequireDefault(_createClass2);
23 |
24 | var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
25 |
26 | var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
27 |
28 | var _inherits2 = require('babel-runtime/helpers/inherits');
29 |
30 | var _inherits3 = _interopRequireDefault(_inherits2);
31 |
32 | var _react = require('react');
33 |
34 | var _react2 = _interopRequireDefault(_react);
35 |
36 | var _theme = require('../theme');
37 |
38 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
39 |
40 | var P = exports.P = function (_React$Component) {
41 | (0, _inherits3.default)(P, _React$Component);
42 |
43 | function P() {
44 | (0, _classCallCheck3.default)(this, P);
45 | return (0, _possibleConstructorReturn3.default)(this, (P.__proto__ || (0, _getPrototypeOf2.default)(P)).apply(this, arguments));
46 | }
47 |
48 | (0, _createClass3.default)(P, [{
49 | key: 'render',
50 | value: function render() {
51 | var style = (0, _extends3.default)({}, _theme.baseFonts, {
52 | fontSize: '15px'
53 | });
54 | return _react2.default.createElement(
55 | 'p',
56 | { style: style },
57 | this.props.children
58 | );
59 | }
60 | }]);
61 | return P;
62 | }(_react2.default.Component);
63 |
64 | var LI = exports.LI = function (_React$Component2) {
65 | (0, _inherits3.default)(LI, _React$Component2);
66 |
67 | function LI() {
68 | (0, _classCallCheck3.default)(this, LI);
69 | return (0, _possibleConstructorReturn3.default)(this, (LI.__proto__ || (0, _getPrototypeOf2.default)(LI)).apply(this, arguments));
70 | }
71 |
72 | (0, _createClass3.default)(LI, [{
73 | key: 'render',
74 | value: function render() {
75 | var style = (0, _extends3.default)({}, _theme.baseFonts, {
76 | fontSize: '15px'
77 | });
78 | return _react2.default.createElement(
79 | 'li',
80 | { style: style },
81 | this.props.children
82 | );
83 | }
84 | }]);
85 | return LI;
86 | }(_react2.default.Component);
87 |
88 | var UL = exports.UL = function (_React$Component3) {
89 | (0, _inherits3.default)(UL, _React$Component3);
90 |
91 | function UL() {
92 | (0, _classCallCheck3.default)(this, UL);
93 | return (0, _possibleConstructorReturn3.default)(this, (UL.__proto__ || (0, _getPrototypeOf2.default)(UL)).apply(this, arguments));
94 | }
95 |
96 | (0, _createClass3.default)(UL, [{
97 | key: 'render',
98 | value: function render() {
99 | var style = (0, _extends3.default)({}, _theme.baseFonts, {
100 | fontSize: '15px'
101 | });
102 |
103 | return _react2.default.createElement(
104 | 'ul',
105 | { style: style },
106 | this.props.children
107 | );
108 | }
109 | }]);
110 | return UL;
111 | }(_react2.default.Component);
112 |
113 | var A = exports.A = function (_React$Component4) {
114 | (0, _inherits3.default)(A, _React$Component4);
115 |
116 | function A() {
117 | (0, _classCallCheck3.default)(this, A);
118 | return (0, _possibleConstructorReturn3.default)(this, (A.__proto__ || (0, _getPrototypeOf2.default)(A)).apply(this, arguments));
119 | }
120 |
121 | (0, _createClass3.default)(A, [{
122 | key: 'render',
123 | value: function render() {
124 | var style = {
125 | color: '#3498db'
126 | };
127 |
128 | return _react2.default.createElement(
129 | 'a',
130 | { href: this.props.href, style: style },
131 | this.props.children
132 | );
133 | }
134 | }]);
135 | return A;
136 | }(_react2.default.Component);
--------------------------------------------------------------------------------
/src/components/PropTable.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import PropVal from './PropVal';
3 |
4 | const stylesheet = {
5 | propTable: {
6 | marginLeft: -10,
7 | borderSpacing: '10px 5px',
8 | borderCollapse: 'separate',
9 | },
10 | };
11 |
12 | function isNotEmpty(obj) {
13 | return obj && Object.keys(obj).length > 0;
14 | }
15 |
16 | const PropTypesMap = new Map();
17 | for (const typeName in React.PropTypes) {
18 | if (!React.PropTypes.hasOwnProperty(typeName)) {
19 | continue;
20 | }
21 | const type = React.PropTypes[typeName];
22 | PropTypesMap.set(type, typeName);
23 | PropTypesMap.set(type.isRequired, typeName);
24 | }
25 |
26 | function renderDocgenPropType(propType) {
27 | if (!propType) {
28 | return 'unknown';
29 | }
30 |
31 | const name = propType.name;
32 |
33 | switch (name) {
34 | case 'arrayOf':
35 | return `${propType.value.name}[]`;
36 | case 'instanceOf':
37 | return propType.value;
38 | case 'union':
39 | return propType.raw;
40 | default:
41 | return name;
42 | }
43 | }
44 |
45 | function hasDocgen(type) {
46 | return isNotEmpty(type.__docgenInfo);
47 | }
48 |
49 | function propsFromDocgen(type) {
50 | let props = null;
51 |
52 | const docgenInfo = type.__docgenInfo || {};
53 | const docgenInfoProps = docgenInfo.props;
54 |
55 | if (docgenInfoProps) {
56 | props = {};
57 | for (const propName in docgenInfoProps) {
58 | if (!docgenInfoProps.hasOwnProperty(propName)) {
59 | continue;
60 | }
61 | const docgenInfoProp = docgenInfoProps[propName];
62 | const defaultValueDesc = docgenInfoProp.defaultValue || {};
63 | const propType = docgenInfoProp.flowType || docgenInfoProp.type || 'other';
64 |
65 | props[propName] = {
66 | property: propName,
67 | propType: renderDocgenPropType(propType),
68 | required: docgenInfoProp.required,
69 | description: docgenInfoProp.description,
70 | defaultValue: defaultValueDesc.value,
71 | };
72 | }
73 | }
74 | return props;
75 | }
76 |
77 | function propsFromPropTypes(type) {
78 | let props = null;
79 |
80 | if (type.propTypes) {
81 | props = {};
82 | for (const property in type.propTypes) {
83 | if (!type.propTypes.hasOwnProperty(property)) {
84 | continue;
85 | }
86 | const typeInfo = type.propTypes[property];
87 | const propType = PropTypesMap.get(typeInfo) || 'other';
88 | const required = typeInfo.isRequired === undefined ? 'yes' : 'no';
89 | props[property] = { property, propType, required };
90 | }
91 | }
92 |
93 | if (type.defaultProps) {
94 | for (const property in type.defaultProps) {
95 | if (!type.defaultProps.hasOwnProperty(property)) {
96 | continue;
97 | }
98 | const value = type.defaultProps[property];
99 | if (value === undefined) {
100 | continue;
101 | }
102 | if (!props[property]) {
103 | props[property] = { property };
104 | }
105 | props[property].defaultValue = value;
106 | }
107 | }
108 | return props;
109 | }
110 |
111 | export default class PropTable extends React.Component {
112 | render() {
113 | const type = this.props.type;
114 |
115 | if (!type) {
116 | return null;
117 | }
118 |
119 | const props = hasDocgen(type) ? propsFromDocgen(type) : propsFromPropTypes(type);
120 |
121 | if (isNotEmpty(props)) {
122 | return (
123 |
124 |
125 |
126 | property
127 | propType
128 | required
129 | default
130 | description
131 |
132 |
133 |
134 | {Object.values(props).sort((a, b) => a.property > b.property).map(row => (
135 |
136 | {row.property}
137 | {row.propType}
138 | {row.required}
139 | {row.defaultValue === undefined ? '-' : }
140 | {row.description}
141 |
142 | ))}
143 |
144 |
145 | );
146 | } else {
147 | return No propTypes defined! ;
148 | }
149 | }
150 | }
151 |
152 | PropTable.displayName = 'PropTable';
153 | PropTable.propTypes = {
154 | type: React.PropTypes.func,
155 | };
156 |
--------------------------------------------------------------------------------
/dist/components/markdown/code.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | Object.defineProperty(exports, "__esModule", {
4 | value: true
5 | });
6 | exports.Blockquote = exports.Pre = exports.Code = undefined;
7 |
8 | var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
9 |
10 | var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
11 |
12 | var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
13 |
14 | var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
15 |
16 | var _createClass2 = require('babel-runtime/helpers/createClass');
17 |
18 | var _createClass3 = _interopRequireDefault(_createClass2);
19 |
20 | var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
21 |
22 | var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
23 |
24 | var _inherits2 = require('babel-runtime/helpers/inherits');
25 |
26 | var _inherits3 = _interopRequireDefault(_inherits2);
27 |
28 | var _react = require('react');
29 |
30 | var _react2 = _interopRequireDefault(_react);
31 |
32 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33 |
34 | var Code = exports.Code = function (_React$Component) {
35 | (0, _inherits3.default)(Code, _React$Component);
36 |
37 | function Code() {
38 | (0, _classCallCheck3.default)(this, Code);
39 | return (0, _possibleConstructorReturn3.default)(this, (Code.__proto__ || (0, _getPrototypeOf2.default)(Code)).apply(this, arguments));
40 | }
41 |
42 | (0, _createClass3.default)(Code, [{
43 | key: 'componentDidMount',
44 | value: function componentDidMount() {
45 | this.highlight();
46 | }
47 | }, {
48 | key: 'componentDidUpdate',
49 | value: function componentDidUpdate() {
50 | this.highlight();
51 | }
52 | }, {
53 | key: 'highlight',
54 | value: function highlight() {
55 | if (typeof Prism !== 'undefined') {
56 | Prism.highlightAll();
57 | }
58 | }
59 | }, {
60 | key: 'render',
61 | value: function render() {
62 | var codeStyle = {
63 | fontFamily: 'Menlo, Monaco, "Courier New", monospace',
64 | backgroundColor: '#fafafa'
65 | };
66 |
67 | var preStyle = {
68 | fontFamily: 'Menlo, Monaco, "Courier New", monospace',
69 | backgroundColor: '#fafafa',
70 | padding: '.5rem',
71 | lineHeight: 1.5,
72 | overflowX: 'scroll'
73 | };
74 |
75 | var className = this.props.language ? 'language-' + this.props.language : '';
76 |
77 | return _react2.default.createElement(
78 | 'pre',
79 | { style: preStyle, className: className },
80 | _react2.default.createElement(
81 | 'code',
82 | { style: codeStyle, className: className },
83 | this.props.code
84 | )
85 | );
86 | }
87 | }]);
88 | return Code;
89 | }(_react2.default.Component);
90 |
91 | var Pre = exports.Pre = function (_React$Component2) {
92 | (0, _inherits3.default)(Pre, _React$Component2);
93 |
94 | function Pre() {
95 | (0, _classCallCheck3.default)(this, Pre);
96 | return (0, _possibleConstructorReturn3.default)(this, (Pre.__proto__ || (0, _getPrototypeOf2.default)(Pre)).apply(this, arguments));
97 | }
98 |
99 | (0, _createClass3.default)(Pre, [{
100 | key: 'render',
101 | value: function render() {
102 | var style = {
103 | fontSize: '.88em',
104 | fontFamily: 'Menlo, Monaco, "Courier New", monospace',
105 | backgroundColor: '#fafafa',
106 | padding: '.5rem',
107 | lineHeight: 1.5,
108 | overflowX: 'scroll'
109 | };
110 |
111 | return _react2.default.createElement(
112 | 'pre',
113 | { style: style },
114 | this.props.children
115 | );
116 | }
117 | }]);
118 | return Pre;
119 | }(_react2.default.Component);
120 |
121 | var Blockquote = exports.Blockquote = function (_React$Component3) {
122 | (0, _inherits3.default)(Blockquote, _React$Component3);
123 |
124 | function Blockquote() {
125 | (0, _classCallCheck3.default)(this, Blockquote);
126 | return (0, _possibleConstructorReturn3.default)(this, (Blockquote.__proto__ || (0, _getPrototypeOf2.default)(Blockquote)).apply(this, arguments));
127 | }
128 |
129 | (0, _createClass3.default)(Blockquote, [{
130 | key: 'render',
131 | value: function render() {
132 | var style = {
133 | fontSize: '1.88em',
134 | fontFamily: 'Menlo, Monaco, "Courier New", monospace',
135 | borderLeft: '8px solid #fafafa',
136 | padding: '1rem'
137 | };
138 |
139 | return _react2.default.createElement(
140 | 'blockquote',
141 | { style: style },
142 | this.props.children
143 | );
144 | }
145 | }]);
146 | return Blockquote;
147 | }(_react2.default.Component);
--------------------------------------------------------------------------------
/example/story.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import Button from './Button';
3 | import { storiesOf, action } from '@kadira/storybook';
4 | import backgrounds from 'react-storybook-addon-backgrounds';
5 |
6 | storiesOf('Button')
7 | .addWithInfo(
8 | 'simple usage',
9 | `
10 | This is the basic usage with the button with providing a label to show the text.
11 | `,
12 | () => (
13 |
14 |
15 |
16 |
17 | Click the "?" mark at top-right to view the info.
18 |
19 |
20 | ),
21 | );
22 |
23 | storiesOf('Button')
24 | .addWithInfo(
25 | 'simple usage (inline info)',
26 | `
27 | This is the basic usage with the button with providing a label to show the text.
28 | `,
29 | () => (),
30 | { inline: true },
31 | );
32 |
33 | storiesOf('Button')
34 | .addWithInfo(
35 | 'simple usage (disable source)',
36 | `
37 | This is the basic usage with the button with providing a label to show the text.
38 | `,
39 | () => (),
40 | { source: false, inline: true },
41 | );
42 |
43 | storiesOf('Button')
44 | .addWithInfo(
45 | 'simple usage (no header)',
46 | `
47 | This is the basic usage with the button with providing a label to show the text.
48 | `,
49 | () => (),
50 | { header: false, inline: true },
51 | );
52 |
53 | storiesOf('Button')
54 | .addWithInfo(
55 | 'simple usage (no prop tables)',
56 | `
57 | This is the basic usage with the button with providing a label to show the text.
58 | `,
59 | () => (),
60 | { propTables: false, inline: true },
61 | );
62 |
63 | storiesOf('Button')
64 | .addWithInfo(
65 | 'simple usage (custom propTables)',
66 | `
67 | This is the basic usage with the button with providing a label to show the text.
68 |
69 | Since, the story source code is wrapped inside a div, info addon can't figure out propTypes on it's own.
70 | So, we need to give relevant React component classes manually using \`propTypes\` option as shown below:
71 |
72 | ~~~js
73 | storiesOf('Button')
74 | .addWithInfo(
75 | 'simple usage (custom propTables)',
76 | ,
77 | ,
78 | { inline: true, propTables: [Button]}
79 | );
80 | ~~~
81 | `,
82 | () => (
83 |
84 |
85 |
86 |
87 | ),
88 | { inline: true, propTables: [Button]}
89 | );
90 |
91 | storiesOf('Button')
92 | .addWithInfo(
93 | 'simple usage (JSX description)',
94 | (
95 |
This is a JSX info section
96 |
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
97 | Sed ornare massa rutrum metus commodo, a mattis velit dignissim.
98 | Fusce vestibulum turpis sed massa egestas pharetra. Sed at libero
99 | nulla.
100 |
101 |
103 | This is a link
104 |
105 |
106 |
107 |
108 |
),
109 | () => (
110 |
111 |
112 |
113 |
114 | Click the "?" mark at top-right to view the info.
115 |
116 |
117 | ),
118 | );
119 |
120 | storiesOf('Button')
121 | .addWithInfo(
122 | 'simple usage (inline JSX description)',
123 | (
124 |
This is a JSX info section
125 |
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
126 | Sed ornare massa rutrum metus commodo, a mattis velit dignissim.
127 | Fusce vestibulum turpis sed massa egestas pharetra. Sed at libero
128 | nulla.
129 |
130 |
132 | This is a link
133 |
134 |
135 |
136 |
137 |
),
138 | () => (),
139 | { inline: true }
140 | );
141 |
142 | storiesOf('Button')
143 | .addDecorator(backgrounds([
144 | { name: 'dark', value: '#333', default: true },
145 | ]))
146 | .addWithInfo(
147 | 'with custom styles',
148 | `
149 | This is an example of how to customize the styles of the info components.
150 |
151 | For the full styles available, see \`./src/components/Story.js\`
152 | `,
153 | () => (),
154 | {
155 | inline: true,
156 | styles: (stylesheet) => {
157 | stylesheet.infoPage = {
158 | backgroundColor: '#ccc'
159 | };
160 | return stylesheet;
161 | }
162 | }
163 | );
164 |
--------------------------------------------------------------------------------
/dist/components/Node.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | Object.defineProperty(exports, "__esModule", {
4 | value: true
5 | });
6 |
7 | var _assign = require('babel-runtime/core-js/object/assign');
8 |
9 | var _assign2 = _interopRequireDefault(_assign);
10 |
11 | var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
12 |
13 | var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
14 |
15 | var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
16 |
17 | var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
18 |
19 | var _createClass2 = require('babel-runtime/helpers/createClass');
20 |
21 | var _createClass3 = _interopRequireDefault(_createClass2);
22 |
23 | var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
24 |
25 | var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
26 |
27 | var _inherits2 = require('babel-runtime/helpers/inherits');
28 |
29 | var _inherits3 = _interopRequireDefault(_inherits2);
30 |
31 | var _react = require('react');
32 |
33 | var _react2 = _interopRequireDefault(_react);
34 |
35 | var _Props = require('./Props');
36 |
37 | var _Props2 = _interopRequireDefault(_Props);
38 |
39 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
40 |
41 | var stylesheet = {
42 | containerStyle: {},
43 | tagStyle: {
44 | color: '#777'
45 | }
46 | };
47 |
48 | var Node = function (_React$Component) {
49 | (0, _inherits3.default)(Node, _React$Component);
50 |
51 | function Node(props) {
52 | (0, _classCallCheck3.default)(this, Node);
53 | return (0, _possibleConstructorReturn3.default)(this, (Node.__proto__ || (0, _getPrototypeOf2.default)(Node)).call(this, props));
54 | }
55 |
56 | (0, _createClass3.default)(Node, [{
57 | key: 'render',
58 | value: function render() {
59 | var _props = this.props,
60 | node = _props.node,
61 | depth = _props.depth;
62 | var tagStyle = stylesheet.tagStyle,
63 | containerStyle = stylesheet.containerStyle;
64 |
65 |
66 | var leftPad = {
67 | paddingLeft: 3 + (depth + 1) * 15,
68 | paddingRight: 3
69 | };
70 |
71 | (0, _assign2.default)(containerStyle, leftPad);
72 |
73 | var _getData = getData(node),
74 | name = _getData.name,
75 | text = _getData.text,
76 | children = _getData.children;
77 |
78 | // Just text
79 |
80 |
81 | if (!name) {
82 | return _react2.default.createElement(
83 | 'div',
84 | { style: containerStyle },
85 | _react2.default.createElement(
86 | 'span',
87 | { style: tagStyle },
88 | text
89 | )
90 | );
91 | }
92 |
93 | // Single-line tag
94 | if (!children) {
95 | return _react2.default.createElement(
96 | 'div',
97 | { style: containerStyle },
98 | _react2.default.createElement(
99 | 'span',
100 | { style: tagStyle },
101 | '<',
102 | name
103 | ),
104 | _react2.default.createElement(_Props2.default, { node: node, singleLine: true }),
105 | _react2.default.createElement(
106 | 'span',
107 | { style: tagStyle },
108 | '/>'
109 | )
110 | );
111 | }
112 |
113 | // Keep a copy so that further mutations to containerStyle don't impact us:
114 | var containerStyleCopy = (0, _assign2.default)({}, containerStyle);
115 |
116 | // tag with children
117 | return _react2.default.createElement(
118 | 'div',
119 | null,
120 | _react2.default.createElement(
121 | 'div',
122 | { style: containerStyleCopy },
123 | _react2.default.createElement(
124 | 'span',
125 | { style: tagStyle },
126 | '<',
127 | name
128 | ),
129 | _react2.default.createElement(_Props2.default, { node: node }),
130 | _react2.default.createElement(
131 | 'span',
132 | { style: tagStyle },
133 | '>'
134 | )
135 | ),
136 | _react2.default.Children.map(children, function (childElement) {
137 | return _react2.default.createElement(Node, { node: childElement, depth: depth + 1 });
138 | }),
139 | _react2.default.createElement(
140 | 'div',
141 | { style: containerStyleCopy },
142 | _react2.default.createElement(
143 | 'span',
144 | { style: tagStyle },
145 | '',
146 | name,
147 | '>'
148 | )
149 | )
150 | );
151 | }
152 | }]);
153 | return Node;
154 | }(_react2.default.Component);
155 |
156 | exports.default = Node;
157 |
158 |
159 | function getData(element) {
160 | var data = {
161 | name: null,
162 | text: null,
163 | children: null
164 | };
165 |
166 | if (typeof element == 'string') {
167 | data.text = element;
168 | return data;
169 | }
170 |
171 | if (typeof element === 'number') {
172 | data.text = String.toString(element);
173 | return data;
174 | }
175 |
176 | data.children = element.props.children;
177 | var type = element.type;
178 |
179 | if (typeof type === 'string') {
180 | data.name = type;
181 | } else {
182 | data.name = type.displayName || type.name || 'Unknown';
183 | }
184 |
185 | return data;
186 | }
--------------------------------------------------------------------------------
/dist/components/PropVal.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | Object.defineProperty(exports, "__esModule", {
4 | value: true
5 | });
6 |
7 | var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
8 |
9 | var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
10 |
11 | var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
12 |
13 | var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
14 |
15 | var _createClass2 = require('babel-runtime/helpers/createClass');
16 |
17 | var _createClass3 = _interopRequireDefault(_createClass2);
18 |
19 | var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
20 |
21 | var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
22 |
23 | var _inherits2 = require('babel-runtime/helpers/inherits');
24 |
25 | var _inherits3 = _interopRequireDefault(_inherits2);
26 |
27 | var _typeof2 = require('babel-runtime/helpers/typeof');
28 |
29 | var _typeof3 = _interopRequireDefault(_typeof2);
30 |
31 | var _keys = require('babel-runtime/core-js/object/keys');
32 |
33 | var _keys2 = _interopRequireDefault(_keys);
34 |
35 | var _react = require('react');
36 |
37 | var _react2 = _interopRequireDefault(_react);
38 |
39 | var _reactAddonsCreateFragment = require('react-addons-create-fragment');
40 |
41 | var _reactAddonsCreateFragment2 = _interopRequireDefault(_reactAddonsCreateFragment);
42 |
43 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
44 |
45 | var valueStyles = {
46 | func: {
47 | color: '#170'
48 | },
49 |
50 | attr: {
51 | color: '#666'
52 | },
53 |
54 | object: {
55 | color: '#666'
56 | },
57 |
58 | array: {
59 | color: '#666'
60 | },
61 |
62 | number: {
63 | color: '#a11'
64 | },
65 |
66 | string: {
67 | color: '#22a',
68 | wordBreak: 'break-word'
69 | },
70 |
71 | bool: {
72 | color: '#a11'
73 | },
74 |
75 | empty: {
76 | color: '#777'
77 | }
78 | };
79 |
80 | function previewArray(val) {
81 | var items = {};
82 | val.slice(0, 3).forEach(function (item, i) {
83 | items['n' + i] = _react2.default.createElement(PropVal, { val: item });
84 | items['c' + i] = ', ';
85 | });
86 | if (val.length > 3) {
87 | items.last = '…';
88 | } else {
89 | delete items['c' + (val.length - 1)];
90 | }
91 | return _react2.default.createElement(
92 | 'span',
93 | { style: valueStyles.array },
94 | '[',
95 | (0, _reactAddonsCreateFragment2.default)(items),
96 | ']'
97 | );
98 | }
99 |
100 | function previewObject(val) {
101 | var names = (0, _keys2.default)(val);
102 | var items = {};
103 | names.slice(0, 3).forEach(function (name, i) {
104 | items['k' + i] = _react2.default.createElement(
105 | 'span',
106 | { style: valueStyles.attr },
107 | name
108 | );
109 | items['c' + i] = ': ';
110 | items['v' + i] = _react2.default.createElement(PropVal, { val: val[name] });
111 | items['m' + i] = ', ';
112 | });
113 | if (names.length > 3) {
114 | items.rest = '…';
115 | } else {
116 | delete items['m' + (names.length - 1)];
117 | }
118 | return _react2.default.createElement(
119 | 'span',
120 | { style: valueStyles.object },
121 | '{',
122 | (0, _reactAddonsCreateFragment2.default)(items),
123 | '}'
124 | );
125 | }
126 |
127 | function previewProp(val) {
128 | var braceWrap = true;
129 | var content = null;
130 | if (typeof val === 'number') {
131 | content = _react2.default.createElement(
132 | 'span',
133 | { style: valueStyles.number },
134 | val
135 | );
136 | } else if (typeof val === 'string') {
137 | if (val.length > 50) {
138 | val = val.slice(0, 50) + '…';
139 | }
140 | content = _react2.default.createElement(
141 | 'span',
142 | { style: valueStyles.string },
143 | '"',
144 | val,
145 | '"'
146 | );
147 | braceWrap = false;
148 | } else if (typeof val === 'boolean') {
149 | content = _react2.default.createElement(
150 | 'span',
151 | { style: valueStyles.bool },
152 | '' + val
153 | );
154 | } else if (Array.isArray(val)) {
155 | content = previewArray(val);
156 | } else if (typeof val === 'function') {
157 | content = _react2.default.createElement(
158 | 'span',
159 | { style: valueStyles.func },
160 | val.name ? val.name + '()' : 'anonymous()'
161 | );
162 | } else if (!val) {
163 | content = _react2.default.createElement(
164 | 'span',
165 | { style: valueStyles.empty },
166 | '' + val
167 | );
168 | } else if ((typeof val === 'undefined' ? 'undefined' : (0, _typeof3.default)(val)) !== 'object') {
169 | content = _react2.default.createElement(
170 | 'span',
171 | null,
172 | '\u2026'
173 | );
174 | } else if (_react2.default.isValidElement(val)) {
175 | content = _react2.default.createElement(
176 | 'span',
177 | { style: valueStyles.object },
178 | '<' + (val.type.displayName || val.type.name || val.type) + ' />'
179 | );
180 | } else {
181 | content = previewObject(val);
182 | }
183 |
184 | if (!braceWrap) return content;
185 | return _react2.default.createElement(
186 | 'span',
187 | null,
188 | '{',
189 | content,
190 | '}'
191 | );
192 | }
193 |
194 | var PropVal = function (_React$Component) {
195 | (0, _inherits3.default)(PropVal, _React$Component);
196 |
197 | function PropVal() {
198 | (0, _classCallCheck3.default)(this, PropVal);
199 | return (0, _possibleConstructorReturn3.default)(this, (PropVal.__proto__ || (0, _getPrototypeOf2.default)(PropVal)).apply(this, arguments));
200 | }
201 |
202 | (0, _createClass3.default)(PropVal, [{
203 | key: 'render',
204 | value: function render() {
205 | return previewProp(this.props.val);
206 | }
207 | }]);
208 | return PropVal;
209 | }(_react2.default.Component);
210 |
211 | exports.default = PropVal;
212 |
213 |
214 | module.exports = PropVal;
--------------------------------------------------------------------------------
/dist/components/PropTable.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | Object.defineProperty(exports, "__esModule", {
4 | value: true
5 | });
6 |
7 | var _values = require('babel-runtime/core-js/object/values');
8 |
9 | var _values2 = _interopRequireDefault(_values);
10 |
11 | var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
12 |
13 | var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
14 |
15 | var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
16 |
17 | var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
18 |
19 | var _createClass2 = require('babel-runtime/helpers/createClass');
20 |
21 | var _createClass3 = _interopRequireDefault(_createClass2);
22 |
23 | var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
24 |
25 | var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
26 |
27 | var _inherits2 = require('babel-runtime/helpers/inherits');
28 |
29 | var _inherits3 = _interopRequireDefault(_inherits2);
30 |
31 | var _map = require('babel-runtime/core-js/map');
32 |
33 | var _map2 = _interopRequireDefault(_map);
34 |
35 | var _react = require('react');
36 |
37 | var _react2 = _interopRequireDefault(_react);
38 |
39 | var _PropVal = require('./PropVal');
40 |
41 | var _PropVal2 = _interopRequireDefault(_PropVal);
42 |
43 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
44 |
45 | var PropTypesMap = new _map2.default();
46 | for (var typeName in _react2.default.PropTypes) {
47 | if (!_react2.default.PropTypes.hasOwnProperty(typeName)) {
48 | continue;
49 | }
50 | var type = _react2.default.PropTypes[typeName];
51 | PropTypesMap.set(type, typeName);
52 | PropTypesMap.set(type.isRequired, typeName);
53 | }
54 |
55 | var stylesheet = {
56 | propTable: {
57 | marginLeft: -10,
58 | borderSpacing: '10px 5px',
59 | borderCollapse: 'separate'
60 | }
61 | };
62 |
63 | var PropTable = function (_React$Component) {
64 | (0, _inherits3.default)(PropTable, _React$Component);
65 |
66 | function PropTable() {
67 | (0, _classCallCheck3.default)(this, PropTable);
68 | return (0, _possibleConstructorReturn3.default)(this, (PropTable.__proto__ || (0, _getPrototypeOf2.default)(PropTable)).apply(this, arguments));
69 | }
70 |
71 | (0, _createClass3.default)(PropTable, [{
72 | key: 'render',
73 | value: function render() {
74 | var type = this.props.type;
75 |
76 | if (!type) {
77 | return null;
78 | }
79 |
80 | var props = {};
81 |
82 | if (type.propTypes) {
83 | for (var property in type.propTypes) {
84 | if (!type.propTypes.hasOwnProperty(property)) {
85 | continue;
86 | }
87 | var typeInfo = type.propTypes[property];
88 | var propType = PropTypesMap.get(typeInfo) || 'other';
89 | var required = typeInfo.isRequired === undefined ? 'yes' : 'no';
90 | props[property] = { property: property, propType: propType, required: required };
91 | }
92 | }
93 |
94 | if (type.defaultProps) {
95 | for (var _property in type.defaultProps) {
96 | if (!type.defaultProps.hasOwnProperty(_property)) {
97 | continue;
98 | }
99 | var value = type.defaultProps[_property];
100 | if (value === undefined) {
101 | continue;
102 | }
103 | if (!props[_property]) {
104 | props[_property] = { property: _property };
105 | }
106 | props[_property].defaultValue = value;
107 | }
108 | }
109 |
110 | var array = (0, _values2.default)(props);
111 | if (!array.length) {
112 | return _react2.default.createElement(
113 | 'small',
114 | null,
115 | 'No propTypes defined!'
116 | );
117 | }
118 | array.sort(function (a, b) {
119 | return a.property > b.property;
120 | });
121 |
122 | return _react2.default.createElement(
123 | 'table',
124 | { style: stylesheet.propTable },
125 | _react2.default.createElement(
126 | 'thead',
127 | null,
128 | _react2.default.createElement(
129 | 'tr',
130 | null,
131 | _react2.default.createElement(
132 | 'th',
133 | null,
134 | 'property'
135 | ),
136 | _react2.default.createElement(
137 | 'th',
138 | null,
139 | 'propType'
140 | ),
141 | _react2.default.createElement(
142 | 'th',
143 | null,
144 | 'required'
145 | ),
146 | _react2.default.createElement(
147 | 'th',
148 | null,
149 | 'default'
150 | )
151 | )
152 | ),
153 | _react2.default.createElement(
154 | 'tbody',
155 | null,
156 | array.map(function (row) {
157 | return _react2.default.createElement(
158 | 'tr',
159 | { key: row.property },
160 | _react2.default.createElement(
161 | 'td',
162 | null,
163 | row.property
164 | ),
165 | _react2.default.createElement(
166 | 'td',
167 | null,
168 | row.propType
169 | ),
170 | _react2.default.createElement(
171 | 'td',
172 | null,
173 | row.required
174 | ),
175 | _react2.default.createElement(
176 | 'td',
177 | null,
178 | row.defaultValue === undefined ? '-' : _react2.default.createElement(_PropVal2.default, { val: row.defaultValue })
179 | )
180 | );
181 | })
182 | )
183 | );
184 | }
185 | }]);
186 | return PropTable;
187 | }(_react2.default.Component);
188 |
189 | exports.default = PropTable;
190 |
191 |
192 | PropTable.displayName = 'PropTable';
193 | PropTable.propTypes = {
194 | type: _react2.default.PropTypes.func
195 | };
--------------------------------------------------------------------------------
/dist/components/markdown/htags.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | Object.defineProperty(exports, "__esModule", {
4 | value: true
5 | });
6 | exports.H6 = exports.H5 = exports.H4 = exports.H3 = exports.H2 = exports.H1 = undefined;
7 |
8 | var _extends2 = require('babel-runtime/helpers/extends');
9 |
10 | var _extends3 = _interopRequireDefault(_extends2);
11 |
12 | var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
13 |
14 | var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
15 |
16 | var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
17 |
18 | var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
19 |
20 | var _createClass2 = require('babel-runtime/helpers/createClass');
21 |
22 | var _createClass3 = _interopRequireDefault(_createClass2);
23 |
24 | var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
25 |
26 | var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
27 |
28 | var _inherits2 = require('babel-runtime/helpers/inherits');
29 |
30 | var _inherits3 = _interopRequireDefault(_inherits2);
31 |
32 | var _react = require('react');
33 |
34 | var _react2 = _interopRequireDefault(_react);
35 |
36 | var _theme = require('../theme');
37 |
38 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
39 |
40 | var H1 = exports.H1 = function (_React$Component) {
41 | (0, _inherits3.default)(H1, _React$Component);
42 |
43 | function H1() {
44 | (0, _classCallCheck3.default)(this, H1);
45 | return (0, _possibleConstructorReturn3.default)(this, (H1.__proto__ || (0, _getPrototypeOf2.default)(H1)).apply(this, arguments));
46 | }
47 |
48 | (0, _createClass3.default)(H1, [{
49 | key: 'render',
50 | value: function render() {
51 | var styles = (0, _extends3.default)({}, _theme.baseFonts, {
52 | borderBottom: '1px solid #eee',
53 | fontWeight: 600,
54 | margin: 0,
55 | padding: 0,
56 | fontSize: '40px'
57 | });
58 |
59 | return _react2.default.createElement(
60 | 'h1',
61 | { id: this.props.id, style: styles },
62 | this.props.children
63 | );
64 | }
65 | }]);
66 | return H1;
67 | }(_react2.default.Component);
68 |
69 | var H2 = exports.H2 = function (_React$Component2) {
70 | (0, _inherits3.default)(H2, _React$Component2);
71 |
72 | function H2() {
73 | (0, _classCallCheck3.default)(this, H2);
74 | return (0, _possibleConstructorReturn3.default)(this, (H2.__proto__ || (0, _getPrototypeOf2.default)(H2)).apply(this, arguments));
75 | }
76 |
77 | (0, _createClass3.default)(H2, [{
78 | key: 'render',
79 | value: function render() {
80 | var styles = (0, _extends3.default)({}, _theme.baseFonts, {
81 | fontWeight: 600,
82 | margin: 0,
83 | padding: 0,
84 | fontSize: '30px'
85 | });
86 |
87 | return _react2.default.createElement(
88 | 'h2',
89 | { id: this.props.id, style: styles },
90 | this.props.children
91 | );
92 | }
93 | }]);
94 | return H2;
95 | }(_react2.default.Component);
96 |
97 | var H3 = exports.H3 = function (_React$Component3) {
98 | (0, _inherits3.default)(H3, _React$Component3);
99 |
100 | function H3() {
101 | (0, _classCallCheck3.default)(this, H3);
102 | return (0, _possibleConstructorReturn3.default)(this, (H3.__proto__ || (0, _getPrototypeOf2.default)(H3)).apply(this, arguments));
103 | }
104 |
105 | (0, _createClass3.default)(H3, [{
106 | key: 'render',
107 | value: function render() {
108 | var styles = (0, _extends3.default)({}, _theme.baseFonts, {
109 | fontWeight: 600,
110 | margin: 0,
111 | padding: 0,
112 | fontSize: '22px',
113 | textTransform: 'uppercase'
114 | });
115 |
116 | return _react2.default.createElement(
117 | 'h3',
118 | { id: this.props.id, style: styles },
119 | this.props.children
120 | );
121 | }
122 | }]);
123 | return H3;
124 | }(_react2.default.Component);
125 |
126 | var H4 = exports.H4 = function (_React$Component4) {
127 | (0, _inherits3.default)(H4, _React$Component4);
128 |
129 | function H4() {
130 | (0, _classCallCheck3.default)(this, H4);
131 | return (0, _possibleConstructorReturn3.default)(this, (H4.__proto__ || (0, _getPrototypeOf2.default)(H4)).apply(this, arguments));
132 | }
133 |
134 | (0, _createClass3.default)(H4, [{
135 | key: 'render',
136 | value: function render() {
137 | var styles = (0, _extends3.default)({}, _theme.baseFonts, {
138 | fontWeight: 600,
139 | margin: 0,
140 | padding: 0,
141 | fontSize: '20px'
142 | });
143 |
144 | return _react2.default.createElement(
145 | 'h4',
146 | { id: this.props.id, style: styles },
147 | this.props.children
148 | );
149 | }
150 | }]);
151 | return H4;
152 | }(_react2.default.Component);
153 |
154 | var H5 = exports.H5 = function (_React$Component5) {
155 | (0, _inherits3.default)(H5, _React$Component5);
156 |
157 | function H5() {
158 | (0, _classCallCheck3.default)(this, H5);
159 | return (0, _possibleConstructorReturn3.default)(this, (H5.__proto__ || (0, _getPrototypeOf2.default)(H5)).apply(this, arguments));
160 | }
161 |
162 | (0, _createClass3.default)(H5, [{
163 | key: 'render',
164 | value: function render() {
165 | var styles = (0, _extends3.default)({}, _theme.baseFonts, {
166 | fontWeight: 600,
167 | margin: 0,
168 | padding: 0,
169 | fontSize: '18px'
170 | });
171 |
172 | return _react2.default.createElement(
173 | 'h5',
174 | { id: this.props.id, style: styles },
175 | this.props.children
176 | );
177 | }
178 | }]);
179 | return H5;
180 | }(_react2.default.Component);
181 |
182 | var H6 = exports.H6 = function (_React$Component6) {
183 | (0, _inherits3.default)(H6, _React$Component6);
184 |
185 | function H6() {
186 | (0, _classCallCheck3.default)(this, H6);
187 | return (0, _possibleConstructorReturn3.default)(this, (H6.__proto__ || (0, _getPrototypeOf2.default)(H6)).apply(this, arguments));
188 | }
189 |
190 | (0, _createClass3.default)(H6, [{
191 | key: 'render',
192 | value: function render() {
193 | var styles = (0, _extends3.default)({}, _theme.baseFonts, {
194 | fontWeight: 400,
195 | margin: 0,
196 | padding: 0,
197 | fontSize: '18px'
198 | });
199 |
200 | return _react2.default.createElement(
201 | 'h6',
202 | { id: this.props.id, style: styles },
203 | this.props.children
204 | );
205 | }
206 | }]);
207 | return H6;
208 | }(_react2.default.Component);
--------------------------------------------------------------------------------
/src/components/Story.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import MTRC from 'markdown-to-react-components';
3 | import PropTable from './PropTable';
4 | import Node from './Node';
5 | import { baseFonts } from './theme';
6 | import { Pre } from './markdown';
7 |
8 | const stylesheet = {
9 | link: {
10 | base: {
11 | fontFamily: 'sans-serif',
12 | fontSize: '12px',
13 | display: 'block',
14 | position: 'fixed',
15 | textDecoration: 'none',
16 | background: '#28c',
17 | color: '#fff',
18 | padding: '5px 15px',
19 | cursor: 'pointer',
20 | },
21 | topRight: {
22 | top: 0,
23 | right: 0,
24 | borderRadius: '0 0 0 5px',
25 | },
26 | },
27 | info: {
28 | position: 'absolute',
29 | background: 'white',
30 | top: 0,
31 | bottom: 0,
32 | left: 0,
33 | right: 0,
34 | padding: '0 40px',
35 | overflow: 'auto',
36 | },
37 | children: {
38 | position: 'relative',
39 | zIndex: 0,
40 | },
41 | infoBody: {
42 | ...baseFonts,
43 | fontWeight: 300,
44 | lineHeight: 1.45,
45 | fontSize: '15px',
46 | },
47 | infoContent: {
48 | marginBottom: 0,
49 | },
50 | jsxInfoContent: {
51 | borderTop: '1px solid #eee',
52 | margin: '20px 0 0 0',
53 | },
54 | header: {
55 | h1: {
56 | margin: 0,
57 | padding: 0,
58 | fontSize: '35px',
59 | },
60 | h2: {
61 | margin: '0 0 10px 0',
62 | padding: 0,
63 | fontWeight: 400,
64 | fontSize: '22px',
65 | },
66 | body: {
67 | borderBottom: '1px solid #eee',
68 | paddingTop: 10,
69 | marginBottom: 10,
70 | },
71 | },
72 | source: {
73 | h1: {
74 | margin: '20px 0 0 0',
75 | padding: '0 0 5px 0',
76 | fontSize: '25px',
77 | borderBottom: '1px solid #EEE',
78 | },
79 | },
80 | propTableHead: {
81 | margin: '20px 0 0 0',
82 | },
83 | };
84 |
85 | export default class Story extends React.Component {
86 | constructor(...args) {
87 | super(...args);
88 | this.state = {
89 | open: false,
90 | stylesheet: this.props.styles(JSON.parse(JSON.stringify(stylesheet)))
91 | };
92 | MTRC.configure(this.props.mtrcConf);
93 | }
94 |
95 | componentWillReceiveProps(nextProps) {
96 | this.setState({
97 | stylesheet: nextProps.styles(JSON.parse(JSON.stringify(stylesheet)))
98 | });
99 | }
100 |
101 | _renderStory() {
102 | return (
103 |
104 | { this.props.children }
105 |
106 | );
107 | }
108 |
109 | _renderInline() {
110 | return (
111 |
112 |
113 |
114 | { this._getInfoHeader() }
115 |
116 |
117 |
118 | { this._renderStory() }
119 |
120 |
121 |
122 | { this._getInfoContent() }
123 | { this._getSourceCode() }
124 | { this._getPropTables() }
125 |
126 |
127 |
128 | );
129 | }
130 |
131 | _renderOverlay() {
132 | const linkStyle = {
133 | ...stylesheet.link.base,
134 | ...stylesheet.link.topRight,
135 | };
136 |
137 | const infoStyle = Object.assign({}, stylesheet.info);
138 | if (!this.state.open) {
139 | infoStyle.display = 'none';
140 | }
141 |
142 | const openOverlay = () => {
143 | this.setState({ open: true });
144 | return false;
145 | };
146 |
147 | const closeOverlay = () => {
148 | this.setState({ open: false });
149 | return false;
150 | };
151 |
152 | return (
153 |
154 |
155 | { this.props.children }
156 |
157 |
Show Info
158 |
159 |
×
160 |
161 |
162 | { this._getInfoHeader() }
163 | { this._getInfoContent() }
164 | { this._getSourceCode() }
165 | { this._getPropTables() }
166 |
167 |
168 |
169 |
170 | );
171 | }
172 |
173 | _getInfoHeader() {
174 | if (!this.props.context || !this.props.showHeader) {
175 | return null;
176 | }
177 |
178 | return (
179 |
180 |
{this.props.context.kind}
181 | {this.props.context.story}
182 |
183 | );
184 | }
185 |
186 | _getInfoContent() {
187 | if (!this.props.info) {
188 | return '';
189 | }
190 |
191 | if (React.isValidElement(this.props.info)) {
192 | return (
193 |
197 | {this.props.info}
198 |
199 | );
200 | }
201 |
202 | const lines = this.props.info.split('\n');
203 | while (lines[0].trim() === '') {
204 | lines.shift();
205 | }
206 | let padding = 0;
207 | const matches = lines[0].match(/^ */);
208 | if (matches) {
209 | padding = matches[0].length;
210 | }
211 | const source = lines.map(s => s.slice(padding)).join('\n');
212 | return (
213 |
214 | {MTRC(source).tree}
215 |
216 | );
217 | }
218 |
219 | _getSourceCode() {
220 | if (!this.props.showSource) {
221 | return null;
222 | }
223 |
224 | return (
225 |
226 |
Story Source
227 |
228 | {React.Children.map(this.props.children, (root, idx) => (
229 |
230 | ))}
231 |
232 |
233 | );
234 | }
235 |
236 | _getPropTables() {
237 | const types = new Map();
238 |
239 | if (this.props.propTables === null) {
240 | return null;
241 | }
242 |
243 | if (!this.props.children) {
244 | return null;
245 | }
246 |
247 | if (this.props.propTables) {
248 | this.props.propTables.forEach(function (type) {
249 | types.set(type, true);
250 | });
251 | }
252 |
253 | // depth-first traverse and collect types
254 | function extract(children) {
255 | if (!children) {
256 | return;
257 | }
258 | if (Array.isArray(children)) {
259 | children.forEach(extract);
260 | return;
261 | }
262 | if (children.props && children.props.children) {
263 | extract(children.props.children);
264 | }
265 | if (typeof children === 'string' || typeof children.type === 'string') {
266 | return;
267 | }
268 | if (children.type && !types.has(children.type)) {
269 | types.set(children.type, true);
270 | }
271 | }
272 |
273 | // extract components from children
274 | extract(this.props.children);
275 |
276 | const array = Array.from(types.keys());
277 | array.sort(function (a, b) {
278 | return (a.displayName || a.name) > (b.displayName || b.name);
279 | });
280 |
281 | const propTables = array.map((type, idx) => {
282 | return (
283 |
284 |
"{type.displayName || type.name}" Component
285 |
286 |
287 | );
288 | });
289 |
290 | if (!propTables || propTables.length === 0) {
291 | return null;
292 | }
293 |
294 | return (
295 |
296 |
Prop Types
297 | {propTables}
298 |
299 | );
300 |
301 | return;
302 | }
303 |
304 | render() {
305 | if (this.props.showInline) {
306 | return this._renderInline();
307 | }
308 |
309 | return this._renderOverlay();
310 | }
311 | }
312 |
313 | Story.displayName = 'Story';
314 | Story.propTypes = {
315 | context: React.PropTypes.object,
316 | info: React.PropTypes.oneOfType([
317 | React.PropTypes.string,
318 | React.PropTypes.node,
319 | ]),
320 | propTables: React.PropTypes.arrayOf(React.PropTypes.func),
321 | showInline: React.PropTypes.bool,
322 | showHeader: React.PropTypes.bool,
323 | showSource: React.PropTypes.bool,
324 | styles: React.PropTypes.func.isRequired,
325 | children: React.PropTypes.oneOfType([
326 | React.PropTypes.object,
327 | React.PropTypes.array,
328 | ]),
329 | mtrcConf: React.PropTypes.object
330 | };
331 |
332 | Story.defaultProps = {
333 | showInline: false,
334 | showHeader: true,
335 | showSource: true,
336 | mtrcConf: {}
337 | };
338 |
--------------------------------------------------------------------------------
/dist/components/Story.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | Object.defineProperty(exports, "__esModule", {
4 | value: true
5 | });
6 |
7 | var _from = require('babel-runtime/core-js/array/from');
8 |
9 | var _from2 = _interopRequireDefault(_from);
10 |
11 | var _map = require('babel-runtime/core-js/map');
12 |
13 | var _map2 = _interopRequireDefault(_map);
14 |
15 | var _assign = require('babel-runtime/core-js/object/assign');
16 |
17 | var _assign2 = _interopRequireDefault(_assign);
18 |
19 | var _stringify = require('babel-runtime/core-js/json/stringify');
20 |
21 | var _stringify2 = _interopRequireDefault(_stringify);
22 |
23 | var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
24 |
25 | var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
26 |
27 | var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
28 |
29 | var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
30 |
31 | var _createClass2 = require('babel-runtime/helpers/createClass');
32 |
33 | var _createClass3 = _interopRequireDefault(_createClass2);
34 |
35 | var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
36 |
37 | var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
38 |
39 | var _inherits2 = require('babel-runtime/helpers/inherits');
40 |
41 | var _inherits3 = _interopRequireDefault(_inherits2);
42 |
43 | var _extends2 = require('babel-runtime/helpers/extends');
44 |
45 | var _extends3 = _interopRequireDefault(_extends2);
46 |
47 | var _react = require('react');
48 |
49 | var _react2 = _interopRequireDefault(_react);
50 |
51 | var _markdownToReactComponents = require('markdown-to-react-components');
52 |
53 | var _markdownToReactComponents2 = _interopRequireDefault(_markdownToReactComponents);
54 |
55 | var _PropTable = require('./PropTable');
56 |
57 | var _PropTable2 = _interopRequireDefault(_PropTable);
58 |
59 | var _Node = require('./Node');
60 |
61 | var _Node2 = _interopRequireDefault(_Node);
62 |
63 | var _theme = require('./theme');
64 |
65 | var _markdown = require('./markdown');
66 |
67 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
68 |
69 | var stylesheet = {
70 | link: {
71 | base: {
72 | fontFamily: 'sans-serif',
73 | fontSize: '12px',
74 | display: 'block',
75 | position: 'fixed',
76 | textDecoration: 'none',
77 | background: '#28c',
78 | color: '#fff',
79 | padding: '5px 15px',
80 | cursor: 'pointer'
81 | },
82 | topRight: {
83 | top: 0,
84 | right: 0,
85 | borderRadius: '0 0 0 5px'
86 | }
87 | },
88 | info: {
89 | position: 'absolute',
90 | background: 'white',
91 | top: 0,
92 | bottom: 0,
93 | left: 0,
94 | right: 0,
95 | padding: '0 40px',
96 | overflow: 'auto'
97 | },
98 | children: {
99 | position: 'relative',
100 | zIndex: 0
101 | },
102 | infoBody: (0, _extends3.default)({}, _theme.baseFonts, {
103 | fontWeight: 300,
104 | lineHeight: 1.45,
105 | fontSize: '15px'
106 | }),
107 | infoContent: {
108 | marginBottom: 0
109 | },
110 | jsxInfoContent: {
111 | borderTop: '1px solid #eee',
112 | margin: '20px 0 0 0'
113 | },
114 | header: {
115 | h1: {
116 | margin: 0,
117 | padding: 0,
118 | fontSize: '35px'
119 | },
120 | h2: {
121 | margin: '0 0 10px 0',
122 | padding: 0,
123 | fontWeight: 400,
124 | fontSize: '22px'
125 | },
126 | body: {
127 | borderBottom: '1px solid #eee',
128 | paddingTop: 10,
129 | marginBottom: 10
130 | }
131 | },
132 | source: {
133 | h1: {
134 | margin: '20px 0 0 0',
135 | padding: '0 0 5px 0',
136 | fontSize: '25px',
137 | borderBottom: '1px solid #EEE'
138 | }
139 | },
140 | propTableHead: {
141 | margin: '20px 0 0 0'
142 | }
143 | };
144 |
145 | var Story = function (_React$Component) {
146 | (0, _inherits3.default)(Story, _React$Component);
147 |
148 | function Story() {
149 | var _ref;
150 |
151 | (0, _classCallCheck3.default)(this, Story);
152 |
153 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
154 | args[_key] = arguments[_key];
155 | }
156 |
157 | var _this = (0, _possibleConstructorReturn3.default)(this, (_ref = Story.__proto__ || (0, _getPrototypeOf2.default)(Story)).call.apply(_ref, [this].concat(args)));
158 |
159 | _this.state = {
160 | open: false,
161 | stylesheet: _this.props.styles(JSON.parse((0, _stringify2.default)(stylesheet)))
162 | };
163 | _markdownToReactComponents2.default.configure(_this.props.mtrcConf);
164 | return _this;
165 | }
166 |
167 | (0, _createClass3.default)(Story, [{
168 | key: 'componentWillReceiveProps',
169 | value: function componentWillReceiveProps(nextProps) {
170 | this.setState({
171 | stylesheet: nextProps.styles(JSON.parse((0, _stringify2.default)(stylesheet)))
172 | });
173 | }
174 | }, {
175 | key: '_renderStory',
176 | value: function _renderStory() {
177 | return _react2.default.createElement(
178 | 'div',
179 | null,
180 | this.props.children
181 | );
182 | }
183 | }, {
184 | key: '_renderInline',
185 | value: function _renderInline() {
186 | return _react2.default.createElement(
187 | 'div',
188 | null,
189 | _react2.default.createElement(
190 | 'div',
191 | { style: this.state.stylesheet.infoPage },
192 | _react2.default.createElement(
193 | 'div',
194 | { style: this.state.stylesheet.infoBody },
195 | this._getInfoHeader()
196 | )
197 | ),
198 | _react2.default.createElement(
199 | 'div',
200 | null,
201 | this._renderStory()
202 | ),
203 | _react2.default.createElement(
204 | 'div',
205 | { style: this.state.stylesheet.infoPage },
206 | _react2.default.createElement(
207 | 'div',
208 | { style: this.state.stylesheet.infoBody },
209 | this._getInfoContent(),
210 | this._getSourceCode(),
211 | this._getPropTables()
212 | )
213 | )
214 | );
215 | }
216 | }, {
217 | key: '_renderOverlay',
218 | value: function _renderOverlay() {
219 | var _this2 = this;
220 |
221 | var linkStyle = (0, _extends3.default)({}, stylesheet.link.base, stylesheet.link.topRight);
222 |
223 | var infoStyle = (0, _assign2.default)({}, stylesheet.info);
224 | if (!this.state.open) {
225 | infoStyle.display = 'none';
226 | }
227 |
228 | var openOverlay = function openOverlay() {
229 | _this2.setState({ open: true });
230 | return false;
231 | };
232 |
233 | var closeOverlay = function closeOverlay() {
234 | _this2.setState({ open: false });
235 | return false;
236 | };
237 |
238 | return _react2.default.createElement(
239 | 'div',
240 | null,
241 | _react2.default.createElement(
242 | 'div',
243 | { style: this.state.stylesheet.children },
244 | this.props.children
245 | ),
246 | _react2.default.createElement(
247 | 'a',
248 | { style: linkStyle, onClick: openOverlay },
249 | 'Show Info'
250 | ),
251 | _react2.default.createElement(
252 | 'div',
253 | { style: infoStyle },
254 | _react2.default.createElement(
255 | 'a',
256 | { style: linkStyle, onClick: closeOverlay },
257 | '\xD7'
258 | ),
259 | _react2.default.createElement(
260 | 'div',
261 | { style: this.state.stylesheet.infoPage },
262 | _react2.default.createElement(
263 | 'div',
264 | { style: this.state.stylesheet.infoBody },
265 | this._getInfoHeader(),
266 | this._getInfoContent(),
267 | this._getSourceCode(),
268 | this._getPropTables()
269 | )
270 | )
271 | )
272 | );
273 | }
274 | }, {
275 | key: '_getInfoHeader',
276 | value: function _getInfoHeader() {
277 | if (!this.props.context || !this.props.showHeader) {
278 | return null;
279 | }
280 |
281 | return _react2.default.createElement(
282 | 'div',
283 | { style: this.state.stylesheet.header.body },
284 | _react2.default.createElement(
285 | 'h1',
286 | { style: this.state.stylesheet.header.h1 },
287 | this.props.context.kind
288 | ),
289 | _react2.default.createElement(
290 | 'h2',
291 | { style: this.state.stylesheet.header.h2 },
292 | this.props.context.story
293 | )
294 | );
295 | }
296 | }, {
297 | key: '_getInfoContent',
298 | value: function _getInfoContent() {
299 | if (!this.props.info) {
300 | return '';
301 | }
302 |
303 | if (_react2.default.isValidElement(this.props.info)) {
304 | return _react2.default.createElement(
305 | 'div',
306 | {
307 | style: this.props.showInline ? stylesheet.jsxInfoContent : stylesheet.infoContent
308 | },
309 | this.props.info
310 | );
311 | }
312 |
313 | var lines = this.props.info.split('\n');
314 | while (lines[0].trim() === '') {
315 | lines.shift();
316 | }
317 | var padding = 0;
318 | var matches = lines[0].match(/^ */);
319 | if (matches) {
320 | padding = matches[0].length;
321 | }
322 | var source = lines.map(function (s) {
323 | return s.slice(padding);
324 | }).join('\n');
325 | return _react2.default.createElement(
326 | 'div',
327 | { style: this.state.stylesheet.infoContent },
328 | (0, _markdownToReactComponents2.default)(source).tree
329 | );
330 | }
331 | }, {
332 | key: '_getSourceCode',
333 | value: function _getSourceCode() {
334 | if (!this.props.showSource) {
335 | return null;
336 | }
337 |
338 | return _react2.default.createElement(
339 | 'div',
340 | null,
341 | _react2.default.createElement(
342 | 'h1',
343 | { style: this.state.stylesheet.source.h1 },
344 | 'Story Source'
345 | ),
346 | _react2.default.createElement(
347 | _markdown.Pre,
348 | null,
349 | _react2.default.Children.map(this.props.children, function (root, idx) {
350 | return _react2.default.createElement(_Node2.default, { key: idx, depth: 0, node: root });
351 | })
352 | )
353 | );
354 | }
355 | }, {
356 | key: '_getPropTables',
357 | value: function _getPropTables() {
358 | var _this3 = this;
359 |
360 | var types = new _map2.default();
361 |
362 | if (this.props.propTables === null) {
363 | return null;
364 | }
365 |
366 | if (!this.props.children) {
367 | return null;
368 | }
369 |
370 | if (this.props.propTables) {
371 | this.props.propTables.forEach(function (type) {
372 | types.set(type, true);
373 | });
374 | }
375 |
376 | // depth-first traverse and collect types
377 | function extract(children) {
378 | if (!children) {
379 | return;
380 | }
381 | if (Array.isArray(children)) {
382 | children.forEach(extract);
383 | return;
384 | }
385 | if (children.props && children.props.children) {
386 | extract(children.props.children);
387 | }
388 | if (typeof children === 'string' || typeof children.type === 'string') {
389 | return;
390 | }
391 | if (children.type && !types.has(children.type)) {
392 | types.set(children.type, true);
393 | }
394 | }
395 |
396 | // extract components from children
397 | extract(this.props.children);
398 |
399 | var array = (0, _from2.default)(types.keys());
400 | array.sort(function (a, b) {
401 | return (a.displayName || a.name) > (b.displayName || b.name);
402 | });
403 |
404 | var propTables = array.map(function (type, idx) {
405 | return _react2.default.createElement(
406 | 'div',
407 | { key: idx },
408 | _react2.default.createElement(
409 | 'h2',
410 | { style: _this3.state.stylesheet.propTableHead },
411 | '"',
412 | type.displayName || type.name,
413 | '" Component'
414 | ),
415 | _react2.default.createElement(_PropTable2.default, { type: type })
416 | );
417 | });
418 |
419 | if (!propTables || propTables.length === 0) {
420 | return null;
421 | }
422 |
423 | return _react2.default.createElement(
424 | 'div',
425 | null,
426 | _react2.default.createElement(
427 | 'h1',
428 | { style: this.state.stylesheet.source.h1 },
429 | 'Prop Types'
430 | ),
431 | propTables
432 | );
433 |
434 | return;
435 | }
436 | }, {
437 | key: 'render',
438 | value: function render() {
439 | if (this.props.showInline) {
440 | return this._renderInline();
441 | }
442 |
443 | return this._renderOverlay();
444 | }
445 | }]);
446 | return Story;
447 | }(_react2.default.Component);
448 |
449 | exports.default = Story;
450 |
451 |
452 | Story.displayName = 'Story';
453 | Story.propTypes = {
454 | context: _react2.default.PropTypes.object,
455 | info: _react2.default.PropTypes.oneOfType([_react2.default.PropTypes.string, _react2.default.PropTypes.node]),
456 | propTables: _react2.default.PropTypes.arrayOf(_react2.default.PropTypes.func),
457 | showInline: _react2.default.PropTypes.bool,
458 | showHeader: _react2.default.PropTypes.bool,
459 | showSource: _react2.default.PropTypes.bool,
460 | styles: _react2.default.PropTypes.func.isRequired,
461 | children: _react2.default.PropTypes.oneOfType([_react2.default.PropTypes.object, _react2.default.PropTypes.array]),
462 | mtrcConf: _react2.default.PropTypes.object
463 | };
464 |
465 | Story.defaultProps = {
466 | showInline: false,
467 | showHeader: true,
468 | showSource: true,
469 | mtrcConf: {}
470 | };
--------------------------------------------------------------------------------