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

673 B

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.

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)}
/>;