Skip to content

Commit 511aa8c

Browse files
Created - Feature Section using map function
1 parent 0f5595a commit 511aa8c

File tree

4 files changed

+159
-0
lines changed

4 files changed

+159
-0
lines changed

public/images/isloading-main.jpg

2.47 KB
Loading

src/Home.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react'
22
import HeroSection from './components/HeroSection'
33
import Services from './components/Services'
44
import Trusted from './components/Trusted'
5+
import FeatureProduct from './components/FeatureProduct'
56

67
const Home = () => {
78
const data = {
@@ -11,6 +12,7 @@ const Home = () => {
1112
return (
1213
<>
1314
<HeroSection myData={data}/>
15+
<FeatureProduct/>
1416
<Services/>
1517
<Trusted/>
1618
</>

src/components/FeatureProduct.js

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import React from 'react'
2+
import { useProductContext } from '../context/productcontext'
3+
import styled from 'styled-components'
4+
import Product from './Product'
5+
6+
const FeatureProduct = () => {
7+
8+
const {isLoading, featureProducts} = useProductContext()
9+
console.log(featureProducts)
10+
11+
if(isLoading){
12+
return <div>
13+
<img src="/images/isloading-main.jpg" alt='...loading' style={{width:75, display:'block', marginLeft:'auto', marginRight:'auto' }}></img>
14+
</div>
15+
}
16+
17+
return (
18+
<Wrapper className="section">
19+
<div className="container">
20+
<div className="intro-data">Check Now!</div>
21+
<div className="common-heading">Our Feature Services</div>
22+
<div className="grid grid-three-column">
23+
{featureProducts.map((curElem) => {
24+
return <Product key={curElem.id} {...curElem} />;
25+
})}
26+
</div>
27+
</div>
28+
</Wrapper>
29+
)
30+
}
31+
32+
const Wrapper = styled.section`
33+
padding: 9rem 0;
34+
background-color: ${({ theme }) => theme.colors.bg};
35+
36+
.container {
37+
max-width: 120rem;
38+
}
39+
40+
figure {
41+
width: auto;
42+
display: flex;
43+
justify-content: center;
44+
align-items: center;
45+
position: relative;
46+
overflow: hidden;
47+
transition: all 0.5s linear;
48+
&::after {
49+
content: "";
50+
position: absolute;
51+
top: 0;
52+
left: 0;
53+
width: 0%;
54+
height: 100%;
55+
background-color: rgba(0, 0, 0, 0.5);
56+
transition: all 0.2s linear;
57+
cursor: pointer;
58+
}
59+
&:hover::after {
60+
width: 100%;
61+
}
62+
&:hover img {
63+
transform: scale(1.2);
64+
}
65+
img {
66+
max-width: 90%;
67+
margin-top: 1.5rem;
68+
height: 20rem;
69+
transition: all 0.2s linear;
70+
}
71+
72+
.caption {
73+
position: absolute;
74+
top: 15%;
75+
right: 10%;
76+
text-transform: uppercase;
77+
background-color: ${({ theme }) => theme.colors.bg};
78+
color: ${({ theme }) => theme.colors.helper};
79+
padding: 0.8rem 2rem;
80+
font-size: 1.2rem;
81+
border-radius: 2rem;
82+
}
83+
}
84+
85+
.card {
86+
background-color: #fff;
87+
border-radius: 1rem;
88+
89+
.card-data {
90+
padding: 0 2rem;
91+
}
92+
93+
.card-data-flex {
94+
margin: 2rem 0;
95+
display: flex;
96+
justify-content: space-between;
97+
align-items: center;
98+
}
99+
100+
h3 {
101+
color: ${({ theme }) => theme.colors.text};
102+
text-transform: capitalize;
103+
}
104+
105+
.card-data--price {
106+
color: ${({ theme }) => theme.colors.helper};
107+
}
108+
109+
.btn {
110+
margin: 2rem auto;
111+
background-color: rgb(0 0 0 / 0%);
112+
border: 0.1rem solid rgb(98 84 243);
113+
display: flex;
114+
justify-content: center;
115+
align-items: center;
116+
117+
&:hover {
118+
background-color: rgb(98 84 243);
119+
}
120+
121+
&:hover a {
122+
color: #fff;
123+
}
124+
a {
125+
color: rgb(98 84 243);
126+
font-size: 1.4rem;
127+
}
128+
}
129+
}
130+
`;
131+
132+
export default FeatureProduct

src/components/Product.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react'
2+
import { NavLink } from 'react-router-dom'
3+
4+
const Product = (curElem) => {
5+
const { id, name, image, price, category } = curElem
6+
return (
7+
<NavLink to={`/singleproduct/${id}`}>
8+
<div className="card">
9+
<figure>
10+
<img src={image} alt={name} />
11+
<figcaption className="caption">{category}</figcaption>
12+
</figure>
13+
14+
<div className="card-data">
15+
<div className="card-data-flex">
16+
<h3>{name}</h3>
17+
<p className="card-data--price">{price}</p>
18+
</div>
19+
</div>
20+
</div>
21+
</NavLink>
22+
)
23+
}
24+
25+
export default Product

0 commit comments

Comments
 (0)