Skip to content

Commit 3cba878

Browse files
committed
Adding Storybook
1 parent 1f64c77 commit 3cba878

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+6251
-4653
lines changed

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ test
1515
gulpfile.js
1616
readme.md
1717
tslint.json
18-
ts-build
18+
ts-build
19+
.storybook

.storybook/addons.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@storybook/addon-storysource/register';

.storybook/config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {configure} from "@storybook/react";
2+
import "../node_modules/draft-js/dist/Draft.css";
3+
import "../src/styles/react-mde-all.scss";
4+
import "./styles/demo.scss";
5+
6+
function loadStories() {
7+
require("./stories/layouts/VerticalLayoutStory.tsx");
8+
require("./stories/layouts/HorizontalLayoutStory.tsx");
9+
require("./stories/layouts/TabbedLayoutStory.tsx");
10+
require("./stories/layouts/NoPreviewLayoutStory.tsx");
11+
}
12+
13+
configure(loadStories, module);

.storybook/preview-head.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import * as React from "react";
2+
import * as Showdown from "showdown";
3+
import ReactMde, {ReactMdeTypes} from "../../../src/index";
4+
import {storiesOf} from "@storybook/react";
5+
6+
interface VerticalLayoutStoryComponentState {
7+
mdeState: ReactMdeTypes.MdeState;
8+
}
9+
10+
class VerticalLayoutStoryComponent extends React.Component<{}, VerticalLayoutStoryComponentState> {
11+
converter: Showdown.Converter;
12+
13+
constructor(props) {
14+
super(props);
15+
this.state = {
16+
mdeState: {
17+
markdown: "**Hello world!**",
18+
},
19+
};
20+
this.converter = new Showdown.Converter({
21+
tables: true,
22+
simplifiedAutoLink: true,
23+
strikethrough: true,
24+
tasklists: true,
25+
});
26+
}
27+
28+
handleValueChange = (mdeState: ReactMdeTypes.MdeState) => {
29+
this.setState({mdeState});
30+
}
31+
32+
render() {
33+
return (
34+
<ReactMde
35+
layout="horizontal"
36+
onChange={this.handleValueChange}
37+
editorState={this.state.mdeState}
38+
generateMarkdownPreview={(markdown) => Promise.resolve(this.converter.makeHtml(markdown))}
39+
/>
40+
);
41+
}
42+
}
43+
44+
storiesOf("Layouts", module)
45+
.add("horizontal", () => (
46+
<VerticalLayoutStoryComponent/>
47+
));
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import * as React from "react";
2+
import * as Showdown from "showdown";
3+
import ReactMde, {ReactMdeTypes} from "../../../src/index";
4+
import {storiesOf} from "@storybook/react";
5+
6+
interface VerticalLayoutStoryComponentState {
7+
mdeState: ReactMdeTypes.MdeState;
8+
}
9+
10+
class VerticalLayoutStoryComponent extends React.Component<{}, VerticalLayoutStoryComponentState> {
11+
converter: Showdown.Converter;
12+
13+
constructor(props) {
14+
super(props);
15+
this.state = {
16+
mdeState: {
17+
markdown: "**Hello world!**",
18+
},
19+
};
20+
this.converter = new Showdown.Converter({
21+
tables: true,
22+
simplifiedAutoLink: true,
23+
strikethrough: true,
24+
tasklists: true,
25+
});
26+
}
27+
28+
handleValueChange = (mdeState: ReactMdeTypes.MdeState) => {
29+
this.setState({mdeState});
30+
}
31+
32+
render() {
33+
return (
34+
<ReactMde
35+
layout="noPreview"
36+
onChange={this.handleValueChange}
37+
editorState={this.state.mdeState}
38+
generateMarkdownPreview={(markdown) => Promise.resolve(this.converter.makeHtml(markdown))}
39+
/>
40+
);
41+
}
42+
}
43+
44+
storiesOf("Layouts", module)
45+
.add("noPreview", () => (
46+
<VerticalLayoutStoryComponent/>
47+
));
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import * as React from "react";
2+
import * as Showdown from "showdown";
3+
import ReactMde, {ReactMdeTypes} from "../../../src/index";
4+
import {storiesOf} from "@storybook/react";
5+
6+
interface VerticalLayoutStoryComponentState {
7+
mdeState: ReactMdeTypes.MdeState;
8+
}
9+
10+
class VerticalLayoutStoryComponent extends React.Component<{}, VerticalLayoutStoryComponentState> {
11+
converter: Showdown.Converter;
12+
13+
constructor(props) {
14+
super(props);
15+
this.state = {
16+
mdeState: {
17+
markdown: "**Hello world!**",
18+
},
19+
};
20+
this.converter = new Showdown.Converter({
21+
tables: true,
22+
simplifiedAutoLink: true,
23+
strikethrough: true,
24+
tasklists: true,
25+
});
26+
}
27+
28+
handleValueChange = (mdeState: ReactMdeTypes.MdeState) => {
29+
this.setState({mdeState});
30+
}
31+
32+
render() {
33+
return (
34+
<ReactMde
35+
layout="tabbed"
36+
onChange={this.handleValueChange}
37+
editorState={this.state.mdeState}
38+
generateMarkdownPreview={(markdown) => Promise.resolve(this.converter.makeHtml(markdown))}
39+
/>
40+
);
41+
}
42+
}
43+
44+
storiesOf("Layouts", module)
45+
.add("tabbed", () => (
46+
<VerticalLayoutStoryComponent/>
47+
));
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import * as React from "react";
2+
import * as Showdown from "showdown";
3+
import ReactMde, {ReactMdeTypes} from "../../../src/index";
4+
import {storiesOf} from "@storybook/react";
5+
6+
interface VerticalLayoutStoryComponentState {
7+
mdeState: ReactMdeTypes.MdeState;
8+
}
9+
10+
class VerticalLayoutStoryComponent extends React.Component<{}, VerticalLayoutStoryComponentState> {
11+
converter: Showdown.Converter;
12+
13+
constructor(props) {
14+
super(props);
15+
this.state = {
16+
mdeState: {
17+
markdown: "**Hello world!**",
18+
},
19+
};
20+
this.converter = new Showdown.Converter({
21+
tables: true,
22+
simplifiedAutoLink: true,
23+
strikethrough: true,
24+
tasklists: true,
25+
});
26+
}
27+
28+
handleValueChange = (mdeState: ReactMdeTypes.MdeState) => {
29+
this.setState({mdeState});
30+
}
31+
32+
render() {
33+
return (
34+
<ReactMde
35+
layout="vertical"
36+
onChange={this.handleValueChange}
37+
editorState={this.state.mdeState}
38+
generateMarkdownPreview={(markdown) => Promise.resolve(this.converter.makeHtml(markdown))}
39+
/>
40+
);
41+
}
42+
}
43+
44+
storiesOf("Layouts", module)
45+
.add("vertical", () => (
46+
<VerticalLayoutStoryComponent/>
47+
));

.storybook/styles/demo.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@import 'variables.scss';
2+
3+
body {
4+
font-size: 14px;
5+
font-family: sans-serif;
6+
}

0 commit comments

Comments
 (0)