Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use grid-template-areas in styled-components with react? [duplicate]

I'm trying to make a grid where I define the areas but the grid layout doesn't work on the screen. I'm not sure how can I debug this. It seems to me that I have defined everything correctly. What I'm missing?

const GridLayout = styled.div`
  height: 100vh;
  display: grid;
  grid-template-areas:
    'nav nav nav'
    'aside main aside'
    'footer footer footer';
  grid-template-rows: 1fr 9fr 1fr;
  grid-template-columns: 1fr 6fr 1fr;
`;

const Nav = styled.nav`
  grid-area: nav;
`;
const Aside = styled.aside`
  grid-area: aside;
`;
const Main = styled.main`
  grid-area: main;
`;
const Footer = styled.footer`
  grid-area: footer;
`;

function App() {
  return (
    <>
      <GlobalStyle globalProps={globalProps} />
      <ThemeProvider theme={theme}>
        <GridLayout>
          <Nav>Nav Area</Nav>
          <Aside />
          <Main>Main area</Main>
          <Aside />
          <Footer>Footer area</Footer>
        </GridLayout>
      </ThemeProvider>
    </>
  );
}
like image 341
karolis2017 Avatar asked Jul 05 '19 10:07

karolis2017


1 Answers

You can't have an area (aside in this case) with "parts" that are placed in unconnected sections of the grid. Create asideLeft and asideRight instead of a single aside area (sandbox):

const GridLayout = styled.div`
  height: 100vh;
  display: grid;
  grid-template-areas:
    "nav nav nav"
    "asideLeft main asideRight"
    "footer footer footer";
  grid-template-rows: 1fr 9fr 1fr;
  grid-template-columns: 1fr 6fr 1fr;
`;

const Nav = styled.nav`
  grid-area: nav;
`;
const AsideLeft = styled.aside`
  grid-area: asideLeft;
`;
const AsideRight = styled.aside`
  grid-area: asideRight;
`;
const Main = styled.main`
  grid-area: main;
`;
const Footer = styled.footer`
  grid-area: footer;
`;
like image 96
Ori Drori Avatar answered Nov 15 '22 08:11

Ori Drori