PromucFlow_constructor/app/client/src/components/propertyControls/DatePickerControl.tsx

49 lines
1.2 KiB
TypeScript
Raw Normal View History

2019-11-06 12:12:41 +00:00
import React from "react";
import BaseControl, { ControlProps } from "./BaseControl";
import { StyledDatePicker } from "./StyledControls";
2019-11-25 05:07:27 +00:00
import { ControlType } from "constants/PropertyControlConstants";
2019-11-06 12:12:41 +00:00
import moment from "moment-timezone";
class DatePickerControl extends BaseControl<DatePickerControlProps> {
render() {
return (
<StyledDatePicker
formatDate={this.formatDate}
parseDate={this.parseDate}
placeholder={"DD/MM/YYYY"}
showActionsBar={true}
timePickerProps={{
useAmPm: true,
value: this.props.propertyValue || new Date(),
showArrowButtons: true,
}}
onChange={this.onDateSelected}
value={this.props.propertyValue || new Date()}
/>
2019-11-06 12:12:41 +00:00
);
}
formatDate = (date: Date): string => {
return moment(date).format("DD/MM/YYYY");
};
parseDate = (dateStr: string): Date => {
return moment(dateStr).toDate();
};
onDateSelected = (date: Date): void => {
this.updateProperty(this.props.propertyName, date);
};
getControlType(): ControlType {
return "DATE_PICKER";
}
}
export interface DatePickerControlProps extends ControlProps {
placeholderText: string;
propertyValue: Date;
}
export default DatePickerControl;