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

Add equal height row component #5039

Merged
merged 1 commit into from Apr 11, 2024
Merged

Conversation

mas-who
Copy link
Contributor

@mas-who mas-who commented Mar 28, 2024

Done

Added the equal height row component which includes the following features:

  • Consistent alignment of grid items across all column in a row
  • Out of box responsive behaviour for grid items
  • Support for use in standard and 25-75 grid layouts
  • Insert dividers that can span across all columns in a row (bridges grid gaps) on large screens and breaks up into smaller per column dividers on smaller screen sizes

Fixes: WD-10102

QA

Check if PR is ready for release

If this PR contains Vanilla SCSS code changes, it should contain the following changes to make sure it's ready for the release:

  • PR should have one of the following labels to automatically categorise it in release notes:
    • Feature 🎁, Breaking Change 💣, Bug 🐛, Documentation 📝, Maintenance 🔨.
  • Vanilla version in package.json should be updated relative to the most recent release, following semver convention:
    • if CSS class names are not changed it can be bugfix relesase (x.x.X)
    • if CSS class names are changed/added/removed it should be minor version (x.X.0)
    • see the wiki for more details
  • Any changes to component class names (new patterns, variants, removed or added features) should be listed on the what's new page.

Screenshots

Screenshot from 2024-04-04 18-40-40
Screenshot from 2024-04-04 18-41-29
Screenshot from 2024-04-04 18-41-56

@mas-who mas-who added the Feature 🎁 New feature or request label Mar 28, 2024
@webteam-app
Copy link

@mas-who
Copy link
Contributor Author

mas-who commented Mar 28, 2024

A rough initial setup to get a sense for what needs to be implemented. There are still some discussions to be had about the approach.

@mas-who mas-who changed the title feat: advanced grid layout patterns [WIP] feat: advanced grid layout patterns [WD-9963] Mar 28, 2024
@mas-who mas-who changed the title feat: advanced grid layout patterns [WD-9963] feat: advanced grid layout patterns [WIP] Mar 28, 2024
@mas-who mas-who force-pushed the advanced-grid-patterns branch 2 times, most recently from 79f17c2 to a018a27 Compare March 28, 2024 15:26
@mas-who mas-who changed the title feat: advanced grid layout patterns [WIP] feat: equal height grid row patterns [WIP] Apr 2, 2024
@mas-who mas-who force-pushed the advanced-grid-patterns branch 10 times, most recently from 5a838b0 to f41463c Compare April 3, 2024 12:13
Copy link
Contributor

@lyubomir-popov lyubomir-popov left a comment

Choose a reason for hiding this comment

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

looks good, some comments in the code

scss/_patterns_equal-height-row.scss Outdated Show resolved Hide resolved
scss/_patterns_equal-height-row.scss Outdated Show resolved Hide resolved
.p-equal-height-col {
display: grid;
grid-column: span calc($grid-columns / 4);
grid-row: span 10;
Copy link
Contributor

Choose a reason for hiding this comment

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

10? wasn't there an auto value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can't be auto because .p-equal-height-col is a subgrid and its parent grid has grid-template-rows set to default auto. This means the subgrid is actually defining the row structure for the parent grid, so we need to explicitly define the row span. Although we can set the span to 4 instead of 10 to cater for maximum 4 grid items, previously this is set to 10 to cater for an arbitrary number of grid items in a column, but we have decided to have maximum 4 items in a column now.

scss/_patterns_equal-height-row.scss Outdated Show resolved Hide resolved
{% block content %}

<div class="row">
<div class='p-equal-height-row has-divider-below-item-1'>
Copy link
Contributor

Choose a reason for hiding this comment

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

Iwould refer to the dividers as "above". They are attached top the element that follows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we use "above", then the dividers will have to start at item-2 i.e. has-divider-above-item-2, has-divider-above-item-3, has-divider-above-item-4. Seems a little weird to start at item-2 for me, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In separate discussion with bartek, we think has-1st-divider, has-2nd-divider and has-3rd-divider might be a good compromise to make the classes less verbose, wdyt?

@mas-who mas-who force-pushed the advanced-grid-patterns branch 2 times, most recently from 82d9f37 to a1bdf81 Compare April 3, 2024 15:44
releases.yml Outdated Show resolved Hide resolved
}

// For smaller screens, the divider pseudo elements are inserted at the column level
&.p-equal-height-row--divider-below-item-1 .p-equal-height-row__col::before,
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to use actual border on small screens instead of the before/after pseudo element divider?

So, if we have a class name that adds divider between items 1/2 - the item 2 will have border on top:

// pseudo-code, just to give idea
&.has-divider-above-item-2 .p-equal-height-row__item:nth-child(2) {
  border-top: 1px solid $colors--theme--border-default;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did try with border first, but it doesn't play nicely with spacing such as margin-top. Using pseudo elements, the absolute positioning inside the grid works for all kinds of spacing between items since the element aligns exactly with the grid tracks.

@mas-who mas-who force-pushed the advanced-grid-patterns branch 2 times, most recently from 5b558ab to cd13e14 Compare April 4, 2024 08:03
@mas-who
Copy link
Contributor Author

mas-who commented Apr 8, 2024

There is one more assumption made that may break things.

In case of default 4 col example, we currently rely on the fact that it's not nested in any row or grid. It's wrong assumption. While it may not be, it doesn't have to be, it can be. Esprcially if it may be wrapped by section component for some padding.

So we need to make sure that cases like:

<div class="u-fixed-width">
  <div class="p-equal-height-row has-1st-divider"> …

or the same nested in row > col-12.

Right now the divideer width will be wrongly calculated (because padding won't be there if nested):

image

Yes agreed, this relates to assuming that width of the divider needs to be calculated with the parent grid padding in mind. The fix based on the other comment changed the divider definition to use grid-column-start and grid-column-end. This resolved the problem because we no longer have to calculate the width of the divider (also works for .equal-height-row nested inside a col-12)

Screenshot from 2024-04-08 18-37-48

@bartaz
Copy link
Contributor

bartaz commented Apr 9, 2024

One last thing would be to update the examples to make them closer to real content.

For default (4 cols) let's use this (hopefully the needed images can be found on assets server):
image

For 3 cols in 25-75 use this:
image

And this could serve as both having 4 items in columns and divider (images like this may not be available, but any placeholder could work for now I think):
image

https://www.figma.com/file/YNYesRrgkpP9bM3JQbFiXz/Responsive-equal-heights-grid?type=design&node-id=0-1&mode=design&t=esDiQnQTIvweaHkG-0

Copy link
Contributor

@bartaz bartaz left a comment

Choose a reason for hiding this comment

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

Some comments on the docs contents.

templates/docs/patterns/equal-height-row.md Outdated Show resolved Hide resolved
templates/docs/patterns/equal-height-row.md Outdated Show resolved Hide resolved
templates/docs/patterns/equal-height-row.md Outdated Show resolved Hide resolved
templates/docs/patterns/equal-height-row.md Outdated Show resolved Hide resolved
@mas-who mas-who force-pushed the advanced-grid-patterns branch 2 times, most recently from 5be756a to fddcd26 Compare April 10, 2024 14:45
@lyubomir-popov
Copy link
Contributor

lyubomir-popov commented Apr 10, 2024

assets for thew above 4 images: https://assets.ubuntu.com/manager?tag=equal-heights-component-example-assets

please also replace these with the onese above ^
image

@mas-who
Copy link
Contributor Author

mas-who commented Apr 10, 2024

assets for thew above 4 images: https://assets.ubuntu.com/manager?tag=equal-heights-component-example-assets

please also replace these with the onese above ^ image

@lyubomir-popov thanks I have replaced the images

Screenshot from 2024-04-10 18-49-12

@bartaz
Copy link
Contributor

bartaz commented Apr 11, 2024

@mas-who Could you also add p-rule--highlight on top of the titles, as per design? (https://vanillaframework.io/docs/patterns/rule#highlighted)

@bartaz
Copy link
Contributor

bartaz commented Apr 11, 2024

One last thing (hopefully) as a drive-by. Currently images have unnecessary spacing below them because they are inline.

I think it would be fine to make images block inside p-media-container, so could you add .p-media-container img { display: block; } to media container component?

image

@mas-who mas-who force-pushed the advanced-grid-patterns branch 4 times, most recently from d4c986f to c3a244b Compare April 11, 2024 12:17
Copy link
Contributor

@bartaz bartaz left a comment

Choose a reason for hiding this comment

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

Small suggestions for the docs

templates/docs/patterns/equal-height-row.md Outdated Show resolved Hide resolved
templates/docs/patterns/equal-height-row.md Outdated Show resolved Hide resolved
templates/docs/patterns/equal-height-row.md Show resolved Hide resolved
- Added equal height grid row pattern with full screen sized dividers

Signed-off-by: Mason Hu <mason.hu@canonical.com>
@lyubomir-popov
Copy link
Contributor

Really nice work @mas-who +1

Copy link
Contributor

@bartaz bartaz left a comment

Choose a reason for hiding this comment

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

Awesome work, thanks @mas-who !

@bartaz bartaz merged commit ef164e0 into canonical:main Apr 11, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants