Coder Social home page Coder Social logo

aritheelk / hedron Goto Github PK

View Code? Open in Web Editor NEW
865.0 13.0 60.0 2.57 MB

A no-frills flexbox grid system for React, powered by styled-components.

Home Page: https://garetmckinley.github.io/hedron

License: MIT License

JavaScript 100.00%
react flexbox styled-components reactjs

hedron's Introduction

hedron logo

Travis npm David All Contributors Spectrum Chat

Quick Jump

Features

  • Add unlimited breakpoints
  • Any property can be altered by a breakpoint
  • Debug mode that allows easy visualization of your layout

Requirements

The follow dependencies must be installed in your project in order for hedron to work.

Installation

Using yarn

yarn add hedron@next

Using npm

npm install hedron@next

Usage

Basic Example

import React from "react";
import ReactDOM from "react-dom";
import Grid from "hedron";

const App = () => (
  <Grid.Bounds direction="vertical">
    <Grid.Box>Header</Grid.Box>
    <Grid.Box>Content</Grid.Box>
    <Grid.Box>Footer</Grid.Box>
  </Grid.Bounds>
);

ReactDOM.render(<App />, document.getElementById("root"));

Responsive Example

To make your layout responsive, use the Grid.Provider to define breakpoints. You can add as many or as few breakpoints as you'd like.

import React from "react";
import ReactDOM from "react-dom";
import Grid from "hedron";

const App = () => (
  <Grid.Provider
    padding="20px"
    breakpoints={{ sm: "-500", md: "501-750", lg: "+750" }}
  >
    <Grid.Bounds direction="vertical">
      <Grid.Box sm={{ hidden: true }}>
        This header hides on small screens
      </Grid.Box>
      <Grid.Box>Content</Grid.Box>
      <Grid.Box lg={{ padding: "50px" }}>
        This footer gains extra padding on large screens
      </Grid.Box>
    </Grid.Bounds>
  </Grid.Provider>
);

ReactDOM.render(<App />, document.getElementById("root"));

If you want to be more verbose with your naming convention, that's perfectly fine too! Go ahead and name your breakpoints whatever feels right

import React from "react";
import ReactDOM from "react-dom";
import Grid from "hedron";

const App = () => (
  <Grid.Provider
    breakpoints={{ mobile: "-500", tablet: "501-750", wide: "+750" }}
  >
    <Grid.Bounds direction="vertical">
      <Grid.Box mobile={{ hidden: true }}>Header</Grid.Box>
      <Grid.Box>Content</Grid.Box>
      <Grid.Bounds direction="vertical" wide={{ direction: "horizontal" }}>
        <Grid.Box>These boxes render side by side on wide screens</Grid.Box>
        <Grid.Box>These boxes render side by side on wide screens</Grid.Box>
      </Grid.Bounds>
    </Grid.Bounds>
  </Grid.Provider>
);

ReactDOM.render(<App />, document.getElementById("root"));

You don't need to fill all screen sizes either, if you only need elements to change on a single resolution, just add a single breakpoint! To learn more about breakpoints, check out the documentation for Grid.Provider.

Upgrading

Unfortunately, there's no simple way to upgrade from the pre 1.0.0 version, but here's a few tips to make your life easier if you decide to upgrade (which we recommend doing!)

  • The Page and Section components have been retired. In an effort to simplify, there are only two main components now with one Provider that helps configure the global grid.
  • Row has been replaced by Grid.Bounds. This change was made because Row implies that it can only go in one direction, while Grid.Bounds is capable of arranging children either horizontally or vertically.
  • Column has been replaced by Grid.Box. Again, this change was made because Column implies it only goes in one direction.
  • BreakpointProvider has been replaced by Grid.Provider. It was changed because it's can set more than just breakpoints.

Also: There are no longer default breakpoints. You must define breakpoints yourself via Grid.Provider. You can also finally set custom breakpoints, as many as you want!

Documentation

Grid.Provider

Props

  • padding: string - structure: 20px
    • Default padding to use for child Grid.Box components
  • breakpoints: { key: string } - structure: { name: query }
    • Breakpoints for setting resolution-specific properties on child Grid.Box components. Here's a basic outline for writing breakpoint queries:
      • -500 means that the breakpoint will trigger at 500px and smaller
      • 250-800 means that the breakpoint will trigger between 250px and 800px
      • +900 means that the breakpoint will trigger at 900px and larger
Defining Breakpoints

Defining breakpoints gives you strong control over the way your content is rendered at various screen sizes. Any property that can be set on Grid.Box can be set per-breakpoint. Here's a few things to keep in mind when defining breakpoints:

  • Breakpoints can be named whatever you'd like (with a few exceptions laid out in the next section)
  • When defining breakpoints, you must pass an array object containing only two values: the min and max (both must be integers)
  • Breakpoints can have overlapping values. Use responsibly though, as it's possible to produce unexpected results when setting conflicting values on a Grid.Box with overlapping breakpoints. i.e. if mobile and tablet have overlapping pixels, don't make a Grid.Box hide on mobile and show on tablet.

Restricted Breakpoint Names

Although you can name breakpoints whatever you want, there are a few names that we do not recommend using because they will conflict with existing property names. Most of these are pretty obvious and would never come up in real usage, but it's worth having a list here just to be sure!

  • background
  • border
  • checked
  • className
  • dangerouslySetInnerHTML
  • display
  • height
  • hidden
  • htmlFor
  • margin
  • onChange
  • opacity
  • padding
  • selected
  • style
  • suppressContentEditableWarning
  • suppressHydrationWarning
  • value
  • visibility
  • width

Grid.Bounds

Props

  • debug : boolean
    • Outlines the grid system so you can visualize the layout
  • flex: string - structure: grow shrink basis
    • Controls the CSS flex property
  • direction: string - horizontal or vertical
    • Sets the primary axis the children should be in line with
  • wrap: boolean
    • Sets whether the children should wrap when there's no more room on the primary axis
  • valign: string - top, center, or bottom
    • Alignment of children along the vertical axis
  • halign: string - left, center, or right
    • Alignment of children along the horizontal axis

Grid.Bounds also inherits all properties that Stylable has.

Grid.Bounds accepts aliases for the width property.

Available aliases are:

  • half - 50%
  • quarter - 25%
  • third - 33.3333333%
  • twoThirds - 66.666666%
  • threeQuarters - 75%
<Grid.Bounds sm={{ width: "half", height: "200px" }}>
  This box gains height on small devices
</Grid.Bounds>

Grid.Box

Props

  • debug : boolean
    • Outlines the grid system so you can visualize the layout
  • flex: string - structure: grow shrink basis
    • Controls the CSS flex property
  • fill: boolean
    • Sets whether the Box should fill up all available space
  • fluid: boolean
    • Convenience property for disabling padding
  • shiftRight: boolean
    • Shifts the box to the right of the parent Bounds
  • shiftLeft: boolean
    • Shifts the box to the ;eft of the parent Bounds
  • shiftUp: boolean
    • Shifts the box to the top of the parent Bounds
  • shiftDown: boolean
    • Shifts the box to the bottom of the parent Bounds

Grid.Box also inherits all properties that Stylable has.

Grid.Box accepts aliases for the width property.

Available aliases are:

  • half - 50%
  • quarter - 25%
  • third - 33.3333333%
  • twoThirds - 66.666666%
  • threeQuarters - 75%
<Grid.Box sm={{ width: "half", height: "200px" }}>
  This box gains height on small devices
</Grid.Box>

Contributors

Thanks goes to these wonderful people (emoji key):

Garet McKinley
Garet McKinley

πŸ’» πŸ“– πŸ‘€
Matt Hamil
Matt Hamil

πŸ’¬
Mikko Matilainen
Mikko Matilainen

πŸ’»
Nathaniel PichΓ©
Nathaniel PichΓ©

πŸ’» πŸ“–
Brian Stanback
Brian Stanback

πŸ’»
Stephen Mathieson
Stephen Mathieson

πŸ’»
James G. Best
James G. Best

πŸ’»

This project follows the all-contributors specification. Contributions of any kind are welcome!

Want to help? Join our Spectrum.chat community to get started!

Backers

Support us with a monthly donation and help us continue our activities. [Become a backer]

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor]

sponsored by timber

License

MIT

hedron's People

Contributors

achtan avatar aritheelk avatar brukh avatar cameck avatar dependabot-preview[bot] avatar dependabot[bot] avatar dfrankland avatar gitter-badger avatar iktl avatar jim-at-jibba avatar mandriv avatar mikkom avatar nathanielpiche avatar praxxis avatar stanback avatar stephenmathieson avatar vladpalkanov avatar xdamman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hedron's Issues

Shift not overruled by larger breakpoint?

In the flowing code, the shift is not 0 at md and above. Am I misunderstanding the API? I would expect the shift only to occur from sm to md.

<Row divisions={9} debug>
  <Column md={3}>column 1</Column>
  <Column md={3}>column 2</Column>
  <Column md={3} mdShift={0} smShift={1}>column 3</Column>
</Row>

Replace Row/Column with Container/Box

This is something that @matthamil and I have been discussing in our slack room. Basically, the Row/Column approach really doesn't make sense with flexbox, since flexboxes can be either horizontal or vertical.

Since 1.0.0 will be the first official release with breaking changes, it makes sense to go ahead and resolve the problem then rather than perpetuating an outdated Row/Column grid system. The current Row/Column API will remain the same for all 0.x.x releases, so no need to worry about these changes breaking your existing hedron projects.

The issue with the current API

If you want to make a layout that looks like this

pasted_image_at_2017_01_19_09_43_am

It requires an uncomfortable amount of nesting.

<Page debug>
  <Row>
    <Column xs={12} sm={6} md={4}>Header</Column>
  </Row>
  <Row>
    <Column xs={12}>Navigation</Column>
  </Row>

  <Row>
    <Column xs={12} sm={4}>
      <Row>
        <Column>Sidebar</Column>
      </Row>
      <Row>
        <Column>Some links</Column>
      </Row>
      <Row>
        <Column>Or other things</Column>
      </Row>
    </Column>
    <Column xs={12} sm={6} md={8}>
      <Row>
        <Column>First Post</Column>
        <Column>Second Post</Column>
        <Column>Third Post</Column>
      </Row>
    </Column>
  </Row>
</Page>

This can be resolved by implementing a way to set the flex-direction on the Row component. The biggest problem is that it introduces confusion with naming conventions. The word column refers to "a vertical division of a page or text."; so having columns that are horizontal divisions doesn't make a lot of sense.

It introduces even more confusion because the terms for flex-direction are either row or column.

The proposed solution

For now, we have collectively agreed on the terms Container and Box for our grid components. These components will also abstract away the typical flex properties as well, making flexbox properties easy to configure and most importantly, easy to remember.

(These properties are open to discussion)

Container

  • direction: horizontal|vertical
    • sets the direction of the contained elements. Default: horizontal
  • vAlign: top|middle|bottom
    • sets the vertical alignment of the contained elements. Default: middle
  • hAlign: left|center|right
    • sets the horizontal alignment of the contained elements. Default: center
  • flex: Object
    • allows you to manually set any flex property. Default: {}
    • Note: flex properties are camelCased instead of kabob-case. Also, there is no need for the flex prefix on any of the rules. So flex-direction becomes direction.

Box

The box will have all the same size/shift properties as Column. If the direction of the parent Container is set to horizontal, the boxes will be aligned like columns. If the direction is set to vertical, the boxes will be aligned like rows. This cuts down on the need for nesting πŸ‘

To create the same layout demonstrated above using the new API, it would look like this

<Page height='500px' overflow='scroll' debug>
  <Container direction='vertical' vAlign='middle'>
    <Box xs={12} sm={6} md={4}>Header</Box>
    <Box xs={12}>Navigation</Box>
  </Container>

  <Container direction='horizontal'>
    <Box xs={12} sm={4}>
      <Container direction='vertical' vAlign='top'>
        <Box>Sidebar</Box>
        <Box>Some links</Box>
        <Box>Or other things</Box>
      </Container>
    </Box>
    <Box xs={12} sm={6} md={8}>
      <Container direction='vertical' vAlign='middle'>
        <Box>First Post</Box>
        <Box>Second Post</Box>
        <Box>Third Post</Box>
      </Container>
    </Box>
  </Container>
</Page>

As you can see, the code is shorter and more shallow.

This new API is still being conceptualized, and we'd love to get any feedback you have 😸

If you want to join our discussions on slack, click here to join!

[v1] naming proposal

Hi, i was a bit confused when i saw the new components naming.

my proposal is :
current name -> new name
Section -> Container
Container -> Grid
Box -> Cell

Error in Page documentation

Hi, just a heads up:

On the Grid docs, it says that Page takes a parameter fluid of type Number, but apparently it's PropTypes expect it to be a Boolean instead.

Cheers!

Warning: Received `true` for a non-boolean attribute

There's currently a few warnings that are appearing when using 1.0.0, they look to be all rooted from the same issue, so it shouldn't be too difficult to fix.

Here are two examples that are appearing on https://hedron.garet.io

Warning: Received `true` for a non-boolean attribute `fill`.

If you want to write it to the DOM, pass a string instead: fill="true" or fill={value.toString()}.
    in div (created by styled.div)
    in styled.div (created by Styled(styled.div))
    in Styled(styled.div) (created by Styled(styled.div))
    in Styled(styled.div) (at index.js:53)
    in div (created by styled.div)
    in styled.div (created by Styled(styled.div))
    in Styled(styled.div) (created by Styled(styled.div))
    in Styled(styled.div) (at index.js:52)
    in div (created by styled.div)
    in styled.div (created by Styled(styled.div))
    in Styled(styled.div) (created by Styled(styled.div))
    in Styled(styled.div) (at index.js:51)
    in Provider (at index.js:50)
    in div (created by LiveProvider)
    in LiveProvider (at index.js:45)
    in ThemeProvider (at index.js:44)
    in Editor (created by App)
    in Container (created by App)
    in App
    in ErrorBoundary
Warning: Received `false` for a non-boolean attribute `wrap`.

If you want to write it to the DOM, pass a string instead: wrap="false" or wrap={value.toString()}.

If you used to conditionally omit it with wrap={condition && value}, pass wrap={condition ? value : undefined} instead.
    in div (created by styled.div)
    in styled.div (created by Styled(styled.div))
    in Styled(styled.div) (created by Styled(styled.div))
    in Styled(styled.div)
    in Provider
    in div (created by LivePreview)
    in LivePreview (at index.js:58)
    in div (created by styled.div)
    in styled.div (created by Styled(styled.div))
    in Styled(styled.div) (created by Styled(styled.div))
    in Styled(styled.div) (at index.js:56)
    in div (created by styled.div)
    in styled.div (created by Styled(styled.div))
    in Styled(styled.div) (created by Styled(styled.div))
    in Styled(styled.div) (at index.js:52)
    in div (created by styled.div)
    in styled.div (created by Styled(styled.div))
    in Styled(styled.div) (created by Styled(styled.div))
    in Styled(styled.div) (at index.js:51)
    in Provider (at index.js:50)
    in div (created by LiveProvider)
    in LiveProvider (at index.js:45)
    in ThemeProvider (at index.js:44)
    in Editor (created by App)
    in Container (created by App)
    in App
    in ErrorBoundary

Possibly being surfaced from the Base component.

It's odd, because both those properties (wrap and fill) are being set in propTypes, but it's probably something simple that I'm overlooking. Been staring at code a lot this week, so I'm gonna take a break for the night and revisit tomorrow.

If anybody looking at this has any ideas or wants to take a whack at it, feel free to.

The easiest way to get setup developing is to clone the repo, run yarn install and then yarn storybook. You will get setup with a live reloading storybook that has these warnings present in it.

Add a convenience component for generating <Row><Col/></Row>

Since this is a flexbox system, it's required that the object inside the Row has proper flex properties, or it could be rendered incorrectly. This is why it's always best to the use only the Col component inside the Row component.

This causes a lot of extraneous code, as if we want to make a single-column Row, we have to type it out like

<Row>
  <Column>
    <h1>This is a column that's centered using the shift props</h1>
  </Column>
</Row>

furthermore, nesting becomes a nightmare

<Row>
  <Column>
    <Row>
      <Column>
        <h1>This is a column that's centered using the shift props</h1>
      </Column>
    </Row>
  </Column>
  <Column>
    <Row>
      <Column>
        <h1>This is a column that's centered using the shift props</h1>
      </Column>
    </Row>
  </Column>
</Row>

I think it could be beneficial if there was a component along the lines of RowCol, that would generate both of them, so the above examples could be done with

<RowCol>
  <h1>This is a column that's centered using the shift props</h1>
</RowCol>

and

<Row>
  <Column>
    <RowCol>
      <h1>This is a column that's centered using the shift props</h1>
    </RowCol>
  </Column>
  <Column>
    <RowCol>
      <h1>This is a column that's centered using the shift props</h1>
    </RowCol>
  </Column>
</Row>

It would be able to accept all the props that Col accepts, and it passes the props directly to the Col component. This will speed up rendering for these types of object, as the Row won't have to loop through it's children applying the correct props.

This is not a final sketch of the idea, and I would like to continue discussing and adding to this idea.

'View interactive example on webpackbin' link is broken in README

Links to webpackbin page with the message:

The reason you see this page is that the route is invalid. You have probably clicked an old Webpackbin link. Please notify the author about moving their BIN to the new version of Webpackbin. In the meantime you can continue to the old version.

Add more extensive documentation

Currently the documentation is extremely lacking. All there is, is a basic usage example without much explanation. Each component and utility should be carefully documented listing all the accepted arguments along with expected outputs.

using justifycontent/alignitems?

Hi!

Love the simplicity of this. Was previously using radium grid and decided to give this a go for a small project and its been great. Absolutely love the debug mode.

One question, is there a way of controlling the other flexbox properties?

namely I'd like to do something like styles={{justifyContent: 'center', alignItems: 'center'}}

any ideas?

Error: Can't resolve 'styled-components'

Recently updated hedron, but it seems to be missing a dependency:

ERROR in ./node_modules/hedron/dist/hedron.js
Module not found: Error: Can't resolve 'styled-components' in '/Users/stephenmathieson/dev/src/github.com/stephenmathieson/someapp/node_modules/hedron/dist'
 @ ./node_modules/hedron/dist/hedron.js 2:99-127
 @ ./src/pages/index.js
 @ ./src/routes.js
 @ ./src/index.js
 @ multi (webpack)-dev-server/client?http://localhost:3000 webpack/hot/dev-server ./src/index.js

Maybe we should make note of the fact that you must have styled-components installed in order to use hedron in the README?

Outdated peer dependencies

Hey guys, first of all - great library, many thanks.

A small issue with react and styled-components peer dependencies - these are set for quite outdated versions right now.

warning " > [email protected]" has incorrect peer dependency "react@^15.0.0".
warning " > [email protected]" has incorrect peer dependency "[email protected] || ^2.0.0".

Could you update these to use e.g. react@^16.0.0 and styled-components@^3.0.0? That's the setup I am currently using your library and it is working sweet (except for divisions prop I mentioned in another issue).

Have a great day, cheers!
Wojtek

[v1] support width aliases

support width aliases like:

<Box width={{sm: "half", md: "third"}} />

is equivalent to:

<Box width={{sm: "50%", md: "33.3333333333%"}} />

SSR Components render unstyled at first when used with SSR

I am finding when I include Hedron in a SSR app the initial display of the component from the markup is missing the styling. After loading React rerenders with the correct styles.

This is likely related to styled-components, but I don't know what I need to add to make this work. I am already doing a bunch of work on my server bundle and client bundle for css-modules. Does this library require me to do anything specific for the SSR to work?

Thanks

Remove Styled Components

This project looks great but I won't want to add styled-components as a dependency to my application. Is there any future in which that is no longer a dependency?

[v1.0.0] passing `gutter={0}` on LayoutProvider doesn't set gutter to 0px

The below layout will get rendered with a 20px gutter, when it should be rendered with a 0px gutter. This is due to this line.

<LayoutProvider debug={{ enabled: true }} gutter={0}>
  <Section>
    <Container>
      <Box xs="100%">Header</Box>
    </Container>
    <Container>
      <Box xs="grow" sm="25%">Sidebar</Box>
      <Box sm="grow" fluid>
        <Container>
          <Box sm="100%" md="50%" lg="grow">A blog post</Box>
          <Box sm="100%" md="50%" lg="grow">Another blog post</Box>
          <Box sm="100%" md="50%" lg="grow">Yet another blog post</Box>
        </Container>
      </Box>
    </Container>
    <Container>
      <Box xs="100%">Footer</Box>
    </Container>
  </Section>
</LayoutProvider>

React Native support

qq 20161114224415

i have a problem when i run this compotent on android

i knows react not enough dasy sorry

Page component docs missing

Hey there. I have struggled a bit to get hedron working the way I wanted it to and I found the thing I was missing in the source of Page component. It's not specified in the docs that the fluid property can be used with the Page component. It now seems obvious, but for new people, this could be frustrating.

Integrate flow for type annotations

In an effort to continue maturing this module, I would like to integrate Flow at some point. This isn't too high in terms of importance on my list, but I plan to get to it eventually.

Since this is relatively low priority for me personally, I'm labeling this as help wanted. All contributors will get properly credited in the README 😸

TypeError: ofTypes.includes is not a function in Node v5.11.1

When integrating hedron into ViMD and testing on Travis-CI under node v5.11.1, I'm receiving the following error:

TypeError: ofTypes.includes is not a function

  at node_modules/hedron/dist/hedron.js:7482:60
  at mapSingleChildIntoContext (node_modules/react/lib/ReactChildren.js:107:26)
  at traverseAllChildrenImpl (node_modules/react/lib/traverseAllChildren.js:77:5)
  at traverseAllChildrenImpl (node_modules/react/lib/traverseAllChildren.js:93:23)
  at traverseAllChildren (node_modules/react/lib/traverseAllChildren.js:172:10)
  at mapIntoWithKeyPrefixInternal (node_modules/react/lib/ReactChildren.js:127:3)
  at Object.mapChildren [as map] (node_modules/react/lib/ReactChildren.js:149:3)
  at passOn (node_modules/hedron/dist/hedron.js:7478:42)
  at RowContainer (node_modules/hedron/dist/hedron.js:7502:21)
  at node_modules/react-test-renderer/lib/ReactCompositeComponent.js:306:16

I'm guessing it requires a polyfill or something for it. I don't have time to investigate right now, so I'm putting this up to reference later πŸ‘Œ

Here is the Travis-CI build that is causing the error.

Change the way hedron handles gutters

From Slack:

screen shot 2016-12-24 at 11 42 29 am

So the above thought happened in the jsbro slack room. I want to integrate a better gutter system that better suits the "flexbox way".

Unfortunately, it appears I'm not far off from the "flexbox way"; as this stackoverflow answer sums up that the best way he found to create flexbox gutters is via padding.

So what's the issue?

It's more of a design choice than an issue, but here it is summed up:

If you have a row divided into 4 equal columns each with their own padding, a few interesting things happen:

  • The Row gets 0 padding, it's treated as a fluid element
  • Each of the Column components get rendered with a 20px padding.
  • The 20px padding acts as a 40px gutter.

The issue here is that the first and last Columns have their gutters halved because there's no elements on either side of them granting the additional 20px padding. The solution for this lies inside the stackoverflow answer above, but unfortunately that creates another issue... Since the Row component would have padding, it becomes impossible to use the fluid property on Columns effectively. Since the best case scenario, is that the first and last Columns have a 20px padding, while the others are sitting edge to edge.

This would then force me to add another property onto the Row component for fluid. Which means that to have fluid Columns, we would have to also add fluid to the parent Row.

So why don't I do this?

It adds not only another layer of complexity to the grid layout, it also makes it impossible to mix fluid Columns with padded Columns, as the fluid property would have to be changed on the parent to make our Column sit up against the edge of the Row; which compromises that 20px padding we want added to the Column on the other side.

Implement an easy way to hide/show any component based on browser width

Currently this is semi-possible if you are using styled-components in your project. You can simply import the (currently undocumented) media utility and use it like so:

import styled from 'styled-components';
import { utils } from 'hedron';

const OnlyVisibleOnMobile = styled.div`
  ${utils.media.sm`
    display: hidden;
  `}
`;

This will toggle the display: hidden rule only when the screen size is sm or larger (resulting in it only being displayed on mobile).

The problem is, this requires elements to be encapsulated. Since to hide a button, we'd essentially have to do:

<OnlyVisibleOnMobile>
  <Button>My Button</Button>
</OnlyVisibleOnMobile>

Unless of course we wanted to add the above styled rules onto our Button component. But that wouldn't be practical markup at all, as it would force all of our Button components to be only visible on mobile.

The next possible solution is obviously adding another prop to our Button component that toggles this media query on and off. But this would have to be done for every component that we want to have toggle-able media queries.

This is asking a LOT of our users, when in reality, I want this to work right out of the box.

Need to keep brainstorming...

Vertically centering rows

Is there a recommended way to do this or should we just specify whatever styles directly on the <Page> component?

xs property on Column component doesn't work

I noticed that I must have overlooked something in the Column component. It appears that the xs breakpoint was never properly hooked up to actually resize the Column. So as-is, a Column component will always be 100% width when the xs breakpoint is active.

This is going to be an easy fix, just saving it here so I don't forget it πŸ‘

React version

Hi,
Could you update react version in hedron v0.7 for remove the warning?

Support Server Side Rendering

I am using next.js for server side rendering. I managed to use styled components because they support ssr now, but I have still problems with hedron.

grids do not work on mobile? please help it is driving me crazy

I would like to use Hedron in my project - the grid system works just as expected on desktop however mobile seems to completely ignore the grid system. Am I doing something wrong? Please see the attached image (not very helpful sorry) - also tested from my iPhone, the grid is not registering and rendering as lg desktop.

https://s22.postimg.org/pdgtfmi2p/Screen_Shot_2016_11_20_at_14_22_43.png

Thanks in advance.

I will try to write you some unit tests if I get time soon

Fails on npm run build

First off, great library @garetmckinley !

I just pulled down your library locally to do some hacking on it for the purpose of possibly contributing on some of the outstanding open issues. It failed on executing npm run build on my machine.

Here's my steps after cloning your repo:

  1. yarn install
  2. npm run build

I get this output in my terminal:

> [email protected] build /Users/jstratton/Documents/workspace/hedron
> npm run build:lib && npm run build:dist


> [email protected] build:lib /Users/jstratton/Documents/workspace/hedron
> babel src --out-dir lib

node_modules/nan
resolve failed:  { Error: Cannot find module 'eslint-module-utils'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.requireRelative.resolve (/Users/jstratton/Documents/workspace/hedron/node_modules/require-relative/index.js:30:17)
    at resolve (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:25:26)
    at findAndRemove (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:67:11)
    at /Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:111:13
    at Array.map (native)
    at loadPreset (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:103:29)
    at module.exports (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/index.js:97:19)
    at Object.<anonymous> (/Users/jstratton/Documents/workspace/hedron/node_modules/babel-preset-es2015-rollup/index.js:3:18)
    at Module._compile (module.js:570:32) code: 'MODULE_NOT_FOUND' } eslint-module-utils
resolve failed:  { Error: Cannot find module 'babel-runtime'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.requireRelative.resolve (/Users/jstratton/Documents/workspace/hedron/node_modules/require-relative/index.js:30:17)
    at resolve (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:25:26)
    at findAndRemove (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:67:11)
    at /Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:111:13
    at Array.map (native)
    at loadPreset (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:103:29)
    at module.exports (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/index.js:97:19)
    at Object.<anonymous> (/Users/jstratton/Documents/workspace/hedron/node_modules/babel-preset-es2015-rollup/index.js:3:18)
    at Module._compile (module.js:570:32) code: 'MODULE_NOT_FOUND' } babel-runtime
src/components/Column.js -> lib/components/Column.js
src/components/Page.js -> lib/components/Page.js
src/components/Row.js -> lib/components/Row.js
src/index.js -> lib/index.js
src/utils/divvy.js -> lib/utils/divvy.js
src/utils/index.js -> lib/utils/index.js
src/utils/media.js -> lib/utils/media.js
src/utils/passOn.js -> lib/utils/passOn.js

> [email protected] build:dist /Users/jstratton/Documents/workspace/hedron
> rollup -c && rollup -c --environment PRODUCTION

Creating development bundle...
node_modules/nan
resolve failed:  { Error: Cannot find module 'eslint-module-utils'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.requireRelative.resolve (/Users/jstratton/Documents/workspace/hedron/node_modules/require-relative/index.js:30:17)
    at resolve (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:25:26)
    at findAndRemove (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:67:11)
    at /Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:111:13
    at Array.map (native)
    at loadPreset (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:103:29)
    at module.exports (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/index.js:97:19)
    at Object.<anonymous> (/Users/jstratton/Documents/workspace/hedron/node_modules/babel-preset-es2015-rollup/index.js:3:18)
    at Module._compile (module.js:570:32) code: 'MODULE_NOT_FOUND' } eslint-module-utils
resolve failed:  { Error: Cannot find module 'babel-runtime'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.requireRelative.resolve (/Users/jstratton/Documents/workspace/hedron/node_modules/require-relative/index.js:30:17)
    at resolve (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:25:26)
    at findAndRemove (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:67:11)
    at /Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:111:13
    at Array.map (native)
    at loadPreset (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:103:29)
    at module.exports (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/index.js:97:19)
    at Object.<anonymous> (/Users/jstratton/Documents/workspace/hedron/node_modules/babel-preset-es2015-rollup/index.js:3:18)
    at Module._compile (module.js:570:32) code: 'MODULE_NOT_FOUND' } babel-runtime
Creating production bundle...
node_modules/nan
resolve failed:  { Error: Cannot find module 'eslint-module-utils'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.requireRelative.resolve (/Users/jstratton/Documents/workspace/hedron/node_modules/require-relative/index.js:30:17)
    at resolve (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:25:26)
    at findAndRemove (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:67:11)
    at /Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:111:13
    at Array.map (native)
    at loadPreset (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:103:29)
    at module.exports (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/index.js:97:19)
    at Object.<anonymous> (/Users/jstratton/Documents/workspace/hedron/node_modules/babel-preset-es2015-rollup/index.js:3:18)
    at Module._compile (module.js:570:32) code: 'MODULE_NOT_FOUND' } eslint-module-utils
resolve failed:  { Error: Cannot find module 'babel-runtime'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.requireRelative.resolve (/Users/jstratton/Documents/workspace/hedron/node_modules/require-relative/index.js:30:17)
    at resolve (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:25:26)
    at findAndRemove (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:67:11)
    at /Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:111:13
    at Array.map (native)
    at loadPreset (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/lib/serialize.js:103:29)
    at module.exports (/Users/jstratton/Documents/workspace/hedron/node_modules/modify-babel-preset/index.js:97:19)
    at Object.<anonymous> (/Users/jstratton/Documents/workspace/hedron/node_modules/babel-preset-es2015-rollup/index.js:3:18)
    at Module._compile (module.js:570:32) code: 'MODULE_NOT_FOUND' } babel-runtime

Possibly an upstream dependency of babel rollup preset??

Make the Page component more useful

Adding this issue as an official discussion thread for some new enhancements to the Page component. Currently this component functions as simply a wrapper. It defaults to 960px wide and horizontally centered using margin: 0 auto. It also accepts the debug property and passes it on to all it's children.

It's usefulness stops there though, but I think it has the potential to be so much more; since it's essentially the top level component for your app.

The issue #49 is what inspired me to open up this discussion.

New Property Proposals:

height: string = number[px|%|vh]

<Page height='50vh'>
  <Row>
    <Column>
      <h1>This page is exactly half the viewport height</h1>
    </Column>
  </Row>
</Page>

This would allow you to set a specific height for the Page component. In responsive design, it's generally not too useful to set a static height for your top-level component, but this would exist for those rare edge cases.

overflow: string = hidden|scroll

<Page height='100px' overflow='scroll'>
  <Row>
    <Column>
      <h1>This is a statically sized page that scrolls</h1>
      <h1>This is a statically sized page that scrolls</h1>
      <h1>This is a statically sized page that scrolls</h1>
      <h1>This is a statically sized page that scrolls</h1>
      <h1>This is a statically sized page that scrolls</h1>
    </Column>
  </Row>
</Page>

The overflow property is basically required if we add a height property. It would allow you to set the the action taken on all content that overflows (a mirror of the css overflow property)

fullscreen: boolean = true|false

<Page fullscreen>
  <Row>
    <Column>
      <h1>This is a fullscreen component</h1>
    </Column>
  </Row>
</Page>

If this property exists, it would completely take priority over the width|height properties, however the overflow property would still be useful when using fullscreen. When it's set to true, it would set the width to 100vw and height to 100vh. The biggest issue I see here, is that the body has a margin on it by default, so it would be up to the user of hedron to disable this margin.

The only workaround I see for the default body margin, would be using position: absolute; top: 0; left: 0;. However, this seems like a hacky approach IMO, and not something I'm too eager to implement. This is something that needs discussion.

flex properties (#49)

Integrating the same general flex properties that are available on Row to the Page component would mean greater control over the alignment of the top-level rows without the need for advanced nesting. It would allow you to do stuff like this for vertical-alignments

<Page fullscreen justifyContent='center'>
  <Row>
    <Column>
      <h1>This is a fullscreen component with vertically aligned text</h1>
    </Column>
  </Row>
</Page>
<Page fullscreen justifyContent='flex-end'>
  <Row>
    <Column>
      <h1>This text appears on the very bottom of the viewport</h1>
    </Column>
  </Row>
</Page>

However, since this is a fairly opinionated grid system, the Page component is expecting the very next component to be a Row; and since Row components are not meant to be next to each other, IMO we can remove the options for horizontal alignment. In that case, it might be better to abstract away the justifyContent property into something like vAlign or verticalAlign.

<Page fullscreen verticalAlign='middle|top|bottom'>
  <Row>
    <Column>
      <h1>This is a fullscreen component with vertically aligned text</h1>
    </Column>
  </Row>
</Page>

As always, I'm open to discussing these further before implementing them, as well as any additional property requests that would be useful to add to the Page component πŸ˜„

Bundle size

What do you say to split the modules into files?

import Row from 'hedron/Row'

Implement unit testing

Unit testing needs to be implemented at some point. These tests should be fairly extensive making sure that the components and utilities function as expected.

Some tests that need to be created:

  • Make sure the Row component accepts the divisions prop
  • Make sure the Row component applies the divisions prop to child Columns and Rows.
  • Make sure the Row component only applies the divisions prop to children of type Column or Row.
  • Make sure the Column component renders at width: (100% Γ· props.divisions) * sm
    • Repeat the above test for every media size.
  • Make sure the Column component renders the margin-left in accordance with the xxShift prop.

I'm sure there will be more to list, but this is a solid start for now.

Extending Row & Column styling

Hi,
I'm trying to use Hedron, but I'm running into trouble, when I try to extend Row and Column.
I need to set e.g. background-image, background-color, etc.

import React, { Component } from 'react';
import styled from 'styled-components';
import {Page, Row, Column } from 'hedron';

const DefRow = styled(Row) `
  background: papayawhip;
`;

const DefCol = styled(Column) `
  background: mediumaquamarine;
`;

class App extends Component {
  render() {
    return (
      <Page>
        <DefRow divisions={24}>
          <DefCol lg={12}>col1</DefCol>
          <DefCol lg={12}>col2</DefCol>
        </DefRow>
      </Page>
    );
  }
}

export default App;

But when I then use my DefRow and DefCol, they become kind of "double nested" and all columns fill out the entire width instead of being e.g. one third of the row.
Any suggestions for a fix? Am I maybe extending in a wrong way?

Hedron breaks with babel plugin

Using v1.0.0-beta.12, when I add babel-plugin-styled-components to my .babelrc, everything compiles but the page reports the following:

hedron.js:901 Uncaught TypeError: styled.css.withConfig is not a function
    at hedron.js:901
    at Array.map (<anonymous>)
    at breakpoints (hedron.js:900)
    at new <anonymous> (hedron.js:1168)
    at flatten (styled-components.browser.esm.js:1265)
    at flatten (styled-components.browser.esm.js:1242)
    at ComponentStyle.generateAndInjectStyles (styled-components.browser.esm.js:1449)
    at StyledComponent.generateAndInjectStyles (styled-components.browser.esm.js:2036)
    at StyledComponent.renderInner (styled-components.browser.esm.js:1974)
    at renderInner (styled-components.browser.esm.js:1888)

My .babelrc:

{
  "presets": [
    ["env", {
      "modules": false,
      "targets": {
        "browsers": "> 1%",
        "uglify": true
      },
      "useBuiltIns": true
    }],
    "react"
  ],

  "plugins": [
    "syntax-dynamic-import",
    "transform-object-rest-spread",
    ["transform-class-properties", { "spec": true }],
    "babel-plugin-styled-components"
  ]
}

Fix build so that it doesn't bundle React?

At the moment, when using Webpack to include the module, React is bundled, causing the bundle to be much larger than necessary. Also, the main field in package.json should perhaps point to lib/index.js?

These may well stem from me having a bug in my webpck config, but I don't seem to have similar problems with other modules.

Direct descendants cannot be plain text

This is only currently present in the master branch, not on the deployed npm version (0.2.0).

Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.

This triggers the above

<Row>
  Hello World
</Row>

This does not

<Row>
  <p>Hello World</p>
</Row>

There are no doubt going to be edge cases where you are going to want to place text as the first child under the grid.

The error is persistent on the Page, Row, and Column components (it has to do with the new passOn utility)

1.0.0 Release Checklist

LayoutProvider

  • allow custom debug fill colors/outlines to be set on LayoutProvider.
    • Ideal API: <LayoutProvider debug={{ enabled: true, outline: 'solid 10px green', fill: 'blue' }}>
    • Notes:
      • Debug fills need to always be have an alpha of .15, even when a solid color is passed in.
      • The alpha cannot be set using opacity: .15, this would cause the contents to appear transparent, only the background color should be affected.
      • The ideal way to handle this, would be to extract the individual rgb channels from the input hex and generate a custom rgba() with a .15 alpha set.

Container

  • allow 100% height in Safari
    • This seems like it should be logical enough, but Safari doesn't allow height: 100% to be set on an element unless the parent has an absolute height set. There are a few workaround to this including using position: absolute on the height: 100% element with position: relative on the parent element. But this is less than ideal and will break most of the other layout features, requiring a massive re-write. Need to find another solution.
  • direction should accept either a string or object
    • this should use the same methods as other props like width/height, allowing the direction to be changed based on the active breakpoint.
  • alignX/alignY should accept either a string or object
    • this should use the same methods as other props like width/height, allowing the alignment on both axes to be changed based on the active breakpoint.

flowtype

  • add flow annotations to breakpoint utility

Documentation

Section

  • add a story for height
  • add a story for width
  • add a story for positioning (this should demonstrate the absolute, top, bottom, left, and right props)

Container

  • add a story for height
  • add a story for width
  • add a story for grow
  • add a story for shrink
  • add a story for flex
  • add a story for wrap
  • add a story for direction

Box

  • add a story for height
  • add a story for width
  • add a story for shift
  • add a story for grow
  • add a story for shrink
  • add a story for flex
  • add a story for fluid

pre-production

  • remove all unused/legacy code
  • ensure all variables and class names are relevant
  • finalize the all component property names (these cannot be changed after 1.0.0 is published)

Contributing

If you wish to help on any of these items, please drop a comment down below letting me know what you're working on. This will ensure that two people aren't simultaneously working on the same thing. Thanks!

A fourth breakpoint.

Can this lib. by any means supports more than 3 breakpoints (including the one before all of them xs) ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.