test-jsonforms-react-spectrum-renderers
Version:
React Spectrum Renderer Set for JSONForms
73 lines (69 loc) • 5.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
/*
The MIT License
Copyright (c) 2020 headwire.com, Inc
https://github.com/headwirecom/jsonforms-react-spectrum-renderers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
var react_1 = tslib_1.__importDefault(require("react"));
var merge_1 = tslib_1.__importDefault(require("lodash/merge"));
var react_spectrum_1 = require("@adobe/react-spectrum");
var datepicker_1 = require("@react-spectrum/datepicker");
var date_1 = require("@internationalized/date");
var SpectrumProvider_1 = tslib_1.__importDefault(require("../additional/SpectrumProvider"));
exports.InputDate = react_1.default.memo(function (_a) {
var config = _a.config, data = _a.data, enabled = _a.enabled, handleChange = _a.handleChange, id = _a.id, label = _a.label, path = _a.path, required = _a.required, schema = _a.schema, uischema = _a.uischema;
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
var appliedUiSchemaOptions = merge_1.default({}, config, uischema.options);
var width = appliedUiSchemaOptions.trim
? undefined
: '100%';
var maxValue = appliedUiSchemaOptions.maxValue;
var minValue = appliedUiSchemaOptions.minValue;
var getMinMaxValue = function (minMaxValue) {
if (minMaxValue === 'today') {
return date_1.today(date_1.getLocalTimeZone());
}
else if (minMaxValue) {
return date_1.parseDate(minMaxValue);
}
};
var errorMessage = function () {
if (minValue && maxValue) {
return "Must be between " + minValue + " and " + maxValue + "!";
}
else if (minValue) {
return "Must be at least " + minValue + "!";
}
else if (maxValue) {
return "Must be at most " + maxValue + "!";
}
};
react_1.default.useEffect(function () {
if (!data && (schema === null || schema === void 0 ? void 0 : schema.default)) {
handleChange(path, schema.default);
}
}, [schema === null || schema === void 0 ? void 0 : schema.default]);
return (react_1.default.createElement(SpectrumProvider_1.default, { width: width },
react_1.default.createElement(react_spectrum_1.Provider, { locale: (_b = appliedUiSchemaOptions.locale) !== null && _b !== void 0 ? _b : 'gregory' },
react_1.default.createElement(datepicker_1.DatePicker, { autoFocus: uischema.options && uischema.options.focus, description: (_c = appliedUiSchemaOptions.description) !== null && _c !== void 0 ? _c : null, errorMessage: (_d = appliedUiSchemaOptions.errorMessage) !== null && _d !== void 0 ? _d : errorMessage(), granularity: 'day', hideTimeZone: (_e = appliedUiSchemaOptions.hideTimeZone) !== null && _e !== void 0 ? _e : true, id: id, isDisabled: enabled === undefined ? false : !enabled, isQuiet: (_f = appliedUiSchemaOptions.isQuiet) !== null && _f !== void 0 ? _f : false, isReadOnly: (_h = (_g = appliedUiSchemaOptions.readonly) !== null && _g !== void 0 ? _g : schema.readOnly) !== null && _h !== void 0 ? _h : false, isRequired: required, label: label, labelAlign: (_j = appliedUiSchemaOptions.labelAlign) !== null && _j !== void 0 ? _j : null, labelPosition: (_k = appliedUiSchemaOptions.labelPosition) !== null && _k !== void 0 ? _k : null, maxValue: getMinMaxValue(maxValue), maxVisibleMonths: (_l = appliedUiSchemaOptions.maxVisibleMonths) !== null && _l !== void 0 ? _l : 1, minValue: getMinMaxValue(minValue), necessityIndicator: (_m = appliedUiSchemaOptions.necessityIndicator) !== null && _m !== void 0 ? _m : null, onChange: function (datetime) {
return handleChange(path, datetime ? datetime === null || datetime === void 0 ? void 0 : datetime.toString() : '');
}, showFormatHelpText: (_o = appliedUiSchemaOptions.showFormatHelpText) !== null && _o !== void 0 ? _o : false, width: width, value: data ? date_1.parseDate(data) : null }))));
});
//# sourceMappingURL=InputDate.js.map