[Stefan Bauer] For more than one decade no other SASS revolutionised the way we write CSS nowadays. In modern SharePoint development, this is the core ingredient to deliver optimised and well architecture.
SASS is also one of the core ingredients to develop new customisations for SharePoint through SPFX.
This session will give you an overview of the most useful concepts in SASS. Besides you will get to know some limitations in SPFX and how to handle those properly.
After this session you will be able to:
• Sketch and develop web parts faster
• Create your reusable CSS
• Apply themes to your web parts
• Handle external CSS properly in SPFX
3. OUR GOALS
SASS base concepts
Sketch & develop web parts
Create your own reusable CSS
Handle external CSS properly in
SPFx
Apply themes to your web parts
19. MOST IMPORTANT FEATURE IN
SASS
Works same as in HTML but different
@import url(‘http://getbootstrap.com/someurl’)
HTML import
@import ‘somefile.css’
Merges file directly into CSS
@import <file | url>;
20. MOST IMPORTANT FEATURE IN
SASS
•Partial file through the ‘_’
•File won’t be compiled to ’.css’ file
•Import Reusable components
•Helps you strucuture your CSS Better
@import ‘_custom.scss’;
@import ‘custom’;
21. IMPORT IN SPFX
•Import CSS from any npm package
•Import CSS from bower components
@import ‘_custom.scss’;
@import ‘custom’;
@import ‘node_modules/office-ui-fabric/dist/fabric.css’
37. BENEFIT – AUTOPREFIXING
Cleaner CSS / Less Headache
Configured to support Office 365 /
SharePoint optimal
No legacy code removal
38. SASS COMPILATION IN SPFX
COMPILE SASS
AUTOPREFIX
POSTFIX / TS Class Compilation
39.
40. POSTFIXING – CSS MODULES
.round {
...
}
.round_f6d5fd65{
...
}
BEFOR
E
AFTER
41. POSTFIXING – CSS MODULES
.round {
...
}
.round_f6d5fd65{
...
}
BEFOR
E
AFTER
Make class name unique
42. POSTFIXING
•Web Part cannot effect the overall
experience
•Different web parts – same classes not
possible
•Makes it hard to share code across web
parts – even in same project
43. TYPESCRIPT CLASS COMPILATION
•Each CSS class
style.YourClassName
•CSS becomes somewhat type safe
LIMITATION:
invalid class name – .card-hover
JS doesn’t allow dashes in variable names
44. TYPESCRIPT CLASS COMPILATION
Typescript class = JSON Object
var styles = {
'my-class': 'my-class_2023f0bf’
}
style.my-class //Fails
style[‘my-class’] // CORRECT but not type safe