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

Grid component react #4894

Merged
merged 42 commits into from
Jan 29, 2020
Merged

Grid component react #4894

merged 42 commits into from
Jan 29, 2020

Conversation

zachhardesty7
Copy link
Contributor

@zachhardesty7 zachhardesty7 commented Dec 17, 2019

This is my first major PR (for Carbon & in general) so any feedback is appreciated! My code focuses heavily on readability and simplicity while mimicking design patterns from other React components, Carbon and otherwise.

Add layout helpers for managing a Grid alongside the Carbon Design System layout guidance. Namely, this PR adds support for Grid, Row, and Col components. Grid and Row are roughly the same layout containers, supporting various modes for "condensed" or "no gutter" moments. Column provides support for specifying responsive breakpoints using individual props, as demonstrated by the storybook story and tests. (mostly copied description)

All of this work started before @joshblack's PR #3892. I should have opened an issue sooner... I've mostly incorporated all of his PR, but notable differences of this PR include:

  • noGutterLeft & noGutterRight merged into noGutter as "left" and "right"
  • no object syntax, all props separate. this decision was made to mimic some very popular libraries (Material UI, Ant Design, React Bootstrap). I do also like the object syntax so that could be merged.
  • no array syntax ^, but makes helper functions simpler & cleaner
  • calls classnames function with params & avoids object key calcs for simplicity
  • a lot of focus on code readability
  • propTypes defines supported column span as specific numbers
  • Grid supports noGutter
  • all components don't define any variables in function body
  • includes all of the same tests plus a few extra and they all use shallow rendering
  • includes dynamic knob-based stories while also preserving the easy to copy and paste ones. maybe too many stories?

Changelog

New

  • add Grid component with supporting Grid.Row (and GridRow) and Grid.Col (and GridCol)

Changed

  • minor Storybook configs to support new CSF

Removed

Testing / Reviewing

The styles and examples come roughly from the Grid elements preview.

@zachhardesty7 zachhardesty7 marked this pull request as ready for review December 17, 2019 00:40
@zachhardesty7 zachhardesty7 requested a review from a team as a code owner December 17, 2019 00:40
@ghost ghost requested review from aledavila and asudoh December 17, 2019 00:40
@netlify
Copy link

netlify bot commented Dec 17, 2019

Deploy preview for the-carbon-components ready!

Built with commit 34c2cbf

https://deploy-preview-4894--the-carbon-components.netlify.com

@netlify
Copy link

netlify bot commented Dec 17, 2019

Deploy preview for carbon-elements ready!

Built with commit 34c2cbf

https://deploy-preview-4894--carbon-elements.netlify.com

@netlify
Copy link

netlify bot commented Dec 17, 2019

Deploy preview for carbon-components-react failed.

Built with commit 34c2cbf

https://app.netlify.com/sites/carbon-components-react/deploys/5e31ce0762b86e0008b279b9

@joshblack
Copy link
Contributor

Hi @zachhardesty7! 👋 Thanks so much for taking the time to put this together! I will definitely take a look at this tomorrow!! 🥳

@joshblack
Copy link
Contributor

Taking a quick look, any chance we could remove support for condensed and noGutter? There might be changes in terminology for these so they might not be settled enough to go into stable.

Definitely understand the prop changes in part, I think span and offset were patterns brought over from styled system-esque APIs in my earlier PR. With this named approach, I think something that can feel awkward are the offset* props that come up, as a result (offsetSm, offsetMd, etc). It seems like React bootstrap handles these the best but even within their model one can't do a shorthand notation for offsets which is a bummer.

Are there any other examples that you'd recommend looking at for an ideal grid API here? Seems like we would want:

  • Auto column support
  • Span n columns per breakpoint
  • Offset n columns per breakpoint

@zachhardesty7
Copy link
Contributor Author

@joshblack

I only implemented those since the Grid component/element package demo and the outputted CSS support them. Does the doc here (the red X) indicate that the classes output by the SCSS shouldn't be used? It wasn't quite clear to me whether they're internal or not. It's an easy change though!

I'm not a huge fan of the offset stuff as separate props either, feels a bit messy. I suppose it could be done via a single offset prop in object notation: offset={ sm: 1, lg: 10, max: 12 }. My concern there was not having symmetry with the span props (sm, md). And then should there be two separate ways for the span props via object notation (eg span={ sm: 1, lg: 10, max: 12 } to maintain symmetry?

This implementation handles auto via the string "auto". Bootstrap supports that and a value of true.

In personal and freelance projects, it feels like I've rarely used props as a part of the Grid, but maybe it would benefit us to have some numbers behind how often props are used? I haven't done anything with parsing Github code usage, but I suspect the most popular APIs should mirror usage. Let me look into it a bit further and respond with some more detailed resources of what I find!

@zachhardesty7
Copy link
Contributor Author

@joshblack
Okay, so {breakpoint}Offset style props are not good. The better question is what way "offset" should be handled. Here are what some example React libraries do:

  • Bootstrap React/Reactstrap - no offset prop, must use obj syntax for each breakpoint prop (sm, md)
  • Antd - offset prop applies to all screen sizes, obj syntax for breakpoint specific offset
  • MD - no offset prop
  • SemanticUI - no offset prop

Antd has a cool way of doing it, but since they base it on the Bootstrap style anyway, it makes the most sense to get rid of the offset prop entirely and just support sm={4}, sm={true || false || "auto"} and also lg={{ span: 6, offset: 2 }}. Shouldn't take long to incorporate that here.


Disqualified examples / research data conclusions

(note: repos without a significant commit within about the last year are excluded)

Misc

React MD - too many props
Rebass - CSS-in-JS
Foundation - can't find prop docs?
Pinterest Gestalt - too many props

Seem much more like Carbon DataTable

Grid Layout, AG Grid, Griddle

No flexbox-style responsive grid component (e.g. uses CSS Grid style or no Grid included)

Blueprint, React Toolbox, Belle, Khan Academy, Hedron, Atlas Kit, MS Office Fabric, Grommet

Grid component is not responsive / does not support media queries

Onsen UI, React Virtualized

@joshblack
Copy link
Contributor

@zachhardesty7 would you mind if I push some updates to your PR here or would you prefer if I opened up a PR to merge into this branch? I just wanted to double-check with you to see how you felt about the changes, didn't want it to feel like we were disregarding any of your work here as it's all awesome! Thanks again for taking the time to contribute!

@zachhardesty7
Copy link
Contributor Author

@joshblack Whatever makes the most sense / seems the most reasonable to you is fine by me!

@joshblack
Copy link
Contributor

@zachhardesty7 just pushed some updates, would love to know what you think! Tried to do the following:

  • Split out components into separate files (Grid, Row, and Column)
  • Moved tests that you originally had over into separate files under __tests__ and updated to use our new test helper
    • Tried to use existing tests alongside adding some other checks or doing matching not on exact selector
  • Updated story to include the templates since they seemed really solid, don't think anything changed there
  • Updated the Col component and how it derived the relevant class names, let me know if I missed any functionality here!

@joshblack
Copy link
Contributor

joshblack commented Jan 22, 2020

FYI @alisonjoseph too for Grid components 👀 Relevant storybook story for usage: https://github.com/carbon-design-system/carbon/pull/4894/files#diff-d9adc48479ce140b1bc043298685114c

@joshblack
Copy link
Contributor

Updated @zachhardesty7! Thanks again!

Copy link
Contributor

@abbeyhrt abbeyhrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me! Thank you @zachhardesty7 for taking the time to do this! 🎉

@joshblack joshblack merged commit 354baa8 into carbon-design-system:master Jan 29, 2020
This was referenced Feb 25, 2020
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

Successfully merging this pull request may close these issues.

4 participants