Skip to content

Instantly share code, notes, and snippets.

@mathis-m
Last active February 12, 2021 08:22
Show Gist options
  • Save mathis-m/bee9dca8578357119f862d6074ad0c88 to your computer and use it in GitHub Desktop.
Save mathis-m/bee9dca8578357119f862d6074ad0c88 to your computer and use it in GitHub Desktop.
date-picker plugin
import React from "react";
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
const JsonSchema_string_date = (props) => {
const dateNumber = Date.parse(props.value);
const date = dateNumber
? new Date(dateNumber)
: new Date();
return (
<DatePicker
selected={date}
onChange={d => props.onChange(d.toISOString().substring(0, 10))}
/>
);
}
const JsonSchema_string_date_time = (props) => {
const dateNumber = Date.parse(props.value);
const date = dateNumber
? new Date(dateNumber)
: new Date();
return (
<DatePicker
selected={date}
onChange={d => props.onChange(d.toISOString())}
showTimeSelect
timeFormat="p"
dateFormat="Pp"
/>
);
}
export const DateTimeSwaggerPlugin = {
components: {
JsonSchema_string_date: JsonSchema_string_date,
"JsonSchema_string_date-time": JsonSchema_string_date_time
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment