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

50 lines
1.3 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,
2020-03-20 11:03:50 +00:00
value: new Date(this.props.propertyValue),
showArrowButtons: true,
}}
onChange={this.onDateSelected}
2020-03-20 11:03:50 +00:00
value={new Date(this.props.propertyValue)}
/>
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;
2020-03-20 11:03:50 +00:00
enableTimePicker: boolean;
2019-11-06 12:12:41 +00:00
}
export default DatePickerControl;