diff --git a/src/DatePicker/DatePicker.bs.js b/src/DatePicker/DatePicker.bs.js index 0a765e3..f64c01a 100644 --- a/src/DatePicker/DatePicker.bs.js +++ b/src/DatePicker/DatePicker.bs.js @@ -1,13 +1,24 @@ 'use strict'; +var Curry = require("bs-platform/lib/js/curry.js"); var React = require("react"); var Moment = require("moment"); function DatePicker(Props) { - var date = Moment().format("YYYY-MM-DD"); + var match = React.useState((function () { + return Moment(); + })); + var updateDate = match[1]; + var handleChange = function ($$event) { + var value = $$event.target.value; + return Curry._1(updateDate, (function (param) { + return Moment(value, "YYYY-MM-DD"); + })); + }; return React.createElement(React.Fragment, undefined, React.createElement("input", { type: "date", - value: date + value: match[0].format("YYYY-MM-DD"), + onChange: handleChange })); } diff --git a/src/DatePicker/DatePicker.re b/src/DatePicker/DatePicker.re index 7791d74..702a437 100644 --- a/src/DatePicker/DatePicker.re +++ b/src/DatePicker/DatePicker.re @@ -1,5 +1,21 @@ +type formattedString = string; + [@react.component] let make = () => { - let date = MomentRe.momentNow() |> MomentRe.Moment.format("YYYY-MM-DD"); - <> ; + let (date: MomentRe.Moment.t, updateDate) = + React.useState(MomentRe.momentNow); + + let formatDate: MomentRe.Moment.t => formattedString = + (date: MomentRe.Moment.t) => { + date |> MomentRe.Moment.format("YYYY-MM-DD"); + }; + + let handleChange = (event: ReactEvent.Form.t) => { + let value: formattedString = ReactEvent.Form.target(event)##value; + updateDate(_ => {value->MomentRe.momentWithFormat("YYYY-MM-DD")}); + }; + + <> + + ; }; \ No newline at end of file