'Alignment is not proper in Next.js using chakra UI
I am new to Nexxt.js and recently familiar with chakra UI. I was trying to build a Project using Nextjs and Chakra UI. But my alignment are not proper as i wanted. So my structure is that
1-6-1-6
- first a house picture for rental homes
- then 6 houses which are taking from api call.
- Then again a house picture for buying home.
- then 6 picture for house of buying option.
i have added navbar and footer.
My output is same but not the structure. Rental homes
the same is for buying ones.
i want this to come as
correct structure renting homes 6 photos
repo link - https://github.com/mohitRana-04/React-Project/tree/main/real-estate
Navbar.jsx
import Link from "next/link";
import {
Menu,
MenuButton,
MenuList,
MenuItem,
IconButton,
Flex,
Box,
Spacer,
} from "@chakra-ui/react";
import { FcMenu, FcHome, FcAbout } from "react-icons/fc";
import { BsSearch } from "react-icons/bs";
import { FiKey } from "react-icons/fi";
const Navbar = () => (
<Flex p="2" borderBottom="1px" borderColor="gray.100">
<Box fontSize="3xl" color="blue.400" fontWeight="bold">
<Link href="/" paddingLeft="2">
Realtor
</Link>
</Box>
<Spacer />
<Box>
<Menu>
<MenuButton
as={IconButton}
icon={<FcMenu />}
variant="outlined"
color="red.400"
/>
<MenuList>
<Link href="/" passHref>
<MenuItem icon={<FcHome />}>Home</MenuItem>
</Link>
<Link href="/search" passHref>
<MenuItem icon={<BsSearch />}>Search</MenuItem>
</Link>
<Link href="/search?purpose=for-sale" passHref>
<MenuItem icon={<FcAbout />}>Buy Property</MenuItem>
</Link>
<Link href="/search?purpose=for-sale" passHref>
<MenuItem icon={<FiKey />}>Rent Property</MenuItem>
</Link>
</MenuList>
</Menu>
</Box>
</Flex>
);
export default Navbar;
Layout.jsx
import Head from "next/head";
import { Box } from "@chakra-ui/react";
import Navbar from "./Navbar";
import Footer from "./Footer";
const Layout = ({ children }) => (
<>
<Head>
<title>Real Estate</title>
</Head>
<Box maxWidth="120px" m="auto">
<header>
<Navbar />
</header>
<main>{children}</main>
<footer>
<Footer />
</footer>
</Box>
</>
);
export default Layout;
_app.js
import "../styles/globals.css";
import Router from "next/router";
import Head from "next/head";
import NProgress from "nprogress";
import { ChakraProvider } from "@chakra-ui/react";
import Layout from "../components/Layout";
function MyApp({ Component, pageProps }) {
return (
<>
<Head></Head>
<ChakraProvider>
<Layout>
<Component {...pageProps} />
</Layout>
</ChakraProvider>
</>
);
}
export default MyApp;
property.jsx
import React from "react";
import Link from "next/link";
import Image from "next/image";
import { Box, Flex, Text, Avatar } from "@chakra-ui/react";
import { FaBed, FaBath } from "react-icons/fa";
import { BsGridFill } from "react-icons/bs";
import { GoVerified } from "react-icons/go";
import millify from "millify";
import DefaultImage from "../assets/images/download.jpg";
const Property = ({
property: {
coverPhoto,
price,
rentFrequency,
rooms,
title,
baths,
area,
agency,
isVerified,
externalID,
},
}) => (
<Link href={`/property/$(externalID)`} passHref>
<Flex
flexWrap="wrap"
w="420"
p="5"
paddingTop="0"
justifyContent="flex-start"
cursor="pointer"
>
<Box>
<Image
src={coverPhoto ? coverPhoto.url : DefaultImage}
width={400}
height={260}
alt="house"
/>
</Box>
<Box w="full">
<Flex paddingTop="2" alignItems="center" justifyContent="space-between">
<Flex alignItems="center">
<Box paddingRight="3" color="green.300">
{isVerified && <GoVerified />}
</Box>
<Text fontWeight="bold" fontSize="lg">
AED {millify(price)}
{rentFrequency && `/${rentFrequency}`}
</Text>
</Flex>
<Box>
<Avatar size="sm" src={agency?.logo?.url} />
</Box>
</Flex>
<Flex
alignItems="center"
p="1"
justifyContent="space-between"
w="250px"
color="blue.400"
>
{rooms} <FaBed /> | {baths} <FaBath /> | {millify(area)} sqft{" "}
<BsGridFill />
</Flex>
<Text fontSize="lg">
{title.length > 30 ? `${title.substring(0, 30)}...` : title}
</Text>
</Box>
</Flex>
</Link>
);
export default Property;
index.js
import Link from "next/link";
import Image from "next/image";
import { Flex, Box, Button, Text } from "@chakra-ui/react";
import { baseUrl, fetchApi } from "../utils/fetchApi";
import Property from "../components/Property";
const Banner = ({
purpose,
title1,
title2,
desc1,
desc2,
buttonText,
linkName,
imageUrl,
}) => (
<Flex flexWrap="wrap" justifyContent="center" alignItems="center" m="10">
<Image src={imageUrl} width={500} height={300} alt="banner" />
<Box p="5">
<Text color="gray.500" fontSize="sm" fontWeight="medium">
{purpose}
</Text>
<Text fontSize="3xl" fontWeight="bold">
{title1} <br /> {title2}
</Text>
<Text
fontSize="lg"
paddingTop="3"
paddingBottom="3"
color="gray.700"
fontWeight="medium"
>
{desc1} <br /> {desc2}
</Text>
<Button fontSize="xl">
<Link href={linkName}>{buttonText}</Link>
</Button>
</Box>
{/* he */}
</Flex>
);
export default function Home({ propertiesForSale, propertiesForRent }) {
// console.log(propertiesForSale, propertiesForRent);
return (
<Box>
<h1>Hello</h1>
<Banner
purpose="RENT A HOME"
title1="Rental Homes for"
title2="Everyone"
desc1=" Explore from Apartments, builder floors, villas"
desc2="and more"
buttonText="Explore Renting"
linkName="/search?purpose=for-rent"
imageUrl="https://bayut-production.s3.eu-central-1.amazonaws.com/image/145426814/33973352624c48628e41f2ec460faba4"
/>
<Flex flexWrap="wrap">
{propertiesForRent.map((property) => (
<Property property={property} key={property.id} />
))}
</Flex>
<Banner
purpose="BUY A HOME"
title1=" Find, Buy & Own Your"
title2="Dream Home"
desc1=" Explore from Apartments, land, builder floors,"
desc2=" villas and more"
buttonText="Explore Buying"
linkName="/search?purpose=for-sale"
imageUrl="https://bayut-production.s3.eu-central-1.amazonaws.com/image/110993385/6a070e8e1bae4f7d8c1429bc303d2008"
/>
<Flex flexWrap="wrap">
{propertiesForSale.map((property) => (
<Property property={property} key={property.id} />
))}
</Flex>
</Box>
);
}
export async function getStaticProps() {
const propertyForSale = await fetchApi(
`${baseUrl}/properties/list?locationExternalIDs=5002&purpose=for-sale&hitsPerPage=6`
);
const propertyForRent = await fetchApi(
`${baseUrl}/properties/list?locationExternalIDs=5002&purpose=for-rent&hitsPerPage=6`
);
return {
props: {
propertiesForSale: propertyForSale?.hits,
propertiesForRent: propertyForRent?.hits,
},
};
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
