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

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!

Related

How do I change borderColor in native base Select Component?

I'm trying to change the borderColor on this Select Component from Native base.
Here is an image of the default color and the focused color:
The border is black by default. I already tried with borderColor="" and none/unset but it isn't changing the color.
How can I change the default and active border color?
The code is here..
useState,
} from 'react';
import {
Box,
Select,
CheckIcon,
} from 'native-base';
function Dropdown({
options = [],
placeholder,
backgroundColor,
className,
onChange = () => {},
}) {
const [value, setValue] = useState('');
return (
<Box>
<Box width="3/4" maxWidth="300">
<Select
className={className}
onChange={onChange}
minWidth="200"
selectedValue={value}
accessibilityLabel="Choose Service"
placeholder={placeholder}
backgroundColor={backgroundColor}
_selectedItem={{
bg: 'teal.600',
endIcon: <CheckIcon size="5" />,
}}
_focus={{
bg: 'white',
}}
marginTop={1}
onValueChange={(itemValue) => setValue(itemValue)}
>
{options.map((option) => (
<Select.Item
label={option.label}
value={option.value}
key={option.value}
style={{ display: 'flex', flexDirection: 'column', padding: 5 }}
/>
))}
</Select>
</Box>
</Box>
);
}```
You can use borderColor to specify border color and borderWidth to specify border width. To specify border color for focused inside _focus.
const Example = () => {
let [service, setService] = React.useState('');
return (
<Center>
<Box w="3/4" maxW="300">
<Select
_focus={{ borderColor: 'yellow.500' }}
borderColor="red.500"
selectedValue={service}
minWidth="200"
accessibilityLabel="Choose Service"
placeholder="Choose Service"
_selectedItem={{
bg: 'teal.600',
endIcon: <CheckIcon size="5" />,
}}
mt={1}
onValueChange={(itemValue) => setService(itemValue)}
>
<Select.Item label="UX Research" value="ux" />
<Select.Item label="Web Development" value="web" />
<Select.Item label="Cross Platform Development" value="cross" />
<Select.Item label="UI Designing" value="ui" />
<Select.Item label="Backend Development" value="backend" />
</Select>
</Box>
</Center>
);
};

How to render Material Ui buttons next to image list?

I have an imagelist and I want to render buttons below the images
This is my code so far;
export const Media = (stuff) => {
const { medias } = stuff;
console.log(medias);
const classes = useStyles();
return (
<div className={classes.root}>
<ImageList className={classes.imageList} gap={2} cols={3}>
{medias.map((media) => (
<ImageListItem key={media.cover_photo_url}>
<img
src={media.cover_photo_url}
className={classes.image}
style={{ borderRadius: "15px" }}
/>
<PlayArrowIcon className={classes.overlay} />
<ImageListItemBar subtitle={<LinkIcon></LinkIcon>} position="below"/>
</ImageListItem>
))}
</ImageList>
{medias.map((item) => (
<Buttons item={item} />
))}
</div>
);
};
I can display the buttons with the map function below however it doesnt scroll with the image that is relative with it horizontally
how can i make the buttons stick together with the images?
Thanks
you can try using <Box> like this
import Box from '#material-ui/core/Box';
<Box>
<ImageListItem key={media.cover_photo_url}>
<img
src={media.cover_photo_url}
className={classes.image}
style={{ borderRadius: "15px" }}
/>
<PlayArrowIcon className={classes.overlay} />
<ImageListItemBar subtitle={<LinkIcon></LinkIcon>} position="below"/>
</ImageListItem>
<Buttons item={item} />
</Box>
Just Remove Second loop for buttons and bring button tag in first loop and wrapper ImageListItem and Button with a div
Replace this,
{medias.map((media) => (
<ImageListItem key={media.cover_photo_url}>
<img
src={media.cover_photo_url}
className={classes.image}
style={{ borderRadius: "15px" }}
/>
<PlayArrowIcon className={classes.overlay} />
<ImageListItemBar subtitle={<LinkIcon></LinkIcon>} position="below"/>
</ImageListItem>
))}
</ImageList>
{medias.map((item) => (
<Buttons item={item} />
))}
With this,
{medias.map((media) => (
<Box>
<ImageListItem key={media.cover_photo_url}>
<img
src={media.cover_photo_url}
className={classes.image}
style={{ borderRadius: "15px" }}
/>
<PlayArrowIcon className={classes.overlay} />
<ImageListItemBar subtitle={<LinkIcon></LinkIcon>} position="below"/>
</ImageListItem>
<Buttons item={media} />
</Box>
))}
You can Import the Box by using this
import Box from '#material-ui/core/Box';

Vertically center radio button - React and Bootstrap

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.

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