Merge pull request 'feat: add image to car body style select option (#55)' (#61) from feature/graphic-car-body-select into main
All checks were successful
it-academy/dry-wash-pl/pipeline/head This commit looks good

Reviewed-on: #61
Reviewed-by: Primakov Alexandr Alexandrovich <primakovpro@gmail.com>
This commit is contained in:
Primakov Alexandr Alexandrovich 2025-01-12 10:13:19 +03:00
commit edddf6d857
15 changed files with 123 additions and 20 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -0,0 +1,10 @@
export { default as CoupeImg } from './coupe.webp';
export { default as CrossoverImg } from './crossover.webp';
export { default as HatchbackImg } from './hatchback.webp';
export { default as LiftbackImg } from './liftback.webp';
export { default as MinivanImg } from './minivan.webp';
export { default as PickupImg } from './pickup.webp';
export { default as SedanImg } from './sedan.webp';
export { default as SportsCarImg } from './sports-car.webp';
export { default as StationWagonImg } from './station-wagon.webp';
export { default as SuvImg } from './suv.webp';

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -1 +1,2 @@
export * from './car-body-type';
export { default as DemoVideoPosterImg } from './demo-video-poster.webp';

View File

@ -1,23 +1,92 @@
import React, { forwardRef } from 'react';
import { Select, SelectProps } from '@chakra-ui/react';
import React, { forwardRef, useState } from 'react';
import {
Input,
Image,
InputProps,
Box,
Popover,
PopoverAnchor,
PopoverContent,
PopoverBody,
List,
ListItem,
} from '@chakra-ui/react';
import { useTranslation } from 'react-i18next';
import { carBodySelectOptions } from './helper';
import { CarBodySelectOption } from './types';
export const CarBodySelect = forwardRef<HTMLSelectElement, SelectProps>(
export const CarBodySelect = forwardRef<HTMLInputElement, InputProps>(
function CarBodySelect(props, ref) {
const [selected, setSelected] = useState<Partial<CarBodySelectOption>>({});
const handleOptionClick = (option: CarBodySelectOption) => {
setSelected(option);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
props.onChange(option.value);
};
const [isDropdownOpen, setIsDropdownOpen] = useState<boolean>(false);
const { t } = useTranslation('~', {
keyPrefix: 'dry-wash.order-create.car-body-select',
});
return (
<Select ref={ref} placeholder={t('placeholder')} {...props}>
{carBodySelectOptions.map(({ value, labelTKey }, i) => (
<option key={i} value={value}>
{t(`options.${labelTKey}`)}
</option>
<Box width='100%'>
<Popover
isOpen={isDropdownOpen}
autoFocus={false}
placement='bottom-start'
matchWidth
>
<PopoverAnchor>
<Input
{...props}
ref={ref}
value={
selected?.labelTKey
? t(`options.${selected.labelTKey}`)
: undefined
}
readOnly
onClick={() => setIsDropdownOpen(true)}
onBlur={() => setIsDropdownOpen(false)}
placeholder={t('placeholder')}
/>
</PopoverAnchor>
<PopoverContent width='100%' maxWidth='100%'>
<PopoverBody border='1px' borderColor='gray.300' p={0}>
<List
display='grid'
gridTemplateColumns='repeat(auto-fit, minmax(150px, 1fr))'
>
{carBodySelectOptions.map((option) => (
<ListItem
key={option.value}
display='flex'
flexDirection='column'
justifyContent='flex-end'
alignItems='center'
p={2}
cursor='pointer'
_hover={{
bgColor: 'primary.50',
}}
_active={{
bgColor: 'primary.100',
}}
onClick={() => handleOptionClick(option)}
>
<Image src={option.img} />
{t(`options.${option.labelTKey}`)}
</ListItem>
))}
</Select>
</List>
</PopoverBody>
</PopoverContent>
</Popover>
</Box>
);
},
);

View File

@ -1,3 +1,15 @@
import {
CoupeImg,
CrossoverImg,
HatchbackImg,
LiftbackImg,
MinivanImg,
PickupImg,
SedanImg,
SportsCarImg,
StationWagonImg,
SuvImg
} from "../../../../assets/images";
import { Car } from "../../../../models/landing";
import { CarBodySelectOption } from "./types";
@ -5,43 +17,53 @@ import { CarBodySelectOption } from "./types";
export const carBodySelectOptions: CarBodySelectOption[] = [
{
value: Car.BodyStyle.SEDAN,
labelTKey: 'sedan'
labelTKey: 'sedan',
img: SedanImg
},
{
value: Car.BodyStyle.HATCHBACK,
labelTKey: 'hatchback'
labelTKey: 'hatchback',
img: HatchbackImg
},
{
value: Car.BodyStyle.CROSSOVER,
labelTKey: 'crossover'
labelTKey: 'crossover',
img: CrossoverImg
},
{
value: Car.BodyStyle.SUV,
labelTKey: 'suv'
labelTKey: 'suv',
img: SuvImg
},
{
value: Car.BodyStyle.STATION_WAGON,
labelTKey: 'station-wagon'
labelTKey: 'station-wagon',
img: StationWagonImg
},
{
value: Car.BodyStyle.COUPE,
labelTKey: 'coupe'
labelTKey: 'coupe',
img: CoupeImg
},
{
value: Car.BodyStyle.MINIVAN,
labelTKey: 'minivan'
labelTKey: 'minivan',
img: MinivanImg
},
{
value: Car.BodyStyle.PICKUP,
labelTKey: 'pickup'
labelTKey: 'pickup',
img: PickupImg
},
{
value: Car.BodyStyle.LIFTBACK,
labelTKey: 'liftback'
labelTKey: 'liftback',
img: LiftbackImg
},
{
value: Car.BodyStyle.SPORTS_CAR,
labelTKey: 'sports-car'
labelTKey: 'sports-car',
img: SportsCarImg
},
{
value: Car.BodyStyle.OTHER,

View File

@ -14,4 +14,5 @@ export type CarBodySelectOption = {
'liftback' |
'sports-car' |
'other';
img?: string;
};