1 // Foundation for Sites by ZURB
3 // Licensed under MIT Open Source
9 /// Calculate the percentage size of a cell.
11 /// @param {Number|List} $size [$grid-columns] - Size to make the cell. You can pass a value in multiple formats, such as `6`, `50%`, `1 of 2` or `1/3`.
12 @function xy-cell-size(
15 // Parsing percents, decimals, n of n and number counts
16 @if type-of($size) == 'number' {
17 @if unit($size) == '%' {
21 $size: percentage($size);
24 $size: percentage($size / $grid-columns);
28 // Parsing "n of n" or "n/n" expressions
29 @elseif type-of($size) == 'list' {
30 @if length($size) != 3 {
31 @error 'Wrong syntax for xy-cell-size(). Use the format "n of n" or "n/n".';
34 $size: percentage(nth($size, 1) / nth($size, 3));
37 // Anything else is incorrect
39 @error 'Wrong syntax for xy-cell-size(). Use a number, decimal, percentage, or "n of n" / "n/n".';
45 /// Sets base flex properties for cells.
47 /// @param {Keyword} $size [full] - The size of your cell. Accepts `full`, `auto`, `shrink` or `grow`.
48 @mixin xy-cell-base($size: full) {
49 @if($size == 'full') {
50 // This is the base style, all others inherit from it
55 @elseif ($size == 'auto') {
56 flex: 1 1 0px; // sass-lint:disable-line zero-unit
58 @elseif ($size == 'shrink') {
61 @elseif ($size == 'grow') {
66 /// Resets a cells width (or height if vertical is true) as well as strips its gutters.
68 /// @param {Boolean} $vertical [false] - Set to true to output vertical (height) styles rather than widths.
69 @mixin xy-cell-reset($vertical: true) {
70 $direction: if($vertical == true, width, height);
72 max-#{$direction}: none;
75 // Sets our cell widths or heights depending on gutter type.
76 @mixin -xy-cell-properties($size, $margin-gutter, $vertical) {
77 $direction: if($vertical == true, height, width);
78 @if($size == 'full') {
79 $val: if($margin-gutter == 0, 100%, calc(100% - #{rem-calc($margin-gutter)}));
82 @elseif ($size == 'auto') {
84 $val: if($margin-gutter == 0, 100%, calc(100% - #{rem-calc($margin-gutter)}));
86 @elseif ($size == 'shrink') {
90 $val: if($margin-gutter == 0, #{xy-cell-size($size)}, calc(#{xy-cell-size($size)} - #{rem-calc($margin-gutter)}));
95 /// Creates a cell for your grid.
97 /// @param {Keyword|Number} $size [full] - The size of your cell. Can be `full` (default) for 100% width, `auto` to use up available space and `shrink` to use up only required space.
98 /// @param {Boolean} $gutter-output [true] - Whether or not to output gutters. Always `true` for margin gutters.
99 /// @param {Number|Map} $gutters [$grid-margin-gutters] - Map or single value for gutters.
100 /// @param {Keyword} $gutter-type [margin] - Map or single value for gutters.
101 /// @param {List} $gutter-position [right left] - The position to apply gutters to. Accepts `top`, `bottom`, `left`, `right` in any combination.
102 /// @param {String} $breakpoint [null] - The name of the breakpoint size in your gutters map to get the size from. If using with the `breakpoint()` mixin this will be set automatically unless manually entered.
103 /// @param {Boolean} $vertical [false] - Set to true to output vertical (height) styles rather than widths.
106 $gutter-output: true,
107 $gutters: $grid-margin-gutters,
108 $gutter-type: margin,
109 $gutter-position: right left,
113 @if($breakpoint == null) {
114 // If `$bp-size` is available then use this, otherwise revert to the smallest bp.
115 @if(variable-exists(-zf-size) and type-of($-zf-size) != 'number') and $-zf-size != null {
116 $breakpoint: $-zf-size;
119 $breakpoint: $-zf-zero-breakpoint;
123 // Get the gutter for the passed breakpoint/value.
124 $gutter: -zf-get-bp-val($gutters, $breakpoint);
126 @if($gutter != null) {
127 // Base flex properties
128 @include xy-cell-base($size);
130 $-gutter-output: if($gutter-type == 'margin', true, $gutter-output);
131 $-gutter-margin: if($gutter-type == 'margin', $gutter, 0);
133 @include -xy-cell-properties($size, $-gutter-margin, $vertical);
134 @if ($-gutter-output) {
135 @include xy-gutters($gutter, $gutter-type, $gutter-position);
139 @warn 'xy-cell: no gutters were found in `$gutters` for "$breakpoint: #{$breakpoint}", cell was not generated`'
143 /// Creates a single breakpoint sized grid. Used to generate our grid classes.
145 /// @param {Keyword|Number} $size [full] - The size of your cell. Can be `full` (default) for 100% width, `auto` to use up available space and `shrink` to use up only required space.
146 /// @param {Boolean} $gutter-output [true] - Whether or not to output gutters. Always `true` for margin gutters.
147 /// @param {Number|Map} $gutters [$grid-margin-gutters] - Map or single value for gutters.
148 /// @param {Keyword} $gutter-type [margin] - Map or single value for gutters.
149 /// @param {String} $breakpoint [null] - The name of the breakpoint size in your gutters map to get the size from. If using with the `breakpoint()` mixin this will be set automatically unless manually entered.
150 /// @param {Boolean} $vertical [false] - Set to true to output vertical (height) styles rather than widths.
151 @mixin xy-cell-static(
153 $gutter-output: true,
154 $gutters: $grid-margin-gutters,
155 $gutter-type: margin,
156 $breakpoint: $-zf-zero-breakpoint,
160 $gutter: -zf-get-bp-val($gutters, $breakpoint);
161 $gutter-position: if($vertical == true, top bottom, left right);
163 $-gutter-output: if($gutter-type == 'margin', true, $gutter-output);
164 $-gutter-margin: if($gutter-type == 'margin', $gutter, 0);
166 @include -xy-cell-properties($size, $-gutter-margin, $vertical);
167 @if ($-gutter-output) {
168 @include xy-gutters($gutter, $gutter-type, $gutter-position);