React Hamburger Menu - reactjs

I am new to react and still just grasping some of the concepts. I am trying to add a hamburger menu component, which adds fine, but I am confused about how to add a menu to the hamburger component itself.
Here is the code
render() {
const [isOpen, setOpen] = useState(false);
const {
installationsSection,
selectedInstallationIndex,
} = this.state;
return (
<div className="apollo-premier">
<Helmet>
<title>Apollo Premier</title>
<meta property="og:title" content="Apollo Premier" />
</Helmet>
{this.renderHeader(true)}
{this.renderHeader(false)}
<div className="content">
<div className="hero-container">
<img className="background" src={PremierHeroBackgroundAnimated} />
<img className="paint-background" src={PremierHeroPaint} />
<div className="text">
<p className="large">Breakthrough technology meets high-end design</p>
<div className="divider"><div></div></div>
<p>Apollo Premier is an elevated patent protected digital display for those who want to introduce the finest digital art into their home or business.</p>
<p>Apollo Premier houses your digital motion art collection to bring digital into a physical environment to enjoy your digital library.</p>
<p>A superior display experience, completely customized to each space and integrates seamlessly into smart home technology.</p>
</div>
</div>
<div className="section flex center the-process-section">
<div className="left">
<h2>The Process</h2>
<p>This customization process gives you complete control of the layout, functionality, and design of your Premier Display inside your space. We take you through the concept and implementation of each build meticulously from start to finish.</p>
<p>An array of material and layout options are available to select from to create an authentic and unique installation each and every time. The exclusive finishing touches, including lighting, music, power, and framing, can be customized for each setting.</p>
<div className="cta yellow">Inquire within</div>
</div>
<div className="right">
{/* <div className="the-process-steps">
<div className="the-process-step">
<img src="http://placehold.it/160x160" />
<p>Lorem ipsum dolor sit amet, consectetur</p>
</div>
<div className="the-process-step">
<img src="http://placehold.it/160x160" />
<p>Lorem ipsum dolor sit amet, consectetur</p>
</div>
<div className="the-process-step">
<img src="http://placehold.it/160x160" />
<p>Lorem ipsum dolor sit amet, consectetur</p>
</div>
<div className="the-process-step">
<img src="http://placehold.it/160x160" />
<p>Lorem ipsum dolor sit amet, consectetur</p>
</div>
</div> */}
<div className="the-process-placeholders">
<img src={PremierProcessPlaceholder1} />
<img src={PremierProcessPlaceholder2} />
</div>
</div>
</div>
<section className="section center installations">
{installationsSection && installationsSection.installations && <React.Fragment>
<h2>Customize</h2>
<p>Apollo Premier displays are completely bespoke and designed by in-house teams of architects for the most discerning homes and spaces.</p>
<Carousel
className="installations-carousel"
showThumbs={false}
showStatus={false}
showArrows={false}
swipeable={true}
selectedItem={selectedInstallationIndex}
onChange={this.updateSelectedInstallation}
>
{installationsSection.installations.map((installation, i) => <PremierInstallationItem key={i} installation={installation} />)}
</Carousel>
</React.Fragment>}
</section>
<div className="hero-container premier-plus">
<img className="background" src={PremierPlusBackground} />
<img className="paint-background" src={PremierPlusPaint} />
<div className="text">
<img src={ApolloPremierPlusLogo} alt="Apollo Premier Plus" />
<p className="inverted">Apollo Premier+ is the art lover's membership you have been waiting for, packed with exclusive access to events, fairs, artists and their work. A community with like minded individuals passionate about contemporary art.</p>
<div className="cta blue">Inquire for more information</div>
</div>
</div>
<div className="section center membership-benefits">
<h2>Membership<br />Benefits</h2>
<div className="divider"><div></div></div>
<div className="benefits-container">
<div>
<p className="title">Community</p>
<p className="sub-title">Events</p>
<p className="text">Members will enjoy access to prestigious events and member only programming</p>
</div>
<div>
<p className="title">Access</p>
<p className="sub-title">Unleashed Buying Power</p>
<p className="text">Members will have a 24 hour preview window of new digital NFT work before anyone else. </p>
</div>
<div>
<p className="title">Connection</p>
<p className="sub-title">Networking</p>
<p className="text">Meet like minded individuals that can lead to life-changing collaborations and relationships.</p>
</div>
</div>
</div>
</div>
<div className="intro-footer">
<div className="logo">
<img src={ApolloLogo} />
</div>
<p></p>
<p></p>
<p>
215 W. Huron Suite 1
<br />
Chicago, IL 60554
</p>
</div>
{installationsSection && installationsSection.installations && installationsSection.installations.map((installation, i) => <InstallationItemPopup key={i} installation={installation} />)}
</div>
);
}
renderHeader = (fixed: boolean) => {
return (
<div className={'header' + (fixed ? ' fixed' : '')}>
<div className="pencil-banner">
<div className="apollo-logo"><img src={ApolloLogoBlack} alt="Apollo" /></div>
<div className="concierge">
{/* <img src={IconSupportBlack} /> <span>Concierge</span> */}
</div>
<div className="contact">
<span>+1-877-790-1411</span> <span className="divider">|</span> Contact
</div>
</div>
<div className="nav">
<div className="logo">
<img src={ApolloPremierLogo} alt="Apollo Premier" />
</div>
<div className="nav-links">
<Hamburger toggled={isOpen} toggle={setOpen}>
Apollo App
Apollo Art
Apollo Premier
</Hamburger>
<div>
</div>
</div>
</div>
</div>
);
}
}
Hamburger is obviously where the menu is created.
But I am unable to get a drop down of the links:

I get a hooks error when I try the above code
render() {
const [isOpen, setOpen] = useState(false);
^ Since you're defining a render() method, it means you have a class component. Hooks (like useState) are supposed to be used from within function components.
You don't need hooks in class component, you can simply use this.setState() method to update state and life cycle methods in place of other hooks.

Related

BootStrap 5 React Js 4 products in a row not getting displayed

I'm a beginner in React Js, and I'm using React Js with BootStrap 5.2.0
My product cards are not getting displayed in a row
I want to display 4 product cards in a row.
Adding Codes:
Home Page code:
<div className="container-fluid mb-2">
<Carousel />
<div className="mt-2">
<div className="row">
<div className="col-md-2">
<GetAllCategories />
</div>
<div className="col-md-10">
<div className="row row-cols-1 row-cols-md-4 g-4">
<div className="col">
{products.map((product) => {
return <ProductCard item={product} />;
})}
</div>
</div>
</div>
</div>
</div>
</div>
PRODUCT CARD CODE:
const ProductCard = (product) => {
return (
<div class="card border-color rounded-card card-hover product-card custom-bg">
<img
src={"http://localhost:8080/api/product/" + product.item.imageName}
class="card-img-top rounded mx-auto d-block m-2"
alt="img"
style={{
maxHeight: "270px",
maxWidth: "100%",
width: "auto",
}}
/>
<div class="card-body text-color">
<h5 class="card-title d-flex justify-content-between">
<div>
<b>{product.item.title}</b>
</div>
<CategoryNavigator
item={{
id: product.item.category.id,
title: product.item.category.title,
}}
/>
</h5>
<p className="card-text">
<b>{product.item.description}</b>
</p>
</div>
<div class="card-footer">
<div className="text-center text-color">
<p>
<span>
<h4>Price : ₹{product.item.price}</h4>
</span>
</p>
</div>
<div className="d-flex justify-content-between">
<Link
to={`/product/${product.item.id}/category/${product.item.category.id}`}
className="btn bg-color custom-bg-text"
>
Add to Cart
</Link>
<p class="text-color">
<b>
<i>Stock :</i> {product.item.quantity}
</b>
</p>
</div>
</div>
</div>
);
};
export default ProductCard;
From the past 4 days, I'm struggling to resolve this issue.
Please help me to fix this.
Thank You
You need to move <div className="col"> from home page to ProductCard as first element in return statement. Sample code at https://codesandbox.io/s/falling-thunder-swzukd

Alignment with Tailwind and React

I'm trying to get two different visualizations to properly sit next to each other.
This is the current styling...
<div className="flex flex-col md:flex-row" >
<div className="w-full md:w-2/3">
<div className="text-center mt-4 flex justify-center items-center">
<h1 className="text-blue-500 text-lg font-semibold mr-5">
{format(new Date(selectedDate), 'do, MMMM - yyyy')}{' '}
</h1>
{isLoading && <Loader />}
</div>
<div>
<div className = "grid-cols-2 grid-flow-col" >
<div className = "grid-cols-1">
<h3 className="capitalize">Moodmap Daily Index</h3>
<Overview data={lineGraphData} timing={settingsData} />
</div>
<div>
<Expressions data={expressionsData} />
</div>
</div>
</div>
<div style={{ height: 100, width: 1000 }}>
<SubstanceDetails
fetchSubstances={fetchSubstances}
loading={loading}
data={data}
/>
</div>
</div>
</div>
For some reason when it renders, although I've made a bunch of changes, it comes out like this,
I want them to sit horizontally, with the bottom graph on the right hand side, ideally with the line graph a lot larger, taking up say 2/3. Unsure why this bug keeps happening.
You need to create a grid container by including the grid className in the element where you specify your grid columns:
<div className = "grid-cols-2 grid-flow-col" >
should become:
<div className = "grid grid-cols-2 grid-flow-col" >
https://tailwindcss.com/docs/display#grid
Note, to debug this you could have used the inspector to see that there was no grid container in your output.

React grid layout not working with firebase

I changed my code so that it would bring in the information from cloud firestore instead of hardcoding it. This is my old code without firebase:
<div className="grid">
<div className="grid-child">
<img className="subImg" src={amsterdam}></img>
<p className="subImgTitle">Amsterdam</p>
<p className="subImgText">Hotels from £?</p>
</div>
<div className="grid-child">
<img className="subImg" src={london}></img>
<p className="subImgTitle">London</p>
<p className="subImgText">Hotels from £?</p>
</div>
<div className="grid-child">
<img className="subImg" src={madrid}></img>
<p className="subImgTitle">Madrid</p>
<p className="subImgText">Hotels from £?</p>
</div>
<div className="grid-child">
<img className="subImg" src={paris}></img>
<p className="subImgTitle">Paris</p>
<p className="subImgText">Hotels from £?</p>
</div>
</div>
And this is my new code with firebase:
destinations?.map(destination => {
return (
<div className="grid">
<div className="grid-child">
<img className="subImg" src={destination.img}></img>
<p className="subImgTitle">{destination.title}</p>
<p className="subImgText">Hotels from £{destination.price}</p>
</div>
</div>
)
})
In the original code, the images are all in a row however now they are all in one column. I am not too sure how to fix this so any help would be greatly appreciated. Thanks :)
If you compare the DOM rendered by each example, you will see that the problem is that in the first example you have a single <div className="grid"> but in the second you wrap each image in <div className="grid">. To fix this, just be sure to create only one grid:
<div className="grid">
{ destinations?.map(destination => {
return (
<div className="grid-child">
<img className="subImg" src={destination.img}></img>
<p className="subImgTitle">{destination.title}</p>
<p className="subImgText">Hotels from £{destination.price}</p>
</div>
)
})
}
</div>
As a next step, consider refactoring a GridChild component that encapsulates the HTML for each image in the grid.

How to pass a ref into a class function

I'm making a single-page website and I want to use refs to tell the code where to scroll when a button is clicked. These buttons should scroll to a specific part of the website. I am using this code to scroll to a specific div ref in the window. Specifically, I call scrollToRef() to scroll to the homeRef div. Is there anyway I can pass a ref parameter into scrollToRef() so I can specify which ref to scroll to?
class App extends Component {
constructor(props) {
super(props);
this.aboutRef = React.createRef();
this.demoRef = React.createRef();
this.homeRef = React.createRef();
}
scrollToRef = () => window.scrollTo(0, this.homeRef.current.offsetTop);
render() {
return (
<div className="home-page">
<header className="home-page-header">
<div className="home-page-logo">
<img src={logo} alt="company logo" width="200vh" height="40" />
</div>
<ul className="home-page-links">
<li><button onClick={this.scrollToRef}>Home</button></li>
<li><button >About</button></li>
<li><button >Demo</button></li>
<li><button>Contact</button></li>
</ul>
</header>
<div className="home-page-background" ref={this.homeRef}>
<section className="website-links">
<div>
<button >Home</button>
</div>
<div>
<button >Demo</button>
</div>
</section>
</div>
<div className="about" ref={this.aboutRef}>
<ul>
<li className="orange">
<div>
<h1>Lorem ipsum</h1>
<h3>lorem ipsum lorem ipsum lorem ipsum</h3>
</div>
<div>
<img src={blank} />
</div>
</li>
<li className="blue">
<div>
<img src={blank} />
</div>
<div>
<h1>Lorem ipsum</h1>
<h3>lorem ipsum lorem ipsum lorem ipsum</h3>
</div>
</li>
<li className="orange">
<div>
<h1>Lorem ipsum</h1>
<h3>lorem ipsum lorem ipsum lorem ipsum</h3>
</div>
<div>
<img src={blank} />
</div>
</li>
<li className="blue">
<div>
<img src={blank} />
</div>
<div>
<h1>Lorem ipsum</h1>
<h3>lorem ipsum lorem ipsum lorem ipsum</h3>
</div>
</li>
</ul>
</div>
<div className="virtual-demo" ref={this.demoRef}>
<h1>Demo</h1>
<figure>
<img src={blank} />
<figcaption>Testing image</figcaption>
</figure>
</div>
</div>
);
}
}
Like this?
scrollToRef = (ref) => window.scrollTo(0, ref.current.offsetTop);
<li><button onClick={() => this.scrollToRef(this.homeRef)}>Home</button></li>
You can simply use HTML to do this instead of use JavaScript:
<li>Home</li>
<div className="home-page-background" id="home">

Set the number of lines of the title React

How can I edit the title lines by setting it to two lines?
In the current situation, each word is shown on one line. Instead, I wish the first word "broadcaster" was on one line, while the other "control panels" on the bottom line.
This is my code.
function IndexHeader() {
return (
<>
<div
className="page-header section-dark"
style={{
backgroundImage:
"url(" + require("assets/img/background.jpg") + ")"
}}
>
<div className="filter" />
<div className="content-center">
<Container>
<div className="title-brand">
<h1 className="presentation-title">Broadcaster control panel</h1>
</div>
<h2 className="presentation-subtitle text-center">
Pannello di controllo degli spot AdEx
</h2>
</Container>
</div>
</div>
</>
);
}
export default IndexHeader;
Thanks in advance to those who can help me!
You can try this.
<div className="title-brand">
<h1 className="presentation-title">Broadcaster</h1>
<h1 className="presentation-title">control panel</h1>
</div>
or
<div className="title-brand">
<h1 className="presentation-title">Broadcaster <br/> control panel </h1>
</div>
and you can handle that using CSS.

Resources