synapse-react-client
Version:
[](https://travis-ci.com/Sage-Bionetworks/Synapse-React-Client) [](https://badge.fury.io/js/synaps
44 lines • 2.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomDefaultTemplate = void 0;
var tslib_1 = require("tslib");
var react_1 = (0, tslib_1.__importStar)(require("react"));
var react_bootstrap_1 = require("react-bootstrap");
var icons_1 = require("@material-ui/icons");
var FieldDescriptionTable_1 = (0, tslib_1.__importDefault)(require("./FieldDescriptionTable"));
function CustomDefaultTemplate(props) {
var _a;
var id = props.id, label = props.label, children = props.children, errors = props.errors, help = props.help, hidden = props.hidden, required = props.required, displayLabel = props.displayLabel, formData = props.formData, onChange = props.onChange, schema = props.schema;
var description = (_a = props.description) !== null && _a !== void 0 ? _a : props.schema.description;
var _b = (0, react_1.useState)(false), showDetails = _b[0], setShowDetails = _b[1];
// The formData that we get may be an array (for example, if it was an additionalProperty, but then the key was added to the schema)
// If the object passes through this template, then it should no longer be an array, so we coerce it to a string.
(0, react_1.useEffect)(function () {
if (schema.type !== 'array' && Array.isArray(formData)) {
var newValue_1 = formData.map(function (v) { return "" + v; }).join(', ');
// TODO: This only works when we have a short delay
setTimeout(function () {
onChange(newValue_1);
}, 50);
}
}, []);
if (hidden) {
return react_1.default.createElement("div", { className: "hidden" }, children);
}
return (react_1.default.createElement(react_1.default.Fragment, null,
label && (displayLabel || schema.type === 'boolean') && (react_1.default.createElement("div", { className: "LabelContainer" },
react_1.default.createElement(react_bootstrap_1.FormLabel, { htmlFor: id },
label,
required && react_1.default.createElement("span", { className: "required" }, "*")),
react_1.default.createElement("button", { "aria-label": "More Info", "aria-expanded": showDetails, onClick: function (e) {
e.preventDefault();
setShowDetails(!showDetails);
} },
react_1.default.createElement(icons_1.HelpOutline, { className: "HelpButton SRC-primary-text-color" })))),
children,
react_1.default.createElement(FieldDescriptionTable_1.default, { required: required, type: schema.type, description: description, show: showDetails }),
errors,
help));
}
exports.CustomDefaultTemplate = CustomDefaultTemplate;
//# sourceMappingURL=CustomDefaultTemplate.js.map