21
'Advanced' Sass with Maps and other stuff

Advanced Sass: with Maps and other stuff

Embed Size (px)

DESCRIPTION

Presentation of uses-cases for Maps and other recently added features in Sass, for UpFront 51 in Berlin, Oct 14. 2014

Citation preview

Page 1: Advanced Sass: with Maps and other stuff

'Advanced' Sasswith Maps and other stuff

Page 2: Advanced Sass: with Maps and other stuff

Who am I

• @lunelson

• Canadian freelance dev/designer

• long-time user of CSS pre-processors (LESS, Stylus, Sass, Libsass)

• disclosure: I have always used a CSS pre-processor

• disclosure: I have never given a presentation about them

Page 3: Advanced Sass: with Maps and other stuff

What is Sass

Sass is a CSS pre-processor. Which is...

• kinda like PHP for HTML

• kinda like CoffeeScript for Javascript

• anyway, all about CSS output

Page 4: Advanced Sass: with Maps and other stuff

Imperative -> Meta-Declarative

Page 5: Advanced Sass: with Maps and other stuff

Sass in review

• $variables and math• partial files• nesting

gist?

* Variables are the gateway drug* Nesting is often overused

Page 6: Advanced Sass: with Maps and other stuff

Sass in review

• @mixins• @functions

gist?

* Sass mixins are arbitrary blocks!

Page 7: Advanced Sass: with Maps and other stuff

Sass in review

• conditional directives

• @if, @else if, @else

• lists and loops

• @while, @for

gist?

* Lists are a powerful data-type

Page 8: Advanced Sass: with Maps and other stuff

Sass in review

• @extend

• %placeholder selectors

• string #{$interpolation}

gist?

* @extend is a shotgun method!* You can't interpolate variables

Page 9: Advanced Sass: with Maps and other stuff

...and ?

Page 10: Advanced Sass: with Maps and other stuff

Sass advanced

• the map data-type• @each, @content, @at-root, unique-id()

Page 11: Advanced Sass: with Maps and other stuff

Maps

...are...• more or less the Sass equivalent of objects / hashes /

dictionaries etc.

• an extension of lists (lists of pairs)

Page 12: Advanced Sass: with Maps and other stuff

Maps

...allow us to...

• dynamically collect and reference (by name)

• pass complex arguments

• multi-iterate

• and still manipulate as with lists

Page 13: Advanced Sass: with Maps and other stuff

Maps

...because• giant configs are ugly

• variables don't interpolate

• lists are not enough

Page 14: Advanced Sass: with Maps and other stuff

Maps 1getting

• bundle up your variables, save space

• refer to them dynamically

• syntax, functions

• a map of $sizes

Page 15: Advanced Sass: with Maps and other stuff

Maps 2iterations / arguments

• pass them to functions or mixins

• iterate through them (since they also lists)

• maps as args

• smart transitions

Page 16: Advanced Sass: with Maps and other stuff

Maps 3merging

• store references

• statuses

• calculated / generated values

• color system generation

Page 17: Advanced Sass: with Maps and other stuff

Maps 4

• @content enables fake scope

• @at-root and 'unique-id()' enable dynamic placeholder storage/ref

some variations on 'smart' include/extend mixins

• global flag

• list self-check

• map self-check

Page 18: Advanced Sass: with Maps and other stuff

case study: media queries, dimensions, typography

• maps configure a mobile-first cascade of media-queries/devices -based dimensions and sizing

• setup @mixins populate these maps through merge operations

• outputs are automated for basic elements across all queries

Page 19: Advanced Sass: with Maps and other stuff

case study: media queries, dimensions, typography

• @content-based @mixins manage fake scopes

• context-aware @functions automate query-based or typography-based value lookups

Page 20: Advanced Sass: with Maps and other stuff

result

• abstracted away verbosity, repetition and complexity

• modeled a meta-declarative level on our mental-model, design-logic and 'cascade' of media-queries

• added new utilities e.g scope-/context-aware functions

• query-value() function looks up values

• rem() function converts absolute values per context

Page 21: Advanced Sass: with Maps and other stuff

Thanks for watching.