Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

MTRC configuration #54

Merged
merged 8 commits into from
Aug 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 4 additions & 16 deletions src/components/Story.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,8 @@ import React from 'react';
import MTRC from 'markdown-to-react-components';
import PropTable from './PropTable';
import Node from './Node';
import { H1, H2, H3, H4, H5, H6, Code, Pre, P, UL, A, LI } from './markdown';
import { baseFonts } from './theme';

MTRC.configure({
h1: H1,
h2: H2,
h3: H3,
h4: H4,
h5: H5,
h6: H6,
code: Code,
// pre: Pre,
p: P,
a: A,
li: LI,
ul: UL,
});
import { Pre } from './markdown';

const stylesheet = {
link: {
Expand Down Expand Up @@ -96,6 +81,7 @@ export default class Story extends React.Component {
constructor(...args) {
super(...args);
this.state = { open: false };
MTRC.configure(this.props.mtrcConf);
}

_renderStory() {
Expand Down Expand Up @@ -309,10 +295,12 @@ Story.propTypes = {
React.PropTypes.object,
React.PropTypes.array,
]),
mtrcConf: React.PropTypes.object
};

Story.defaultProps = {
showInline: false,
showHeader: true,
showSource: true,
mtrcConf: {}
};
26 changes: 24 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import _Story from './components/Story';
import { H1, H2, H3, H4, H5, H6, Code, P, UL, A, LI } from './components/markdown';
export const Story = _Story;

const defaultOptions = {
Expand All @@ -8,8 +9,23 @@ const defaultOptions = {
source: true,
};

const defaultMtrcConf = {
h1: H1,
h2: H2,
h3: H3,
h4: H4,
h5: H5,
h6: H6,
code: Code,
p: P,
a: A,
li: LI,
ul: UL,
};

export default {
addWithInfo(storyName, info, storyFn, _options) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you did not mean to remove these following lines :) Removing them might break some stuff.

Copy link
Author

Choose a reason for hiding this comment

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

No. In my first attempt to solve problem I try to put mtrcConf in options object but it was inconvinient so i decided to move configuration to separete prop. Before commit I checked these lines and there are still there :)

Copy link
Contributor

Choose a reason for hiding this comment

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

So here you can see the actual changes made in this PR. There are some changes that we don't need for this feature. I think those were made unintentionally when you do a git pull. Could clean the PR up a bit by keeping only the changes you intended to make?


if (typeof storyFn !== 'function') {
if (typeof info === 'function') {
_options = storyFn;
Expand All @@ -24,14 +40,19 @@ export default {
...defaultOptions,
..._options
};

// props.propTables can only be either an array of components or null
// propTables option is allowed to be set to 'false' (a boolean)
// if the option is false, replace it with null to avoid react warnings
if (!options.propTables) {
options.propTables = null;
}


const mtrcConf = { ...defaultMtrcConf };
if (_options && _options.mtrcConf) {
Object.assign(mtrcConf, _options.mtrcConf);
}

this.add(storyName, (context) => {
const props = {
info,
Expand All @@ -40,6 +61,7 @@ export default {
showHeader: Boolean(options.header),
showSource: Boolean(options.source),
propTables: options.propTables,
mtrcConf
};

return (
Expand Down