React: How to include some standard size to box - css

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);

Related

MaterialUI - Card Component positioning issues

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!

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

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?

Extra Line coming inside Textfield component of material-ui with outlined borders

I am trying to use Textfield component of material ui package. I am using variant="outlined" property of it. But inside that Textfield line is also coming so looks bad from ui prespective.
Any idea how to show only ouline boundary.
(source: imggmi.com)
I guess Textfield by default puts that line. Its is the line just below Phone*.
import React, { Component } from "react";
import { connect } from "react-redux";
import { signIn } from "../../store/actions/authActions";
import { trySignUp } from "../../store/actions/authActions";
import { Redirect } from "react-router-dom";
import Container from "#material-ui/core/Container";
import CssBaseline from "#material-ui/core/CssBaseline";
import Avatar from "#material-ui/core/Avatar";
import Typography from "#material-ui/core/Typography";
import LockOutlinedIcon from "#material-ui/icons/LockOutlined";
import { withStyles } from "#material-ui/styles";
import FormControlLabel from "#material-ui/core/FormControlLabel";
import Checkbox from "#material-ui/core/Checkbox";
import TextField from "#material-ui/core/TextField";
import Button from "#material-ui/core/Button";
class SignIn extends Component {
render() {
const { authError, auth, classes } = this.props;
if (auth.uid) return <Redirect to="/" />;
return (
<Container component="main" maxWidth="xs">
<CssBaseline />
<div className={classes.paper}>
<Avatar className={classes.avatar}>
<LockOutlinedIcon />
</Avatar>
<Typography component="h1" variant="h5">
Sign in
</Typography>
<form onSubmit={this.handleSubmit} className={classes.form}>
{!this.state.isOTPSent && (
<TextField
variant="outlined"
margin="normal"
required
fullWidth
type="tel"
id="phone"
label="Phone"
name="phone"
autoComplete="phone"
autoFocus
onChange={this.handleChange}
/>
)}
{this.state.isOTPSent && (
<TextField
variant="outlined"
margin="normal"
required
fullWidth
id="otp"
label="OTP"
name="otp"
autoFocus
onChange={this.handleChange}
/>
)}
<FormControlLabel
control={<Checkbox value="remember" color="primary" />}
label="Remember me"
/>
<div className="input-field">
<Button
type="submit"
fullWidth
variant="contained"
color="primary"
id="loginButtonId"
onClick={this.state.isOTPSent ? this.handleSubmit : null}
className={classes.submit}
>
{this.state.isOTPSent ? "Login" : "Get OTP"}
</Button>
<div className="red-text center">
{authError ? <p>{authError}</p> : null}
</div>
</div>
</form>
</div>
</Container>
);
}
}
const styles = theme => ({
"#global": {
body: {
backgroundColor: "white"
}
},
paper: {
marginTop: 50,
display: "flex",
flexDirection: "column",
alignItems: "center"
},
avatar: {
margin: 1,
backgroundColor: "red"
},
form: {
width: "100%", // Fix IE 11 issue.
marginTop: 1
},
submit: {
margin: (3, 0, 2)
}
});
const mapStateToProps = state => {
return {
authError: state.auth.authError,
auth: state.firebase.auth
};
};
const mapDispatchToProps = dispatch => {
return {
signIn: phoneNumber => dispatch(signIn(phoneNumber)),
trySignUp: () => dispatch(trySignUp())
};
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(withStyles(styles)(SignIn));
Need to remove the line.

How to change the position of an Icon component, within a Tab component?

I'm using MaterialUI's tabs in my React project.
This is the JSX for the tabs:
<AppBar color="default" position="static">
<Tabs indicatorColor="primary" textColor="primary" value={tabIndex} onChange={this.handleChange}>
{instances.map(instance =>
<StyledTab
style={{ textTransform: 'initial' }}
onClick={() => { this.changeActiveInstance(instance.id) }}
label={this.getTabAddress(instance)}
icon={<ClearIcon ></ClearIcon>}
>
</StyledTab>
)}
</Tabs>
This is how i inject the css:
const StyledTab = withStyles({
root: {
textTransform: 'initial'
},
})(Tab);
The result is this:
I would like to position the "ClearIcon" elsewhere. I tried playing with the style injection a bit, with no success.
Can somebody point me to the right direction?
When trying to customize any Material-UI component, the starting point is the CSS portion of the API documentation. The most relevant classes that you may want to override in this case are wrapper, labelContainer, and label.
The best way to fully understand how these are used and how they are styled by default (and therefore what you may want to override) is to look at the source code.
Here are the most relevant portions of the styles from Tab.js:
/* Styles applied to the `icon` and `label`'s wrapper element. */
wrapper: {
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
width: '100%',
flexDirection: 'column',
},
/* Styles applied to the label container element if `label` is provided. */
labelContainer: {
width: '100%', // Fix an IE 11 issue
boxSizing: 'border-box',
padding: '6px 12px',
[theme.breakpoints.up('md')]: {
padding: '6px 24px',
},
},
And here is the relevant code for understanding how these are used:
if (labelProp !== undefined) {
label = (
<span className={classes.labelContainer}>
<span
className={classNames(classes.label, {
[classes.labelWrapped]: this.state.labelWrapped,
})}
ref={ref => {
this.labelRef = ref;
}}
>
{labelProp}
</span>
</span>
);
}
<span className={classes.wrapper}>
{icon}
{label}
</span>
Below are some examples of possible ways to customize this.
import React from "react";
import PropTypes from "prop-types";
import Paper from "#material-ui/core/Paper";
import { withStyles } from "#material-ui/core/styles";
import Tabs from "#material-ui/core/Tabs";
import Tab from "#material-ui/core/Tab";
import PhoneIcon from "#material-ui/icons/Phone";
import FavoriteIcon from "#material-ui/icons/Favorite";
import PersonPinIcon from "#material-ui/icons/PersonPin";
const styles = {
root: {
flexGrow: 1,
maxWidth: 700
},
firstIcon: {
paddingLeft: 70
},
labelContainer: {
width: "auto",
padding: 0
},
iconLabelWrapper: {
flexDirection: "row"
},
iconLabelWrapper2: {
flexDirection: "row-reverse"
}
};
class IconLabelTabs extends React.Component {
state = {
value: 0
};
handleChange = (event, value) => {
this.setState({ value });
};
render() {
const { classes } = this.props;
return (
<Paper square className={classes.root}>
<Tabs
value={this.state.value}
onChange={this.handleChange}
variant="fullWidth"
indicatorColor="secondary"
textColor="secondary"
>
<Tab
icon={<PhoneIcon className={classes.firstIcon} />}
label="Class On Icon"
/>
<Tab
classes={{
wrapper: classes.iconLabelWrapper,
labelContainer: classes.labelContainer
}}
icon={<FavoriteIcon />}
label="Row"
/>
<Tab
classes={{
wrapper: classes.iconLabelWrapper2,
labelContainer: classes.labelContainer
}}
icon={<PersonPinIcon />}
label="Row-Reverse"
/>
<Tab icon={<PersonPinIcon />} label="Default" />
</Tabs>
</Paper>
);
}
}
IconLabelTabs.propTypes = {
classes: PropTypes.object.isRequired
};
export default withStyles(styles)(IconLabelTabs);
We have a inbuilt property to set the icon position of tab in material ui. Document link
iconPosition:'bottom' | 'end' | 'start' | 'top'

Resources