Skip to content

Commit 4cc20cb

Browse files
feat(date-time-picker-web): create hook to call datepicker controller
1 parent e50e94f commit 4cc20cb

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { ActionValue } from "mendix";
2+
import { useEffect, useState } from "react";
3+
import { TypeEnum } from "typings/DateTimePickerProps";
4+
import { DatePickerController } from "../helpers/DatePickerController";
5+
6+
type UseControllerProps = {
7+
endDate?: Date;
8+
onChange?: ActionValue<"none">;
9+
startDate?: Date;
10+
type: TypeEnum;
11+
};
12+
13+
export function useController({ endDate, startDate, type, onChange }: UseControllerProps): DatePickerController {
14+
const [controller] = useState(
15+
() =>
16+
new DatePickerController({
17+
defaultEnd: endDate,
18+
defaultStart: startDate,
19+
type,
20+
onChange
21+
})
22+
);
23+
24+
useEffect(() => controller.setup(), [controller]);
25+
26+
return controller;
27+
}

0 commit comments

Comments
 (0)