Created
November 18, 2020 20:46
-
-
Save AndrewAllison/22916bd0114cfaff07b5997847abeba5 to your computer and use it in GitHub Desktop.
Playing with gormmet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from 'react'; | |
// eslint-disable-next-line no-unused-vars | |
import { | |
Box, Button, Collapsible, Grommet, Heading, Layer, ResponsiveContext, | |
} from 'grommet'; | |
import PropTypes from 'prop-types'; | |
import { FormClose, Notification } from 'grommet-icons'; | |
const theme = { | |
global: { | |
colors: { | |
brand: '#228BE6', | |
}, | |
font: { | |
family: 'Roboto', | |
size: '18px', | |
height: '20px', | |
}, | |
}, | |
}; | |
const AppBar = ({ children }) => ( | |
<Box | |
tag="header" | |
direction="row" | |
align="center" | |
justify="between" | |
background="brand" | |
pad={{ left: 'medium', right: 'small', vertical: 'small' }} | |
elevation="medium" | |
style={{ zIndex: '1' }} | |
> | |
{children} | |
</Box> | |
); | |
AppBar.propTypes = { | |
children: PropTypes.oneOfType([PropTypes.element, PropTypes.array]).isRequired, | |
}; | |
const App = () => { | |
const [showSidebar, setShowSidebar] = useState(false); | |
return ( | |
<Grommet theme={theme} themeMode="dark" full> | |
<ResponsiveContext.Consumer> | |
{(size) => ( | |
<Box fill> | |
<AppBar> | |
<Heading level="3" margin="none">My App</Heading> | |
<Button | |
icon={<Notification />} | |
onClick={() => setShowSidebar(!showSidebar)} | |
/> | |
</AppBar> | |
<Box direction="row" flex overflow={{ horizontal: 'hidden' }}> | |
<Box flex align="center" justify="center"> | |
app body | |
</Box> | |
{(!showSidebar || size !== 'small') ? ( | |
<Collapsible direction="horizontal" open={showSidebar}> | |
<Box | |
flex | |
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={() => setShowSidebar(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