Created
July 19, 2022 23:41
-
-
Save vmarcosp/383b4ca5c0e623f8ac496799d51bc82e to your computer and use it in GitHub Desktop.
Storybook for ReScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Control = { | |
type t | |
type _control = | |
| Radio | |
| Select | |
| Text | |
| Boolean | |
| Number({min: int, max: int, step: option<int>}) | |
| Range({min: int, max: int, step: option<int>}) | |
let identity: _control => t = control => | |
switch control { | |
| Radio => {"type": "radio"}->Obj.magic | |
| Select => {"type": "select"}->Obj.magic | |
| Text => {"type": "text"}->Obj.magic | |
| Boolean => {"type": "boolean"}->Obj.magic | |
| Range({min, max, step}) => {"type": "range", "min": min, "max": max, "step": step}->Obj.magic | |
| Number({min, max, step}) => | |
{"type": "Number", "min": min, "max": max, "step": step}->Obj.magic | |
} | |
} | |
type argTypes<'value> = { | |
options: option<array<'value>>, | |
defaultValue: option<'value>, | |
control: Control.t, | |
} | |
type story<'props, 'args> = { | |
title: string, | |
component: 'props => React.element, | |
argTypes: option<'args>, | |
} | |
let argType = (~options=?, ~control, ~defaultValue=?, ()) => { | |
options: options, | |
control: control->Control.identity, | |
defaultValue: defaultValue, | |
} | |
@module("./storybook-helpers.js") | |
external addArgTypes: ('props => React.element, 'args) => unit = "withArgTypes" | |
let make = (~title, ~component, ~argTypes=?, ()) => { | |
title: title, | |
component: component, | |
argTypes: argTypes, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment