MaterialUI - Card Component positioning issues - css

Newbie to React, have mercy on my soul.
I'm attempting to create a card with a Collapse component. Cool. I have the following ugly result:
now, once I expand the Collapse component, my bottom bottoms move a bit upwards,
making my ugly result even uglier:
If I turn on pesticide extension, I get the following result once expanded:
it seems like the item below pushes my like and review buttons upwards, or perhaps I'm wrong.
Now, what is weird for me is that my buttons are absolute. by my understanding, they're supposed to be 'relative' to their parents, and act as a 'free entity', so I don't get why would it be moved anyway?
The code for that component:
import React, { useContext, useState } from "react";
import { styled } from "#mui/material/styles";
import Card from "#mui/material/Card";
import CardHeader from "#mui/material/CardHeader";
import CardMedia from "#mui/material/CardMedia";
import CardContent from "#mui/material/CardContent";
import CardActions from "#mui/material/CardActions";
import Collapse from "#mui/material/Collapse";
import Avatar from "#mui/material/Avatar";
import IconButton from "#mui/material/IconButton";
import Typography from "#mui/material/Typography";
import { red } from "#mui/material/colors";
import FavoriteIcon from "#mui/icons-material/Favorite";
import ShareIcon from "#mui/icons-material/Share";
import ExpandMoreIcon from "#mui/icons-material/ExpandMore";
import ExpandLessIcon from "#mui/icons-material/ExpandLess";
import MoreVertIcon from "#mui/icons-material/MoreVert";
import ThumbUpIcon from '#mui/icons-material/ThumbUp';
import ThumbDownIcon from '#mui/icons-material/ThumbDown';
import AuthContext from "../Contexts/isLoggedIn-context";
import usersAndProductsContext from "../Contexts/usersAndProducts-context";
import RateReviewIcon from '#mui/icons-material/RateReview';
import Farmers from "../Pages/Farmers";
import { useNavigate } from "react-router-dom";
import { Paper } from "#mui/material";
import ReviewText from "./ReviewText";
import { Box } from "#mui/system";
import { ExpandLess } from "#mui/icons-material";
// import logo_img from "../../Images/logo.png";
const ExpandMore = styled((props) => {
const { expand, ...other } = props;
return <IconButton {...other} />;
})(({ theme, expand }) => ({
transform: !expand ? "rotate(0deg)" : "rotate(180deg)",
marginLeft: "auto",
transition: theme.transitions.create("transform", {
duration: theme.transitions.duration.shortest,
}),
}));
function FarmerComponent(props) {
let navigate = useNavigate();
let authCtx = useContext(AuthContext)
let usersAndItemsCtx = useContext(usersAndProductsContext)
let [isWritingReviewFlag, edit_isWritingReviewFlag] = useState(false);
let current_logged_user = usersAndItemsCtx.usersVal.find(user => user.id === authCtx.currentLoggedUserId);
console.log(current_logged_user.likedProfilesId)
let flag = (current_logged_user.likedProfilesId.find((id) =>id === props.id) ? true : false)
console.log(flag)
let [isCurrentFarmerLikedFlag, isCurrentFarmerLikedFlagToggle] = useState(flag)
const [expanded, setExpanded] = React.useState(false);
// let [favouriteClicked, set_favouriteClicked] = useState(false);
const handleFavouriteClicked = () => {
let prevLikedStatus = isCurrentFarmerLikedFlag
if(isCurrentFarmerLikedFlag){
current_logged_user.likedProfilesId = current_logged_user.likedProfilesId.filter(userid => props.id !== userid)
isCurrentFarmerLikedFlagToggle(!prevLikedStatus)
}
else {
current_logged_user.likedProfilesId.push(props.id);
isCurrentFarmerLikedFlagToggle(!prevLikedStatus)
}
}
const handleExpandClick = () => {
setExpanded(!expanded);
};
const handleCardClick = () => { //choosing a farmer to view his shop/products.
navigate('/farmershop/'+props.id)
}
const handleNewReview = () => {
edit_isWritingReviewFlag(true)
}
return (
<Paper sx={{width: "300px", border: "none"}}>
{/* props===the farmer card we're on */}
{isWritingReviewFlag ? <ReviewText
edit_isWritingReviewFlag={edit_isWritingReviewFlag}
reviewingFarmer={current_logged_user}
reviewedFarmer={props}
/> : <></>}
<Card
sx={{
height: "600px",
width: "350px",
padding: "5px",
backgroundColor: "#D37C65",
marginTop: "20px",
marginLeft: "20px",
marginRight: "20px",
boxShadow: "5px 16px 5px 0px rgba(0,0,0,0.75)",
borderRadius: "7px",
border: "none",
padding: "50px"
}}>
<div onClick={handleCardClick} style={{marginTop: "10%", letterSpacing: "2px", fontFamily: "sans-serif", cursor: "pointer"}}><h1>{props.firstname + " " + props.lastname}</h1></div>
<CardMedia
component="img"
height="194"
image={props.img}
sx={{borderRadius: "5px"}}
title={props.firstname + " " + props.lastname}
onClick={handleCardClick}
style={{cursor: "pointer", backgroundColor: "#5CBEFD"}}
/>
<Box sx={{borderRadius: "5px", opacity: "80%", position: "relative"}}>
<Typography variant="body2" color="text.secondary" sx={{backgroundColor: "#5CBEFD"}}> <span>Location: {props.location}</span></Typography>
{expanded ? <></> : <Typography variant="body2" color="text.secondary" sx={{backgroundColor: "#5CBEFD"}}><span>more info...</span></Typography>}
<IconButton onClick={handleExpandClick}>
{expanded ? <ExpandLessIcon/> : <ExpandMoreIcon/> }
</IconButton>
<Box sx={{marginTop: "80%"}}>
<Collapse sx={{position: "absolute", marginTop: "-70%" }} in={expanded}>{props.about}</Collapse>
</Box>
</Box>
<Box sx={{position: "absolute", marginTop: "-5%"}}>
<CardActions>
<IconButton onClick={handleFavouriteClicked} aria-label="add to favorites">
{!isCurrentFarmerLikedFlag ? <ThumbUpIcon style={{color: "rgba(0, 194, 0, 1)"}}/> : <ThumbDownIcon style={{color: "rgba(255, 30, 127, 1"}}/> }
</IconButton>
<IconButton onClick={handleNewReview} sx={{display: "flex", alignItems: "center", flexWrap: 'wrap'}} aria-label="add review">
<RateReviewIcon/>
<span style={{letterSpacing: "1px", marginLeft: "3px", marginBottom: "5px", fontSize: "15px"}}>add new review</span>
</IconButton>
</CardActions>
</Box>
</Card>
</Paper>
);
}
export default FarmerComponent;
Many thanks!

Related

How do I set up make styles using MUI for my app?

Im having problems with MUI im trying to color my buttons and the 2 ways ive tried have not worked.
example 1
import React from 'react'
import { Typography } from '#mui/material'
import Button from '#mui/material/Button'
import Container from '#mui/material/Container'
import SendOutlinedIcon from '#mui/icons-material/SendOutlined';
import { makeStyles } from '#mui/styles';
import useStyles from './create-styles'
/* Styling Section (CSS) */
export default function Create() {
const classes = useStyles()
return (
<Container>
<Typography className={classes.title} variant="h6" component='h2' gutterBottom color="textSecondary" align='center'>
Create a New Note
</Typography>
<div>
<Button onClick={() => console.log('you clicked me')} type="submit" variant='contained' endIcon={<SendOutlinedIcon/>}>
Submit
</Button>
</div>
</Container>
)
}
import { makeStyles } from '#mui/styles';
export default makeStyles(() => ({
btn: {
fontSize: 500,
backgroundColor: 'pink',
'&:hover': {
backgroundColor: 'orange'
}
},
title: {
color: 'orange',
textDecoration: 'underline',
marginBottom: 20
}
}))
This isn't working.
and neither is this.
example 2
import React from 'react'
import { Typography } from '#mui/material'
import Button from '#mui/material/Button'
import Container from '#mui/material/Container'
import SendOutlinedIcon from '#mui/icons-material/SendOutlined';
import { makeStyles } from '#mui/styles';
/* Styling Section (CSS) */
const useStyles = makeStyles({
btn: {
fontSize: 500,
backgroundColor: 'pink',
'&:hover': {
backgroundColor: 'orange'
}
},
title: {
color: 'orange',
textDecoration: 'underline',
marginBottom: 20
}
})
export default function Create() {
const classes = useStyles()
return (
<Container>
<Typography className={classes.title} variant="h6" component='h2' gutterBottom color="textSecondary" align='center'>
Create a New Note
</Typography>
<div>
<Button sx={{fontSize: 60, backgroundColor: "red"}} onClick={() => console.log('you clicked me')} type="submit" variant='contained' endIcon={<SendOutlinedIcon/>}>
Submit
</Button>
</div>
</Container>
)
}
only when I use this does it work.
sx={{fontSize: 60, backgroundColor: "red"}}
Are there any solutions so I don't have to style inline?
Im following a video and I guess the old way of styling using MUI has depreciated
Here you go with a solution
In the button element you need to provide classes
import React from 'react'
import { Typography } from '#mui/material'
import Button from '#mui/material/Button'
import Container from '#mui/material/Container'
import SendOutlinedIcon from '#mui/icons-material/SendOutlined';
import { makeStyles } from '#mui/styles';
/* Styling Section (CSS) */
const useStyles = makeStyles({
btn: {
fontSize: 500,
backgroundColor: 'pink',
'&:hover': {
backgroundColor: 'orange'
}
},
title: {
color: 'orange',
textDecoration: 'underline',
marginBottom: 20
}
})
export default function Create() {
const classes = useStyles()
return (
<Container>
<Typography className={classes.title} variant="h6" component='h2' gutterBottom color="textSecondary" align='center'>
Create a New Note
</Typography>
<div>
<Button
classes={{root: classes.btn}} // -- added this classes
onClick={() => console.log('you clicked me')} type="submit" variant='contained' endIcon={<SendOutlinedIcon/>}>
Submit
</Button>
</div>
</Container>
)
}

How can style the backdrop of a MaterialUI modal?

I have a MUI Modal set up, it's currently working, however the backdrop is being displayed as black. I have styling in place, but for some reason the backdrop is not being updated and remains pitch black.
My code is below, a screenshot is also below of what I see when the Modal is opened. Please let me know how I can fix this issue.
import { Box, Modal, Typography } from "#material-ui/core";
import React from "react";
import { makeStyles } from "#material-ui/core/styles";
const useStyles = makeStyles((theme) => ({
modalStyle: {
position: "absolute",
top: "50%",
left: "50%",
transform: "translate(-50%, -50%)",
width: 300,
bgcolor: "background.paper",
boxShadow: 24,
p: 4,
backgroundColor: "white",
borderRadius: "10px",
},
}));
const PopupModal = ({ postModalOpen, handleClose, children }) => {
const classes = useStyles();
return (
<Modal open={postModalOpen} onClose={handleClose}>
<Box className={classes.modalStyle}>
ModalText
<Typography
id="modal-modal-title"
variant="h6"
component="h2"
style={{
fontSize: "14px",
marginLeft: "5px",
}}
>
{children}
</Typography>
</Box>
</Modal>
);
};
export default PopupModal;
If you'd like to style the backdrop, your styles must be passed to the Modal component directly:
For example:
const useStyles = makeStyles((theme) => ({
/** Changed modalStyle */
modalStyle: { backgroundColor: "rgba(255, 0, 0, 0.5)" },
/** Moved content styling to new class */
contentStyle: {
/** Also removed some invalid attributes **/
position: "absolute",
top: "50%",
left: "50%",
transform: "translate(-50%, -50%)",
width: "300px",
backgroundColor: "white",
borderRadius: "10px"
}
}));
const PopupModal = ({ postModalOpen, handleClose, children }) => {
const classes = useStyles();
return (
// Note the changed className props with your sample code
<Modal
open={postModalOpen}
onClose={handleClose}
className={classes.modalStyle}
>
<Box className={classes.contentStyle}>
<Typography
id="modal-modal-title"
variant="h6"
component="h2"
style={{
fontSize: "14px",
marginLeft: "5px"
}}
>
{children}
</Typography>
</Box>
</Modal>
);
};
Working Example: https://codesandbox.io/s/material-demo-forked-edhqx?file=/demo.js
FYI: You can also override all backdrops in your application, on a global scale, by passing a MuiBackdrop override object to createMuiTheme().
This is how I customized my MUI Backdrop (MUI v5)
<Backdrop open={isOpen} sx={{ backgroundColor: 'rgba(0, 0, 0, 0.25)', zIndex: 1 }} onClick={handleCloseMenu} />

Can't Make MouseEnter and MouseLeave Animation on React

I'm new at react. I'm using media cards to present some picture and small text and have been trying to give small sliding animation to my text and background layer. However I failed. Codes are below:
import React, { useState, Component } from 'react';
import { makeStyles } from '#material-ui/core/styles';
import CardActionArea from '#material-ui/core/CardActionArea';
import CardContent from '#material-ui/core/CardContent';
import CardMedia from '#material-ui/core/CardMedia';
import Typography from '#material-ui/core/Typography';
import Grid from '#material-ui/core/Grid';
import Paper from '#material-ui/core/Paper';
export default function SectionCard(props) {
const [areaHeight, setAreaHeight] = useState(100);
const [imgSize, setImgSize] = useState(1);
const [lineColor, setLineColor] = useState('dodgerblue');
const [textPosition, setTextPosition] = useState(0);
const useStyles = makeStyles((theme) => ({
root: {
maxWidth: 345,
},
media: {
height: 400,
scale: imgSize,
},
greyCover: {
backgroundColor: 'rgba(0, 0, 0, 0.5)',
height: areaHeight,
width: '100%',
bottom: 0,
position: 'absolute',
},
line: {
backgroundColor: lineColor,
height: 5,
width: '100%',
borderRadius: 0,
},
textPosition: {
paddingTop: textPosition,
fontFamily: 'Quicksand !important',
color: 'white !important',
},
body: {
fontFamily: 'Quicksand !important',
},
}));
const classes = useStyles();
return (
<Grid item xs={12} sm={4} onMouseEnter={() => (setAreaHeight('100%'), setLineColor('red'), setImgSize(1.2), setTextPosition('150px!important'))} onMouseLeave={() => (setAreaHeight(100), setLineColor('dodgerblue'), setImgSize(1), setTextPosition('0px !important'))}>
<CardActionArea>
<CardMedia
className={classes.media}
image={props.img}
/>
<CardContent className={classes.greyCover} style={{ fontFamily: 'Quicksand', }}>
<div className={classes.textPosition}>
<Typography gutterBottom variant="h5" component="h2" align="center">
{props.title}
</Typography>
<Typography component="p" align="center">
{props.text}
</Typography>
</div>
</CardContent>
</CardActionArea>
<Paper className={classes.line} />
</Grid>
);
}
Codes are probably messy. Sorry for that. onMouseEnter and onMouseLeave are working fine. I just want to see that greyCover class and text moves slowly to height 100% and text to mid of the frame.
I didn't want to use another packages yet I don't know how to use too to be honest.
What I'm doing wrong?

Element positioned absolute inside Dialog Material UI React

I have Dialog component where I have a button(bottom right corner) which shows another div with an item list. The problem I'm facing is that the list is being rendered inside the Dialog component and it's being cropped. I set the position: absolute, z-index and set the position: relative to the parent but it does not work. Here is how it looks like. Any helpful tips I would appreciate it.
1) Before I click the button to show the list
2) After I click the button. Highlighted css properties for the list element
And the code for Dialog component :
import React, { useState } from "react";
import { makeStyles } from "#material-ui/core";
import Button from "#material-ui/core/Button";
import Dialog from "#material-ui/core/Dialog";
import DialogContent from "#material-ui/core/DialogContent";
import DialogContentText from "#material-ui/core/DialogContentText";
import DialogTitle from "#material-ui/core/DialogTitle";
import IconButton from "#material-ui/core/IconButton";
import CloseIcon from "#material-ui/icons/Close";
import Typography from "#material-ui/core/Typography";
import OutlinedInput from "#material-ui/core/OutlinedInput";
import { ProjectTreeWindow } from "../index";
const useStyles = makeStyles(theme => ({
addTaskButton: {
marginTop: 10
},
dialog: {
width: "40%",
maxHeight: 435
},
closeButton: {
position: "absolute",
right: theme.spacing(1),
top: theme.spacing(1),
color: theme.palette.grey[500]
},
controlsWrapper: {
display: "flex",
alignItems: "center",
justifyContent: "space-between"
}
}));
const AddQuickTaskDialog = props => {
const classes = useStyles(props);
const { open, close } = props;
const [quickTaskDescription, setQuickTaskDescription] = useState("");
const [textInputRef, setTextInputRef] = useState(null);
const handleChangeQuickTaskDescription = event => {
setQuickTaskDescription(event.target.value);
};
const handleAddQuickTaskSubmit = () => {
alert("Quick task submitted");
close(textInputRef);
};
return (
<Dialog
data-testid="add-task-quick"
classes={{
paper: classes.dialog
}}
maxWidth="lg"
open={open}
keepMounted
onClose={() => {
close(textInputRef);
}}
aria-labelledby="quick-task-dialog"
aria-describedby="quick-task-dialog-description"
>
<DialogTitle id="quick-task-dialog-title">
<Typography variant="h6">Quick Add Task</Typography>
{close ? (
<IconButton
aria-label="close"
className={classes.closeButton}
onClick={() => {
close(textInputRef);
}}
>
<CloseIcon />
</IconButton>
) : null}
</DialogTitle>
<DialogContent>
<div className={classes.wrapper}>
<OutlinedInput
onChange={handleChangeQuickTaskDescription}
inputRef={input => {
setTextInputRef(input);
return input && input.focus();
}}
fullWidth
// className={showAddTaskInput ? classes.show : classes.hide}
placeholder="e.g. Take the dog out for a walk"
inputProps={{ "aria-label": "add task" }}
/>
<div className={classes.controlsWrapper}>
<Button
className={classes.addTaskButton}
disabled={quickTaskDescription.length === 0}
data-testId="quick-add-task-submit"
// onClick={handleAddTaskSubmit}
color="primary"
onClick={handleAddQuickTaskSubmit}
>
Add Task
</Button>
<ProjectTreeWindow />
</div>
</div>
</DialogContent>
</Dialog>
);
};
export default AddQuickTaskDialog;
and for the List component:
import React, { useState } from "react";
import { makeStyles } from "#material-ui/core";
import ListAltTwoToneIcon from "#material-ui/icons/ListAltTwoTone";
import IconButton from "#material-ui/core/IconButton";
import { CustomizedToolTip } from "../index";
import OutlinedInput from "#material-ui/core/OutlinedInput";
import DoneTwoToneIcon from "#material-ui/icons/DoneTwoTone";
import List from "#material-ui/core/List";
import ListItem from "#material-ui/core/ListItem";
import ListItemIcon from "#material-ui/core/ListItemIcon";
import ListItemText from "#material-ui/core/ListItemText";
import FiberManualRecordTwoToneIcon from "#material-ui/icons/FiberManualRecordTwoTone";
import { useProjectsValue, useSelectedProjectValue } from "../../context";
const useStyles = makeStyles(theme => ({
root: {
position: "absolute",
zIndex: 9999,
top: 200,
left: 0,
display: "flex",
flexDirection: "column",
"&:hover $child": {
visibility: "visible"
}
},
wrapper: {
position: "relative !important"
},
selected: {
"& $child": {
visibility: "visible !important"
}
},
hidden: {
visibility: "hidden"
},
listItemIcon: {
minWidth: 30
}
}));
const ProjectTreeWindowList = props => {
const [textInputRef, setTextInputRef] = useState(null);
const [typeProject, setTypedProject] = useState("");
const classes = useStyles(props);
const { projects } = useProjectsValue();
return (
<div className={classes.root}>
<OutlinedInput
// onChange={handleChangeQuickTaskDescription}
inputRef={input => {
setTextInputRef(input);
return input && input.focus();
}}
placeholder="Type a project"
inputProps={{ "aria-label": "select project" }}
/>
<List>
{projects &&
projects.map((project, index) => (
<ListItem
onClick={() => {
alert("move selected project to input");
}}
// selected={active === project.projectId}
button
// classes={{
// root: classes.root,
// selected: classes.selected
// }}
>
<ListItemIcon
className={classes.listItemIcon}
style={{ color: project.color }}
>
<FiberManualRecordTwoToneIcon />
</ListItemIcon>
<ListItemText primary={project.name} />
<ListItemIcon
className={`${classes.listItemIcon} ${classes.hidden}`}
>
<DoneTwoToneIcon />
</ListItemIcon>
</ListItem>
))}
</List>
</div>
);
};
const ProjectTreeWindow = props => {
const classes = useStyles(props);
const [showProjectTreeWindow, setShowProjectTreeWindow] = useState(false);
const handleShowProjectWindow = () => {
setShowProjectTreeWindow(!showProjectTreeWindow);
};
const handleCloseProjectWindow = () => {
setShowProjectTreeWindow(false);
};
return (
<div className={classes.wrapper}>
<CustomizedToolTip title="Select a project">
<IconButton onClick={handleShowProjectWindow} aria-label="add-project">
<ListAltTwoToneIcon />
</IconButton>
</CustomizedToolTip>
{showProjectTreeWindow ? <ProjectTreeWindowList /> : null}
</div>
);
};
export default ProjectTreeWindow;
It is because of the combinaison of position: relative and overflow-y: auto from the <Paper> component. If you override one of this property, it won't be hidden anymore.
To do this, there is a PaperProps property in <Dialog>.
Example:
<Dialog {...otherProps} PaperProps={{style: {position: 'static'} }}/>

React: How to include some standard size to box

I have been given some code which I do not fully understand. The project is hosted at: https://konekto.world/ and I am currently working on https://konekto.world/emergency_sent. I want the website to have a similar size in terms of size of textbox and padding as the one at https://konekto.world/. You can see the code below:
This is the screen I want to work on. As you can see I already wanted to apply style={padding} to the Grid but somehow this has no effect at all to the display.
import React from 'react';
import axios from 'axios';
//import Box from '#material-ui/core/Box';
import { makeStyles, withStyles } from '#material-ui/core/styles';
//import { styled } from '#material-ui/styles';
import { Header } from '../Layout';
import { CANCELLED } from 'dns';
import { Grid, Container, Box, Typography, Button } from '#material-ui/core';
//import { styled } from '#material-ui/styles';
import CONSTANTS from '../utils/Constants';
const styles = theme => ({
container: {
alignItems: 'center',
background: 'white',
border: 'black',
'border-width': 'medium',
'margin-top': '80px',
background: 'rgba(255, 255, 255, 0.8)',
'border-radius': '20px'
},
item: {
//background: 'red',
width: '80%',
//background: 'white',
'text-align': 'center',
'border-radius': '5px',
'margin-top': '10px'
},
label: {
background: 'white'
}
});
class EmergencySent extends React.Component {
constructor(props) {
super(props);
this.state = {};
this.classes = props.classes;
}
render() {
var elementStyle = {
padding: 2,
textAlign: 'center',
fontSize: '12px'
};
var buttonStyle = {
padding: 10,
textAlign: 'center',
fontSize: '12px'
};
let location_display = null;
if (this.state.location) {
location_display = (
<Typography>
{this.state.location.longitude}, {this.state.location.latitude}
</Typography>
);
}
var padding = {
padding: '20px',
maxwidt: '200px'
};
/*
deleted after you location...
(logitude, latitude):
{location_display}
*/
return (
<React.Fragment>
<Header />
<Grid
container
className={this.classes.container}
direction="column"
spacing={2}
style={padding}
>
<Grid item sm={12} className={this.classes.item} />
<br />
<h2> Emergency sent!</h2>
<br />
<Typography>
Your location and personal information was transmitted. You will be contacted soon.
</Typography>
<br />
<Button
item
className={this.classes.item}
variant="contained"
color="primary"
onClick={this.onSpecify}
>
Specify Emergency
</Button>
<Typography>
<br />
Press the 'Specify Emergency'-button to enter details of your
emergency situation and guide incoming help.
</Typography>
<br />
<br />
<br />
<Button
className={this.classes.item}
item
variant="contained"
color="secondary"
onClick={this.onCancel}
>
Cancel Emergency
</Button>
<br />
</Grid>
</React.Fragment>
);
}
}
export default withStyles(styles)(EmergencySent);
The code for the first screen (https://konekto.world/ ) to which I want to have a similar screen is this:
import React from 'react';
import axios from 'axios';
import { Link as RouterLink } from 'react-router-dom';
import {
Grid,
Box,
IconButton,
Link,
Typography,
FormControl,
FormLabel
} from '#material-ui/core';
import ArrowForward from '#material-ui/icons/ArrowForward';
import { makeStyles, withStyles } from '#material-ui/core/styles';
import CONST from '../utils/Constants';
import CheckBoxGroup from './CheckBoxGroup';
import CheckBox from './CheckBox';
import SOSButton from './SOSButton';
const styles = theme => ({
container: {
alignItems: 'center',
// background: 'white',
border: 'black',
'border-width': 'medium',
'margin-top': '80px',
background: 'rgba(255, 255, 255, 0.8)',
'border-radius': '20px'
},
item: {
// background: 'red',
width: '100%',
//background: 'white',
'text-align': 'center',
'border-radius': '5px',
'margin-top': '10px'
},
label: {
// background: 'white'
}
// forwardbutton: {
// 'text-align': 'right'
// }
});
class FormEmergencyType extends React.Component {
//const classes = useStyles(); //React HOOK API => looks nice
constructor(props) {
super(props);
//const { classes } = props;
this.classes = props.classes;
this.state = {}
}
render() {
return (
<Grid
container
className={this.classes.container}
direction="column"
spacing={2}
>
<Grid item sm={12} className={this.classes.item}>
<Typography variant="h5">Who do you want to contact?</Typography>
<CheckBoxGroup>
<CheckBox
title="Ambulance"
onChange={this.handleChange}
checked={this.state['ambulance']}
value="ambulance"
/>
<CheckBox
title="Fire Service"
onChange={this.handleChange}
checked={this.state['fire_service']}
value="fire_service"
/>
<CheckBox
title="Police"
onChange={this.handleChange}
checked={this.state['police']}
value="police"
/>
<CheckBox
title="Car Service"
onChange={this.handleChange}
checked={this.state['car_service']}
value="car_service"
/>
<CheckBox
title="Emergency Contacts"
onChange={this.handleChange}
checked={this.state['emergency_contacts']}
value="emergency_contacts"
/>
</CheckBoxGroup>
<Grid />
<Grid
item
sm={12}
className={(this.classes.item, this.classes.forwardbutton)}
>
<SOSButton onSubmit={this.props.onSubmit} />
</Grid>
</Grid>
</Grid>
);
}
}
export default withStyles(styles)(FormEmergencyType);
Thank you very much for your help!
When using material ui, to modify styles you need to put them inside the styles object. Then inside the component you make the component's class name classes.something. So what if you notice the Grid component has a className of classes.container so all you need to do is to add the padding styles to container inside the style object like so
import React from "react";
import axios from "axios";
//import Box from '#material-ui/core/Box';
import { makeStyles, withStyles } from "#material-ui/core/styles";
//import { styled } from '#material-ui/styles';
import { Header } from "../Layout";
import { CANCELLED } from "dns";
import { Grid, Container, Box, Typography, Button } from "#material-ui/core";
//import { styled } from '#material-ui/styles';
import CONSTANTS from "../utils/Constants";
const styles = theme => ({
container: {
alignItems: "center",
background: "white",
border: "black",
"border-width": "medium",
"margin-top": "80px",
background: "rgba(255, 255, 255, 0.8)",
"border-radius": "20px",
padding: "20px",
maxWidth: "200px"
},
item: {
//background: 'red',
width: "80%",
//background: 'white',
"text-align": "center",
"border-radius": "5px",
"margin-top": "10px"
},
label: {
background: "white"
}
});
class EmergencySent extends React.Component {
constructor(props) {
super(props);
this.state = {};
}
render() {
const { classes } = this.props;
var elementStyle = {
padding: 2,
textAlign: "center",
fontSize: "12px"
};
var buttonStyle = {
padding: 10,
textAlign: "center",
fontSize: "12px"
};
let location_display = null;
if (this.state.location) {
location_display = (
<Typography>
{this.state.location.longitude}, {this.state.location.latitude}
</Typography>
);
}
var padding = {};
/*
deleted after you location...
(logitude, latitude):
{location_display}
*/
return (
<React.Fragment>
<Header />
<Grid
container
className={classes.container}
direction="column"
spacing={2}
>
<Grid item sm={12} className={classes.item} />
<br />
<h2> Emergency sent!</h2>
<br />
<Typography>
Your location and personal information was transmitted. You will be
contacted soon.
</Typography>
<br />
<Button
item
className={classes.item}
variant="contained"
color="primary"
onClick={this.onSpecify}
>
Specify Emergency
</Button>
<Typography>
<br />
Press the 'Specify Emergency'-button to enter details of your
emergency situation and guide incoming help.
</Typography>
<br />
<br />
<br />
<Button
className={classes.item}
item
variant="contained"
color="secondary"
onClick={this.onCancel}
>
Cancel Emergency
</Button>
<br />
</Grid>
</React.Fragment>
);
}
}
export default withStyles(styles)(EmergencySent);

Resources