You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
3.0 KiB

3 years ago
import React, { useState } from "react";
import "./CounterDesign.scss";
import blackDisLikeIcon from "../../assets/icons/black-dislike-icon.svg";
import blackLikeIcon from "../../assets/icons/black-like-icon.svg";
import decrementCounterIcon from "../../assets/icons/decrement-counter-icon.svg";
import incrementCounterIcon from "../../assets/icons/increment-counter-icon.svg";
// {deliveryIcon && (
// <img src={blackDeliveryIcon} alt="" className="ml-1 w-3" />
// )}
const CounterDesign = ({
counterColor,
counterIncreaseBtn,
counterDecreaseBtn,
likeBtn,
}) => {
3 years ago
const [count, setCount] = useState(0);
return (
<section className="w-11/12 mx-auto p-4 bg-white rounded-md shadow-md my-8">
<div className="flex items-center justify-between mb-6">
<h2 className="text-base bg-blue-300 rounded-full shadow-md shadow-blue-900 text-white p-2">
طراحی کانتر
</h2>
</div>
3 years ago
<div className="my-4">
<p className="leading-10">
نام این کامپوننت
<span className="bg-blue-400 text-white rounded shadow-sm px-2 py-1 mx-2">
counterDesign
</span>
است.
</p>
</div>
3 years ago
{/* counter design */}
3 years ago
<div className="flex flex-col items-center justify-center">
{likeBtn && (
<div className="flex items-center">
3 years ago
<img
src={blackLikeIcon}
alt=""
3 years ago
className="w-8 mb-4 cursor-pointer pointer transition delay-150 duration-300 ease-in-out hover:-translate-y-2"
3 years ago
onClick={() => setCount(count + 1)}
/>
<img
src={blackDisLikeIcon}
alt=""
3 years ago
className="w-8 mb-4 cursor-pointer transition delay-150 duration-300 ease-in-out hover:translate-y-2"
3 years ago
onClick={() => setCount(count - 1)}
/>
</div>
)}
{counterIncreaseBtn && (
3 years ago
<img
src={incrementCounterIcon}
alt=""
3 years ago
className="w-8 mb-4 cursor-pointer transition delay-150 duration-300 ease-in-out hover:-translate-y-2"
3 years ago
onClick={() => setCount(count + 1)}
/>
)}
<p
3 years ago
className={`text-sm sm:text-base md:text-2xl font-bold text-counterColor`}
style={count > 0 ? { color: "green" } : { color: "red" }}
>
3 years ago
{count}
</p>
{counterDecreaseBtn && (
3 years ago
<img
src={decrementCounterIcon}
alt=""
3 years ago
className="w-8 mt-4 cursor-pointer transition delay-150 duration-300 ease-in-out hover:translate-y-2"
3 years ago
onClick={() => setCount(count - 1)}
/>
)}
</div>
</section>
);
};
export default CounterDesign;
// color classes that i defined in tailwind.config.js and we can use for text color:
// ----> text-lightBlueTextColor
// ----> text-darkRedTextColor
CounterDesign.defaultProps = {
counterColor: "text-darkRedTextColor",
// for icons
3 years ago
likeBtn: true,
3 years ago
counterIncreaseBtn: true,
counterDecreaseBtn: true,
};