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

neal-react need media queries #24

Open
bySabi opened this issue May 15, 2016 · 0 comments
Open

neal-react need media queries #24

bySabi opened this issue May 15, 2016 · 0 comments

Comments

@bySabi
Copy link
Contributor

bySabi commented May 15, 2016

Hi @dennybritz. We need mediaqueries for Navbar code. I like very much current simple and clean aproach but I cannot put any logic on childrens cause this component are add twice on Navbar render.
I create a mediaquery module for this: https://www.npmjs.com/package/react-mediaquery-props

And rewrote Navbar like this.

import React from "react";
import classNames from "classnames";
import { mediaQuery } from "./media-query.jsx";
import { mdUp } from "./bootstrap4-media-query.js";

export const Navbar = mediaQuery(class Navbar extends React.Component {

  static propTypes = {
    brand: React.PropTypes.node.isRequired,
  };

  render() {
    const _className = classNames("navbar neal-navbar", this.props.className);

    const mdUp = this.props.mq.mdUp
      ? { id: 'header-nav', div: '', ul: 'pull-right' }   // medium Up
      : { id: 'mobile-nav', div: 'collapse neal-mobile-nav', ul: '' };

    return (
      <header className="neal-navbar-wrapper">
        <nav className={_className}>
          <div className="container">
            <button className="navbar-toggler hidden-md-up" type="button" data-toggle="collapse"
              data-target="#mobile-nav">
              &#9776;
            </button>
            <a className="navbar-brand hidden-sm-down" href="/">{this.props.brand}</a>
            <div className={`navbar-toggleable-sm ${mdUp.div}`} id={mdUp.id}>
              <ul className={`nav navbar-nav ${mdUp.ul}`}>
                {this.props.children}
              </ul>
            </div>
          </div>
        </nav>
      </header>
    );
  }
}, mdUp);

Tell me is OK for you and I will make a PR.

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

1 participant