-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(due): Add due date for tasks (#24)
- Implement with `@mui/x-date-pickers/DateTimePicker`. - Can select a date with time. able to select time back before today. - Will turn red background if past and incomplete. - Add new field `due` for `task`, default null. --------- Co-authored-by: ZL Asica <[email protected]>
- Loading branch information
1 parent
fbe2ca4
commit 5b90ff4
Showing
6 changed files
with
259 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// @ts-check | ||
|
||
import CalendarTodayIcon from '@mui/icons-material/CalendarToday' | ||
import { Box, IconButton } from '@mui/material' | ||
import { useTheme } from '@mui/material/styles' | ||
import { LocalizationProvider } from '@mui/x-date-pickers' | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs' | ||
import { DateTimePicker as MUIDateTimePicker } from '@mui/x-date-pickers/DateTimePicker' | ||
import { useRef, useState } from 'react' | ||
|
||
export function DateTimePicker({ | ||
value, | ||
onChange, | ||
label = 'Select date and time', | ||
}) { | ||
const [open, setOpen] = useState(false) | ||
const anchorRef = useRef(null) | ||
const theme = useTheme() | ||
|
||
const toggleOpen = () => setOpen((prev) => !prev) // Toggle the open state | ||
|
||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
gap: 1, | ||
backgroundColor: value ? theme.palette.primary.light : '#eeeeee', | ||
borderRadius: 2, | ||
marginRight: 1, | ||
}} | ||
> | ||
<IconButton ref={anchorRef} onClick={toggleOpen} aria-label={label}> | ||
<CalendarTodayIcon | ||
className='h-5 w-5' | ||
style={{ | ||
color: value ? theme.palette.primary.dark : undefined, | ||
}} | ||
/> | ||
</IconButton> | ||
<MUIDateTimePicker | ||
open={open} | ||
onClose={toggleOpen} | ||
onOpen={toggleOpen} | ||
value={value} | ||
onChange={onChange} | ||
slotProps={{ | ||
actionBar: { | ||
actions: ['clear', 'accept'], | ||
}, | ||
textField: { | ||
sx: { display: 'none' }, | ||
}, | ||
popper: { | ||
anchorEl: anchorRef.current, | ||
placement: 'bottom-start', | ||
sx: { zIndex: 1300 }, | ||
}, | ||
}} | ||
/> | ||
</Box> | ||
</LocalizationProvider> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters