Skip to content

Commit

Permalink
Merge pull request #1422 from primer/layout-flow-as-row
Browse files Browse the repository at this point in the history
Improve dividers and allow sidebar positioning when `Layout` is flowing as row.
  • Loading branch information
simurai authored May 27, 2021
2 parents fe5b245 + 3955254 commit f780741
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 28 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-masks-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/css': patch
---

Improve dividers and allow sidebar positioning when `Layout` is flowing as row.
38 changes: 37 additions & 1 deletion docs/content/components/layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ of the sidebar position.

### Dividers

Add `Layout--divided` to the `Layout` to show the dividers.
Use `Layout--divided` in conjuction with a `Layout-divider` to show a divider between the main content and the sidebar.
Flowing as row:
- default: shows a `1px` line between main and sidebar
- `Layout-divider--flowRow-shallow`: shows a filled `8px` divider.
- `Layout-divider--flowRow-hidden`: hides the divider


```html live
<div class="Layout Layout--divided">
Expand All @@ -53,6 +58,16 @@ Add `Layout--divided` to the `Layout` to show the dividers.
<div class="Layout-divider"></div>
<div class="Layout-sidebar border">divider hidden</div>
</div>
<div class="Layout Layout--divided">
<div class="Layout-main border">main content</div>
<div class="Layout-divider Layout-divider--flowRow-shallow"></div>
<div class="Layout-sidebar border">flowRow shallow divider</div>
</div>
<div class="Layout Layout--divided">
<div class="Layout-main border">main content</div>
<div class="Layout-divider Layout-divider--flowRow-hidden"></div>
<div class="Layout-sidebar border">flowRow hidden divider</div>
</div>
```

### Centered content
Expand Down Expand Up @@ -181,6 +196,27 @@ Add `Layout--divided` to the `Layout` to show the dividers.
</div>
```

### Sidebar positioning as rows

- `Layout--sidebarPosition-flowRow-start` (default): when stacked, render the sidebar first
- `Layout--sidebarPosition-flowRow-end`: when stacked, render the sidebar last
- `Layout--sidebarPosition-flowRow-none`: when stacked, hide the sidebar

```html live
<div class="Layout Layout--sidebarPosition-flowRow-start">
<div class="Layout-main border">main</div>
<div class="Layout-sidebar border">sidebar</div>
</div>
<div class="Layout Layout--sidebarPosition-flowRow-end">
<div class="Layout-main border">main</div>
<div class="Layout-sidebar border">sidebar</div>
</div>
<div class="Layout Layout--sidebarPosition-flowRow-none">
<div class="Layout-main border">main</div>
<div class="Layout-sidebar border">sidebar</div>
</div>
```

### Layout stacking

- Default: stacks when container is `sm`.
Expand Down
2 changes: 2 additions & 0 deletions src/layout/index.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@import "../support/index.scss";
@import "./mixins.scss";

@import "./container.scss";
@import "./grid.scss";
@import "./grid-offset.scss";
Expand Down
30 changes: 3 additions & 27 deletions src/layout/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,18 @@
--Layout-gutter: 16px;

@media (max-width: calc(#{$width-sm} - 1px)) {
grid-auto-flow: row;
grid-template-columns: 1fr !important;

.Layout-sidebar,
.Layout-divider,
.Layout-main {
width: 100% !important;
grid-column: 1 !important;
}
@include flow-as-row;
}

&.Layout--flowRow-until-md {
@media (max-width: calc(#{$width-md} - 1px)) {
grid-auto-flow: row;
grid-template-columns: 1fr !important;

.Layout-sidebar,
.Layout-divider,
.Layout-main {
width: 100% !important;
grid-column: 1 !important;
}
@include flow-as-row;
}
}

&.Layout--flowRow-until-lg {
@media (max-width: calc(#{$width-lg} - 1px)) {
grid-auto-flow: row;
grid-template-columns: 1fr !important;

.Layout-sidebar,
.Layout-divider,
.Layout-main {
width: 100% !important;
grid-column: 1 !important;
}
@include flow-as-row;
}
}

Expand Down
64 changes: 64 additions & 0 deletions src/layout/mixins.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Layout mixins

@mixin flow-as-row {
grid-auto-flow: row;
grid-template-columns: 1fr !important;

.Layout-sidebar,
.Layout-divider,
.Layout-main {
width: 100% !important;
grid-column: 1 !important;
}

&.Layout--divided {
@include flow-as-row-divider;
}

&.Layout--sidebarPosition-flowRow-start {
.Layout-sidebar {
grid-row: 1;
}

.Layout-main {
grid-row: 2 / span 2;
}
}

&.Layout--sidebarPosition-flowRow-end {
.Layout-sidebar {
grid-row: 2 / span 2;
}

.Layout-main {
grid-row: 1;
}
}

&.Layout--sidebarPosition-flowRow-none {
.Layout-sidebar {
display: none;
}
}
}

@mixin flow-as-row-divider {
--Layout-gutter: 0;

.Layout-divider {
height: 1px;

&.Layout-divider--flowRow-hidden {
display: none;
}

&.Layout-divider--flowRow-shallow {
height: 8px;
margin-right: 0;
background: var(--color-bg-canvas-inset);
border-color: var(--color-border-primary);
border-style: solid;
border-width: $border-width 0;
}
}
}

0 comments on commit f780741

Please sign in to comment.