diff --git a/src/components/PickItemRow.tsx b/src/components/PickItemRow.tsx index 1eaf3b4..cf409ff 100644 --- a/src/components/PickItemRow.tsx +++ b/src/components/PickItemRow.tsx @@ -10,8 +10,10 @@ import { IconButton, Stack, Typography, + useMediaQuery, } from '@mui/material'; -import { alpha } from '@mui/material/styles'; +import { alpha, useTheme } from '@mui/material/styles'; +import type React from 'react'; import { useState } from 'react'; import { PickItem } from '../models/PickItem'; import { Product } from '../models/Product'; @@ -35,8 +37,10 @@ export const PickItemRow = ({ onStatusChange, onDelete, }: PickItemRowProps) => { + const theme = useTheme(); const [isConfirmOpen, setIsConfirmOpen] = useState(false); const [isControlsOpen, setIsControlsOpen] = useState(false); + const isNarrowScreen = useMediaQuery(theme.breakpoints.down('sm')); const packagingLabel = item.is_carton ? product?.bulk_name ?? 'Carton' : product?.unit_type ?? 'Unit'; @@ -50,6 +54,25 @@ export const PickItemRow = ({ setIsConfirmOpen(false); }; + const handleRowClick = () => { + if (isNarrowScreen) { + setIsControlsOpen(true); + } + }; + + const handleRowKeyDown = (event: React.KeyboardEvent) => { + if (!isNarrowScreen) return; + + if (event.key === 'Enter' || event.key === ' ') { + event.preventDefault(); + setIsControlsOpen(true); + } + }; + + const stopPropagation = (event: React.SyntheticEvent) => { + event.stopPropagation(); + }; + return ( setIsControlsOpen(true)} - role="button" - tabIndex={0} - onKeyDown={(event) => { - if (event.key === 'Enter' || event.key === ' ') { - event.preventDefault(); - setIsControlsOpen(true); - } + cursor: isNarrowScreen ? 'pointer' : 'default', }} + onClick={handleRowClick} + role={isNarrowScreen ? 'button' : undefined} + tabIndex={isNarrowScreen ? 0 : undefined} + onKeyDown={handleRowKeyDown} > - - Tap to adjust quantity and packaging - + {isNarrowScreen && ( + + Tap to adjust quantity and packaging + + )} - setIsControlsOpen(false)} - fullWidth - maxWidth="xs" - aria-labelledby="item-controls-title" - > - - - {product?.name ?? 'Unknown product'} - - setIsControlsOpen(false)}> - + {!isNarrowScreen && ( + + { + stopPropagation(event); + onToggleCarton(); + }} + sx={{ + boxShadow: item.is_carton + ? (theme) => `0 0 0 8px ${alpha(theme.palette.primary.main, 0.15)}` + : 'none', + }} + > + - - - - - Quantity: {item.quantity} {packagingLabel} + { + stopPropagation(event); + onDecrementQuantity(); + }} + > + + + { + stopPropagation(event); + onIncrementQuantity(); + }} + > + + + { + stopPropagation(event); + setIsConfirmOpen(true); + }} + aria-label="Delete item" + > + + + + )} + + {isNarrowScreen && ( + setIsControlsOpen(false)} + fullWidth + maxWidth="xs" + aria-labelledby="item-controls-title" + > + + + {product?.name ?? 'Unknown product'} - - `0 0 0 8px ${alpha(theme.palette.primary.main, 0.15)}` - : 'none', - }} - > - - - - - - - - - setIsConfirmOpen(true)} - aria-label="Delete item" - > - - + { + stopPropagation(event); + setIsControlsOpen(false); + }} + > + + + + + + + Quantity: {item.quantity} {packagingLabel} + + + { + stopPropagation(event); + onToggleCarton(); + }} + sx={{ + boxShadow: item.is_carton + ? (theme) => `0 0 0 8px ${alpha(theme.palette.primary.main, 0.15)}` + : 'none', + }} + > + + + { + stopPropagation(event); + onDecrementQuantity(); + }} + > + + + { + stopPropagation(event); + onIncrementQuantity(); + }} + > + + + { + stopPropagation(event); + setIsConfirmOpen(true); + }} + aria-label="Delete item" + > + + + - - - + + + )} Delete