-
Notifications
You must be signed in to change notification settings - Fork 367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: [M3-8936] - Add Date Presets Functionality to Date Picker component. #11395
Changes from all commits
b274baf
f958dab
5d0a476
93aab07
d7deb4f
a550f05
de0f63e
426c42c
3fb49a6
6c76508
1653a6b
00421cf
959730a
d9bd490
960415e
b9f4745
b0b9264
6c70559
96eb34d
74b1635
70d1422
342fd96
bfed239
8a19f9b
9e9c14f
a25728e
3196f2a
4794d04
e977a94
add3f10
2fafd33
b3463ae
a325e30
b1e2a51
1b0931b
9b2de1d
ff89c50
4dbe28d
b2b7d97
04514de
e343821
7fd4fa5
81ec4f8
4e25a94
52a7276
423f4b7
34f03e3
f87fbce
f47f919
2578b83
43810e7
fa7bd52
3b6f981
9b10623
9d32d3d
11d8780
862134f
2643bd6
7aec8c9
0c379a2
73e0a20
194b0d2
0ffaade
b2d591f
efcfe5c
2ca7adf
31dc03e
cd875be
5f35d70
208b2a0
d1c3fa1
6186d26
2cd8366
b8f2d73
51b1a29
e523043
f0dd5c0
9abec60
fa3e186
de2097b
006371e
bf1133f
8c465b2
ac59703
555a0be
b5c3606
bea7bac
4ff411b
510485a
0cf080f
729c184
727c59c
9ebfb7f
25dc1e5
e856275
15d9134
132ed74
69355ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Added | ||
--- | ||
|
||
Add Date Presets Functionality to Date Picker component ([#11395](https://github.com/linode/manager/pull/11395)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { Divider } from '@linode/ui'; | ||
import { InputAdornment, TextField } from '@linode/ui'; | ||
import { Box } from '@linode/ui'; | ||
import { TextField } from '@linode/ui'; | ||
import CalendarTodayIcon from '@mui/icons-material/CalendarToday'; | ||
import { Grid, Popover } from '@mui/material'; | ||
import { AdapterLuxon } from '@mui/x-date-pickers/AdapterLuxon'; | ||
import { DateCalendar } from '@mui/x-date-pickers/DateCalendar'; | ||
|
@@ -66,7 +67,7 @@ export const DateTimePicker = ({ | |
onApply, | ||
onCancel, | ||
onChange, | ||
placeholder = 'yyyy-MM-dd HH:mm', | ||
placeholder = 'Select Date', | ||
showTime = true, | ||
showTimeZone = true, | ||
sx, | ||
|
@@ -75,13 +76,22 @@ export const DateTimePicker = ({ | |
value = null, | ||
}: DateTimePickerProps) => { | ||
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null); | ||
|
||
// Current and original states | ||
const [selectedDateTime, setSelectedDateTime] = useState<DateTime | null>( | ||
value | ||
); | ||
const [selectedTimeZone, setSelectedTimeZone] = useState<null | string>( | ||
timeZoneSelectProps.value || null | ||
); | ||
|
||
const [originalDateTime, setOriginalDateTime] = useState<DateTime | null>( | ||
value | ||
); | ||
const [originalTimeZone, setOriginalTimeZone] = useState<null | string>( | ||
timeZoneSelectProps.value || null | ||
); | ||
|
||
const TimePickerFieldProps: TextFieldProps = { | ||
label: timeSelectProps?.label ?? 'Select Time', | ||
noMarginTop: true, | ||
|
@@ -115,6 +125,8 @@ export const DateTimePicker = ({ | |
|
||
const handleApply = () => { | ||
setAnchorEl(null); | ||
setOriginalDateTime(selectedDateTime); | ||
setOriginalTimeZone(selectedTimeZone); | ||
onChange(selectedDateTime); | ||
|
||
if (onApply) { | ||
|
@@ -124,6 +136,9 @@ export const DateTimePicker = ({ | |
|
||
const handleClose = () => { | ||
setAnchorEl(null); | ||
setSelectedDateTime(originalDateTime); | ||
setSelectedTimeZone(originalTimeZone); | ||
|
||
if (onCancel) { | ||
onCancel(); | ||
} | ||
|
@@ -139,16 +154,32 @@ export const DateTimePicker = ({ | |
<LocalizationProvider dateAdapter={AdapterLuxon}> | ||
<Box sx={{ minWidth: '300px', ...sx }}> | ||
<TextField | ||
InputProps={{ | ||
readOnly: true, | ||
startAdornment: ( | ||
<InputAdornment position="start"> | ||
<CalendarTodayIcon | ||
sx={{ | ||
color: '#c2c2ca !important', | ||
fontSize: '20px !important', | ||
left: '8px', | ||
position: 'absolute', | ||
Comment on lines
+162
to
+166
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this will be removed when replacing MUI calendar icon with give SVG. |
||
}} | ||
/> | ||
</InputAdornment> | ||
), | ||
sx: { paddingLeft: '32px' }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it possible to use theme spacing instead of hardcoding values? eg There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cpathipa Let's use the |
||
}} | ||
value={ | ||
selectedDateTime | ||
? `${selectedDateTime.toFormat(format)}${ | ||
selectedTimeZone ? ` (${selectedTimeZone})` : '' | ||
}` | ||
: '' | ||
} | ||
InputProps={{ readOnly: true }} | ||
errorText={errorText} | ||
label={label} | ||
noMarginTop | ||
onClick={(event) => setAnchorEl(event.currentTarget)} | ||
placeholder={placeholder} | ||
/> | ||
|
@@ -247,10 +278,6 @@ export const DateTimePicker = ({ | |
<Divider /> | ||
<Box display="flex" justifyContent="flex-end"> | ||
<ActionsPanel | ||
primaryButtonProps={{ | ||
label: 'Apply', | ||
onClick: handleApply, | ||
}} | ||
secondaryButtonProps={{ | ||
buttonType: 'outlined', | ||
label: 'Cancel', | ||
|
@@ -260,6 +287,7 @@ export const DateTimePicker = ({ | |
marginBottom: theme.spacing(1), | ||
marginRight: theme.spacing(2), | ||
})} | ||
primaryButtonProps={{ label: 'Apply', onClick: handleApply }} | ||
/> | ||
</Box> | ||
</Popover> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, the MUI calendar icon is being used, but it will be replaced with the SVG provided by the UX.