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

xs={0} or md={0} for hide #57

Open
ivansglazunov opened this issue Aug 26, 2016 · 13 comments
Open

xs={0} or md={0} for hide #57

ivansglazunov opened this issue Aug 26, 2016 · 13 comments

Comments

@ivansglazunov
Copy link

Why not make it easy to hide elements at certain screen sizes? Please please please :)

@oliverbenns
Copy link

oliverbenns commented Nov 15, 2016

Not sure about the props. In the past I've created <Visible> or <Hidden> elements. This might be a better approach? Not sure if that really fits in with the scope of this project though, but I certainly appreciate the need for it.

E.g.

<Visible xs sm>
    <h1>Only on mobile!</h1>
</Visible>

This was referenced Dec 23, 2016
@arjshiv
Copy link

arjshiv commented Mar 6, 2017

👍 This would be very useful

@silvenon
Copy link
Collaborator

silvenon commented Mar 6, 2017

@arjshiv follow #82 for news about this. The feature has not yet landed it flexboxgrid itself, as I understood.

@arjshiv
Copy link

arjshiv commented Mar 6, 2017

@silvenon Thanks!

In the meantime, I'm using a solution similar to @oliverbenns, but with a pure CSS show-on-mobile / hide-on-mobile class that toggles display using media queries. As much as I'd like a pure React solution, this helps me solve this quickly for mobile screens without extra React components to handle display.

@lfender6445
Copy link

lfender6445 commented Jul 10, 2017

@ivansglazunov i really liked your proposal so I wanted to share this snippet which wraps the original component adding support for something like: <Col small={0} large={12} />

I simplified the API to small and large distinctions because I only care about distinguishing phones from tablets and desktops, but feel free to modify it for your needs

Usage:

<Col small={0} large={12} /> /* displays only on medium/large devices (tablets, desktops, large monitors) */
<Col small={12} large={0} /> /* displays only on phones/small devices (phones) */
import React, { PureComponent, PropTypes } from 'react'

import {
  Grid,
  Row,
  Col as FlexCol,
} from 'react-flexbox-grid'

import cn from 'classnames'

class Col extends PureComponent {
  // NOTE: add /fleboxgrid/ to css loader webpack config before use
  // https:/roylee0704/react-flexbox-grid#minimal-configuration

  static propTypes: {
    className: PropTypes.string,
    // less than 768px (phones)
    xs: PropTypes.number,
    // min width of 768px (tablets)
    sm: PropTypes.number,
    // min width of 1024px (laptops/desktops)
    md: PropTypes.number,
    // min width of 1200px (large monitors)
    lg: PropTypes.number,
    // less than 768px (phones)
    small: PropTypes.number,
    // more than 768px (anything larger than a phone)
    large: PropTypes.number,
  }

  get mappedProps() {
    const clonedProps = Object.assign({}, this.props)
    const newProps = {}

    const { small, large } = this.props

    if (typeof small === 'number') {
      if (small <= 0) {
        newProps.className = cn(this.props.className, 'hideOnSmall')
      } else {
        newProps.xs = small
      }
    }

    if (typeof large === 'number') {
      if (large <= 0) {
        newProps.className = cn(this.props.className, 'hideOnLarge')
      }
      newProps.sm = large
      newProps.md = large
      newProps.lg = large
    }

    delete clonedProps.small
    delete clonedProps.large

    return {
      ...clonedProps,
      ...newProps,
    }
  }

  render() {
    return (
      <FlexCol {...this.mappedProps} />
    )
  }
}

export { Row, Col }
export default Grid

From here you can easily toggle display via class toggles and media queries:

/* global.css */
@media screen and (max-width: 768px) {
  :global .hideOnMobile {
    display: none;
  }
}

@media screen and (min-width: 768px) {
  :global .hideOnLarge {
    display: none;
  }
}

x

@tawanorg
Copy link

+1

Please merge!

@benoj
Copy link

benoj commented Oct 9, 2017

This has been a long time coming? Seems like flexbox css has been abandoned – does that mean this project is going to become stale too?

@anton6
Copy link

anton6 commented Apr 7, 2018

Should this issue be marked as closed in favour of #138?

Just use className with any of these in your Column or Row:
.hidden-xs
.hidden-sm
.hidden-md
.hidden-lg
.hidden-xl

Fore more info: imevro/flexboxgrid2#4

@isaachinman
Copy link

Any update on this? Is this project still maintained?

@marcramser
Copy link

marcramser commented May 28, 2019

Would still be useful

@jpcmf
Copy link

jpcmf commented May 28, 2020

Very useful

1 similar comment
@patrickml
Copy link

Very useful

@jigmeloday
Copy link

if you guys are not using boostrap or other there is one solution using react useQueryMedia hook. i would be glad if we can handle those thing by grid itself like fxlayout.

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

No branches or pull requests