@limetech/lime-elements
Version:
66 lines (65 loc) • 1.98 kB
JavaScript
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import moment from 'moment/moment';
import React from 'react';
import { LimeElementsWidgetAdapter } from '../adapters';
export class DatePicker extends React.Component {
constructor(props) {
super(props);
this.props = props;
this.state = {
modified: false,
};
this.handleChange = this.handleChange.bind(this);
}
render() {
var _a, _b;
const _c = this.props, { type = 'datetime' } = _c, props = __rest(_c, ["type"]);
return React.createElement(LimeElementsWidgetAdapter, {
name: 'limel-date-picker',
value: this.getValue(),
events: {
change: this.handleChange,
},
widgetProps: props,
extraProps: Object.assign({ type: type }, (_b = (_a = props.schema.lime) === null || _a === void 0 ? void 0 : _a.component) === null || _b === void 0 ? void 0 : _b.props),
});
}
getValue() {
if (typeof this.props.value === 'string') {
return new Date(this.props.value);
}
else {
return this.props.value;
}
}
handleChange(event) {
const props = this.props;
event.stopPropagation();
if (!props.onChange) {
return;
}
if (!event.detail) {
props.onChange(null);
return;
}
const formatMapping = {
'date-time': 'YYYY-MM-DDTHH:mm:ssZ',
date: 'YYYY-MM-DD',
time: 'HH:mm:ss',
};
const dateString = moment(event.detail).format(formatMapping[props.schema.format]);
props.onChange(dateString);
}
}
//# sourceMappingURL=date-picker.js.map