Created
February 26, 2019 06:45
-
-
Save alex35mil/e2c545ed6d37da56b358ec943f4f6fdd to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Modifier = { | |
type t = | |
| Date(Js.Date.t) | |
| Range(Js.Date.t, Js.Date.t) | |
| Fn(Js.Date.t => bool); | |
let toJs = | |
(. x) => | |
switch (x) { | |
| Date(date) => date | |
| Range(startDate, endDate) => | |
{"from": startDate, "to": endDate}->Obj.magic | |
| Fn(fn) => fn->Obj.magic | |
}; | |
}; | |
[@bs.module "react-day-picker"] | |
external reactClass: React.reactClass = "default"; | |
let make = | |
( | |
~initialMonth: option(Js.Date.t)=?, | |
~fromMonth: option(Js.Date.t)=?, | |
~numberOfMonths: option(int)=?, | |
~showOutsideDays: option(bool)=?, | |
~selectedDays: option(Modifier.t), | |
~modifiers: option(Js.Dict.t(Modifier.t))=?, | |
~classNames: option(Js.t({..}))=?, | |
~onDayClick: | |
option( | |
(Js.Date.t, Js.Dict.t(Modifier.t), ReactEvent.Mouse.t) => unit, | |
)=?, | |
~onMonthChange: option(Js.Date.t => unit)=?, | |
children, | |
) => | |
React.wrapJsForReason( | |
~reactClass, | |
~props={ | |
"initialMonth": initialMonth->Js.Nullable.fromOption, | |
"fromMonth": fromMonth->Js.Nullable.fromOption, | |
"numberOfMonths": numberOfMonths->Js.Nullable.fromOption, | |
"showOutsideDays": showOutsideDays->Js.Nullable.fromOption, | |
"selectedDays": | |
selectedDays | |
->Option.map(x => Modifier.toJs(. x)) | |
->Js.Nullable.fromOption, | |
"modifiers": | |
modifiers | |
->Option.map(x => x->Js.Dict.map(Modifier.toJs, _)) | |
->Js.Nullable.fromOption, | |
"classNames": classNames->Js.Nullable.fromOption, | |
"onDayClick": onDayClick->Js.Nullable.fromOption, | |
"onMonthChange": onMonthChange->Js.Nullable.fromOption, | |
}, | |
children, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment