layout-tools-for-susy 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +209 -9
- data/lib/layout-tools-for-susy.rb +2 -2
- data/stylesheets/functions/_list-px-to-em.scss +1 -1
- data/stylesheets/mixins/_type-base.scss +2 -2
- data/stylesheets/mixins/_type-context.scss +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9da75cb63b3401fefbc37d62bf126c5d0da68cc0
|
4
|
+
data.tar.gz: 1a6772cca9a86a94e0f7a6de4457dffd6cb7bf2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06835402a614d99ada02d19dcf29adb649228489f9633ab9c2729e43ab934cf8a3d652ec573e1a0065657b0f67b08a9e1727779308778b6a327b1098901d3362
|
7
|
+
data.tar.gz: eecd8f4d8e64274ed3e3b2325ea6955106dc7ebc95254554040b407afeebd012d5ff97727aa8558cd8526c1b57dd15faec29be2d859bbd3b2bfa3ddd0f9869be
|
data/README.md
CHANGED
@@ -2,6 +2,28 @@
|
|
2
2
|
|
3
3
|
Layout Tools for Susy is a set of handy mixins and functions to structure, organize and access layout settings over multiple breakpoints. Combined with the power of Susy’s grid calculations it allows you to set up responsive grid layouts fast and with ease.
|
4
4
|
|
5
|
+
## Table of Contents
|
6
|
+
* [Installation](#installation)
|
7
|
+
* [NPM](#npm)
|
8
|
+
* [Bower](#bower)
|
9
|
+
* [Bundler](#bundler)
|
10
|
+
* [How to use](#how-to-use)
|
11
|
+
* [Defining layout contexts](#defining-layout-contexts)
|
12
|
+
* [Using layout contexts](#using-layout-contexts)
|
13
|
+
* [Settings groups](#settings-groups)
|
14
|
+
* [Susy settings](#susy-settings)
|
15
|
+
* [Base font size and line height](#base-font-size-and-line-height)
|
16
|
+
* [Separating layout settings](#separating-layout-settings)
|
17
|
+
* [Defining layout breakpoints](#defining-layout-breakpoints)
|
18
|
+
* [More handy helpers](#more-handy-helpers)
|
19
|
+
* [Units](#units)
|
20
|
+
* [Typography](#typography)
|
21
|
+
* [Colors](#colors)
|
22
|
+
* [Constants](#constants)
|
23
|
+
* [Tips and tricks](#tips-and-tricks)
|
24
|
+
* [Contribute](#contribute)
|
25
|
+
|
26
|
+
|
5
27
|
## Installation
|
6
28
|
### NPM
|
7
29
|
```bash
|
@@ -53,7 +75,7 @@ Include Susy and Layout Tools for Susy in your stylesheets.
|
|
53
75
|
## How to use
|
54
76
|
Since Susy2 switched to storing all grid settings in SASS maps, it seems to be quite a good idea to store other basic layout settings the same way. Layout Tools for Susy provides tools to store and access layout settings while making the interaction with SASS maps to a minimum. Let’s see how it’s done.
|
55
77
|
|
56
|
-
### Defining
|
78
|
+
### Defining layout contexts
|
57
79
|
The foundation Layout Tools for Susy build on is a SASS map storing the basic layout settings for your Susy setup and more. Here’s an example:
|
58
80
|
```scss
|
59
81
|
// Layout settings
|
@@ -119,7 +141,7 @@ $layouts: (
|
|
119
141
|
```
|
120
142
|
The root properties of the map $layouts represent the different layout contexts. Layout contexts may be layout variations depending on breakpoints or layout settings specific for e.g. a certain template. There are some important settings that will be defined by default if you don’t set them yourself. The `default` layout will be set up by—you guessed it—default with the properties `susy`—containing Susy’s default settings—and `base`—setting a `base__font-size` and `base__line-height` value. To implement your custom layouts, you have to create your settings map like shown above overriding the defaults and adding additional layout specifications.
|
121
143
|
|
122
|
-
####
|
144
|
+
#### Using layout contexts
|
123
145
|
The `default` layout context is the most basic. It will be used everywhere where no other layout context is set (by using the `layout-use` mixin). All other layout contexts extend the `default` context and thus override its settings. If you want to extend a specific context, you can define it using the `extends` property within a layout context’s definition map. In the example above the layout context `L` extends `M`. That means the settings and values you will be working with in the layout context `L` are the result from first merging `M` into `default` and then `L` into the first merge’s result. So within the context of `L` the value of `base__font-size` will be 18px. This behaviour allows you create a sophisticated system of layout settings through controlled inheritance of settings and values.
|
124
146
|
|
125
147
|
As said before, after using ```@include layout-init($layouts);``` the `default` layout context is established. Switching to another context is done using the ```layout-use()``` mixin as shown below:
|
@@ -168,6 +190,14 @@ $layouts: (
|
|
168
190
|
)
|
169
191
|
)
|
170
192
|
```
|
193
|
+
|
194
|
+
#### Susy settings
|
195
|
+
The `susy` property represents the Susy settings map. For more information on configuration settings and how to work with Susy, go to: http://susydocs.oddbird.net/en/latest/
|
196
|
+
|
197
|
+
#### Base font size and line height
|
198
|
+
Within a layout context, there will be two global vars available named `$base__font-size` and `$base__line-height`. They are retrieved automatically from the current layout context’s settings. To override them, define the pixel values of your choice for ```base__font-size``` and ```base__line-height``` in your layout contexts’ ```base``` group.
|
199
|
+
|
200
|
+
#### Separating layout settings
|
171
201
|
To give you even more possibilities to modulize your SASS code base, you can keep e.g. component-specific settings with the corresponding styles in separate files and import them where needed. This is done by using the ```layout-extend()``` mixin like shown below:
|
172
202
|
```scss
|
173
203
|
// separate file _my-component.scss
|
@@ -212,21 +242,191 @@ $my-component: (
|
|
212
242
|
|
213
243
|
```
|
214
244
|
|
215
|
-
|
216
|
-
|
245
|
+
### Defining layout breakpoints
|
246
|
+
Layout Tools for Susy make responsiveness easy. You can define breakpoints through adding the breakpoint property to any (but default) layout context like in this mobile first (smallest screen as default) example:
|
247
|
+
```scss
|
248
|
+
$layouts: (
|
249
|
+
default: (
|
250
|
+
susy: (
|
251
|
+
...
|
252
|
+
),
|
253
|
+
base: (
|
254
|
+
...
|
255
|
+
)
|
256
|
+
),
|
257
|
+
M: (
|
258
|
+
susy: (
|
259
|
+
// new grid settings
|
260
|
+
...
|
261
|
+
),
|
262
|
+
base: (
|
263
|
+
// new base font size, etc.
|
264
|
+
...
|
265
|
+
),
|
266
|
+
breakpoint: (
|
267
|
+
(
|
268
|
+
min-width: 480px,
|
269
|
+
max-width: 800px,
|
270
|
+
min-height: 650px
|
271
|
+
),
|
272
|
+
(
|
273
|
+
min-width: 640px,
|
274
|
+
max-width: 800px
|
275
|
+
)
|
276
|
+
)
|
277
|
+
),
|
278
|
+
L: (
|
279
|
+
// we keep and grid settings
|
280
|
+
extend: M,
|
281
|
+
breakpoint: (
|
282
|
+
min-width: 801px
|
283
|
+
)
|
284
|
+
)
|
285
|
+
)
|
286
|
+
```
|
287
|
+
As you can see, it's possible to define a single, simple breakpoint through adding media query properties directly as well as more complex breakpoints by providing multiple media queries as a list. You can just add any media query property value pair you need and even define media types by adding e.g. ```medium: screen``` (default is ```all```). As soon as you apply a layout context by using ```layout-use()```, all content passed into the mixin will be wrapped in a media query generated from your definition. As said before you can manipulate the media queries by passing one of the keywords ```down``` or ```up``` with the context name. Using the mixin within your stylesheets is pretty great, as you can define layout changes right where they belong like this:
|
288
|
+
```scss
|
289
|
+
...
|
290
|
+
.section {
|
291
|
+
&--text {
|
292
|
+
// retrieve font size and line height from current layout context
|
293
|
+
$text__font-size: layout-get(section, text__font-size);
|
294
|
+
$text__line-height: layout-get(section, text__line-height);
|
295
|
+
@include type-context($text__font-size, $text__line-height) {
|
296
|
+
// convert px values to em using list-px-to-em() helper that also comes with Layout Tools
|
297
|
+
padding: list-px-to-em((30px 20px 40px), $local__font-size);
|
298
|
+
}
|
217
299
|
|
218
|
-
|
219
|
-
|
300
|
+
@include layout-use(M) {
|
301
|
+
// retrieve font size and line height from new layout context
|
302
|
+
$text__font-size: layout-get(section, text__font-size);
|
303
|
+
$text__line-height: layout-get(section, text__line-height);
|
304
|
+
@include type-context($text__font-size, $text__line-height) {
|
305
|
+
padding: list-px-to-em((30px 20px 40px), $local__font-size);
|
306
|
+
}
|
307
|
+
}
|
308
|
+
}
|
309
|
+
}
|
310
|
+
```
|
311
|
+
That’s it. Easy, isn’t it?
|
312
|
+
|
313
|
+
## More handy helpers
|
314
|
+
Layout Tools for Susy come with some more handy helpers.
|
315
|
+
|
316
|
+
### Units
|
317
|
+
```scss
|
318
|
+
// Convert px to em
|
319
|
+
$rem-value: px-to-rem(10px);
|
320
|
+
|
321
|
+
// Convert px to em
|
322
|
+
$em-value: px-to-em(10px, $base__font-size);
|
323
|
+
|
324
|
+
// Convert px to percentage
|
325
|
+
$pc-value: px-to-pc(10px, 100px);
|
326
|
+
|
327
|
+
// Convert px values in list to em
|
328
|
+
$box__margin: 10px auto 40px auto;
|
329
|
+
margin: list-px-to-em($box__margin);
|
330
|
+
|
331
|
+
```
|
332
|
+
|
333
|
+
### Typography
|
334
|
+
Two really useful tools are the mixins called ```type-base``` and ```type-context```. Especially if you are trying to keep everything modular and try to deal with font sizes in a way similar to this approach: https://css-tricks.com/rems-ems/.
|
335
|
+
|
336
|
+
The mixin ```type-base()``` will add style definitions for ```font-size``` and ```line-height``` in ```rem``` relatively to the root element’s font size with a pixel fallback. If no parameters are passed it will use the current layout context’s base font size and base line height. If you want to set a custom value, pass in a pixel value for font size and line height. If you pass content into the mixin, the globals $base__font-size, $base__line-height as well as $local__font-size and $local__line-height (more on this in a second) will be set to the new values within the mixins scope. That comes pretty handy if you want to reset the font size within a element or component to make it independent from the environment it will be used in.
|
337
|
+
|
338
|
+
```scss
|
339
|
+
...
|
340
|
+
body {
|
341
|
+
// set base font size and line height in body element
|
342
|
+
@include type-base();
|
343
|
+
}
|
344
|
+
|
345
|
+
.page {
|
346
|
+
|
347
|
+
&__header {
|
348
|
+
// retrieve font sizes from layout context
|
349
|
+
$header__font-size: layout-get(page, header__font-size);
|
350
|
+
$header__line-height: layout-get(page, header__line-height);
|
351
|
+
// apply new font size and line height locally and relatively to base values using 'type-context()'
|
352
|
+
@include type-context($header__font-size, $header__line-height) {
|
353
|
+
// $base__font-size and $base__line-height stay the same
|
354
|
+
// $local__font-size and $local__line-height are set to the new values
|
355
|
+
// $local__font-size equals $header__font-size in here
|
356
|
+
// $local__line-height equals $header__line-height in here
|
357
|
+
padding: px-to-em(30px, $local__font-size) 0;
|
358
|
+
}
|
359
|
+
}
|
360
|
+
}
|
220
361
|
|
362
|
+
.my-component {
|
363
|
+
@extends %component;
|
364
|
+
// reset font size and line height to custom values
|
365
|
+
$component__font-size: layout-get(compontents, component__font-size);
|
366
|
+
$component__line-height: layout-get(compontents, component__line-height);
|
367
|
+
@include type-base($component__font-size, $component__line-height, false) {
|
368
|
+
// Font size and line height values are reset for all content passed into mixin
|
369
|
+
// $base__font-size equals $local__font-size equals $components__font-size in here
|
370
|
+
// $base__line-height equals $local__line-height equals $components__line-height in here
|
371
|
+
padding: px-to-em(10px, $local__font-size) 0;
|
221
372
|
|
222
|
-
|
373
|
+
&__title {
|
374
|
+
// retrieve font size and line height from current layout context
|
375
|
+
$title__font-size: layout-get(components, title__font-size);
|
376
|
+
$title__line-height: layout-get(components, title__line-height);
|
377
|
+
// set relative type context
|
378
|
+
@include type-context($title__font-size, $title__line-height) {
|
379
|
+
// $base__font-size and $base__line-height stay the same
|
380
|
+
// $local__font-size and $local__line-height are set to the new values
|
381
|
+
margin-bottom: px-to-em(15px, $local__font-size);
|
223
382
|
|
224
|
-
|
383
|
+
span {
|
384
|
+
@include type-context(.5 * $title__font-size, .5 * $title__line-height) {
|
385
|
+
...
|
386
|
+
}
|
387
|
+
}
|
388
|
+
}
|
389
|
+
}
|
390
|
+
}
|
391
|
+
}
|
392
|
+
```
|
393
|
+
In the example above the ```type-context``` mixin is used to set new local font sizes and line heights as ```em``` values. In contrast to ```type-base``` the base values ```$base__font-size``` and ```$base__line-height``` won’t be altered within the mixins scope. Multiple type contexts can be embedded into each other and the mixin will take track of the relative font sizes and line heights and the necessary calculations.
|
225
394
|
|
226
395
|
### Colors
|
396
|
+
```scss
|
397
|
+
// Store colors
|
398
|
+
// @include color-set($palette, $tone, $value);
|
399
|
+
|
400
|
+
// Define complete palette 'blueish'
|
401
|
+
@include color-set(blueish, (
|
402
|
+
bright: #0000fa,
|
403
|
+
base: #000077,
|
404
|
+
dark: #000042,
|
405
|
+
transparent: rgba(#000077, .75)
|
406
|
+
));
|
407
|
+
// Add tone to a palette (defined as 'bright' tone of 'blueish' palette)
|
408
|
+
@include color-set(blueish, bright, #0000fa);
|
409
|
+
|
410
|
+
// Get colors
|
411
|
+
// $val: color-get($palette, $tone);
|
412
|
+
|
413
|
+
// Get 'base' tone of 'blueish' palette
|
414
|
+
color: color-get(blueish);
|
415
|
+
|
416
|
+
// Get 'bright' tone of 'blueish' palette
|
417
|
+
color: color-get(blueish, bright);
|
418
|
+
|
419
|
+
```
|
227
420
|
|
228
421
|
### Constants
|
422
|
+
```scss
|
423
|
+
// Define new constant
|
424
|
+
@include const('BG_IMG_PATH', '/assets/images/');
|
425
|
+
|
426
|
+
// Retrieve constant
|
427
|
+
background-image: url(const(BG_IMG_PATH) + 'hero_bg.jpg');
|
428
|
+
```
|
229
429
|
|
230
|
-
###
|
430
|
+
### Tips and tricks
|
231
431
|
|
232
432
|
### Contribute
|
@@ -7,7 +7,7 @@
|
|
7
7
|
@for $i from 1 through length($list) {
|
8
8
|
$value: nth($list, $i);
|
9
9
|
@if(type-of($value) == number and unit($value) == px) {
|
10
|
-
$list: set-nth($list, $i,
|
10
|
+
$list: set-nth($list, $i, px-to-em($value, $context));
|
11
11
|
}
|
12
12
|
}
|
13
13
|
@return $list;
|
@@ -18,8 +18,8 @@
|
|
18
18
|
//set styles
|
19
19
|
@if ($set-styles) {
|
20
20
|
font-size: $base__font-size;
|
21
|
-
font-size:
|
22
|
-
line-height:
|
21
|
+
font-size: px-to-rem($base__font-size);
|
22
|
+
line-height: px-to-em($base__line-height, $base__font-size);
|
23
23
|
}
|
24
24
|
// include content
|
25
25
|
@content;
|
@@ -13,8 +13,8 @@
|
|
13
13
|
$local__line-height: $line-height !global;
|
14
14
|
// set styles
|
15
15
|
@if($set-styles) {
|
16
|
-
font-size:
|
17
|
-
line-height:
|
16
|
+
font-size: px-to-em($font-size, $local__font-size--parent);
|
17
|
+
line-height: px-to-em($line-height, $local__font-size);
|
18
18
|
}
|
19
19
|
// include content
|
20
20
|
@content;
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: layout-tools-for-susy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oliver Wehn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sass
|