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

Responsive styles #10

Closed
bkrall opened this issue Mar 22, 2017 · 10 comments
Closed

Responsive styles #10

bkrall opened this issue Mar 22, 2017 · 10 comments
Labels

Comments

@bkrall
Copy link

bkrall commented Mar 22, 2017

I'm curious about the recommended way to show different styles for different screen sizes.

i.e., I have a two column layout for tablet and up, but for mobile, I'd like for my grid to stack to one column. Is that currently possible is should I just hide/show my content for responsive?

@wadackel
Copy link
Owner

wadackel commented Mar 23, 2017

Hi @bkrall. Thanks for Issues 😃

There is no plan to add column changes due to response as a function.

Instead, how about using react-sizeme as the parent component and changing the column by its width?

Example idea:

import React, { Component } from 'react';
import sizeMe from 'react-sizeme';
import StackGrid from 'react-stack-grid';

class YourComponent extends Component {
  render() {
    const { width } = this.props;

    return (
      <StackGrid
        // more...
        columnWidth={width <= 768 ? '100%' : '33.33%'}
      >
        // Grid items...
      </StackGrid>
    );
  }
}

export default sizeMe()(YourComponent);

@bkrall
Copy link
Author

bkrall commented Mar 23, 2017

This is a good solution, thanks!

@wadackel
Copy link
Owner

@bkrall You're welcome ! I am hoping that you will succeed ! 😃

@danielstaleiny
Copy link

You should write about this solution and how to go on different layouts based on screen size in readme.

@wadackel
Copy link
Owner

Hi @danielstaleiny, Sorry late...

Added to the document ✋
https://github.com/tsuyoshiwada/react-stack-grid#responsive-layout

@iammatthias
Copy link

@tsuyoshiwada can the responsive documentation be expanded on? Based on this thread, I assume that this code should display 3 columns on desktop, and 1 column on mobile?

columnWidth={width <= 768 ? '100%' : '33.33%'}

When I use that, it stays at 3 columns across all devices. I took a look at the documentation for "react-sizeme", but didn't come across a solution for this.

@danielstaleiny
Copy link

@iammatthias
Make sure that you are listening on width and that width has value.

@iammatthias
Copy link

iammatthias commented Mar 5, 2018

@danielstaleiny as far as I can tell, I am. I can see the width value change in the console when I reaize the window.

My code is here: https://github.com/iammatthias/net/blob/master/src/templates/post.js

Does anything stand out? I’m fairly new to React, so any help would be appreciated.

@danielstaleiny
Copy link

danielstaleiny commented Mar 5, 2018

Hey I can see that you are parsing width from data.contetnfullgalery but size me gives you size obj in this.props that means that you have to take with from this.props.size.width so change this line
const { title, createdAt, featuredImage, content, blurb, images, width } = this.props.data.contentfulGallery
to:
const { title, createdAt, featuredImage, content, blurb, images } = this.props.data.contentfulGallery
const {width} = this.props.size

next time console log variables you create and make sure that they have values.

@iammatthias
Copy link

That worked perfectly, thank you!

I thought I was calling it in the right place before, because I could see a width value changing in the Console. Really appreciate you pointing me in the right direction!

screenshot 2018-03-05 08 03 37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants