|
| 1 | +import { Today } from '@mui/icons-material' |
| 2 | +import { Box, Button, ButtonGroup } from '@mui/material' |
| 3 | +import dayjs from 'src/dayjs' |
| 4 | +import './DateNavigator.scss' |
| 5 | + |
| 6 | +interface DateNavigatorProps { |
| 7 | + currentTime: dayjs.Dayjs |
| 8 | + onChange: (time: dayjs.Dayjs) => void |
| 9 | +} |
| 10 | + |
| 11 | +export const DateNavigator = ({ currentTime, onChange }: DateNavigatorProps) => { |
| 12 | + const handleChange = (amount: number, unit: 'day' | 'week') => { |
| 13 | + const newTime = |
| 14 | + amount > 0 ? currentTime.add(amount, unit) : currentTime.subtract(Math.abs(amount), unit) |
| 15 | + onChange(newTime) |
| 16 | + } |
| 17 | + |
| 18 | + const handleToday = () => onChange(dayjs()) |
| 19 | + |
| 20 | + return ( |
| 21 | + <Box sx={{ width: { xs: '100%', sm: '100%' }, my: 1 }}> |
| 22 | + <ButtonGroup |
| 23 | + variant="outlined" |
| 24 | + fullWidth |
| 25 | + sx={{ |
| 26 | + bgcolor: 'background.paper', |
| 27 | + boxShadow: '0 2px 4px rgba(0,0,0,0.05)', |
| 28 | + borderRadius: 2, |
| 29 | + }}> |
| 30 | + <Button onClick={() => handleChange(-1, 'week')} className="nav-btn"> |
| 31 | + שבוע קודם |
| 32 | + </Button> |
| 33 | + <Button onClick={() => handleChange(-1, 'day')} className="nav-btn"> |
| 34 | + יום קודם |
| 35 | + </Button> |
| 36 | + <Button |
| 37 | + onClick={handleToday} |
| 38 | + className="nav-btn today" |
| 39 | + startIcon={<Today fontSize="small" />}> |
| 40 | + היום |
| 41 | + </Button> |
| 42 | + <Button onClick={() => handleChange(1, 'day')} className="nav-btn"> |
| 43 | + יום הבא |
| 44 | + </Button> |
| 45 | + <Button onClick={() => handleChange(1, 'week')} className="nav-btn"> |
| 46 | + שבוע הבא |
| 47 | + </Button> |
| 48 | + </ButtonGroup> |
| 49 | + </Box> |
| 50 | + ) |
| 51 | +} |
0 commit comments