// Component con cho các nút hành động (số lượng, thêm vào giỏ) const ProductActions = ({ quantity, setQuantity, onAddToCart, itemCode, config }) => { // Dựa vào config.lang để hiển thị song ngữ const addToCartText = config?.lang === 'vi' ? 'Thêm vào giỏ' : 'Add to Cart'; return (
{addToCartText}} onClick={() => onAddToCart(itemCode, quantity)} variant='danger' type='button' style={{ marginLeft: '15px', // Giảm khoảng cách padding: '6px 12px', // Giảm padding để nút nhỏ gọn hơn fontSize: '0.9rem', // Giảm kích thước chữ height: '31px', // Đồng bộ chiều cao với nút số lượng marginTop:'-5px' }} tabIndex={0} />
); }; const OrderQuantity = (props) => { const { Button, InputGroup, FormControl } = ReactBootstrap; const { quantity, setQuantity, config } = props; const MIN_VALUE = 1; const MAX_VALUE = 99999; const handleIncrement = () => { if (quantity < MAX_VALUE) { setQuantity(prev => Number(prev) + 1); } }; const handleDecrement = () => { if (quantity > MIN_VALUE) { setQuantity(prev => Number(prev) - 1); } }; const handleInputChange = (e) => { const value = e.target.value; if (value === '') { setQuantity(''); return; } const numValue = parseInt(value, 10); if (!isNaN(numValue)) { setQuantity(Math.min(Math.max(numValue, 0), MAX_VALUE)); } }; const handleBlur = () => { if (quantity === '' || quantity < MIN_VALUE) { setQuantity(MIN_VALUE); } }; // Style constants để code JSX sạch hơn const btnStyle = { width: 32, height: 32, display: 'flex', alignItems: 'center', justifyContent: 'center' }; const inputStyle = { fontSize: '14px', width: '50px', height: 32, borderLeft: 'none', borderRight: 'none' }; return (
); };