Skip to content

Instantly share code, notes, and snippets.

@schabluk
Created March 25, 2019 19:42
Show Gist options
  • Save schabluk/6999e07cd44233da751e12a0f03ccd37 to your computer and use it in GitHub Desktop.
Save schabluk/6999e07cd44233da751e12a0f03ccd37 to your computer and use it in GitHub Desktop.
Collapsible CSS Grid
const GridSpace = styled.section`
height: 100%;
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: auto fit-content(100%);
grid-template-areas:
'c c c c'
't t t t';
`
const GridChart = styled.div`
background-color: #ccc;
grid-area: c;
display: flex;
flex-direction: column;
`
const GridTable = styled.div`
background-color: #ddd;
grid-area: t;
display: flex;
flex-direction: column;
`
const DataGrid = props => {
const [expanded, setExpanded] = React.useState(true)
return (
<GridSpace>
<GridChart>
Grid Chart
</GridChart>
<GridTable>
<Button size='small' color='primary' onClick={e => setExpanded(!expanded)}>
{expanded ? 'Close' : 'Open'}
</Button>
{expanded && <p>Grid Table</p>}
</GridTable>
</GridSpace>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment