indicator 기능 추가
This commit is contained in:
@@ -12,36 +12,47 @@ const SpottableComponent = Spottable("button");
|
|||||||
|
|
||||||
export default function Indicator() {
|
export default function Indicator() {
|
||||||
const images = useSelector((state) => state.main.productImages);
|
const images = useSelector((state) => state.main.productImages);
|
||||||
|
|
||||||
const [selectedImage, setSelectedImage] = useState(null);
|
const [selectedImage, setSelectedImage] = useState(null);
|
||||||
const [selectedIndex, setSelectedIndex] = useState(0);
|
const [selectedIndex, setSelectedIndex] = useState(0);
|
||||||
|
const [visibleImages, setVisibleImages] = useState([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (images && images.length > 0) {
|
if (images && images.length > 0) {
|
||||||
setSelectedImage(images[0]);
|
setSelectedImage(images[0]);
|
||||||
|
setVisibleImages(images.slice(0, 3));
|
||||||
}
|
}
|
||||||
}, [images]);
|
}, [images]);
|
||||||
|
|
||||||
const handlePrevClick = () => {
|
const handleUpClick = () => {
|
||||||
setSelectedImage((prevSelectedImage) => {
|
setSelectedImage((prevSelectedImage) => {
|
||||||
const currentIndex = images.indexOf(prevSelectedImage);
|
const currentIndex = images.indexOf(prevSelectedImage);
|
||||||
return currentIndex === 0
|
const prevIndex = currentIndex === 0 ? 0 : currentIndex - 1;
|
||||||
? images[images.length - 1]
|
if (prevIndex >= 0 && prevIndex <= images.length - 3) {
|
||||||
: images[currentIndex - 1];
|
setVisibleImages(images.slice(prevIndex, prevIndex + 3));
|
||||||
|
}
|
||||||
|
setSelectedIndex(prevIndex);
|
||||||
|
return images[prevIndex];
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleNextClick = () => {
|
const handleDownClick = () => {
|
||||||
setSelectedImage((prevSelectedImage) => {
|
setSelectedImage((prevSelectedImage) => {
|
||||||
const currentIndex = images.indexOf(prevSelectedImage);
|
const currentIndex = images.indexOf(prevSelectedImage);
|
||||||
return currentIndex === images.length - 1
|
const nextIndex =
|
||||||
? images[0]
|
currentIndex === images.length - 1 ? currentIndex : currentIndex + 1;
|
||||||
: images[currentIndex + 1];
|
if (nextIndex >= 2 && nextIndex <= images.length - 1) {
|
||||||
|
setVisibleImages(images.slice(nextIndex - 2, nextIndex + 1));
|
||||||
|
}
|
||||||
|
setSelectedIndex(nextIndex);
|
||||||
|
return images[nextIndex];
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleItemClick = (image, index) => {
|
const handleItemClick = (image) => {
|
||||||
|
const globalIndex = images.indexOf(image);
|
||||||
setSelectedImage(image);
|
setSelectedImage(image);
|
||||||
setSelectedIndex(index);
|
setSelectedIndex(globalIndex);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -49,30 +60,31 @@ export default function Indicator() {
|
|||||||
<div>
|
<div>
|
||||||
{images && <img src={selectedImage} alt="" className={css.thumbnail} />}
|
{images && <img src={selectedImage} alt="" className={css.thumbnail} />}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div className={css.indicator}>
|
||||||
<SpottableComponent
|
<SpottableComponent onClick={handleUpClick} className={css.upButton} />
|
||||||
onClick={handlePrevClick}
|
{visibleImages &&
|
||||||
className={css.upButton}
|
visibleImages.map((image, index) => (
|
||||||
/>
|
<Image
|
||||||
{images &&
|
key={index}
|
||||||
images
|
src={image}
|
||||||
.slice(0, 3)
|
alt={""}
|
||||||
.map((image, index) => (
|
onClick={() => handleItemClick(image, index)}
|
||||||
<Image
|
selected={selectedIndex === images.indexOf(image)}
|
||||||
key={index}
|
className={classNames(
|
||||||
src={image}
|
css.image,
|
||||||
alt={""}
|
selectedIndex === images.indexOf(image) && css.selected
|
||||||
onClick={() => handleItemClick(image, index)}
|
)}
|
||||||
selected={selectedIndex === index}
|
>
|
||||||
className={classNames(
|
<span
|
||||||
css.image,
|
className={
|
||||||
selectedIndex === index && css.selected
|
selectedIndex === images.indexOf(image) && css.checkIcon
|
||||||
)}
|
}
|
||||||
/>
|
/>
|
||||||
))}
|
</Image>
|
||||||
|
))}
|
||||||
<SpottableComponent
|
<SpottableComponent
|
||||||
className={css.downButton}
|
className={css.downButton}
|
||||||
onClick={handleNextClick}
|
onClick={handleDownClick}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -32,9 +32,40 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.image {
|
.image {
|
||||||
|
.size(@w: 144px , @h: 144px);
|
||||||
margin: 0 0 6px 0;
|
margin: 0 0 6px 0;
|
||||||
border: solid 1px #dadada;
|
border: solid 1px #dadada;
|
||||||
.size(@w: 144px , @h: 144px);
|
position: relative;
|
||||||
|
|
||||||
|
|
||||||
|
&.selected {
|
||||||
|
&:after{
|
||||||
|
.size(@w: 144px , @h: 144px);
|
||||||
|
content:"";
|
||||||
|
position: absolute;
|
||||||
|
background-color: #7a808d;
|
||||||
|
opacity:.7;
|
||||||
|
|
||||||
|
&:after {
|
||||||
|
content: "";
|
||||||
|
.size(@w: 49px , @h: 49px);
|
||||||
|
background-image: url('../../../../assets/icon/ic-check-thumb.svg');
|
||||||
|
background-position: center;
|
||||||
|
background-size: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.checkIcon {
|
||||||
|
.position(@position: absolute, @top: auto, @right: 44px, @bottom: 48px, @left: auto);
|
||||||
|
.size(@w: 49px , @h: 49px);
|
||||||
|
|
||||||
|
background-image: url('../../../../assets/icon/ic-check-thumb.svg');
|
||||||
|
background-position: center;
|
||||||
|
background-size: cover;
|
||||||
|
|
||||||
|
z-index: 20;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,13 @@
|
|||||||
import React, { useEffect } from 'react';
|
import React, { useEffect } from "react";
|
||||||
|
|
||||||
import {
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
useDispatch,
|
|
||||||
useSelector,
|
|
||||||
} from 'react-redux';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getProductGroup,
|
getProductGroup,
|
||||||
getProductOption,
|
getProductOption,
|
||||||
} from '../../../actions/productActions';
|
} from "../../../actions/productActions";
|
||||||
import OptionGroup from '../components/optionTypes/OptionGroup';
|
import OptionGroup from "../components/optionTypes/OptionGroup";
|
||||||
import css from './ProductOption.module.less';
|
import css from "./ProductOption.module.less";
|
||||||
|
|
||||||
export default function ProductOption({ selectedPatnrId, selectedPardtId }) {
|
export default function ProductOption({ selectedPatnrId, selectedPardtId }) {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@@ -18,9 +15,6 @@ export default function ProductOption({ selectedPatnrId, selectedPardtId }) {
|
|||||||
const productOpionInfos = useSelector((state) => state.product.prdtOptInfo);
|
const productOpionInfos = useSelector((state) => state.product.prdtOptInfo);
|
||||||
const groupInfos = useSelector((state) => state.product.groupInfo);
|
const groupInfos = useSelector((state) => state.product.groupInfo);
|
||||||
|
|
||||||
console.log("# productOpionInfos", productOpionInfos);
|
|
||||||
console.log("# groupInfos", groupInfos);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(
|
dispatch(
|
||||||
getProductOption({
|
getProductOption({
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
.Wrap {
|
.Wrap {
|
||||||
padding-left: 120px;
|
padding-left: 120px;
|
||||||
.size(@w: 894px, @h: 930px);
|
.size(@w: 894px, @h: 930px);
|
||||||
|
|
||||||
.order {
|
.order {
|
||||||
.font(@fontFamily: @baseFontBold, @fontSize: 30px);
|
.font(@fontFamily: @baseFontBold, @fontSize: 30px);
|
||||||
.size(@w: 560px, @h: 68px);
|
.size(@w: 560px, @h: 68px);
|
||||||
@@ -12,8 +11,7 @@
|
|||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
line-height: 68px;
|
line-height: 68px;
|
||||||
background-color: #f2f2f2;
|
background-color: #f2f2f2;
|
||||||
|
margin: 10px 0 0 10px;
|
||||||
margin-top: 10px;
|
|
||||||
> div {
|
> div {
|
||||||
padding: 0 33px 0 30px;
|
padding: 0 33px 0 30px;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user