Skip to content

Instantly share code, notes, and snippets.

@sanketsingh27
Created July 13, 2019 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanketsingh27/4cbb97b2915b1d8892a52091930aa898 to your computer and use it in GitHub Desktop.
Save sanketsingh27/4cbb97b2915b1d8892a52091930aa898 to your computer and use it in GitHub Desktop.
Implementation of everything that is given on the official gormmet website.
Remove these files:
src/App.css
src/App.test.js
src/index.css
src/logo.svg
Inside src/index.js, remove the import of index.css.
INSTALL ALL THE GORMMET DEPENDENCY
------------------------------------
npm install grommet grommet-icons styled-components --save
------------------------------------------------------------------------------------------------------------------------------------------------
import React from 'react';
import {
Box,
Button,
Collapsible,
Heading,
Grommet,
Layer,
ResponsiveContext
} from 'grommet'
import {FormClose,Notification} from 'grommet-icons'
const AppBar = (props) => (
<Box
tag='header'
direction='row'
align='center'
justify='between'
background='brand'
pad={{left:'medium',right:'small', vertical:'small'}}
elevation="medium"
style={{zIndex:'1'}}
{...props}
/>
)
class App extends React.Component {
state ={
showSidebar : false
}
render(){
const {showSidebar} = this.state;
const theme = {
global: {
colors:{
brand: '#eeeeee'
},
font: {
family: 'Roboto',
size: '14px',
height: '20px',
},
},
};
return (
<Grommet theme={theme} full>
<ResponsiveContext.Consumer>
{size => (
<Box fill>
<AppBar>
<Heading level='3' margin='none'>Hello I am Sanket</Heading>
<Button
icon={<Notification/>}
onClick={()=>this.setState((prevState) =>({showSidebar: !prevState.showSidebar}))}
/>
</AppBar>
<Box
direction='row'
align='center'
justify='center'
flex overflow={{horizontal:'hidden'}}>
{/* app body */}
<Box flex
width='medium'
align='center' justify='center'>
App Body
</Box>
{/* sidebar */}
{ (!showSidebar || size !== 'small') ? (
<Collapsible direction="horizontal" open={showSidebar}>
<Box
width="medium"
background='light-2'
elevation='small'
align='center'
justify='center'
>
Sidebar
</Box>
</Collapsible>
):(
<Layer>
<Box
background='light-2'
tag='header'
justify='end'
align='center'
direction='row'
>
<button
icon={<FormClose/>}
onClick={() => this.setState({showSidebar:false})}
/>
</Box>
<Box
fill
background='light-2'
align='center'
justify='center'
>
sidebar
</Box>
</Layer>
)
}
</Box>
</Box>
)}
</ResponsiveContext.Consumer>
</Grommet>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment