|
| 1 | +import React from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | + |
| 4 | +const Render = ({ component }) => <param type="render" content={component} />; |
| 5 | + |
| 6 | +Render.propTypes = { |
| 7 | + component: PropTypes.func, |
| 8 | +}; |
| 9 | + |
| 10 | +const Content = ({ json, contentType, text }) => { |
| 11 | + const ComponentsArray = []; |
| 12 | + |
| 13 | + if (contentType) |
| 14 | + ComponentsArray.push(<param key="contentType" type="content-type" content={contentType} />); |
| 15 | + if (json) ComponentsArray.push(<param key="json" type="json" content={json} />); |
| 16 | + if (text) ComponentsArray.push(<param key="text" type="text" content={text} />); |
| 17 | + |
| 18 | + return ComponentsArray; |
| 19 | +}; |
| 20 | + |
| 21 | +Content.propTypes = { |
| 22 | + json: PropTypes.any, |
| 23 | + contentType: PropTypes.string, |
| 24 | + text: PropTypes.string, |
| 25 | +}; |
| 26 | + |
| 27 | +const Status = ({ statusCode }) => <param type="status" content={statusCode} />; |
| 28 | + |
| 29 | +Status.propTypes = { |
| 30 | + statusCode: PropTypes.number, |
| 31 | +}; |
| 32 | + |
| 33 | +const Redirect = ({ path, statusCode }) => <param type="redirect" content={{ path, statusCode }} />; |
| 34 | + |
| 35 | +Redirect.propTypes = { |
| 36 | + path: PropTypes.string.isRequired, |
| 37 | + statusCode: PropTypes.number, |
| 38 | +}; |
| 39 | + |
| 40 | +const SendFile = ({ path, options, onError = () => {} }) => ( |
| 41 | + <param type="send-file" content={{ path, options, onError }} /> |
| 42 | +); |
| 43 | + |
| 44 | +SendFile.propTypes = { |
| 45 | + path: PropTypes.string.isRequired, |
| 46 | + options: PropTypes.object, |
| 47 | + onError: PropTypes.func, |
| 48 | +}; |
| 49 | + |
| 50 | +export const Res = { |
| 51 | + Render, |
| 52 | + Content, |
| 53 | + Status, |
| 54 | + Redirect, |
| 55 | + SendFile, |
| 56 | +}; |
0 commit comments