@curveball/browser
Version:
Automatic API browser generator. A middleware that turns your JSON responses into HTML if accessed by a browser.
31 lines • 1.55 kB
JavaScript
import * as React from 'react';
import { Button } from './button.js';
/**
* This component renders actions that can be expressed as a single button.
*
* This is only the case for actions that have no fields or only fields with
* type=hidden
*/
export function ButtonForm(props) {
const action = props.action;
const fields = action.fields.map(field => React.createElement(ActionField, { field: field, key: field.name }));
if (action.method === 'GET') {
return React.createElement("form", { action: action.uri, method: action.method, id: action.name, className: "button-form" },
fields,
React.createElement(Button, { method: action.method, title: action.title || action.name || null }));
}
else {
return React.createElement("form", { action: action.uri, method: action.method, encType: action.contentType, id: action.name, className: "button-form" },
props.csrfToken ? React.createElement("input", { type: "hidden", name: "csrf-token", defaultValue: props.csrfToken }) : '',
fields,
React.createElement(Button, { method: action.method, title: action.title || action.name || null }));
}
}
function ActionField(props) {
const field = props.field;
if (field.type !== 'hidden') {
throw new Error('The ActionButtonForm can only render forms that have no fields');
}
return React.createElement("input", { name: field.name, type: field.type, defaultValue: field.value?.toString() });
}
//# sourceMappingURL=ketting-action-button.js.map