Creat Hyperlink For Footer in React - reactjs

So i want to create hyperlinks for my footer which will redirect me to specific links first i used Link but it gives me an error telling me that i cannot use Link outside the Router so help me with that here is my current footer component.
import React from 'react'
import { FontAwesomeIcon } from '#fortawesome/react-fontawesome';
import { faCopyright } from '#fortawesome/free-solid-svg-icons';
import { Row, Col, Container } from 'react-bootstrap';
import logo from '../assets/SE-logo.png';
export const Footer = () => (
<div style={{marginTop:'1em', width:'100%'}}>
<Container fluid>
<Row>
<Col md lg>
<div id="footerFD">
<p style={{fontSize:"40px", fontWeight:"500", color:"#fb7840"}}>Got a project?<br/>
<span style={{fontSize:"30px", fontWeight:"300", color:"#fff"}}>We want to hear about it.</span></p>
<div id="footerSD">
<Row>
<Col lg md id="colF">
<Row>
<Col-4 md lg>
<p style={{fontSize:"20px", fontWeight:"300"}}> (+789) 132 4657</p>
</Col-4>
<Col md lg>
<p style={{fontSize:"20px", fontWeight:"300"}}>example#example.com</p>
</Col>
</Row>
</Col>
</Row>
</div>
</div>
</Col>
<Col md lg>
<div id="footerFD2">
<div>
<img src={logo} alt="logo" id="footerLogo"/>
</div>
<div id="footerSD2">
<Row>
<Col md lg><p>Home</p></Col>
<Col md lg><p>Services</p></Col>
<Col md lg><p>Projects</p></Col>
<Col md lg><p>Contact</p></Col>
</Row>
</div>
</div>
</Col>
</Row>
</Container>
<p style={{marginTop:'1em', width:'100%', textAlign:'center'}}>Developed By <span style={{color:'#fb7840'}}>Hassan Uddin Sheikh</span><br/>All Rights Reserved <FontAwesomeIcon icon={faCopyright}/> 2020</p>
</div>
)

You need to wrap your app in browser router like so:
<BrowserRouter>
<App />
</BrowserRouter>
The link cannot stand on its own without a browser router wrapper somewhere higher up.
Reference: https://reacttraining.com/react-router/web/api/BrowserRouter

I use Nav.Link instead and it works
<Nav>
<Nav.Item>
<Nav.Link href="/"></Nav.Link>
<Nav.Item>
</Nav>

Related

Occupy content space based on the screen size in ReactJS

I have a structure which consists:
an image horizontally stacked with a text array which are vertically stacked like this:
Here is the snippet for the same:
import React from "react";
export default function BoxHeader(props) {
return (
<div style={{ marginTop: `${props.Gap}rem` }}>
<div className="Image-wrapper">
<img
className="Profile-Image-Decorator"
alt=""
src="https://i.redd.it/rm6sqwpmesb41.jpg"
></img>
</div>
<div className="Collapsible-Navbar">
{props.Msg.map((element) => (
<div className="Message-Holder">{element}</div>
))}
</div>
</div>
);
}
What I want to achieve is on reducing the screensize, the text should move below the image, but what I actually get is this:
By using Bootstrap classes I managed to make a responsive navbar... but I wanted the same with my this section as well. Does anyone have any suggestions for the same?
For reproducing goto this link
Use Row and Col components to create responsive grids.
...
import { Row, Col } from "react-bootstrap";
export default function BoxHeader(props) {
return (
<div style={{ marginTop: `${props.Gap}rem` }}>
<div className="Body-wrapper">
<Row>
<Col sm={12} md={6}>
<div className="Image-wrapper">
<img
className="Profile-Image-Decorator"
alt=""
src="https://i.redd.it/rm6sqwpmesb41.jpg"
></img>
</div>
</Col>
<Col sm={12} md={6}>
<div className="Collapsible-Navbar">
{props.Msg.map((element) => (
<div className="Message-Holder">{element}</div>
))}
</div>
</Col>
</Row>
</div>
</div>
);
}

How do I get a react bootstrap card to center vertically?

I have the following code for a card to that I want to center vertically:
import React from 'react';
import {
Card,
CardHeader,
CardBody,
CardTitle,
Row,
Col,
Container
} from "reactstrap";
const Login = () => {
return(
<Container className="d-flex h-100">
<Row className="justify-content-center align-self-center">
<Col>
<Card>
<CardHeader>
<CardTitle>
Login
</CardTitle>
</CardHeader>
<CardBody>
do something
</CardBody>
</Card>
</Col>
</Row>
</Container>
);
};
export default Login;
However the result is as follows:
Anyone have any ideas why it isn't working?
I think what you want is vh-100 for viewport units. I suspect the containing box of Container is not set to take up the viewport
<Container className="d-flex vh-100">
<Row className="m-auto align-self-center">
<Col>
<Card>
<CardHeader>
<CardTitle>Login</CardTitle>
</CardHeader>
<CardBody>do something</CardBody>
</Card>
</Col>
</Row>
</Container>

React Apollo Client Query throwing error "Invalid prop `children` of type `array` supplied to `Query`, expected `function`"

I am working on a React JS project. My app needs to consume GraphQL API. So I am using Apollo client for that. When I use the Query component with ApolloProvider component, it is throwing error. Following is my code.
This is my app.js
import React from "react";
import ReactDOM from "react-dom";
import { createBrowserHistory } from "history";
import { HashRouter, Route, Switch, Redirect } from "react-router-dom";
import AdminLayout from "./layouts/Admin";
import { ApolloProvider } from '#apollo/react-hooks';
import ApolloClient, { gql } from 'apollo-boost';
const client = new ApolloClient({
uri: 'https://48p1r2roz4.sse.codesandbox.io',
});
const hist = createBrowserHistory();
ReactDOM.render(
<ApolloProvider client={client}>
<HashRouter history={hist}>
<Switch>
<Route path="/admin" render={(props) => <AdminLayout {...props} />} />
<Redirect to="/admin/dashboard" />
</Switch>
</HashRouter>
</ApolloProvider>,
document.getElementById("app")
);
As you can see I declare the Apollo client and assign it to the client prop of the ApolloProvider component.
I have a component called, RestaurantForm component that is using GraphQL Query component as follow.
import React from 'react';
import {Button, Card, CardBody, CardFooter, CardHeader, CardTitle, Col, Form, FormGroup, Input, Row} from "reactstrap";
import gql from 'graphql-tag';
import { Query } from 'react-apollo';
const EXCHANGE_RATES_QUERY = gql`
{
rates(currency: "USD") {
currency
rate
}
}
`;
class RestaurantForm extends React.Component {
render() {
return (
<Query query={EXCHANGE_RATES_QUERY}>
{({ data }) => {
<>
<div className="content">
<Row>
<Col md="4">
<Card className="card-user">
<div className="image">
<img
alt="..."
src={"assets/paper-dashboard/img/damir-bosnjak.jpg"}
/>
</div>
<CardBody>
<div className="author">
<a href="#pablo" onClick={(e) => e.preventDefault()}>
<img
alt="..."
className="avatar border-gray"
src={"assets/paper-dashboard/img/mike.jpg"}
/>
<h5 className="title">Chet Faker</h5>
</a>
<p className="description">#chetfaker</p>
</div>
<p className="description text-center">
"I like the way you work it <br />
No diggity <br />I wanna bag it up"
</p>
</CardBody>
<CardFooter>
<hr />
<div className="button-container">
<Row>
<Col className="ml-auto" lg="3" md="6" xs="6">
<h5>
12 <br />
<small>Files</small>
</h5>
</Col>
<Col className="ml-auto mr-auto" lg="4" md="6" xs="6">
<h5>
2GB <br />
<small>Used</small>
</h5>
</Col>
<Col className="mr-auto" lg="3">
<h5>
24,6$ <br />
<small>Spent</small>
</h5>
</Col>
</Row>
</div>
</CardFooter>
</Card>
</Col>
<Col md="8">
<Card className="card-user">
<CardHeader>
<CardTitle tag="h5">Edit Profile</CardTitle>
</CardHeader>
<CardBody>
<Form>
<Row>
<Col className="pr-1" md="5">
<FormGroup>
<label>Company (disabled)</label>
<Input
defaultValue="Creative Code Inc."
disabled
placeholder="Company"
type="text"
/>
</FormGroup>
</Col>
<Col className="px-1" md="3">
<FormGroup>
<label>Username</label>
<Input
defaultValue="michael23"
placeholder="Username"
type="text"
/>
</FormGroup>
</Col>
<Col className="pl-1" md="4">
<FormGroup>
<label htmlFor="exampleInputEmail1">
Email address
</label>
<Input placeholder="Email" type="email" />
</FormGroup>
</Col>
</Row>
<Row>
<Col className="pr-1" md="6">
<FormGroup>
<label>First Name</label>
<Input
defaultValue="Chet"
placeholder="Company"
type="text"
/>
</FormGroup>
</Col>
<Col className="pl-1" md="6">
<FormGroup>
<label>Last Name</label>
<Input
defaultValue="Faker"
placeholder="Last Name"
type="text"
/>
</FormGroup>
</Col>
</Row>
<Row>
<Col md="12">
<FormGroup>
<label>Address</label>
<Input
defaultValue="Melbourne, Australia"
placeholder="Home Address"
type="text"
/>
</FormGroup>
</Col>
</Row>
<Row>
<Col className="pr-1" md="4">
<FormGroup>
<label>City</label>
<Input
defaultValue="Melbourne"
placeholder="City"
type="text"
/>
</FormGroup>
</Col>
<Col className="px-1" md="4">
<FormGroup>
<label>Country</label>
<Input
defaultValue="Australia"
placeholder="Country"
type="text"
/>
</FormGroup>
</Col>
<Col className="pl-1" md="4">
<FormGroup>
<label>Postal Code</label>
<Input placeholder="ZIP Code" type="number" />
</FormGroup>
</Col>
</Row>
<Row>
<Col md="12">
<FormGroup>
<label>About Me</label>
<Input
type="textarea"
defaultValue="Oh so, your weak rhyme You doubt I'll bother, reading into it"
/>
</FormGroup>
</Col>
</Row>
<Row>
<div className="update ml-auto mr-auto">
<Button
className="btn-round"
color="primary"
type="submit"
>
Update Profile
</Button>
</div>
</Row>
</Form>
</CardBody>
</Card>
</Col>
</Row>
</div>
</>
}}
{ null }
</Query>
)
}
}
export default RestaurantForm;
When I run my app and go to the RestaurantForm component page, I got the following error.
app.js:66453 Warning: Failed prop type: Invalid prop `children` of type `array` supplied to `Query`, expected `function`.
in Query (created by RestaurantForm)
in RestaurantForm (created by Context.Consumer)
in Route (created by Dashboard)
in Switch (created by Dashboard)
in div (created by Dashboard)
in div (created by Dashboard)
in Dashboard (created by Context.Consumer)
in Route
in Switch
in ApolloProvider
in Router (created by HashRouter)
in HashRouter
The thing is without using the Query component and ApolloProvider component if I just instantiate the client in the RestaurantForm component and query it in the componentDidMount hook, it is working. But I need to use ApolloProvider and Query components. What is wrong with my code and how can I fix it?
The Query component above has two children:
a function: {({ data }) => {...}
null: { null }
Remove the { null } so that you're only passing in one child (the function) to resolve the error.
The callback also needs to return
{({ data }) => {
return (
//here are your components
)
}}
The error normally means what's inside Query is mal-formatted.
Here's a post https://github.com/apollographql/react-apollo/issues/2050
Maybe you have extra comma, or maybe your code wasn't working even without Query.

Passing an icon component to another component in ReactJS

Lets say I have this CardHeader component and I want to receive a titleIcon props (which is a react component) like this:
export default function CardHeader({ title, cardContent, titleIcon }) {
return (
<S.MiddleContainer>
<div className="white-card">
<div className="campaign-title p-1">
<div className="d-flex justify-content-center align-items-center pt-1">
{titleIcon}
<span id="title">{title}</span>
</div>
<div className="pr-2">
<MdInfo color="#969FAA" size={28} />
</div>
</div>
<p id="border" />
<div className="campaign-information">
{cardContent}
</div>
</div>
</S.MiddleContainer>
This is where I pass the icon prop
import { MdInfo } from 'react-icons/md'
<Col md={3}>
<S.ProductContainer>
<CardHeader
title="Sponsors Channel"
icon="<MdInfo color="#969FAA" size={28} />"/>
<Card title="Mobile notification boost" />
</S.ProductContainer>
</Col>
What is the best way to approach this?
you can pass your icon as a React.Node (not as a string), like so :
<Col md={3}>
<S.ProductContainer>
<CardHeader
title="Sponsors Channel"
icon={<MdInfo color="#969FAA" size={28} />} />
<Card title="Mobile notification boost" />
</S.ProductContainer>
</Col>
And you will have access to it via props in CardHeader :
export default function CardHeader({ title, cardContent, icon }) {
return (
<S.MiddleContainer>
<div className="white-card">
<div className="campaign-title p-1">
<div className="d-flex justify-content-center align-items-center pt-1">
{icon}
<span id="title">{title}</span>
</div>
<div className="pr-2">
<MdInfo color="#969FAA" size={28} />
</div>
</div>
<p id="border" />
<div className="campaign-information">
{cardContent}
</div>
</div>
Here you are:
<CardHeader
title="Sponsors Channel"
titleIcon={<MdInfo color="#969FAA" size={28} />}
/>

How can I structure a modal from a navbar in react with Bootstrap?

I'm new to React, so I apologize in advance. Here's my navbar component:
import React, { Component } from 'react';
import AuthModal from './modals/AuthModal'
import { Nav, NavItem, Navbar, NavDropdown, MenuItem } from 'react-bootstrap'
export default class MyNavbar extends Component {
render() {
return (
<Navbar inverse>
<Navbar.Header>
<Navbar.Brand>
<span className="logo">SITE</span>
</Navbar.Brand>
<Navbar.Toggle />
</Navbar.Header>
<Navbar.Collapse>
<Nav className="navleft">
<NavItem eventKey={1} href="#">Link</NavItem>
<NavItem eventKey={2} href="#">Link</NavItem>
<NavDropdown eventKey={3} title="Dropdown" id="basic-nav-dropdown">
<MenuItem eventKey={3.1}>Action</MenuItem>
<MenuItem eventKey={3.2}>Another action</MenuItem>
<MenuItem eventKey={3.3}>Something else here</MenuItem>
<MenuItem divider />
<MenuItem eventKey={3.3}>Separated link</MenuItem>
</NavDropdown>
</Nav>
<Nav pullRight className="navright">
<NavItem eventKey={1} href="#"><AuthModal/></NavItem>
</Nav>
</Navbar.Collapse>
</Navbar>
);
}
}
I need my nav to look like:
It's close:
Except, "Sign Up" and "Log In" appear to be one button currently. They need to be 2 separate buttons.
In my actual modal, I have
import React, { Component } from 'react'
import { Button, Modal, OverlayTrigger, Popover, Tooltip, Nav, NavItem, Row, Col, FormGroup, FieldGroup, Checkbox } from 'react-bootstrap'
export default class AuthModal extends Component {
constructor() {
super();
this.render.bind(this);
this.state = {showModal: false}
}
close() {
this.setState({ showModal: false });
}
open() {
this.setState({ showModal: true });
}
handleSelect(eventKey) {
event.preventDefault();
alert(`selected ${eventKey}`);
}
render () {
const popover = (
<Popover id="modal-popover" title="popover">
very popover. such engagement
</Popover>
);
const tooltip = (
<Tooltip id="modal-tooltip">
wow.
</Tooltip>
);
return (
<div>
<span onClick={this.open.bind(this)}>Sign Up</span>
<span onClick={this.open.bind(this)}>Log In</span>
<Modal show={this.state.showModal} onHide={this.close.bind(this)}>
<Modal.Body>
<Row>
<Col md={12}>
<Nav bsStyle='pills' activeKey={this.eventKey} onSelect={this.handleSelect}>
<NavItem eventKey={1} title="Item" ><span className="login-nav-tab">Log In</span></NavItem>
<NavItem eventKey={1} title="Item" ><span className="login-nav-tab">Sign Up</span></NavItem>
</Nav>
</Col>
</Row>
<Row className='top-space' >
<form>
<FormGroup >
<Row>
<Col md={12}>
<input className="col-md-10 col-md-offset-1 top-space fat-input" placeholder="Email"/>
<input className="col-md-10 col-md-offset-1 top-space fat-input" placeholder="Password"/>
</Col>
</Row>
<Row className='top-space'>
<Col md={5} mdOffset={1}>
<Checkbox className="checkbox-login"> Remember Me </Checkbox>
</Col>
<Col md={6} className='forgot-password'>
Forgot Password
</Col>
</Row>
<Row className='top-space'>
<Col md={10} mdOffset={1}>
<Button bsStyle="btn btn-black btn-block">Login</Button>
</Col>
</Row>
</FormGroup>
</form>
</Row>
<hr></hr>
<Row>
<Col md={12} className="text-center">
Login with blah
</Col>
</Row>
<Row className="top-space">
<Col md={6}>
<Button bsStyle='btn btn-block btn-danger'>
Google
</Button>
</Col>
<Col md={6}>
<Button bsStyle='btn btn-block btn-info'>
Facebook
</Button>
</Col>
</Row>
</Modal.Body>
<Modal.Footer>
<Button onClick={this.close.bind(this)}>Close</Button>
</Modal.Footer>
</Modal>
</div>
)
}
}
How can I have it so there's 2 separate links in the nav, and one modal. Depending on which one you click, the modal will either show the signup stuff or the sign in stuff?
You could modify your open() instance method to accept an argument that would tell which of the modal's content to show and it's value would be stored in the component's state with setState, in say a modalType key of the state object, and in your render() method you will want to have an if statement to check against this modalType state key to display the appropriate content inside your modal's body.
export default class AuthModal extends Component {
const MODAL_TYPE_LOGIN = 1, MODAL_TYPE_SIGNUP = 2;
constructor() {
super();
this.render.bind(this);
this.state = {
showModal: false
}
}
close() {
this.setState({ showModal: false });
}
open(modalType) {
this.setState({
showModal: true,
modalType: modalType
});
}
handleSelect(eventKey) {
event.preventDefault();
alert(`selected ${eventKey}`);
}
render () {
const popover = (
<Popover id="modal-popover" title="popover">
very popover. such engagement
</Popover>
);
const tooltip = (
<Tooltip id="modal-tooltip">
wow.
</Tooltip>
);
return (
<div>
<span onClick={this.open.bind(this, MODAL_TYPE_SIGNUP)}>Sign Up</span>
<span onClick={this.open.bind(this, MODAL_TYPE_LOGIN)}>Log In</span>
<Modal show={this.state.showModal} onHide={this.close.bind(this)}>
<Modal.Body>
<Row>
<Col md={12}>
<Nav bsStyle='pills' activeKey={this.eventKey} onSelect={this.handleSelect}>
<NavItem eventKey={1} title="Item" ><span className="login-nav-tab">Log In</span></NavItem>
<NavItem eventKey={1} title="Item" ><span className="login-nav-tab">Sign Up</span></NavItem>
</Nav>
</Col>
</Row>
{this.state.modalType == MODAL_TYPE_LOGIN ? (
<Row className='top-space' >
<form>
<FormGroup >
<Row>
<Col md={12}>
<input className="col-md-10 col-md-offset-1 top-space fat-input" placeholder="Email"/>
<input className="col-md-10 col-md-offset-1 top-space fat-input" placeholder="Password"/>
</Col>
</Row>
<Row className='top-space'>
<Col md={5} mdOffset={1}>
<Checkbox className="checkbox-login"> Remember Me </Checkbox>
</Col>
<Col md={6} className='forgot-password'>
Forgot Password
</Col>
</Row>
<Row className='top-space'>
<Col md={10} mdOffset={1}>
<Button bsStyle="btn btn-black btn-block">Login</Button>
</Col>
</Row>
</FormGroup>
</form>
</Row>
<hr></hr>
<Row>
<Col md={12} className="text-center">
Login with blah
</Col>
</Row>
<Row className="top-space">
<Col md={6}>
<Button bsStyle='btn btn-block btn-danger'>
Google
</Button>
</Col>
<Col md={6}>
<Button bsStyle='btn btn-block btn-info'>
Facebook
</Button>
</Col>
</Row>
) : (
<div>Your sign-up form goes in here</div>
)}
</Modal.Body>
<Modal.Footer>
<Button onClick={this.close.bind(this)}>Close</Button>
</Modal.Footer>
</Modal>
</div>
)
}
}
Though, ideally you would want to use redux so that you can control which type of modal to open from anywhere in your application, even if the components aren't related. Here is an interesting read and example of a modal logic implemented using redux.

Resources