Created
January 7, 2021 16:21
-
-
Save s-bauer/7ecfaf62c24a17c6a92c8599f414de37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwaggerUI from "swagger-ui-react" | |
import './App.css'; | |
import React from "react"; | |
import DatePicker from "react-datepicker"; | |
import "swagger-ui-react/swagger-ui.css" | |
import "react-datepicker/dist/react-datepicker.css"; | |
function App() { | |
return ( | |
<SwaggerUI url="https://gist.githubusercontent.com/s-bauer/0d84bcbbd9e733ce027bbfef6b4211cb/raw/92d9daa4f0db648c8cb7bbe89646f7ffcc2802f4/gistfile1.txt" plugins={[DateTimeSwaggerPlugin]} /> | |
); | |
} | |
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" | |
/> | |
); | |
} | |
const DateTimeSwaggerPlugin = { | |
components: { | |
JsonSchema_string_date: JsonSchema_string_date, | |
"JsonSchema_string_date-time": JsonSchema_string_date_time | |
} | |
}; | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment