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

27 lines
673 B
Markdown
Raw Normal View History

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