Vertically center radio button - React and Bootstrap - css

I have a container hosting a radio button on the left and other buttons on the right. For some reason, I am unable to align the radio buttons inline with the buttons on the right. Please advice me on a way to fix this.
This is what I have so far:
Code:
import React, { Component } from "react";
import { Box, Flex } from "#rebass/grid";
import cx from "classnames";
import styled from "styled-components/macro";
import {
Button,
ButtonGroup,
Classes,
Colors,
Divider,
Icon,
Radio,
RadioGroup
} from "#blueprintjs/core";
import { IconNames } from "#blueprintjs/icons";
import "normalize.css/normalize.css";
import "#blueprintjs/core/lib/css/blueprint.css";
import "#blueprintjs/icons/lib/css/blueprint-icons.css";
import "#blueprintjs/select/lib/css/blueprint-select.css";
import "bootstrap/dist/css/bootstrap.css";
const ScenarioIcon = styled(Button)`
transition: all 0.2s ease;
}
`;
class App extends Component {
constructor() {
super();
this.state = {
name: "React"
};
}
render() {
return (
<Flex>
<Box width={"100%"}>
<div
style={{
padding: "20px",
backgroundColor: "red"
}}
className={cx("bp3-card bp3-interactive")}
>
<Flex alignItems="center" style={{ backgroundColor: "green" }}>
<RadioGroup onChange={() => {}} selectedValue={1}>
<Radio
style={{ backgroundColor: "yellow" }}
className={cx(Classes.TEXT_LARGE)}
label={"Sample"}
value={1}
/>
</RadioGroup>
<Box flex="auto" />
<ButtonGroup>
<ScenarioIcon
className="utility-button"
icon={<Icon icon={IconNames.EDIT} color={Colors.WHITE} />}
minimal={true}
title="Edit"
/>
<ScenarioIcon
className="utility-button"
icon={
<Icon icon={IconNames.DUPLICATE} color={Colors.WHITE} />
}
minimal={true}
title="Copy"
/>
<ScenarioIcon
className="utility-button"
icon={
<Icon
icon={IconNames.DOCUMENT_SHARE}
color={Colors.WHITE}
/>
}
minimal={true}
title={"Archive"}
/>
<ScenarioIcon
className="utility-button"
icon={
<Icon
icon={IconNames.TRASH}
color={Colors.RED1}
color={Colors.WHITE}
/>
}
minimal={true}
title="Delete"
/>
<Divider />
</ButtonGroup>
<Icon
icon={IconNames.CHEVRON_RIGHT}
color={Colors.WHITE}
className="align-self-center"
iconSize={20}
/>
</Flex>
</div>
</Box>
</Flex>
);
}
}
export default App;
CodeSandbox Link: Link
P.S: I am open to using bootstrap as well for alignment.

From what i see, there is some bottom margin to Radio.
If you use below style on 'Radio', it works just fine.
style={{ backgroundColor: "yellow", marginBottom: "0" }}

Set margin-bottom: 0; for label.

Related

custom accordion in Mui Nextjs and mui

there is quite a new component introduced in #mui/lab which is Masonary which deals with accordions on the sidebar but not the one I posted above. so far I have achieved
import React from 'react';
import IconButton from '#mui/material/IconButton';
import FavoriteIcon from '#mui/icons-material/Favorite';
import Devider from '#mui/material/Divider';
import ExpandMoreIcon from '#mui/icons-material/ExpandMore';
import { styled } from '#mui/material/styles';
import { css } from '#emotion/react';
import { Rating, Paper, Card, Box, CardHeader, CardContent, CardMedia, CardActions, Toolbar, Typography, Collapse } from '#mui/material';
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,
}),
}));
const DropDownPaperSection = ({ Pages, error }) => {
const [expanded, setExpanded] = React.useState(false);
const handleExpandClick = () => {
setExpanded(!expanded);
};
if (error) {
return <div className={style.Container} >An error occured: {error.message}</div>;
}
return (
<>
<Toolbar sx={{ bgcolor : '#f4f4f8'}}>
{Pages.data.map(Pages => (
//<div classname={style.main}>
<Box key={`$Pages.id`} variant='outlined' spacing={2 } elevation={1} style={{ margin: "16px 0px", border: "1px solid black" }}
css={css`
color: #20b2aa;
:hover {
color: #2e8b57;
}
`}>
{/* {Pages.attributes.Title}
{Pages.attributes.createdAt}
*/}
<Box>
<Typography variant="body2" color="text.secondary" className="hover:bg-violet-300">
{Pages.attributes.Title}</Typography>
</Box>
<Box enableSpacing>
<ExpandMore
expand={expanded}
onClick={handleExpandClick}
aria-expanded={expanded}
aria-label="show more"
>
<ExpandMoreIcon />
</ExpandMore>
</Box>
<Collapse in={expanded} timeout="auto" unmountOnExit>
<Typography paragraph padding="10px">
<Box sx={{ my: 8, spacing: 10, margin: 2 }} key={`$Pages.id`}> {Pages.attributes.Description} </Box></Typography>
<Devider />
<Box sx={{ my: 8, spacing: 10, margin: 2 }} key={`$Pages.id`}> {Pages.attributes.Content} </Box>
</Collapse>
</Box>
))} </Toolbar>
</>
)
}
export default DropDownPaperSection
But I am stuck with detaching those two elements as seen in the picture.
if you need you may find the rest of the code in github is there any possible way to achieve the closest one? I am not very sure how can i proceed next to detach this accordion. Maybe I am missing very evil details to detach them.
EDIT :
if we somehow use the portal and update the component it comes out as a combined section of multiple rows of data But not the desired output that I want.
```..........
<Collapse in={expanded} timeout="auto" unmountOnExit>
<Portal container={container.current} key={`$Pages.id`}>
<Typography paragraph padding="10px">
<Box sx={{ my: 8, spacing: 10, margin: 2 }} key={`$Pages.id`}> {Pages.attributes.Description} </Box></Typography>
<Devider />
<Box sx={{ my: 8, spacing: 10, margin: 2 }} key={`$Pages.id`}> {Pages.attributes.Content} </Box>
</Portal>
</Collapse>
<Box sx={{ p: 1, my: 1, border: '1px solid' }} key={`$Pages.id`} ref={container} />
</Box>
))} </Toolbar>
</React.Fragment> ```

Chakra UI : The background does not dim when the drawer opens

This is the first time I am using chakra UI for my project. I am following the documentation to implement the UI. The drawer example mentioned in the documentation works perfectly. But when I try to use the same for my project the background does not dim.
Here is the screenshot of the same.
Below is the code for the same.
Filename: Campaigns.js
The drawer component is at the end of the file (CreateCampaign)
import React from "react";
import {
Avatar,
Box,
Collapse,
DrawerContent,
DrawerOverlay,
Flex,
Icon,
IconButton,
Input,
InputGroup,
InputLeftElement,
Text,
useColorModeValue,
useDisclosure,
useColorMode,
Button,
Drawer,
} from "#chakra-ui/react";
import {AddIcon} from '#chakra-ui/icons';
import { FaBell, FaClipboardCheck, FaRss } from "react-icons/fa";
import { FaMoon, FaSun } from "react-icons/fa";
import { AiFillGift } from "react-icons/ai";
import { BsGearFill } from "react-icons/bs";
import { FiMenu, FiSearch } from "react-icons/fi";
import { HiCode, HiCollection } from "react-icons/hi";
import { MdHome, MdKeyboardArrowRight } from "react-icons/md";
import { BrowserRouter, Switch, Route,useRouteMatch } from 'react-router-dom';
import DonationBasedForm from '../../components/CreateDonationBased/CreateDonationBased'
import Campaigns from "../Campaigns/Campaigns";
import CreateCampaign from "../../components/CreateCampaign/CreateCampaign";
export default function Swibc() {
const sidebar = useDisclosure();
const integrations = useDisclosure();
// Create campaign drawer hooks
const { isOpen, onOpen, onClose } = useDisclosure();
const btnRef = React.useRef();
let { path, url } = useRouteMatch();
const { toggleColorMode: toggleMode } = useColorMode();
const SwitchIcon = useColorModeValue(FaMoon, FaSun);
const NavItem = (props) => {
const { icon, children, ...rest } = props;
return (
<Flex
align="center"
px="4"
pl="4"
py="3"
cursor="pointer"
color={useColorModeValue("inherit", "gray.400")}
_hover={{
bg: useColorModeValue("gray.100", "gray.900"),
color: useColorModeValue("gray.900", "gray.200"),
}}
role="group"
fontWeight="semibold"
transition=".15s ease"
{...rest}
>
{icon && (
<Icon
mr="2"
boxSize="4"
as={icon}
/>
)}
{children}
</Flex>
);
};
const SidebarContent = (props) => (
<Box
as="nav"
pos="fixed"
top="0"
left="0"
zIndex="sticky"
h="full"
pb="10"
overflowX="hidden"
overflowY="auto"
bg={useColorModeValue("white", "gray.800")}
borderColor={useColorModeValue("inherit", "gray.700")}
borderRightWidth="1px"
w="60"
{...props}
>
<Flex px="4" py="5" align="center">
<Text
fontSize="2xl"
ml="2"
color={useColorModeValue("brand.500", "white")}
fontWeight="semibold"
>
cffp
</Text>
</Flex>
<Flex
direction="column"
as="nav"
fontSize="sm"
color="gray.600"
aria-label="Main Navigation"
>
<NavItem icon={MdHome}>Home</NavItem>
<NavItem icon={FaRss}>Articles</NavItem>
<NavItem icon={HiCollection}>Collections</NavItem>
<NavItem icon={FaClipboardCheck}>Checklists</NavItem>
<NavItem icon={HiCode} onClick={integrations.onToggle}>
Integrations
<Icon
as={MdKeyboardArrowRight}
ml="auto"
transform={integrations.isOpen && "rotate(90deg)"}
/>
</NavItem>
<Collapse in={integrations.isOpen}>
<NavItem pl="12" py="2">
Shopify
</NavItem>
<NavItem pl="12" py="2">
Slack
</NavItem>
<NavItem pl="12" py="2">
Zapier
</NavItem>
</Collapse>
<NavItem icon={AiFillGift}>Changelog</NavItem>
<NavItem icon={BsGearFill}>Settings</NavItem>
</Flex>
</Box>
);
return (
<>
<Box
as="section"
bg={useColorModeValue("gray.50", "gray.700")}
minH="100vh"
>
<SidebarContent display={{ base: "none", md: "unset" }} />
<Drawer
isOpen={sidebar.isOpen}
onClose={sidebar.onClose}
placement="left"
>
<DrawerOverlay />
<DrawerContent>
<SidebarContent w="full" borderRight="none" />
</DrawerContent>
</Drawer>
<Box ml={{ base: 0, md: 60 }} transition=".3s ease">
<Flex
as="header"
align="center"
justify="space-between"
w="full"
px="4"
bg={useColorModeValue("white", "gray.800")}
borderBottomWidth="1px"
borderColor={useColorModeValue("inherit", "gray.700")}
h="14"
>
<IconButton
aria-label="Menu"
display={{ base: "inline-flex", md: "none" }}
onClick={sidebar.onOpen}
icon={<FiMenu />}
size="sm"
/>
<InputGroup w="96" display={{ base: "none", md: "flex" }}>
<InputLeftElement color="gray.500" children={<FiSearch />} />
<Input placeholder="Search for articles..." />
</InputGroup>
<Flex align="center">
<Button
colorScheme="brand"
size="sm"
mr={[1,1,3]}
onClick={onOpen}
ref={btnRef}
>
Create <AddIcon ml={[1,1,2]} />
</Button>
<Avatar
mr="4"
size="sm"
name="anubra266"
src="https://avatars.githubusercontent.com/u/30869823?v=4"
cursor="pointer"
/>
<Icon mr={4} ml={4} color="gray.500" as={SwitchIcon} cursor="pointer" onClick={toggleMode}/>
</Flex>
</Flex>
<Box as="main" p="4">
<Switch>
<Route path={path} exact>
<Campaigns />
</Route>
<Route path={`${path}/new`}>
<DonationBasedForm />
</Route>
</Switch>
</Box>
</Box>
</Box>
<CreateCampaign onClose={onClose} isOpen={isOpen} btnRef={btnRef}/>
</>
);
}
Filename : CreateCampaigns.js
import React from 'react';
import {
Drawer,
DrawerContent,
DrawerCloseButton,
DrawerFooter,
DrawerBody,
DrawerHeader,
Stack,
Box,
FormLabel,
InputGroup,
Input,
InputLeftAddon,
InputRightAddon,
Textarea,
Button,
Select
} from '#chakra-ui/react';
const CreateCampaign = (props) => {
return (
<Drawer
isOpen={props.isOpen}
placement="right"
onClose={props.onClose}
size="xl"
>
<DrawerContent>
<DrawerCloseButton />
<DrawerHeader borderBottomWidth="1px">
Create a new account
</DrawerHeader>
<DrawerBody>
<Stack spacing="24px">
<Box>
<FormLabel htmlFor="username">Name</FormLabel>
<Input
id="username"
placeholder="Please enter user name"
/>
</Box>
<Box>
<FormLabel htmlFor="url">Url</FormLabel>
<InputGroup>
<InputLeftAddon>http://</InputLeftAddon>
<Input
type="url"
id="url"
placeholder="Please enter domain"
/>
<InputRightAddon>.com</InputRightAddon>
</InputGroup>
</Box>
<Box>
<FormLabel htmlFor="owner">Select Owner</FormLabel>
<Select id="owner" defaultValue="segun">
<option value="segun">Segun Adebayo</option>
<option value="kola">Kola Tioluwani</option>
</Select>
</Box>
<Box>
<FormLabel htmlFor="desc">Description</FormLabel>
<Textarea id="desc" />
</Box>
</Stack>
</DrawerBody>
<DrawerFooter borderTopWidth="1px">
<Button variant="outline" mr={3} onClick={props.onClose}>
Cancel
</Button>
<Button colorScheme="blue">Submit</Button>
</DrawerFooter>
</DrawerContent>
</Drawer>
)
}
export default CreateCampaign;
You'll need to use the DrawerOverlay component:
import { DrawerOverlay } from '#chakra-ui/react'
As seen in this example on line 30, the DrawerOverlay component should be at the top of the Drawer component:
import React from 'react';
import {
Drawer,
DrawerOverlay,
DrawerContent,
DrawerCloseButton,
DrawerFooter,
DrawerBody,
DrawerHeader,
Stack,
Box,
FormLabel,
InputGroup,
Input,
InputLeftAddon,
InputRightAddon,
Textarea,
Button,
Select
} from '#chakra-ui/react';
const CreateCampaign = (props) => {
return (
<Drawer
isOpen={props.isOpen}
placement="right"
onClose={props.onClose}
size="xl"
>
<DrawerOverlay />
<DrawerContent>
<DrawerCloseButton />
<DrawerHeader borderBottomWidth="1px">
Create a new account
</DrawerHeader>
<DrawerBody>
<Stack spacing="24px">
<Box>
<FormLabel htmlFor="username">Name</FormLabel>
<Input
id="username"
placeholder="Please enter user name"
/>
</Box>
<Box>
<FormLabel htmlFor="url">Url</FormLabel>
<InputGroup>
<InputLeftAddon>http://</InputLeftAddon>
<Input
type="url"
id="url"
placeholder="Please enter domain"
/>
<InputRightAddon>.com</InputRightAddon>
</InputGroup>
</Box>
<Box>
<FormLabel htmlFor="owner">Select Owner</FormLabel>
<Select id="owner" defaultValue="segun">
<option value="segun">Segun Adebayo</option>
<option value="kola">Kola Tioluwani</option>
</Select>
</Box>
<Box>
<FormLabel htmlFor="desc">Description</FormLabel>
<Textarea id="desc" />
</Box>
</Stack>
</DrawerBody>
<DrawerFooter borderTopWidth="1px">
<Button variant="outline" mr={3} onClick={props.onClose}>
Cancel
</Button>
<Button colorScheme="blue">Submit</Button>
</DrawerFooter>
</DrawerContent>
</Drawer>
)
}
export default CreateCampaign;
I hope that this answers your question!

How to increase the vertical spacing between a Material UI FormLabel and Slider?

I'm working on a map with an image overlay that has adjustable opacity. Here is the component code:
import React from 'react'
import PropTypes from 'prop-types'
import { MapWithGroundOverlay } from './MapWithGroundOverlay'
import { withStyles } from '#material-ui/core/styles'
import Box from '#material-ui/core/Box'
import FormLabel from '#material-ui/core/FormLabel'
import Slider from '#material-ui/lab/Slider'
import Grid from '#material-ui/core/Grid'
import Paper from '#material-ui/core/Paper'
const styles = theme => ({
root: {
flexGrow: 1,
},
paper: {
padding: theme.spacing(2),
textAlign: 'center',
color: theme.palette.text.secondary,
},
label: {
padding: theme.spacing(3),
}
})
class AdjustableGroundoverlay extends React.PureComponent {
constructor(props, context) {
super(props, context)
this.state = {opacity: 0.5}
this.handleChange = this.handleChange.bind(this);
}
handleChange(event, value) {
this.setState(state => ({
opacity: value
}));
}
render() {
return (
<Grid container className={this.props.classes.root} spacing={2}>
<Grid item xs={12}>
<MapWithGroundOverlay
googleMapURL={`https://maps.googleapis.com/maps/api/js?key=${process.env.REACT_APP_GOOGLE_MAPS_API_KEY}&v=3.exp&libraries=geometry,drawing,places`}
loadingElement={<div style={{ height: `100%` }} />}
containerElement={<div style={{ height: `600px` }} />}
mapElement={<div style={{ height: `100%` }} />}
opacity={this.state.opacity}
/>
</Grid>
<Grid item xs={6}>
<Paper className={this.props.classes.paper}>
<Box flexDirection="column">
<FormLabel className={this.props.classes.label}>Overlay opacity</FormLabel>
<Slider
value={this.state.opacity}
min={0}
max={1}
onChange={this.handleChange}
/>
</Box>
</Paper>
</Grid>
</Grid>
);
}
}
AdjustableGroundoverlay.propTypes = {
classes: PropTypes.object.isRequired,
}
export default withStyles(styles)(AdjustableGroundoverlay)
The problem is that the FormLabel and Slider are too close together. If I hover over them, I see that the Slider has a negative margin of -24px:
It seems like the content of the FormLabel therefore sits directly on top of it:
I've tried to change the styling of the Slider by adding these classes to the component in accordance with https://material-ui.com/api/slider/#css:
<Slider
classes={{container: {marginTop: -12}}}
value={this.state.opacity}
min={0}
max={1}
onChange={this.handleChange}
/>
but the spacing between the FormLabel and the Slider remains the same. Any idea what is wrong with this implementation?
Update
I've noticed in the console that there is this error:
I'm not sure why the key 'container' is not valid though since it is mentioned in https://material-ui.com/api/slider/#css.
I resolved this by putting the slider in a Box with mt set to 1:
<Paper className={this.props.classes.paper}>
<Box flexDirection="column">
<FormLabel className={this.props.classes.label}>Overlay opacity</FormLabel>
<Box mt={1}>
<Slider
value={this.state.opacity}
min={0}
max={1}
onChange={this.handleChange}
/>
</Box>
</Box>
</Paper>
Now there is more spacing between the label and the slider:

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

How to align React Material-UI list items using fontAwesome icons and Tailwind.css

I want to left-align the text of my list items. I also want to make all the icons the same size. The size of the envelope icon used with the Gmail list item. Currently, I have this:
How can I accomplish this?
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '#material-ui/core/styles';
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 DraftsIcon from '#material-ui/icons/Drafts';
import { FontAwesomeIcon } from '#fortawesome/react-fontawesome';
import { faFacebook, faGoogle, faGooglePlus, faTwitter, faYoutube, } from '#fortawesome/free-brands-svg-icons';
const styles = theme => ({
root: {
width: '100%',
maxWidth: 360,
backgroundColor: theme.palette.background.paper,
},
container: {
width: '20px', // this does not work
}
});
function SimpleList(props) {
const { classes } = props;
return (
<div className={classes.root}>
<List component="nav">
<ListItem button>
<ListItemIcon className="container">
<FontAwesomeIcon icon={faGoogle} />
</ListItemIcon>
<ListItemText primary="Login with Google" />
</ListItem>
<ListItem button>
<ListItemIcon className="container">
<FontAwesomeIcon icon={faTwitter} />
</ListItemIcon>
<ListItemText primary="Login with Twitter" />
</ListItem>
<ListItem button>
<ListItemIcon className="container">
<DraftsIcon />
</ListItemIcon>
<ListItemText primary="Login with Gmail" />
</ListItem>
<ListItem button>
<ListItemIcon className="container">
<FontAwesomeIcon icon={faFacebook} />
</ListItemIcon>
<ListItemText primary="Login with Facebook" />
</ListItem>
<ListItem button>
<ListItemIcon className="container">
<FontAwesomeIcon icon={faYoutube} />
</ListItemIcon>
<ListItemText primary="Login with Youtube" />
</ListItem>
<ListItem button>
<ListItemIcon className="container">
<FontAwesomeIcon icon={faGooglePlus} />
</ListItemIcon>
<ListItemText primary="Login with Google Plus" />
</ListItem>
</List>
</div>
);
}
SimpleList.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(SimpleList);
Using fontSize CSS on the FontAwesomeIcon and DraftsIcon should do the trick. You most likely will also need to override any default padding and margin on the icons.
...
const styles = theme => ({
root: {
width: '100%',
maxWidth: 360,
backgroundColor: theme.palette.background.paper,
},
faIcon: {
fontSize: 18,
// padding if needed (e.g., theme.spacing.unit * 2)
// margin if needed
},
muiIcon: {
fontSize: 18,
// padding if needed
// margin if needed
}
});
class SimpleList extends React.Component {
render() {
const { classes } = this.props;
const list = [
{
label: 'label 1',
icon: <FontAwesomeIcon className={classes.faIcon} icon={faTwitter} />
},
{
label: 'label 2',
icon: <DraftsIcon className={classes.muiIcon} />
}
];
return <div className={classes.root}>
<List component='nav'>
{
list.map((item, key) => (
<ListItem button>
<ListItemIcon>
{ item.icon }
</ListItemIcon>
<ListItemText primary={ item.label } />
</ListItem>
))
}
</List>
</div>;
}
}
SimpleList.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(SimpleList);

Resources