Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle conditional grid areas #2

Closed
3 tasks done
kettanaito opened this issue May 11, 2018 · 2 comments
Closed
3 tasks done

Handle conditional grid areas #2

kettanaito opened this issue May 11, 2018 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@kettanaito
Copy link
Owner

kettanaito commented May 11, 2018

What

Need to handle conditional grid areas.

Why

Consider:

const templateMobile = `
  'text'
`

const templateTablet = `
  'text subtext'
`

<Layout
  template={templateMobile}
  templateSm={templateTablet}>
  {({ Text, Subtext }) => (...)}
</Layout>

Using this example the Layout will throw when trying to render Subtext on mobile (subtext area is not preset in the template, therefore, its component is not created).

How

  1. Maybe creating an "empty" placeholder component for the areas which are not defined:
const Placeholder = () => null
  1. Maybe analyze each template to know the fullest list of areas, and create them all, no matter the screen size.

Roadmap

  • Implement conditional grid areas
  • Break down parseTemplateString composite function into smaller pure functions
  • Write unit tests
@kettanaito
Copy link
Owner Author

kettanaito commented May 13, 2018

Another idea may be using MediaQuery library to wrap the grid area according to its query size (xs, sm, etc.).

It's also quite fair to expect from the end developer to check for the conditional area existence before rendering it. In the end, it is the end developer who decides on which screen sizes certain areas are visible.

{ Subtext && <Subtext /> }

Benefits

  • Solves conditional rendering on different screen sizes

Downsides

  • Introduces extra dependency
  • Undefined window during SSR?

@kettanaito
Copy link
Owner Author

Update

Conditional grid areas were implemented using react-responsive.

Now, whenever conditional area is found, it is being wrapped in <MediaQuery /> with proper minWidth or/and maxWidth to match the requested resolution of the area.

@kettanaito kettanaito added the enhancement New feature or request label May 28, 2018
@kettanaito kettanaito self-assigned this May 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant