feat: add image to car body style select option (#55)
BIN
src/assets/images/car-body-type/coupe.webp
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
src/assets/images/car-body-type/crossover.webp
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
src/assets/images/car-body-type/hatchback.webp
Normal file
After Width: | Height: | Size: 1.9 KiB |
10
src/assets/images/car-body-type/index.ts
Normal 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';
|
BIN
src/assets/images/car-body-type/liftback.webp
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
src/assets/images/car-body-type/minivan.webp
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
src/assets/images/car-body-type/pickup.webp
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
src/assets/images/car-body-type/sedan.webp
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
src/assets/images/car-body-type/sports-car.webp
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
src/assets/images/car-body-type/station-wagon.webp
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
src/assets/images/car-body-type/suv.webp
Normal file
After Width: | Height: | Size: 2.0 KiB |
@ -1 +1,2 @@
|
|||||||
|
export * from './car-body-type';
|
||||||
export { default as DemoVideoPosterImg } from './demo-video-poster.webp';
|
export { default as DemoVideoPosterImg } from './demo-video-poster.webp';
|
@ -1,23 +1,92 @@
|
|||||||
import React, { forwardRef } from 'react';
|
import React, { forwardRef, useState } from 'react';
|
||||||
import { Select, SelectProps } from '@chakra-ui/react';
|
import {
|
||||||
|
Input,
|
||||||
|
Image,
|
||||||
|
InputProps,
|
||||||
|
Box,
|
||||||
|
Popover,
|
||||||
|
PopoverAnchor,
|
||||||
|
PopoverContent,
|
||||||
|
PopoverBody,
|
||||||
|
List,
|
||||||
|
ListItem,
|
||||||
|
} from '@chakra-ui/react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { carBodySelectOptions } from './helper';
|
import { carBodySelectOptions } from './helper';
|
||||||
|
import { CarBodySelectOption } from './types';
|
||||||
|
|
||||||
export const CarBodySelect = forwardRef<HTMLSelectElement, SelectProps>(
|
export const CarBodySelect = forwardRef<HTMLInputElement, InputProps>(
|
||||||
function CarBodySelect(props, ref) {
|
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('~', {
|
const { t } = useTranslation('~', {
|
||||||
keyPrefix: 'dry-wash.order-create.car-body-select',
|
keyPrefix: 'dry-wash.order-create.car-body-select',
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Select ref={ref} placeholder={t('placeholder')} {...props}>
|
<Box width='100%'>
|
||||||
{carBodySelectOptions.map(({ value, labelTKey }, i) => (
|
<Popover
|
||||||
<option key={i} value={value}>
|
isOpen={isDropdownOpen}
|
||||||
{t(`options.${labelTKey}`)}
|
autoFocus={false}
|
||||||
</option>
|
placement='bottom-start'
|
||||||
))}
|
matchWidth
|
||||||
</Select>
|
>
|
||||||
|
<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>
|
||||||
|
))}
|
||||||
|
</List>
|
||||||
|
</PopoverBody>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
</Box>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
import {
|
||||||
|
CoupeImg,
|
||||||
|
CrossoverImg,
|
||||||
|
HatchbackImg,
|
||||||
|
LiftbackImg,
|
||||||
|
MinivanImg,
|
||||||
|
PickupImg,
|
||||||
|
SedanImg,
|
||||||
|
SportsCarImg,
|
||||||
|
StationWagonImg,
|
||||||
|
SuvImg
|
||||||
|
} from "../../../../assets/images";
|
||||||
import { Car } from "../../../../models/landing";
|
import { Car } from "../../../../models/landing";
|
||||||
|
|
||||||
import { CarBodySelectOption } from "./types";
|
import { CarBodySelectOption } from "./types";
|
||||||
@ -5,43 +17,53 @@ import { CarBodySelectOption } from "./types";
|
|||||||
export const carBodySelectOptions: CarBodySelectOption[] = [
|
export const carBodySelectOptions: CarBodySelectOption[] = [
|
||||||
{
|
{
|
||||||
value: Car.BodyStyle.SEDAN,
|
value: Car.BodyStyle.SEDAN,
|
||||||
labelTKey: 'sedan'
|
labelTKey: 'sedan',
|
||||||
|
img: SedanImg
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: Car.BodyStyle.HATCHBACK,
|
value: Car.BodyStyle.HATCHBACK,
|
||||||
labelTKey: 'hatchback'
|
labelTKey: 'hatchback',
|
||||||
|
img: HatchbackImg
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: Car.BodyStyle.CROSSOVER,
|
value: Car.BodyStyle.CROSSOVER,
|
||||||
labelTKey: 'crossover'
|
labelTKey: 'crossover',
|
||||||
|
img: CrossoverImg
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: Car.BodyStyle.SUV,
|
value: Car.BodyStyle.SUV,
|
||||||
labelTKey: 'suv'
|
labelTKey: 'suv',
|
||||||
|
img: SuvImg
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: Car.BodyStyle.STATION_WAGON,
|
value: Car.BodyStyle.STATION_WAGON,
|
||||||
labelTKey: 'station-wagon'
|
labelTKey: 'station-wagon',
|
||||||
|
img: StationWagonImg
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: Car.BodyStyle.COUPE,
|
value: Car.BodyStyle.COUPE,
|
||||||
labelTKey: 'coupe'
|
labelTKey: 'coupe',
|
||||||
|
img: CoupeImg
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: Car.BodyStyle.MINIVAN,
|
value: Car.BodyStyle.MINIVAN,
|
||||||
labelTKey: 'minivan'
|
labelTKey: 'minivan',
|
||||||
|
img: MinivanImg
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: Car.BodyStyle.PICKUP,
|
value: Car.BodyStyle.PICKUP,
|
||||||
labelTKey: 'pickup'
|
labelTKey: 'pickup',
|
||||||
|
img: PickupImg
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: Car.BodyStyle.LIFTBACK,
|
value: Car.BodyStyle.LIFTBACK,
|
||||||
labelTKey: 'liftback'
|
labelTKey: 'liftback',
|
||||||
|
img: LiftbackImg
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: Car.BodyStyle.SPORTS_CAR,
|
value: Car.BodyStyle.SPORTS_CAR,
|
||||||
labelTKey: 'sports-car'
|
labelTKey: 'sports-car',
|
||||||
|
img: SportsCarImg
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: Car.BodyStyle.OTHER,
|
value: Car.BodyStyle.OTHER,
|
||||||
|
@ -14,4 +14,5 @@ export type CarBodySelectOption = {
|
|||||||
'liftback' |
|
'liftback' |
|
||||||
'sports-car' |
|
'sports-car' |
|
||||||
'other';
|
'other';
|
||||||
|
img?: string;
|
||||||
};
|
};
|
||||||
|