Get/Set with JS // DOM elements const $el = document.getElementById(‘target’); const $root = document.documentElement; // Get window.getComputedStyle($el).getPropertyValue(“—color”); // Set $el.style.setProperty(‘—color’, ‘black’);
Gotcha: dang browsers
Some calculations fall foul of browser variation. SCSS is at least normalised calculation.
Slide 33
90% of the effort is in the last 10%
Slide 34
Think of the childrenIE11 childrenIE11
Calc: supported but buggy Custom Props: no support
Slide 35
PostCSS to the rescue! postcss([ postCSSCustomProperties({ importFrom: ‘./dist/css-variables.css’ }), postCSSCalc() ]))
.selector { margin-top: 40px; margin-top: calc(var(—space-l) * 1.25); }
Slide 36
A choice
Put up with IE11 bloat in your CSS 2. Serve IE11 its own CSS
Slide 37
Heresy alert! var ua = navigator.userAgent; var uamatch = ua.match(/(msie|trident(?=/))/?\s*([\d.]+)/i) || []; if(/trident/i.test(uamatch[1]) && parseInt(/\brv[ :]+(\d+)/g.exec(ua)[1], 10) === 11) { document.querySelector(‘head’).innerHTML += ‘<link rel=”stylesheet” href=”ie11.css” type }
Available at https://bitbucket.org/snippets/200ok
Slide 38
What I really missed… was errors Error: Undefined variable: “$button-border-widht”. on line 31 of path/to/button.scss from line 8 of path/to/qbit-all.scss >> -width: #{$button-border-widht}; ———————————————-^
Slide 39
What I really missed… was errors .selector { color: var(—colour-that-does-not-exist); }
This was really hard to debug.
Slide 40
Stylelint to the rescue!
gulpStylelint “plugins”: [ “stylelint-scss”, “stylelint-value-no-unknown-custom-properties” ]
Slide 41
Stylelint to the rescue!
gulpStylelint path/to/component.css 85:18 ✖ Unexpected custom property “—colour-hoover” inside declaration “color”.
Slide 42
Do we still need SCSS?
Slide 43
CSS
Variables Calculations Runtime power
Many tools
Bundling Concatenation Postprocessing Linting/errors
SCSS
Mixins Loops
Slide 44
Demand native specs!
Mixins Loops CSS require
Slide 45
You might still use SCSS…
…for massive projects …because it’s still right for you
Slide 46
You might not need SCSS…
…in your API …for small projects