How to Resize Modal height and width in react-bootstrap? - css

I'm trying to use React Bootstrap Modal in my application but the dialog is too small, and I want to make it bigger. How can I achieve that ? I already finished the Code but i think the css doesn't work
Here's the code:
<Modal show={showModal} onHide={handleClose} className='modalSize'>
<Modal.Body >
<Row>
<Col lg={6}>
<img
className
src= {modalData.picture}
/>
</Col>
<Col lg={6}>
<h1>{modalData.name}</h1>
<h1>{modalData.position}</h1>
</Col>
</Row>
</Modal.Body>
</Modal>
CSS :
.modalSize{
width: 100% !important;
}

From the react-bootstrap docs: Size
You can add a parameter for the size of the modal just using size="lg" as below
function Example() {
const [smShow, setSmShow] = useState(false);
const [lgShow, setLgShow] = useState(false);
return (
<>
<Button onClick={() => setSmShow(true)} className="me-2">
Small modal
</Button>
<Button onClick={() => setLgShow(true)}>Large modal</Button>
<Modal
size="sm"
show={smShow}
onHide={() => setSmShow(false)}
aria-labelledby="example-modal-sizes-title-sm"
>
<Modal.Header closeButton>
<Modal.Title id="example-modal-sizes-title-sm">
Small Modal
</Modal.Title>
</Modal.Header>
<Modal.Body>...</Modal.Body>
</Modal>
<Modal
size="lg"
show={lgShow}
onHide={() => setLgShow(false)}
aria-labelledby="example-modal-sizes-title-lg"
>
<Modal.Header closeButton>
<Modal.Title id="example-modal-sizes-title-lg">
Large Modal
</Modal.Title>
</Modal.Header>
<Modal.Body>...</Modal.Body>
</Modal>
</>
);
}

Related

How to add sliding animation MUI using CSS

I am facing an issue of adding the slide animation on the question and answer. I want on click of the radio button the slide effect comes and next question comes with Slideup animation.
<Grid item xs={12} sm={8} md={8}>
<Slide direction="up"
in={checked}
appear={true}
mountOnEnter
unmountOnExit
timeout={{ enter: 1000 , exit: checked ? 1 : 900}}
>
<Card variant="outlined" sx={{ bgcolor: "#bea"}} elevation={0}>
<CardContent>
<form onSubmit= {handleSubmit}>
<CardActions>
<Button type="submit" color="warning" variant="outlined" disabled={currentQuestion===0} className={classes.button} onClick={previousQuestion}>
Previous</Button>
</CardActions>
<FormControl component='fieldset' className={classes.formControl}
data-hidden={questions[currentQuestion].number !==
currentQuestion[questions[currentQuestion] .number]} >
<FormLabel component='legend'>
{questions[currentQuestion].question}
</FormLabel>
<FormLabel component='legend'>
{questions[currentQuestion].description}
</FormLabel>
<RadioGroup
aria-label='quiz'
name='quiz'
value={questions[currentQuestion].value}
checked={checked}
onChange={(e)=> handleRadioChange(questions[currentQuestion].number, e)}
sx={{
color: pink[800],
'&.Mui-checked': {
color: blue[600],
},
}}>
{options.map((option) => (
<FormControlLabel
key={option.score}
value={option.score}
control={<Radio sx={{
color: pink[800],
'&.Mui-checked': {
color: blue[600],
},
}}/>}
label={option.label}
/>
))}
</RadioGroup>
</FormControl>
<CardActions>
<Button type="submit" variant="contained" color="primary" className={classes.button} disabled={currentQuestion != 5} onClick={handleSubmit}>
Submit
</Button>
</CardActions>
</form>
</CardContent>
</Card>
</Slide>
This is not working smoothly. So please help. The problem is on click of previous button the value disappeared. The slide effect is not flawless.

How to display react-bootstrap card component side by side horizontally

Hi guys so I'm trying to create some e-commerce web app using react-bootstrap. I wanted to map my item by using Card component from bootstrap. I manage to display each of the card, but I can't make them displayed side by side horizontally. I want each row to have 4/5 items anyone know how I can accomplish it ? here's my code:
Product.js
<Row>
<Col lg={4}>
{productList && productList.map(product =>{
const {id, title, price, category,description,image} = product;
return(
<>
<Card key={id} className="productlist">
<Card.Img variant="top" src={"#"} />
<Card.Body>
<Card.Title>{title}</Card.Title>
<Card.Text>{description}</Card.Text>
<Card.Text>{category}</Card.Text>
<Card.Text>
{price}
</Card.Text>
<Button variant="primary">Add to cart</Button>
</Card.Body>
</Card>
</>
)
})}
</Col>
</Row>
You can do it simply using d-flex and flex fill react bootstrap class. It will also fulfill your need of equal height cards in a row.
Try below code may be its work as expected you want.
<Row lg={3}>
{productList &&
productList.map((product) => {
const { id, title, price, category, description, image } =
product;
return (
<Col className="d-flex">
<Card className="flex-fill" key={id} className="productlist">
<Card.Img variant="top" src={"#"} />
<Card.Body>
<Card.Title>{title}</Card.Title>
<Card.Text>{description}</Card.Text>
<Card.Text>{category}</Card.Text>
<Card.Text>{price}</Card.Text>
<Button variant="primary">Add to cart</Button>
</Card.Body>
</Card>
</Col>
);
})}
</Row>
<Row>
{productList &&
productList.map((product) => {
const { id, title, price, category, description, image } =
product;
return (
<Col className="col-6">
<Card key={id} className="productlist">
<Card.Img variant="top" src={"#"} />
<Card.Body>
<Card.Title>{title}</Card.Title>
<Card.Text>{description}</Card.Text>
<Card.Text>{category}</Card.Text>
<Card.Text>{price}</Card.Text>
<Button variant="primary">Add to cart</Button>
</Card.Body>
</Card>
</Col>
);
})}
</Row>

How to map on react JS with button?

currently I'm trying to create a react app. I have 3 button and I want to show different information and image depending on the button chosen. It will only display the info of the chosen button for example, if user click de'spa it will only show information about id 1.
How can I map each of them with mapping in react? and one more question. Can I directly write the path for my img in the array ? if can't, how to do it ?
Here's the current code I have
import {Carousel, Container, Row, Col} from 'react-bootstrap'
import '../CSS/Facilities.css'
const facsInfo = [
{
Id: "1",
Title: "De'Spa",
Description: "",
upperleftimg:"./Images/photo1.png",
upperrightimg:"./Images/photo2.png",
},
{
Id: "2",
Title: "De'Resto",
Description: "",
upperleftimg:"./Images/photo3.png",
upperrightimg:"./Images/photo4.png",
},
]
const Facilities = () => {
return (
<>
<Container fluid>
<Row className="facsbuttwrapper text-center">
<Col sm={4} lg={4}>
<button className="facsButton">De'Spa</button>
</Col>
<Col sm={4} lg={4}>
<button className="facsButton">De'Resto</button>
</Col>
<Col sm={4} lg={4}>
<button className="facsButton">Meeting Room</button>
</Col>
</Row>
</Container>
<Container fluid>
<Row className="text-center">
<Col md={12} lg={12}>
{facsInfo.map((show) =>{
const {Title, Description, OpeningHours, Id} = show
return(
<div key={Id}>
<h1>{Title}</h1>
<h5>{Description}</h5>
</div>
)
})}
</Col>
</Row>
</Container>
<Container fluid>
<Row>
<Col md={12} lg={12}>
{facsInfo.map((show) =>{
const {upperleftimg, upperrightimg, Id} = show
return(
<div key={Id} className="FacilitiesImg">
<img src={upperleftimg} alt="Image 1"></img>
<img src={upperrightimg} alt="Image 2"></img>
</div>
)
})}
</Col>
</Row>
</Container>
</>
)
}
export default Facilities
You could use a state to do that
In your Facilities component:
const [id, setID] = useState('');
Then in your buttons:
<Row className="facsbuttwrapper text-center">
{facsInfo.map(fac => (
<Col sm={4} lg={4}>
<button className="facsButton" onClick={() => setId(fac.Id)}>
{fac.Title}
</button>
</Col>
))}
<Col sm={4} lg={4}>
<button className="facsButton">Meeting Room</button>
</Col>
</Row>;
To show correct image:
<Row>
<Col md={12} lg={12}>
{facsInfo.find(show => {
if (show.id === id) {
const { upperleftimg, upperrightimg, Id } = show;
return (
<div key={Id} className="FacilitiesImg">
<img src={upperleftimg} alt="Image 1"></img>
<img src={upperrightimg} alt="Image 2"></img>
</div>
);
}
})}
</Col>
</Row>;
Add onClick events on your buttons and pass the ID into the click handler.
Set a State with selected id.
Instead of using facsInfo.map, use facsInfo.find(f => f.id === selectedID) [selectedID being the state].
You need a state to save information.
filter facsInfo based on current information state
const [current, setCurrent] = React.useState(`De'Spa`)
const handleInfoChange = (evt) => {
setCurrent(evt.currentTarget.dataset.info)
}
const filteredFacsInfo = facsInfo.filter(x => x.Title === current)
return (
<Container fluid>
<Row className="facsbuttwrapper text-center">
<Col sm={4} lg={4}>
<button data-info="De'Spa" className="facsButton" onClick={handleInfoChange}>De'Spa</button>
</Col>
<Col sm={4} lg={4}>
<button data-info="De'Resto" className="facsButton" onClick={handleInfoChange}>De'Resto</button>
</Col>
<Col sm={4} lg={4}>
<button data-info="Meeting Room" className="facsButton" onClick={handleInfoChange}>Meeting Room</button>
</Col>
</Row>
</Container>
<Container fluid>
<Row className="text-center">
<Col md={12} lg={12}>
{filteredFacsInfo.map((show) => /* your render content about info */)}
</Col>
</Row>
</Container>
<Container fluid>
<Row className="text-center">
<Col md={12} lg={12}>
{filteredFacsInfo.map((show) => /* your render content about image */)}
</Col>
</Row>
</Container>
)
and one more question. Can I directly write the path for my img in the array ? if can't, how to do it ?
Yes, you can.
For achieving your aim, you need to define a state:
const [currentId, setCurrentId] = useState();
And a function which will filter facs:
const showSelectedFact = () => {
var fac = facsInfo.filter((x) => x.Id == currentId)[0];
const { Title, Description, OpeningHours, Id } = fac;
return (
<div key={Id}>
<h1>{Title}</h1>
<h5>{Description}</h5>
</div>
);
};
Here's the code:
import { Carousel, Container, Row, Col } from "react-bootstrap";
import { useEffect, useState } from "react";
// import '../CSS/Facilities.css'
const facsInfo = [
{
Id: "1",
Title: "De'Spa",
Description: "",
upperleftimg: "./Images/photo1.png",
upperrightimg: "./Images/photo2.png"
},
{
Id: "2",
Title: "De'Resto",
Description: "",
upperleftimg: "./Images/photo3.png",
upperrightimg: "./Images/photo4.png"
},
{
Id: "3",
Title: "Meeting Room",
Description: "",
upperleftimg: "./Images/photo3.png",
upperrightimg: "./Images/photo4.png"
}
];
const Facilities = () => {
const [currentId, setCurrentId] = useState();
useEffect(() => {
console.log(currentId);
}, [currentId]);
const showSelectedFact = () => {
var fac = facsInfo.filter((x) => x.Id == currentId)[0];
const { Title, Description, OpeningHours, Id } = fac;
return (
<div key={Id}>
<h1>{Title}</h1>
<h5>{Description}</h5>
</div>
);
};
return (
<>
<Container fluid>
<Row className="facsbuttwrapper text-center">
<Col sm={4} lg={4}>
<button
value="1"
className="facsButton"
onClick={(e) => setCurrentId(e.target.value)}
>
De'Spa
</button>
</Col>
<Col sm={4} lg={4}>
<button
value="2"
className="facsButton"
onClick={(e) => setCurrentId(e.target.value)}
>
De'Resto
</button>
</Col>
<Col sm={4} lg={4}>
<button
value="3"
className="facsButton"
onClick={(e) => setCurrentId(e.target.value)}
>
Meeting Room
</button>
</Col>
</Row>
</Container>
<Container fluid>
<Row className="text-center">
<Col md={12} lg={12}>
{showSelectedFact()}
</Col>
</Row>
</Container>
<Container fluid>
<Row>
<Col md={12} lg={12}>
{facsInfo.map((show) => {
const { upperleftimg, upperrightimg, Id } = show;
return (
<div key={Id} className="FacilitiesImg">
<img src={upperleftimg} alt="Image 1"></img>
<img src={upperrightimg} alt="Image 2"></img>
</div>
);
})}
</Col>
</Row>
</Container>
</>
);
};
export default function App() {
return <Facilities />;
}

how to give button a button right alignment in bootstrap?

I'm trying to align two buttons at the right corner of a row but no matter what method I use it shows the same result every time here's the code for your reference:
import React from "react";
import bootstrap from "bootstrap";
import Container from "react-bootstrap/Container";
import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col";
const AdminPanel = () => {
const users = [{ name: "Talha" }, { name: "Ali" }];
return (
<Container className="pt-5">
<Row className="d-flex" style={{ height: "70vh" }}>
<Col className="shadow-lg bg-white rounded mx-5">
{users.map((user) => (
<Row
className="shadow my-3 mx-2 py-2 px-2 rounded font-weight-bold"
style={{ height: "7vh" }}
>
{user.name}
<div className="btn-group">
<a href="#">
<button className="btn btn-primary">Edit</button>
</a>
<a href="#">
<button className="btn btn-danger">Delete</button>
</a>
</div>
</Row>
))}
</Col>
<Col className="shadow-lg bg-white rounded mx-5">
<h1>
list
</h1>
</Col>
</Row>
</Container>
);
};
export default AdminPanel;
the result I'm getting is this:
Any help would be appreciated!!!!!
Add class: ml-auto (= margin-left:auto !important) into:
<div className="btn-group ml-auto">
As this div is in a div.row that has the property display:flex; applied, it should push it to the right automaticly
Add
className="float-right"
to the div wrapping the buttons
You can add each block of child Element of your Row in a Col Component and add the justify-content-between class to the Row Component like this
<Col className="shadow-lg bg-white rounded mx-5">
{users.map((user) => (
<Row
className="justify-content-between shadow my-3 mx-2 py-2 px-2 rounded font-weight-bold"
style={{ height: "7vh" }}
>
<Col>
{user.name}
</Col>
<Col>
<div className="btn-group">
<a href="#">
<button className="btn btn-primary">Edit</button>
</a>
<a href="#">
<button className="btn btn-danger">Delete</button>
</a>
</div>
</Col>
</Row>
))}
</Col>

Reactjs boostrap grid

I am learning React and I have some trouble with using the bootstrap grid/reactstrap. Somehow when I use the grid system, instead of aligning horizontal columns, I got a vertical one.
Film.js
import React from "react";
import logo from "./ghibli.png";
import { Container, Row, Col } from "reactstrap";
import { Card, CardImg, CardText, CardBody,
CardTitle, CardSubtitle, Button } from 'reactstrap';
const Films = props => (
<Container>
<Row>
<Col md= "3">
<Card>
<CardImg top width="100%" src={logo} alt="Card image cap" />
<CardBody>
<CardTitle>{props.title}</CardTitle>
<CardSubtitle>{props.director}</CardSubtitle>
<CardText>{props.description}</CardText>
<Button>Button</Button>
</CardBody>
</Card>
</Col>
</Row>
</Container>
);
export default Films;
Currently, you only have one column (col) in a row.
As soon as you add more than column into a row, they'll start showing up side by side i.e. horizontally.
I have no clue about reactjs but I suspect that the following code will probably do the trick and produce 2 columns in a row:
const Films = props => (
<Container>
<Row>
<Col md= "3">
<Card>
<CardImg top width="100%" src={logo} alt="Card image cap" />
<CardBody>
<CardTitle>{props.title}</CardTitle>
<CardSubtitle>{props.director}</CardSubtitle>
<CardText>{props.description}</CardText>
<Button>Button</Button>
</CardBody>
</Card>
</Col>
<Col md= "3">
<Card>
<CardImg top width="100%" src={logo} alt="Card image cap" />
<CardBody>
<CardTitle>{props.title}</CardTitle>
<CardSubtitle>{props.director}</CardSubtitle>
<CardText>{props.description}</CardText>
<Button>Button</Button>
</CardBody>
</Card>
</Col>
</Row>
</Container>
);

Resources