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

feat(grid): improve grid to a column layout with more flexibility #10485

Merged
merged 20 commits into from
Feb 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8493d38
feat(responsive): add beginnings of new grid system
brandyscarney Feb 14, 2017
1176521
test(responsive): add new tests for responsive grid
brandyscarney Feb 14, 2017
e484cca
test(responsive): improve responsive tests
brandyscarney Feb 14, 2017
21d8f5a
feat(grid): add new grid system
brandyscarney Feb 14, 2017
0c9d07c
chore(sass): fix linter errors
brandyscarney Feb 14, 2017
265158f
refactor(grid): fix an issue with old grid / new grid styles
brandyscarney Feb 14, 2017
96aaa74
test(responsive): make more similar to grid basic
brandyscarney Feb 14, 2017
0c93d2f
Merge branch 'master' of https://github.com/driftyco/ionic into deskt…
brandyscarney Feb 14, 2017
b010894
refactor(responsive): move files to take advantage of docs
brandyscarney Feb 15, 2017
b89f2f1
feat(grid): support max-width on the grid container
brandyscarney Feb 16, 2017
8aa216a
chore(grid): renaming files
brandyscarney Feb 16, 2017
0da17c2
test(grid): remove old tests, add one for cards
brandyscarney Feb 16, 2017
8f19433
docs(grid): add initial documentation for grid, split directives
brandyscarney Feb 17, 2017
d574d6d
test(grid): tweak test to match documentation
brandyscarney Feb 17, 2017
c8e74be
Merge branch 'master' into desktop-support
brandyscarney Feb 17, 2017
28f8a81
refactor(grid): don't fix the width of the grid by default
brandyscarney Feb 17, 2017
57b314c
feat(grid): add in horizontal alignment attrs, rename vertical
brandyscarney Feb 17, 2017
3edc5f7
chore(col): rename column to col
brandyscarney Feb 17, 2017
7467b5e
docs(grid): rearrange order of grid docs
brandyscarney Feb 21, 2017
f0c8fa7
Merge branch 'master' into desktop-support
brandyscarney Feb 21, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/components/grid/col.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Directive } from '@angular/core';

/**
* @name Col
* @module ionic
* @description
*
* Column description
*
* ## Column attributes
*
* By default, columns will stretch to fill the entire height of the row.
* There are several attributes that can be added to a column to customize this behavior.
*
* | Property | Description |
* |-----------------------|-------------------------------------------------------------------------------------------------------------|
* | align-self-start | Adds `align-self: flex-start`. The column will be vertically aligned at the top. |
* | align-self-center | Adds `align-self: center`. The column will be vertically aligned in the center. |
* | align-self-end | Adds `align-self: flex-end`. The column will be vertically aligned at the bottom. |
* | align-self-stretch | Adds `align-self: stretch`. The column will be stretched to take up the entire height of the row. |
* | align-self-baseline | Adds `align-self: baseline`. The column will be vertically aligned at its baselines. |
*
*
*/
@Directive({
selector: 'ion-col, [ion-col]',
host: {
'class': 'col'
}
})
export class Col {

}
302 changes: 302 additions & 0 deletions src/components/grid/grid.mixins.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,302 @@
@import "../../themes/ionic.globals";

// Responsive Mixins
// --------------------------------------------------

// Creates a grid with padding
// ---------------------------------------------------------------------------------

@mixin make-grid($padding-width: $grid-padding-width) {
padding: $padding-width / 2;
margin-left: auto;
margin-right: auto;
width: 100%;

// Remove the padding from the grid and all immediate children columns
&[no-padding] {
padding: 0;

> .row > .col {
padding: 0;
}
}
}

// Creates maximum widths for the grid based on screen size
// ---------------------------------------------------------------------------------

@mixin make-grid-max-widths($max-widths: $grid-max-widths, $breakpoints: $grid-breakpoints) {
@each $breakpoint, $container-max-width in $max-widths {
@include media-breakpoint-up($breakpoint, $breakpoints) {
width: $container-max-width;
max-width: 100%;
}
}
}

// Creates a row used to align columns
// ---------------------------------------------------------------------------------

@mixin make-row() {
display: flex;
flex-wrap: wrap;

&[nowrap] {
flex-wrap: nowrap;
}

&[wrap-reverse] {
flex-wrap: wrap-reverse;
}

&[align-items-start] {
align-items: flex-start;
}

&[align-items-center] {
align-items: center;
}

&[align-items-end] {
align-items: flex-end;
}

&[align-items-stretch] {
align-items: stretch;
}

&[align-items-baseline] {
align-items: baseline;
}

&[justify-content-start] {
justify-content: flex-start;
}

&[justify-content-center] {
justify-content: center;
}

&[justify-content-end] {
justify-content: flex-end;
}

&[justify-content-around] {
justify-content: space-around;
}

&[justify-content-between] {
justify-content: space-between;
}
}


// Creates the base column which has shared styles among all columns
// ---------------------------------------------------------------------------------

@mixin make-column-base($padding-width: $grid-padding-width) {
position: relative;

padding: $padding-width / 2;

width: 100%;
margin: 0;
min-height: 1px; // Prevent columns from collapsing when empty
flex-basis: 0;
flex-grow: 1;
max-width: 100%;

&[align-self-start] {
align-self: flex-start;
}

&[align-self-end] {
align-self: flex-end;
}

&[align-self-center] {
align-self: center;
}

&[align-self-stretch] {
align-self: stretch;
}

&[align-self-baseline] {
align-self: baseline;
}
}


// Create an individual column
// ---------------------------------------------------------------------------------

@mixin make-column($size, $columns: $grid-columns) {
flex: 0 0 percentage($size / $columns);
width: percentage($size / $columns);
// Add a `max-width` to ensure content within each column does not blow out
// the width of the column. Applies to IE10+ and Firefox. Chrome and Safari
// do not appear to require this.
max-width: percentage($size / $columns);
}


// Adds padding to the column
// ---------------------------------------------------------------------------------

@mixin make-column-padding($padding-widths: $grid-padding-widths) {
@each $breakpoint in map-keys($padding-widths) {
@include media-breakpoint-up($breakpoint) {
$padding-width: map-get($padding-widths, $breakpoint);
padding: ($padding-width / 2);
}
}
}


// Offset the column using margin-left
// ---------------------------------------------------------------------------------

@mixin make-column-offset($size, $columns: $grid-columns) {
margin-left: percentage($size / $columns);
}


// Push the column using left
// ---------------------------------------------------------------------------------

@mixin make-column-push($size, $columns: $grid-columns) {
left: if($size > 0, percentage($size / $columns), auto);
}


// Pull the column using right
// ---------------------------------------------------------------------------------

@mixin make-column-pull($size, $columns: $grid-columns) {
right: if($size > 0, percentage($size / $columns), auto);
}


// Determine which modifier to add
// ---------------------------------------------------------------------------------

@mixin make-column-modifier($type, $size, $columns) {
// Work around the lack of dynamic mixin @include support (https://github.com/sass/sass/issues/626)
@if $type == push {
@include make-column-push($size, $columns);
} @else if $type == pull {
@include make-column-pull($size, $columns);
} @else if $type == offset {
@include make-column-offset($size, $columns);
}
}


// Create the responsive grid columns
// --------------------------------------------------

@mixin make-grid-columns($columns: $grid-columns, $padding-widths: $grid-padding-widths, $breakpoints: $grid-breakpoints) {
@each $breakpoint in map-keys($breakpoints) {
$infix: breakpoint-infix($breakpoint, $breakpoints);

// Allow columns to stretch full width below their breakpoints
@for $i from 1 through $columns {
[col#{$infix}-#{$i}] {
@include make-column-padding($padding-widths);
}
}

[col#{$infix}] {
@include make-column-padding($padding-widths);
}

@include media-breakpoint-up($breakpoint, $breakpoints) {
// Provide basic `[col-{bp}]` attributes for equal-width flexbox columns
[col#{$infix}] {
flex-basis: 0;
flex-grow: 1;

max-width: 100%;
}

[col#{$infix}-auto] {
flex: 0 0 auto;

width: auto;
}

@for $i from 1 through $columns {
[col#{$infix}-#{$i}] {
@include make-column($i, $columns);
}
}

@each $modifier in (pull, push) {
@for $i from 0 through $columns {
[#{$modifier}#{$infix}-#{$i}] {
@include make-column-modifier($modifier, $i, $columns)
}
}
}

// `$columns - 1` because offsetting by the width of an entire row isn't possible
@for $i from 0 through ($columns - 1) {
@if not ($infix == "" and $i == 0) { // Avoid emitting useless [offset-xs-0]
[offset#{$infix}-#{$i}] {
@include make-column-modifier(offset, $i, $columns)
}
}
}
}
}
}


// Breakpoint Mixins
// ---------------------------------------------------------------------------------

// Breakpoint viewport sizes and media queries.
//
// Breakpoints are defined as a map of (name: minimum width), order from small to large:
//
// (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px)
//
// The map defined in the `$grid-breakpoints` global variable is used as the `$breakpoints` argument by default.

// ---------------------------------------------------------------------------------

// Minimum breakpoint width. Null for the smallest (first) breakpoint.
//
// >> breakpoint-min(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
// 576px
@function breakpoint-min($name, $breakpoints: $grid-breakpoints) {
$min: map-get($breakpoints, $name);
@return if($min != 0, $min, null);
}


// Returns a blank string if smallest breakpoint, otherwise returns the name with a dash infront.
// Useful for making responsive utilities.
//
// >> breakpoint-infix(xs, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
// "" (Returns a blank string)
// >> breakpoint-infix(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
// "-sm"
@function breakpoint-infix($name, $breakpoints: $grid-breakpoints) {
@return if(breakpoint-min($name, $breakpoints) == null, "", "-#{$name}");
}


// Media of at least the minimum breakpoint width. No query for the smallest breakpoint.
// Makes the @content apply to the given breakpoint and wider.
@mixin media-breakpoint-up($name, $breakpoints: $grid-breakpoints) {
$min: breakpoint-min($name, $breakpoints);
@if $min {
@media (min-width: $min) {
@content;
}
} @else {
@content;
}
}
Loading