Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

feat(grid): base implementation #93

Merged
merged 2 commits into from
Aug 20, 2018
Merged

feat(grid): base implementation #93

merged 2 commits into from
Aug 20, 2018

Conversation

bmdalex
Copy link
Collaborator

@bmdalex bmdalex commented Aug 15, 2018

Grid

This PR will introduce the Grid component with the following props:

  • columns=[number|string]
  • rows=[number|string]

The Grid will specify the layout of the elements it encapsulates as children or in the content prop.

See also:

TODO

  • Conformance test
  • Minimal doc site example
  • Stardust base theme
  • Teams Light theme
  • Teams Dark theme
  • Teams Contrast theme
  • Confirm RTL usage
  • W3 accessibility check
  • Stardust accessibility check
  • Update glossary props table
  • Update the CHANGELOG.md

API Proposal

columns

We can specify a certain amount of columns:

columncount

or the explicit columns for a grid:

columnexplicit

<Grid columns="7">
  <Image fluid src="img1.png" />
  <Image fluid src="img2.png" />
  <Image fluid src="img3.png" />
  ...
</Grid>

and

<Grid columns="repeat(3, 1fr) 2fr 2fr 110px 14rem 50px 20%">
  <Image fluid src="img1.png" />
  <Image fluid src="img2.png" />
  <Image fluid src="img3.png" />
  ...
</Grid>

generate:

<div class="ui-grid a b c d e f k">
  <img src="img1.png" class="ui-image h i b j" />
  <img src="img2.png" class="ui-image h i b j" />
  <img src="img3.png" class="ui-image h i b j" />
  ...
</div>

rows

We can specify a certain amount of rows:

rowcount

or the explicit rows for a grid:

rowexplicit

<Grid rows="2">
  <Image fluid src="img1.png" />
  <Image fluid src="img2.png" />
  <Image fluid src="img3.png" />
  ...
</Grid>

and

<Grid rows="2fr repeat(2, 1fr)">
  <Image fluid src="img1.png" />
  <Image fluid src="img2.png" />
  <Image fluid src="img3.png" />
  ...
</Grid>

generate:

<div class="ui-grid a b c d e f k">
  <img src="img1.png" class="ui-image h i b j" />
  <img src="img2.png" class="ui-image h i b j" />
  <img src="img3.png" class="ui-image h i b j" />
  ...
</div>

@codecov
Copy link

codecov bot commented Aug 15, 2018

Codecov Report

Merging #93 into master will increase coverage by 0.31%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #93      +/-   ##
==========================================
+ Coverage   86.52%   86.84%   +0.31%     
==========================================
  Files          39       41       +2     
  Lines         668      684      +16     
  Branches      102      103       +1     
==========================================
+ Hits          578      594      +16     
  Misses         87       87              
  Partials        3        3
Impacted Files Coverage Δ
src/components/Grid/Grid.tsx 100% <100%> (ø)
src/index.ts 100% <100%> (ø) ⬆️
src/components/Grid/index.tsx 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 00375ed...dc7e057. Read the comment docs.

@kuzhelov
Copy link
Contributor

sorry in advance, maybe I am missing something. Could you, please, suggest if there is any way for me as a client of this functionality to explicitly provide division on rows - in a way similar to Semantic UI does:

<Grid >
  <Grid.Row>
     .. elements here..
  </Grid.Row>
  <Grid.Row>
     .. another elements here..
  </Grid.Row>
</Grid>

@gaui
Copy link

gaui commented Aug 15, 2018

What are those extra letter classes? a b c d e f k

@bmdalex bmdalex changed the title feat(grid): base implementation [READY FOR REVIEW] feat(grid): base implementation Aug 15, 2018
@bmdalex
Copy link
Collaborator Author

bmdalex commented Aug 15, 2018

@kuzhelov no, this new Grid version does not have the concept of rows and columns as these are controlled with props; see proposal #11.

Therefore, all we have are grid items (that can be any element as we do not have any constraints there); in the future we're probably going to add a GridItem component for controlling styles of individual items

@bmdalex
Copy link
Collaborator Author

bmdalex commented Aug 15, 2018

@gaui Fella related classes that add the styles internally; if it's confusing I'm gonna delete them from the example as they are irrelevant there

@bmdalex
Copy link
Collaborator Author

bmdalex commented Aug 15, 2018

@levithomason removed itemSize from the API and adjusted default gap and padding; this is ready for review now and can probably be merged as is

Copy link
Member

@levithomason levithomason left a comment

Choose a reason for hiding this comment

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

Per chat, let's only merge rows / columns for now. These props hit our use cases.

The itemSize can be discussed in more detail later on subsequent PRs. It has some implications that will need collaboratively worked out before merging.

<div>
<Grid content={images} />
</div>
)
Copy link
Member

Choose a reason for hiding this comment

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

Wrapping div is not required, this can be reduced to:

const GridExample = () => <Grid content={images} />

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done


const images = imageNames.map((name, index) => (
<Image key={`${name}-${index}`} fluid src={`public/images/avatar/large/${name}`} />
))
Copy link
Member

Choose a reason for hiding this comment

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

Given the amount of code required to abstract and loop over the images, it would be less code and easier for users to scan if we inline the images:

<Image fluid src="public/images/avatar/large/ade.jpg" />
<Image fluid src="public/images/avatar/large/chris.jpg" />
<Image fluid src="public/images/avatar/large/christian.jpg" />
<Image fluid src="public/images/avatar/large/daniel.jpg" />
<Image fluid src="public/images/avatar/large/elliot.jpg" />
<Image fluid src="public/images/avatar/large/elyse.png" />
<Image fluid src="public/images/avatar/large/helen.jpg" />
<Image fluid src="public/images/avatar/large/jenny.jpg" />
<Image fluid src="public/images/avatar/large/joe.jpg" />
<Image fluid src="public/images/avatar/large/justen.jpg" />

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@levithomason
I have 20+ images in other grid examples to make it clear to users how the grid looks like ; duplicating 20+ lines in other places doesn't really make sense; do we want to change it only for these 2 examples (GridExample.shorthand.tsx and GridExample.tsx) ?

Copy link
Member

Choose a reason for hiding this comment

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

The criteria for examples is concise and readable. We want them to fit on the minimal number of lines so that the can be easily viewed inline in the doc site. In cases where abstractions significantly reduce the amount code, then they are helpful and we should use them.

In the example here, given any number of images, the abstracted code will require more lines of code since each image path in the array already requires a line of code. Any lines required for abstraction are not needed.

In examples where the array of images is used more than once, then we'll certainly saves lines by abstracting. We should use an abstraction for those. However, you might consider removing the map code and just creating an array of images once:

const images = [
  <Image key="ade" fluid src="public/images/avatar/large/ade.jpg" />,
  <Image key="chris" fluid src="public/images/avatar/large/chris.jpg" />,
  <Image key="christian" fluid src="public/images/avatar/large/christian.jpg" />,
  <Image key="daniel" fluid src="public/images/avatar/large/daniel.jpg" />,
  <Image key="elliot" fluid src="public/images/avatar/large/elliot.jpg" />,
  <Image key="elyse" fluid src="public/images/avatar/large/elyse.png" />,
  <Image key="helen" fluid src="public/images/avatar/large/helen.jpg" />,
  <Image key="jenny" fluid src="public/images/avatar/large/jenny.jpg" />,
  <Image key="joe" fluid src="public/images/avatar/large/joe.jpg" />,
  <Image key="justen" fluid src="public/images/avatar/large/justen.jpg" />,
]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

PropTypes.arrayOf(customPropTypes.itemShorthand),
customPropTypes.itemShorthand,
]),
]),
Copy link
Member

Choose a reason for hiding this comment

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

In the case of a Grid component, I'm not sure content makes sense. Perhaps here we only support children?

Why? There is no processing to be done on the content by Grid. It is also an "invisible" component in that it only formats children, but doesn't render its own subcomponents.

Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree with the reasons, but we have following things preventing us to do so:

  • all components should support shorthand version; removing content breaks that pattern basically; it'd be the first component without shorthand support, right?
  • we were discussing introducing GridItem component for controlling individual items; maybe it'll make sense at that point

Copy link
Member

Choose a reason for hiding this comment

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

Yes, good points. We probably should not make those types of decisions in this PR. Let's keep it as is and we can discuss it in another. This would be a framework level design change.

export { default as List } from './components/List/listStyles'
export { default as ListItem } from './components/List/listItemStyles'

export { default as Menu } from './components/Menu/menuStyles'

Copy link
Member

Choose a reason for hiding this comment

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

Let's avoid unnecessary whitespace changes. It will make the PR smaller and prevent us from flip flopping on code style updates over time.

A good way to propose and implement style fixes is to make a PR introducing auto fixable lint rules or prettier config. This way, code style is automatic and enforced.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was just removing some random new lines, at least grouping by components with same letter; ok, I'll add my change only

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@levithomason levithomason changed the title [READY FOR REVIEW] feat(grid): base implementation feat(grid): base implementation Aug 15, 2018
@levithomason levithomason added needs author feedback Author's opinion is asked and removed 🚀 ready for review labels Aug 15, 2018
@bmdalex bmdalex added 🚀 ready for review and removed needs author feedback Author's opinion is asked labels Aug 15, 2018
@bmdalex
Copy link
Collaborator Author

bmdalex commented Aug 15, 2018

@levithomason I see some visual tests failing but I cannot login to this screener thingie to see what's up

@levithomason
Copy link
Member

Send me the email you'd like to use on Screener privately and I'll add you.

@bmdalex bmdalex force-pushed the feat/grid-v1 branch 2 times, most recently from fa9b88a to 888c4e5 Compare August 17, 2018 01:44
@bmdalex
Copy link
Collaborator Author

bmdalex commented Aug 17, 2018

@levithomason solved the screener issue with help from Miro. Everything is passing and I think I addressed all comments

@bmdalex bmdalex force-pushed the feat/grid-v1 branch 3 times, most recently from 7c3ccac to c71be9c Compare August 20, 2018 12:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants