Skip to content

Commit 0a69163

Browse files
authored
Merge pull request #7 from ryyppy/pairing-session
2 parents df23337 + e8747c6 commit 0a69163

File tree

10 files changed

+8711
-0
lines changed

10 files changed

+8711
-0
lines changed

example/.storybook/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
stories: ['../stories/**/*.js'],
3+
addons: ['@storybook/addon-actions', '@storybook/addon-links', '@storybook/addon-knobs/register'],
4+
};

example/bindings/Storybook.bs.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
2+
3+
import * as List from "bs-platform/lib/es6/list.js";
4+
import * as React from "@storybook/react";
5+
import * as Js_null_undefined from "bs-platform/lib/es6/js_null_undefined.js";
6+
import * as React$1 from "@storybook/addon-knobs/react";
7+
8+
var Story = { };
9+
10+
function createStory(title, decorators, _module, param) {
11+
var story = React.storiesOf(title, _module);
12+
List.iter((function (dec) {
13+
story.addDecorator(dec);
14+
return /* () */0;
15+
}), decorators);
16+
return {
17+
add: (function (name, c) {
18+
story.add(name, c);
19+
return /* () */0;
20+
})
21+
};
22+
}
23+
24+
var Main = {
25+
createStory: createStory
26+
};
27+
28+
var Notes = { };
29+
30+
function text(label, defaultValue, param) {
31+
return React$1.text(label, Js_null_undefined.fromOption(defaultValue));
32+
}
33+
34+
function $$boolean(label, $staropt$star, param) {
35+
var defaultValue = $staropt$star !== undefined ? $staropt$star : false;
36+
return React$1.boolean(label, defaultValue);
37+
}
38+
39+
function date(label, defaultValue, param) {
40+
return React$1.date(label, Js_null_undefined.fromOption(defaultValue));
41+
}
42+
43+
function button(label, handler, param) {
44+
return React$1.button(label, handler);
45+
}
46+
47+
var Knobs = {
48+
text: text,
49+
$$boolean: $$boolean,
50+
date: date,
51+
button: button
52+
};
53+
54+
var Addons = { };
55+
56+
var Action = { };
57+
58+
export {
59+
Story ,
60+
Main ,
61+
Notes ,
62+
Knobs ,
63+
Addons ,
64+
Action ,
65+
66+
}
67+
/* @storybook/react Not a pure module */

example/bindings/Storybook.re

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
module Story = {
2+
type section;
3+
4+
type webpackModule;
5+
6+
type chapter = unit => ReasonReact.reactElement;
7+
8+
type decorator = chapter => ReasonReact.reactElement;
9+
10+
[@bs.val] [@bs.module "@storybook/react"]
11+
external storiesOf: (string, webpackModule) => section;
12+
13+
[@bs.send] external add: (section, string, chapter) => section;
14+
15+
[@bs.send] external addDecorator: (section, decorator) => section;
16+
};
17+
18+
module Main = {
19+
type chapter = unit => ReasonReact.reactElement;
20+
21+
type section;
22+
23+
[@bs.val] [@bs.module "@storybook/react"]
24+
external storiesOf: (string, 'a) => section;
25+
26+
[@bs.send] external extAdd: (section, string, chapter) => unit = "add";
27+
28+
type decorator = chapter => ReasonReact.reactElement;
29+
30+
[@bs.send] external addDecorator: (section, decorator) => unit;
31+
32+
type webpackModule;
33+
34+
type chapterAdd = (string, chapter) => unit;
35+
36+
type story = {add: chapterAdd};
37+
38+
let createStory =
39+
(
40+
~title: string,
41+
~decorators: list(decorator),
42+
~_module: webpackModule,
43+
(),
44+
)
45+
: story => {
46+
let story = storiesOf(title, _module);
47+
List.iter(dec => addDecorator(story, dec), decorators);
48+
{add: (name: string, c: chapter) => extAdd(story, name, c)};
49+
};
50+
};
51+
52+
module Notes = {
53+
type decoratedChapter = Main.chapter => Main.chapter;
54+
55+
[@bs.module "@storybook/addon-notes"]
56+
external withNotes: string => decoratedChapter;
57+
};
58+
59+
module Knobs = {
60+
[@bs.val] [@bs.module "@storybook/addon-knobs/react"]
61+
external withKnobs: Main.decorator;
62+
63+
[@bs.val] [@bs.module "@storybook/addon-knobs/react"]
64+
external extText: (string, Js.null_undefined(string)) => string = "text";
65+
66+
let text = (~label: string, ~defaultValue: option(string)=?, ()) =>
67+
extText(label, Js.Nullable.fromOption(defaultValue));
68+
69+
[@bs.val] [@bs.module "@storybook/addon-knobs/react"]
70+
external extBoolean: (string, bool) => bool = "boolean";
71+
72+
let boolean = (~label: string, ~defaultValue=false, ()) =>
73+
extBoolean(label, defaultValue);
74+
75+
type rangeConfig = {
76+
range: bool,
77+
min: float,
78+
max: float,
79+
step: float,
80+
};
81+
82+
[@bs.module "@storybook/addon-knobs/react"]
83+
external number:
84+
(~label: string, ~defaultValue: float, ~range: rangeConfig=?, unit) =>
85+
float =
86+
"number";
87+
88+
[@bs.module "@storybook/addon-knobs/react"]
89+
external object_:
90+
(~label: string, ~defaultValue: Js.t('a), unit) => Js.t('a) =
91+
"object";
92+
93+
[@bs.module "@storybook/addon-knobs/react"]
94+
external color: (~label: string, ~defaultValue: string=?, unit) => string =
95+
"color";
96+
97+
type selectConfig('a) = 'a;
98+
99+
[@bs.module "@storybook/addon-knobs/react"]
100+
external select:
101+
(
102+
~label: string,
103+
~options: selectConfig('a),
104+
~defaultValue: string,
105+
unit
106+
) =>
107+
string =
108+
"select";
109+
110+
[@bs.module "@storybook/addon-knobs/react"]
111+
external selectFromArray:
112+
(~label: string, ~options: array('a), ~defaultValue: string, unit) => 'a =
113+
"select";
114+
115+
[@bs.module "@storybook/addon-knobs/react"]
116+
external selectFromDict:
117+
(~label: string, ~options: Js.Dict.t('a), ~defaultValue: string, unit) =>
118+
'a =
119+
"select";
120+
121+
[@bs.module "@storybook/addon-knobs/react"]
122+
external selectFromAny:
123+
(~label: string, ~options: 'a, ~defaultValue: string, unit) => 'a =
124+
"select";
125+
126+
[@bs.module "@storybook/addon-knobs/react"]
127+
external extDate: (string, Js.null_undefined(Js_date.t)) => string = "date";
128+
129+
let date = (~label: string, ~defaultValue: option(Js_date.t)=?, ()) =>
130+
extDate(label, Js.Nullable.fromOption(defaultValue));
131+
132+
type button;
133+
134+
[@bs.val] [@bs.module "@storybook/addon-knobs/react"]
135+
external extButton: (string, ReactEvent.Mouse.t => unit) => button =
136+
"button";
137+
138+
let button = (~label: string, ~handler: ReactEvent.Mouse.t => unit, ()) =>
139+
extButton(label, handler);
140+
};
141+
142+
module Addons = {
143+
type t;
144+
145+
type api;
146+
147+
type channel;
148+
149+
type callback = api => unit;
150+
151+
type channelListener = string => unit;
152+
153+
type panelConfig = {
154+
.
155+
"title": string,
156+
"render": unit => ReasonReact.reactElement,
157+
};
158+
159+
[@bs.module "@storybook/addons"] external addons: t = "default";
160+
161+
[@bs.send] external register: (t, string, callback) => unit = "register";
162+
163+
[@bs.send] external addPanel: (t, string, panelConfig) => unit = "addPanel";
164+
165+
[@bs.send] external getChannel: (t, unit) => channel = "getChannel";
166+
167+
[@bs.send] external emitChannel: (channel, string, string) => unit = "emit";
168+
169+
[@bs.send]
170+
external onChannel: (channel, string, channelListener) => unit = "on";
171+
172+
[@bs.send]
173+
external removeChannelListener: (channel, string, channelListener) => unit =
174+
"removeListener";
175+
176+
[@bs.send] external onStory: (api, unit => unit) => unit = "onStory";
177+
};
178+
179+
module Action = {
180+
type actionHandler('a) = 'a => unit;
181+
182+
[@bs.val] [@bs.module "@storybook/addon-actions"]
183+
external action: string => actionHandler('a);
184+
};

example/bsconfig.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "storybook-test",
3+
"namespace": false,
4+
"reason": { "react-jsx": 3 },
5+
"refmt": 3,
6+
"bs-dependencies": ["reason-react"],
7+
"ppx-flags": [],
8+
"sources": [
9+
{ "dir": "src", "subdirs": true },
10+
{ "dir": "bindings", "subdirs": true },
11+
{ "dir": "stories", "subdirs": true }
12+
],
13+
"package-specs": {
14+
"module": "es6",
15+
"in-source": true
16+
},
17+
"suffix": ".bs.js",
18+
"bsc-flags": ["-bs-no-version-header", "-bs-super-errors", "-bs-g"]
19+
}

example/package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "example",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"dependencies": {
7+
"reason-react": "^0.7.1"
8+
},
9+
"devDependencies": {
10+
"@babel/core": "^7.9.6",
11+
"@storybook/addon-actions": "^5.3.18",
12+
"@storybook/addon-knobs": "^5.3.18",
13+
"@storybook/addon-links": "^5.3.18",
14+
"@storybook/addons": "^5.3.18",
15+
"@storybook/react": "^5.3.18",
16+
"babel-loader": "^8.1.0",
17+
"bs-platform": "7.1.1"
18+
},
19+
"scripts": {
20+
"storybook": "start-storybook -p 6006",
21+
"build-storybook": "build-storybook",
22+
"bs:start": "bsb -make-world -w"
23+
}
24+
}

example/src/MyButton.bs.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
3+
import * as React from "react";
4+
5+
function MyButton(Props) {
6+
var style = {
7+
border: "solid black thin",
8+
display: "inline-block",
9+
padding: "4px"
10+
};
11+
return React.createElement("div", {
12+
style: style
13+
}, "Hi");
14+
}
15+
16+
var make = MyButton;
17+
18+
export {
19+
make ,
20+
21+
}
22+
/* react Not a pure module */

example/src/MyButton.re

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[@react.component]
2+
let make = () => {
3+
let style =
4+
ReactDOMRe.Style.make(
5+
~display="inline-block",
6+
~border="solid black thin",
7+
~padding="4px",
8+
(),
9+
);
10+
<div style> "Hi"->React.string </div>;
11+
};

0 commit comments

Comments
 (0)