Occupy content space based on the screen size in ReactJS - 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>
);
}

Related

Is there a way to get a React Bootsrap card to show one card per row dynamically on a small screen

I am trying to get react bootstrap cards to show only card per row when the screen is small but it shows a mix of one and three cards per row . Please help.....example code is below
return (
<Container className="align-middle g-0 bg-transparent">
<Card.Body>
<Row className="justify-content-center">
{
cards.map((card) => {
return (
<Col className="col-lg-3 col-md-6 col-sm-12 col-xs-12">
<CardComponent data={data} />
</Col>
)
})
}
</Row>
</Card.Body>
</Container>
)
Instead of using className use the Bootstrap default way of defying columns, otherwise it adds a default col class
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
<Container className="align-middle g-0 bg-transparent">
<Card.Body>
<Row className="justify-content-center">
{cards.map((card) => (
<Col xs='12' md='6' lg='3'>
{card}
</Col>
))}
</Row>
</Card.Body>
</Container>
</div>
);

Creat Hyperlink For Footer in React

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>

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} />}
/>

horizontal align card using map function ReactJS

I'm trying to align horizontal card using grid with react-bootstrap and map function
I'm using redux to bring the Data through the props so I create a JSON to traverse it with a function Map
this is a fraction of my code
render() {
//const { tablaCliente } = this.state
//const { isLoading } = this.state
const { entity } = this.props;
return (
<div>
<Header></Header>
<div className="col-xs-4">
<a className="btn btn-primary" href="/newclient">Nuevo Cliente</a>
</div>
<br />
<center>
<Spinner animation="border" role="status">
<span className="sr-only">Loading...</span>
</Spinner>
</center>
<Container>
{entity && entity.getAllEntities && entity.getAllEntities.length > 0 && entity.getAllEntities.map((item, index) => {
return (
<CardGroup value={item}key={index}>
<Card style={{ width: '1rem' }} >
<Card.Img variant="top" src="data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22286%22%20height%3D%22180%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20286%20180%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_16b0e6bd8ef%20text%20%7B%20fill%3A%23999%3Bfont-weight%3Anormal%3Bfont-family%3AHelvetica%2C%20monospace%3Bfont-size%3A14pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_16b0e6bd8ef%22%3E%3Crect%20width%3D%22286%22%20height%3D%22180%22%20fill%3D%22%23373940%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22107.203125%22%20y%3D%2296.3%22%3E286x180%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E" />
<Card.Body>
<Card.Title> Cliente {item.name}</Card.Title>
<Card.Text>
{item.description}
</Card.Text>
</Card.Body>
<ListGroup className="list-group-flush">
<ListGroupItem>Estado:{''}{JSON.stringify(item.state)}</ListGroupItem>
<ListGroupItem>Creado por: {item.createby}</ListGroupItem>
</ListGroup>
<Card.Body>
<Card.Link href="/cliente">Card Link</Card.Link>
<Card.Link href="/cliente">Editar</Card.Link>
</Card.Body>
</Card>
</CardGroup>)
})}
</Container>
</div>
);
}
I dont use react-bootstrap but u can achieve it by doing
<Container>
<div class='row'>
{this.map(value => {
return (
<div class='col-md-6'>
<Card />
</div>
)
});}
</div>
</Container>
This should work
Wrap the map function in row and the returning jsx in col
And dont just write a whole logic in jsx use functions or components

Materialize Cards not displaying properly in React app

I am having Issues with Materialize cards in react I want them to display side by side and instead they are displaying vertically one on top of the other. Any help would be much appreciated.
{this.state.players.length ? (
<Row className="basketball-BG">
<Col m={3}>
<div className="card-content">
<PlayersList>
{this.state.players.map(player => (
<PlayersInfo key={player._id}>
<Card className="card small'"
header={<CardTitle ></CardTitle>}>
<a className="player-card" href={"/players/" + player._id}>
<div className="card-content">
<h4>
{player.lName +" "}
{player.fName}
</h4>
<p>
{player.jersey}
</p>
<p>
{player.position}
</p>
</div>
</a>
<DeleteBtn onClick={() => this.deletePlayer(player._id)} />
</Card>
</PlayersInfo>
))}
</PlayersList>
</div>
</Col>
</Row>
) : (
<h3 className="center">You Dont Have any Players yet Add them to the roster</h3>
)}
You can use flex layouts
// in your component
<PlayersList class='row-wise-spread'>
</PlayersList>
In a css file
.row-wise-spread {
display: flex;
flex-direction: row;
}

Resources