Skip to content

Commit 11a1b86

Browse files
feat(date-time-picker-web): add DateTimePickerContainer component
1 parent beb059e commit 11a1b86

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import classNames from "classnames";
2+
import ReactDatePicker from "react-datepicker";
3+
import { DateTimePickerContainerProps } from "typings/DateTimePickerProps";
4+
import { useController } from "../hooks/useController";
5+
import { useSetupProps } from "../hooks/useSetupProps";
6+
7+
export function DateTimePickerContainer(props: DateTimePickerContainerProps) {
8+
const controller = useController({
9+
endDate: props.endDateAttribute?.status === "available" ? (props.endDateAttribute.value as Date) : undefined,
10+
startDate: props.dateAttribute.status === "available" ? (props.dateAttribute.value as Date) : undefined,
11+
type: props.type,
12+
onChange: props.onChange
13+
});
14+
const pickerProps = useSetupProps(props, controller);
15+
const label = props.showLabel && props.label?.status === "available" ? props.label.value : null;
16+
const portalId = `datepicker_` + Math.random();
17+
18+
console.info("Rendering DateTimePicker", label, pickerProps);
19+
20+
// still have to add validation for max and min time and validation message
21+
console.info("unused props", {
22+
name: props.name,
23+
editabilityCondition: props.editabilityCondition,
24+
readOnlyStyle: props.readOnlyStyle,
25+
visible: props.visible,
26+
validationType: props.validationType,
27+
customValidation: props.customValidation,
28+
validationMessage: props.validationMessage
29+
});
30+
31+
const hasValidationMessage =
32+
props.validationMessage?.status === "available" && props.validationMessage.value.length > 0;
33+
34+
return (
35+
<div
36+
className={classNames("widget-datetimepicker", props.class)}
37+
data-focusindex={props.tabIndex}
38+
style={props.style}
39+
>
40+
<div className="widget-datetimepicker-label-wrapper">
41+
<div id={portalId} />
42+
43+
{label ? (
44+
<label className="widget-datetimepicker-label" id={pickerProps.ariaLabelledBy}>
45+
{label}
46+
</label>
47+
) : (
48+
<span className="sr-only" id={pickerProps.ariaLabelledBy}>
49+
Date picker
50+
</span>
51+
)}
52+
</div>
53+
54+
<div className="widget-datetimepicker-wrapper">
55+
<ReactDatePicker {...pickerProps} ref={controller.pickerRef} />
56+
57+
<button
58+
aria-controls={portalId}
59+
aria-expanded={controller.expanded}
60+
aria-haspopup
61+
aria-label="Show calendar"
62+
className="widget-datetimepicker-input-button"
63+
onKeyDown={controller.handleButtonKeyDown}
64+
onMouseDown={controller.handleButtonMouseDown}
65+
type="button"
66+
>
67+
<span className="mx-icon-filled mx-icon-calendar" />
68+
</button>
69+
{hasValidationMessage && <div role="alert">{props.validationMessage?.value}</div>}
70+
</div>
71+
</div>
72+
);
73+
}

0 commit comments

Comments
 (0)