Skip to content

Commit 569d1b0

Browse files
refactor(date-time-picker-web): remove hardcodded label from DateTimePicker and update styles
1 parent c6d9bbc commit 569d1b0

File tree

4 files changed

+37
-97
lines changed

4 files changed

+37
-97
lines changed

packages/pluggableWidgets/date-time-picker-web/src/DateTimePicker.editorPreview.tsx

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,23 @@ import { DateTimePickerPreviewProps } from "../typings/DateTimePickerProps";
33
import "./ui/DateTimePicker.scss";
44

55
export function preview(props: DateTimePickerPreviewProps): ReactElement {
6-
const label = props.showLabel ? props.label : null;
7-
const portalId = `datepicker_` + Math.random();
8-
96
return (
107
<div className="widget-datetimepicker">
11-
{label ? (
12-
<div className="widget-datetimepicker-label-wrapper">
13-
<div id={portalId} />
14-
15-
<label className="widget-datetimepicker-label" id="datepicker-label">
16-
{label}
17-
</label>
18-
</div>
19-
) : (
20-
<span className="sr-only" id="datepicker-label">
21-
Date picker
22-
</span>
23-
)}
24-
25-
<div className="widget-datetimepicker-wrapper">
26-
<div className="react-datepicker-wrapper">
27-
<div className="react-datepicker__input-container">
28-
<input
29-
className="widget-datetimepicker-input react-datepicker-ignore-onclickoutside"
30-
placeholder={props.placeholder ?? ""}
31-
readOnly
32-
type="text"
33-
value={props.dateAttribute ? `[${props.dateAttribute}]` : "[Date time picker]"}
34-
/>
35-
</div>
8+
<div className="react-datepicker-wrapper">
9+
<div className="react-datepicker__input-container">
10+
<input
11+
className="widget-datetimepicker-input react-datepicker-ignore-onclickoutside"
12+
placeholder={props.placeholder ?? ""}
13+
readOnly
14+
type="text"
15+
value={props.dateAttribute ? `[${props.dateAttribute}]` : "[Date time picker]"}
16+
/>
3617
</div>
37-
38-
<button aria-label="Show calendar" className="widget-datetimepicker-input-button" type="button">
39-
<span className="mx-icon-filled mx-icon-calendar" />
40-
</button>
4118
</div>
19+
20+
<button aria-label="Show calendar" className="widget-datetimepicker-input-button" type="button">
21+
<span className="mx-icon-filled mx-icon-calendar" />
22+
</button>
4223
</div>
4324
);
4425
}
Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import classNames from "classnames";
21
import ReactDatePicker from "react-datepicker";
32
import { DateTimePickerContainerProps } from "typings/DateTimePickerProps";
43
import { useController } from "../hooks/useController";
@@ -12,15 +11,12 @@ export function DateTimePickerContainer(props: DateTimePickerContainerProps) {
1211
onChange: props.onChange
1312
});
1413
const pickerProps = useSetupProps(props, controller);
15-
const label = props.showLabel && props.label?.status === "available" ? props.label.value : null;
1614
const portalId = `datepicker_` + Math.random();
1715

1816
// still have to add validation for max and min time and validation message
1917
console.info("unused props", {
2018
name: props.name,
21-
editabilityCondition: props.editabilityCondition,
22-
readOnlyStyle: props.readOnlyStyle,
23-
visible: props.visible,
19+
id: props.id,
2420
validationType: props.validationType,
2521
customValidation: props.customValidation,
2622
validationMessage: props.validationMessage
@@ -30,42 +26,22 @@ export function DateTimePickerContainer(props: DateTimePickerContainerProps) {
3026
props.validationMessage?.status === "available" && props.validationMessage.value.length > 0;
3127

3228
return (
33-
<div
34-
className={classNames("widget-datetimepicker", props.class)}
35-
data-focusindex={props.tabIndex}
36-
style={props.style}
37-
>
38-
{label ? (
39-
<div className="widget-datetimepicker-label-wrapper">
40-
<div id={portalId} />
29+
<div className="widget-datetimepicker" data-focusindex={props.tabIndex}>
30+
<ReactDatePicker {...pickerProps} ref={controller.pickerRef} />
4131

42-
<label className="widget-datetimepicker-label" id={pickerProps.ariaLabelledBy}>
43-
{label}
44-
</label>
45-
</div>
46-
) : (
47-
<span className="sr-only" id={pickerProps.ariaLabelledBy}>
48-
Date picker
49-
</span>
50-
)}
51-
52-
<div className="widget-datetimepicker-wrapper">
53-
<ReactDatePicker {...pickerProps} ref={controller.pickerRef} />
54-
55-
<button
56-
aria-controls={portalId}
57-
aria-expanded={controller.expanded}
58-
aria-haspopup
59-
aria-label="Show calendar"
60-
className="widget-datetimepicker-input-button"
61-
onKeyDown={controller.handleButtonKeyDown}
62-
onMouseDown={controller.handleButtonMouseDown}
63-
type="button"
64-
>
65-
<span className="mx-icon-filled mx-icon-calendar" />
66-
</button>
67-
{hasValidationMessage && <div role="alert">{props.validationMessage?.value}</div>}
68-
</div>
32+
<button
33+
aria-controls={portalId}
34+
aria-expanded={controller.expanded}
35+
aria-haspopup
36+
aria-label="Show calendar"
37+
className="widget-datetimepicker-input-button"
38+
onKeyDown={controller.handleButtonKeyDown}
39+
onMouseDown={controller.handleButtonMouseDown}
40+
type="button"
41+
>
42+
<span className="mx-icon-filled mx-icon-calendar" />
43+
</button>
44+
{hasValidationMessage && <div role="alert">{props.validationMessage?.value}</div>}
6945
</div>
7046
);
7147
}

packages/pluggableWidgets/date-time-picker-web/src/hooks/useSetupProps.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function useSetupProps(
1616
dateTimeFormat,
1717
placeholder,
1818
dateAttribute,
19-
editable,
19+
endDateAttribute,
2020
ariaRequired,
2121
onEnter,
2222
onLeave
@@ -34,7 +34,7 @@ export function useSetupProps(
3434
timeFormat,
3535
dateTimeFormat,
3636
dateAttribute.value ?? new Date(),
37-
null,
37+
endDateAttribute?.value ?? null,
3838
locale
3939
);
4040

@@ -59,6 +59,8 @@ export function useSetupProps(
5959
]
6060
};
6161

62+
const disabled = dateAttribute.readOnly || false;
63+
6264
return {
6365
// Static props
6466
allowSameDay: false,
@@ -76,7 +78,7 @@ export function useSetupProps(
7678
// Base props
7779
ariaLabelledBy: `${id}-label`,
7880
ariaRequired: ariaRequired.toString(),
79-
disabled: editable === "never",
81+
disabled,
8082
locale: calendarLocale,
8183
placeholderText: placeholder?.status === "available" ? placeholder.value : "",
8284
tabIndex: tabIndex ?? 0,

packages/pluggableWidgets/date-time-picker-web/src/ui/DateTimePicker.scss

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,10 @@
22
align-items: center;
33
color: var(--font-color-default);
44
display: flex;
5+
flex: 1;
56
font-size: var(--font-size-small);
6-
margin: 0 -15px 16px -15px;
7-
8-
&-label-wrapper {
9-
flex: 0 0 25%;
10-
max-width: 25%;
11-
padding: 0 16px;
12-
}
13-
14-
&-label {
15-
font-size: var(--font-size-default);
16-
font-weight: 600;
17-
text-align: right;
18-
text-overflow: ellipsis;
19-
width: 100%;
20-
}
21-
22-
&-wrapper {
23-
align-items: center;
24-
display: flex;
25-
flex: 1;
26-
padding: 0 16px;
27-
}
7+
margin: 0 -15px;
8+
padding: 0 16px;
289

2910
&-input {
3011
background-color: var(--bg-color-secondary);

0 commit comments

Comments
 (0)