|
| 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 | +}; |
0 commit comments