1 // Foundation for Apps ALPHA
\r
3 // foundation.zurb.com
\r
4 // Licensed under MIT Open Source
\r
6 $include-css: () !default;
\r
7 $modules: () !default;
\r
8 $rem-base: 16px !default;
\r
10 /// Checks if a module is in use.
\r
11 @function using($name) {
\r
12 // Import from global scope
\r
13 $include-css: $include-css !global;
\r
14 $module-key: map-get($include-css, $name);
\r
16 @if $module-key == true or $module-key == null {
\r
24 /// Checks if a module's CSS has already been exported.
\r
25 @function imported($name) {
\r
26 // Import from global scope
\r
27 $modules: $modules !global;
\r
28 // Check if the module is already on the imported list
\r
29 @if type-of(index($modules, $name)) == 'number' {
\r
37 /// Outputs the chunk of content passed if component $name hasn't yet been output.
\r
38 /// This prevents code duplication by keeping track of which components have already been output.
\r
40 /// @param {string} $name - Name of component to output
\r
42 /// @output The content passed, if the component has not yet been exported.
\r
43 @mixin exports($name) {
\r
44 // Check if the module has already been imported
\r
45 @if not(imported($name)) {
\r
46 // Check if the module should be used
\r
48 $modules: append($modules, $name) !global;
\r
55 /// Converts a Sass map to a URL-encoded string, like this: `key1=value1&key2=value2`. We use this function to encode the media queries in the `$breakpoints` variable, so it can be transferred to our JavaScript for use there.
\r
57 /// @param {map} $map - Map to convert.
\r
59 /// @return A string with a map converted to a string.
\r
60 @function map-serialize($map) {
\r
62 @each $key, $value in $map {
\r
63 $str: $str + $key + '=' + $value + '&';
\r
65 $str: str-slice($str, 1, -2);
\r
71 /// Find the next key in a map.
\r
73 /// @param {map} $map - Map to traverse.
\r
74 /// @param {mixed} $key - Key to use as a starting point.
\r
76 /// @return The value for the key after `$key` if `$key` was found. If `$key` was not found, or `$key` was the last value in the map, returns null.
\r
77 @function map-next($map, $key) {
\r
78 // Store the values of the map as a list, so we can access them with nth
\r
79 $values: map-values($map);
\r
84 @each $val in map-keys($map) {
\r
85 @if $found == false {
\r
86 @if ($key == $val) {
\r
93 // If the key doesn't exist, or it's the last key in the map, return null
\r
94 @if $i > length($map) {
\r
97 // Otherwise return the value
\r
99 @return nth($values, $i);
\r
104 /// Checks the lightness of $color, and if it passes the $threshold of lightness, it returns the `$yes` color. Otherwise, it returns the `$no` color. Use this function to dynamically output a foreground color based on a given background color.
\r
106 /// @param {color} $color - Color to check the lightness of.
\r
107 /// @param {color} $yes - Color to return if $color is light.
\r
108 /// @param {color} $no - Color to return if $color is dark.
\r
109 /// @param {percentage} $threshold - Threshold of lightness to check against.
\r
111 /// @return The $yes color or $no color.
\r
112 @function isitlight($color, $yes: #000, $no: #fff, $threshold: 60%) {
\r
113 @if (lightness($color) > $threshold) {
\r
122 /// Scales a color to be lighter if it's light, or darker if it's dark. Use this function to "fade" a color appropriate to its lightness.
\r
124 /// @param {color} $color - Color to scale.
\r
125 /// @param {percentage} $scale - Amount to scale up or down.
\r
126 /// @param {percentage} $threshold - Threshold of lightness to check against.
\r
128 /// @return A scaled color.
\r
129 @function smartscale($color, $scale: 5%, $threshold: 60%) {
\r
130 @if lightness($color) > $threshold {
\r
133 @return scale-color($color, $lightness: $scale);
\r
137 /// Returns true if a value is not 0, null, or none. Use this function to check for values like `border: 0` or `box-shadow: none`.
\r
139 /// @param $val - Value to check.
\r
141 /// @return True if `$val` is not 0, null, or none.
\r
142 @function hasvalue($val) {
\r
143 @if $val == null or $val == none {
\r
146 @if type-of($val) == 'number' and strip-unit($val) == 0 {
\r
153 /// Determine a top/right/bottom/right value on a padding, margin, etc. property, no matter how many values were passed in. Use this function if you need to know the specific side of a value, but don't know if the value is using shorthand.
\r
155 /// @param {list|number} $val - Value to analyze. Should be a shorthand sizing property, e.g. "1em 2em 1em"
\r
156 /// @param {keyword} $side - Side to return. Should be top, right, bottom, or left.
\r
158 /// @return A single value based on `$val` and `$side`.
\r
159 @function get-side($val, $side) {
\r
160 $length: length($val);
\r
168 bottom: nth($val, 1),
\r
169 left: nth($val, 2),
\r
170 right: nth($val, 2),
\r
176 left: nth($val, 2),
\r
177 right: nth($val, 2),
\r
178 bottom: nth($val, 3),
\r
184 right: nth($val, 2),
\r
185 bottom: nth($val, 3),
\r
186 left: nth($val, 4),
\r
191 /// Get Border Value
\r
192 /// Given border $val, find a specific element of the border, which is $elem. The possible values for $elem are width, style, and color.
\r
194 /// @param {list} $val - Border value to find a value in.
\r
195 /// @param {keyword} $elem - Border component to extract.
\r
197 /// @param If the value exists, returns the value. If the value is not in the border definition, the function will return a 0px width, solid style, or black border.
\r
198 @function get-border-value($val, $elem) {
\r
199 // Find the width, style, or color and return it
\r
201 $type: type-of($v);
\r
202 @if $elem == width and $type == 'number' {
\r
205 @if $elem == style and $type == 'string' {
\r
208 @if $elem == color and $type == 'color' {
\r
219 @return map-get($defaults, $elem);
\r
222 /// Get Shadow Value
\r
223 /// Given shadow value $val, find a specific element of the shadow, which is $elem. The possible values for $elem are x, y, size, spread, color, and inset.
\r
225 /// @param {list} $val - Shadow value to find a value in.
\r
226 /// @param {keyword} $elem - Shadow component to extract.
\r
228 /// @return If the value exists, returns the value. If the value is not set, returns false. If `$elem` is "inset", returns true, otherwise false.
\r
229 @function get-shadow-value($val, $elem) {
\r
230 // Return "none" if there's no shadow
\r
235 // Inset and color are always at the beginning and end
\r
236 @if $elem == inset {
\r
237 @return nth($val, 1) == inset;
\r
239 @if $elem == color {
\r
240 @if type-of(nth($val, -1)) == color {
\r
241 @return nth($val, -1);
\r
248 // The rest of the values are located perilously in the middle
\r
251 @if type-of($v) == 'number' {
\r
252 $values: append($values, $v);
\r
256 @if length($values) >= 1 {
\r
257 @return nth($values, 1);
\r
263 @else if $elem == y {
\r
264 @if length($values) >= 2 {
\r
265 @return nth($values, 2);
\r
271 @else if $elem == size {
\r
272 @if length($values) >= 3 {
\r
273 @return nth($values, 3);
\r
279 @else if $elem == spread {
\r
280 @if length($values) >= 4 {
\r
281 @return nth($values, 4);
\r
293 /// Removes the unit (e.g. px, em, rem) from a value, returning the number only.
\r
295 /// @param {number} $num - Number to strip unit from.
\r
297 /// @return The same number, sans unit.
\r
298 @function strip-unit($num) {
\r
299 @return $num / ($num * 0 + 1);
\r
302 /// Turn to Degrees
\r
303 /// Converts a turn unit to the equivalent unit in degrees. 1turn is equal to 360 degrees. Not all browsers support turn, so this function allows us to use turns while outputting a value that all browsers understand.
\r
305 /// @param {number} $value - Turn value to convert.
\r
307 /// @return The same value, but in degrees.
\r
308 @function turn-to-deg($value) {
\r
309 @return strip-unit($value) * 360deg;
\r
313 /// Converts a pixel value to matching rem value. *Any* value passed, regardless of unit, is assumed to be a pixel value. By default, the base pixel value used to calculate the rem value is taken from the `$rem-base` variable.
\r
315 /// @param {number} $value - Pixel value to convert.
\r
317 /// @return A number in rems, calculated based on the given value and the base pixel value.
\r
318 @function convert-to-rem($value, $base-value: $rem-base) {
\r
319 $value: strip-unit($value) / strip-unit($base-value) * 1rem;
\r
320 @if ($value == 0rem) { $value: 0; } // Turn 0rem into 0
\r
325 /// Converts one or more pixel values into matching rem values. This function works a lot like `convert-to-rem`, except it can convert more than one value at once, which is useful when setting multiple values on a `margin` or `padding` property.
\r
327 /// @param {number|list} $values - One or more values to convert. Be sure to separate them with spaces and not commas. If you need to convert a comma-separated list, wrap the list in parentheses.
\r
329 /// @return A list of converted values.
\r
330 @function rem-calc($values, $base-value: null) {
\r
331 @if $base-value == null {
\r
332 $base-value: $rem-base;
\r
334 $max: length($values);
\r
336 @if $max == 1 { @return convert-to-rem(nth($values, 1), $base-value); }
\r
339 @for $i from 1 through $max {
\r
340 $remValues: append($remValues, convert-to-rem(nth($values, $i), $base-value));
\r
342 @return $remValues;
\r