Skip to content

Instantly share code, notes, and snippets.

@vmarcosp
Created July 19, 2022 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vmarcosp/383b4ca5c0e623f8ac496799d51bc82e to your computer and use it in GitHub Desktop.
Save vmarcosp/383b4ca5c0e623f8ac496799d51bc82e to your computer and use it in GitHub Desktop.
Storybook for ReScript
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