473,624 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to have a universal js file in reactjs

Exequiel
288 Contributor
Hello guys, I'm new in REACTJS and Im using Material UI. My question is how can I chop chop this code here, I want to separate the functions for drawer in other file and called it DrawerSlider.js and import it to HTML tags in DrawerView.js wich contains the html tags,

Expand|Select|Wrap|Line Numbers
  1. import React from 'react';
  2. import clsx from 'clsx';
  3. import { makeStyles, useTheme } from '@material-ui/core/styles';
  4. import Drawer from '@material-ui/core/Drawer';
  5. import AppBar from '@material-ui/core/AppBar';
  6. import Toolbar from '@material-ui/core/Toolbar';
  7. import List from '@material-ui/core/List';
  8. import CssBaseline from '@material-ui/core/CssBaseline';
  9. import Typography from '@material-ui/core/Typography';
  10. import Divider from '@material-ui/core/Divider';
  11. import IconButton from '@material-ui/core/IconButton';
  12. import MenuIcon from '@material-ui/icons/Menu';
  13. import ChevronLeftIcon from '@material-ui/icons/ChevronLeft';
  14. import ChevronRightIcon from '@material-ui/icons/ChevronRight';
  15. import ListItem from '@material-ui/core/ListItem';
  16. import ListItemIcon from '@material-ui/core/ListItemIcon';
  17. import ListItemText from '@material-ui/core/ListItemText';
  18. import InboxIcon from '@material-ui/icons/MoveToInbox';
  19. import MailIcon from '@material-ui/icons/Mail';
  20.  
  21. const drawerWidth = 240;
  22.  
  23. const useStyles = makeStyles((theme) => ({
  24.   root: {
  25.     display: 'flex',
  26.   },
  27.   appBar: {
  28.     zIndex: theme.zIndex.drawer + 1,
  29.     transition: theme.transitions.create(['width', 'margin'], {
  30.       easing: theme.transitions.easing.sharp,
  31.       duration: theme.transitions.duration.leavingScreen,
  32.     }),
  33.   },
  34.   appBarShift: {
  35.     marginLeft: drawerWidth,
  36.     width: `calc(100% - ${drawerWidth}px)`,
  37.     transition: theme.transitions.create(['width', 'margin'], {
  38.       easing: theme.transitions.easing.sharp,
  39.       duration: theme.transitions.duration.enteringScreen,
  40.     }),
  41.   },
  42.   menuButton: {
  43.     marginRight: 36,
  44.   },
  45.   hide: {
  46.     display: 'none',
  47.   },
  48.   drawer: {
  49.     width: drawerWidth,
  50.     flexShrink: 0,
  51.     whiteSpace: 'nowrap',
  52.   },
  53.   drawerOpen: {
  54.     width: drawerWidth,
  55.     transition: theme.transitions.create('width', {
  56.       easing: theme.transitions.easing.sharp,
  57.       duration: theme.transitions.duration.enteringScreen,
  58.     }),
  59.   },
  60.   drawerClose: {
  61.     transition: theme.transitions.create('width', {
  62.       easing: theme.transitions.easing.sharp,
  63.       duration: theme.transitions.duration.leavingScreen,
  64.     }),
  65.     overflowX: 'hidden',
  66.     width: theme.spacing(7) + 1,
  67.     [theme.breakpoints.up('sm')]: {
  68.       width: theme.spacing(9) + 1,
  69.     },
  70.   },
  71.   toolbar: {
  72.     display: 'flex',
  73.     alignItems: 'center',
  74.     justifyContent: 'flex-end',
  75.     padding: theme.spacing(0, 1),
  76.     // necessary for content to be below app bar
  77.     ...theme.mixins.toolbar,
  78.   },
  79.   content: {
  80.     flexGrow: 1,
  81.     padding: theme.spacing(3),
  82.   },
  83. }));
  84.  
  85. export default function MiniDrawer() {
  86.   const classes = useStyles();
  87.   const theme = useTheme();
  88.   const [open, setOpen] = React.useState(false);
  89.  
  90.   const handleDrawerOpen = () => {
  91.     setOpen(true);
  92.   };
  93.  
  94.   const handleDrawerClose = () => {
  95.     setOpen(false);
  96.   };
  97.  
  98.   return (
  99.     <div className={classes.root}>
  100.       <CssBaseline />
  101.       <AppBar
  102.         position="fixed"
  103.         className={clsx(classes.appBar, {
  104.           [classes.appBarShift]: open,
  105.         })}
  106.       >
  107.         <Toolbar>
  108.           <IconButton
  109.             color="inherit"
  110.             aria-label="open drawer"
  111.             onClick={handleDrawerOpen}
  112.             edge="start"
  113.             className={clsx(classes.menuButton, {
  114.               [classes.hide]: open,
  115.             })}
  116.           >
  117.             <MenuIcon />
  118.           </IconButton>
  119.           <Typography variant="h6" noWrap>
  120.             Mini variant drawer
  121.           </Typography>
  122.         </Toolbar>
  123.       </AppBar>
  124.       <Drawer
  125.         variant="permanent"
  126.         className={clsx(classes.drawer, {
  127.           [classes.drawerOpen]: open,
  128.           [classes.drawerClose]: !open,
  129.         })}
  130.         classes={{
  131.           paper: clsx({
  132.             [classes.drawerOpen]: open,
  133.             [classes.drawerClose]: !open,
  134.           }),
  135.         }}
  136.       >
  137.         <div className={classes.toolbar}>
  138.           <IconButton onClick={handleDrawerClose}>
  139.             {theme.direction === 'rtl' ? <ChevronRightIcon /> : <ChevronLeftIcon />}
  140.           </IconButton>
  141.         </div>
  142.         <Divider />
  143.         <List>
  144.           {['Inbox', 'Starred', 'Send email', 'Drafts'].map((text, index) => (
  145.             <ListItem button key={text}>
  146.               <ListItemIcon>{index % 2 === 0 ? <InboxIcon /> : <MailIcon />}</ListItemIcon>
  147.               <ListItemText primary={text} />
  148.             </ListItem>
  149.           ))}
  150.         </List>
  151.         <Divider />
  152.         <List>
  153.           {['All mail', 'Trash', 'Spam'].map((text, index) => (
  154.             <ListItem button key={text}>
  155.               <ListItemIcon>{index % 2 === 0 ? <InboxIcon /> : <MailIcon />}</ListItemIcon>
  156.               <ListItemText primary={text} />
  157.             </ListItem>
  158.           ))}
  159.         </List>
  160.       </Drawer>
  161.       <main className={classes.content}>
  162.         <div className={classes.toolbar} />
  163.         <Typography paragraph>
  164.           Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
  165.           ut labore et dolore magna aliqua. Rhoncus dolor purus non enim praesent elementum
  166.           facilisis leo vel. Risus at ultrices mi tempus imperdiet. Semper risus in hendrerit
  167.           gravida rutrum quisque non tellus. Convallis convallis tellus id interdum velit laoreet id
  168.           donec ultrices. Odio morbi quis commodo odio aenean sed adipiscing. Amet nisl suscipit
  169.           adipiscing bibendum est ultricies integer quis. Cursus euismod quis viverra nibh cras.
  170.           Metus vulputate eu scelerisque felis imperdiet proin fermentum leo. Mauris commodo quis
  171.           imperdiet massa tincidunt. Cras tincidunt lobortis feugiat vivamus at augue. At augue eget
  172.           arcu dictum varius duis at consectetur lorem. Velit sed ullamcorper morbi tincidunt. Lorem
  173.           donec massa sapien faucibus et molestie ac.
  174.         </Typography>
  175.         <Typography paragraph>
  176.           Consequat mauris nunc congue nisi vitae suscipit. Fringilla est ullamcorper eget nulla
  177.           facilisi etiam dignissim diam. Pulvinar elementum integer enim neque volutpat ac
  178.           tincidunt. Ornare suspendisse sed nisi lacus sed viverra tellus. Purus sit amet volutpat
  179.           consequat mauris. Elementum eu facilisis sed odio morbi. Euismod lacinia at quis risus sed
  180.           vulputate odio. Morbi tincidunt ornare massa eget egestas purus viverra accumsan in. In
  181.           hendrerit gravida rutrum quisque non tellus orci ac. Pellentesque nec nam aliquam sem et
  182.           tortor. Habitant morbi tristique senectus et. Adipiscing elit duis tristique sollicitudin
  183.           nibh sit. Ornare aenean euismod elementum nisi quis eleifend. Commodo viverra maecenas
  184.           accumsan lacus vel facilisis. Nulla posuere sollicitudin aliquam ultrices sagittis orci a.
  185.         </Typography>
  186.       </main>
  187.     </div>
  188.   );
  189. }
  190.  
or you can visit this site,
https://material-ui.com/components/drawers/#drawer

and scroll down to Mini variant drawer, you can view the code there. Hopefully you understand what I mean.
Than you.
Jul 14 '20 #1
0 2104

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1906
by: matt | last post by:
Hi I want to use a universal file "settings.inc" to hold the values for 3 or 4 php scripts. I have tried including it into all the pages in the top of the script, but have thus far been unsuccessful. Do i need to declate the values in some special way? Ta matt
3
4598
by: Pernell Williams | last post by:
Hi all: I am new to Python, and this is my first post (and it won't be my last!), so HELLO EVERYONE!! I am attempting to use "xreadlines", an outer loop and an inner loop in conjunction with "file.tell() and file.seek() in order to navigate through a file in order to print specific lines (for example, every 5th line). Allow me to illustrate by example:
1
771
by: Girish | last post by:
We have two db's. One live and one test. When I right click on the live one in SQL Enterprise Manager and select properties -> Data Files -> File Name is LIVE.MDF Location is F:\Data\LIVE.MDF When I right click on the test one in SQL Enterprise Manager and select properties -> Data Files -> File Name is LIVE.MDF
6
1540
by: strawberry | last post by:
i have a db set up that i access using an ftp connection, and an sql script file that i wish to run, how do i go about doing so? tia
3
2503
by: Larry R Harrison Jr | last post by:
I have an Access 97 secured database which I designed myself. I have the workgroup file and I have been both been trying to access it using a custom shortcut--which I updated to reflect the current filepaths of both the database and workgroup file--and I also tried just manually joining the workgrup file and double-clicking the aplication. I was successful at "joining" the workgroup file. I keep getting 'You Don't Have the Necessary...
2
2173
by: guru.slt | last post by:
my c program fails to write file that is bigger than 2G bytes. I used gcc compiler. After writing for a while, It says: "filesize limit exceed". How to solve this? But, if I compile the c code by "c++", then it can write more than 2G bytes in a file. Where is the problem for "gcc"? the code is here: --------------------------- #include <stdio.h>
1
1173
by: chiranjiv choudhary via .NET 247 | last post by:
Can we have CodeBehind file in another server or same machine but diffrent location or directory -------------------------------- From: chiranjiv choudhary ----------------------- Posted by a user from .NET 247 (http://www.dotnet247.com/) <Id>8svNZUU0T0eArey2uATMWw==</Id>
3
1671
by: MilanB | last post by:
Hello I'm asking is it possible that two or more Web User Control have same file (.ascx) name within same project? Namespace is different. I got error message: "CS1595: 'ASP.EditForm_ascx' is defined in multiple places;" I know that I have two controls EditForm, in different namespaces, but with same file name: "EditForm_ascx" If it is of any importance, I use both user controls on same page.
2
1203
by: dev121 | last post by:
Hi all, I have attempted to create a vb.net application that can extract neccessary data from a xml file to txt format. This is all working fine. The next step for me is to be able to scan a default folder for new files using a timer. I understand how the timer will work but need obviously to know how to scan a folder for files. which class do i use for that? every new xml file in the default folder should be converted when the...
1
2258
by: 4124 | last post by:
how can i cheak if the file empty or not in c language (i have function(FILE* fopenOrDie(char* name);))
0
8236
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8173
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8475
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7159
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.