1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2024-12-27 00:31:35 +01:00
foris-js/src/bootstrap/DataTimeInput.md
2020-08-18 16:17:00 +02:00

27 lines
673 B
Markdown

Adopted from `react-datetime/DateTime` datatime picker component. It uses
`momentjs` see example.
It requires `ForisTranslations.locale` to be defined in order to use right
locale.
```js
ForisTranslations = { locale: "en" };
import { useState, useEffect } from "react";
import moment from "moment/moment";
const [dataTime, setDataTime] = useState(moment());
const [error, setError] = useState();
useEffect(() => {
dataTime.isValid() ? setError(null) : setError("Invalid value!");
}, [dataTime]);
<DataTimeInput
label="Time to sleep"
value={dataTime}
error={error}
helpText="Example helptext..."
onChange={(value) => setDataTime(value)}
/>;
```