Working date changer!
This commit is contained in:
parent
95eb73a166
commit
72318bb286
2 changed files with 31 additions and 4 deletions
|
@ -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
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,21 @@
|
|||
type formattedString = string;
|
||||
|
||||
[@react.component]
|
||||
let make = () => {
|
||||
let date = MomentRe.momentNow() |> MomentRe.Moment.format("YYYY-MM-DD");
|
||||
<> <input type_="date" value=date /> </>;
|
||||
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")});
|
||||
};
|
||||
|
||||
<>
|
||||
<input type_="date" value={formatDate(date)} onChange=handleChange />
|
||||
</>;
|
||||
};
|
Loading…
Add table
Reference in a new issue