SPFX - Learning And Findings - Part One

Introduction 

 
Hello everyone, I work on SharePoint, so I like to play around. This time I thought maybe I pen down my learnings and findings. This is my first blog so I will try to start with less complicated stuff.
 
This blog is about SPFx and my findings. I cannot write everything in one blog, so I have created a series, and this is the first in that series.
 

Warning suppression in SPFx

 
I was working on one of the projects where I wanted to use office fabric 7 but as you know scaffolding gives you only fabric 6 for now, so I went ahead and updated the fabric version. I thought things will break but it worked fine for me. I tested this on classic page, and I found some styling issues. OOB css from corev15 was overriding few of fabric CSS. To fix that it was simple, I just reset it to default in my SPFx scss file. Below is the few sample css changes:
  1. :global{  
  2.   .ms-core-tableNoSpace{  
  3.     width80%;  
  4.   }  
  5.   .ms-Callout-container{  
  6.     input[type=button], input[type=reset], input[type=submit], button {  
  7.       min-width: initial;  
  8.       margin-left: initial;  
  9.     }  
  10.     input, select, label, textarea, button, option {  
  11.        vertical-align: initial;  
  12.     }  
  13.     input[type=button]:active, input[type=reset]:active, input[type=submit]:active,   
  14.     input[type=button]:hover, input[type=reset]:hover, input[type=submit]:hover {  
  15.       border-color: initial;  
  16.       background-color:initial;  
  17.     }  
  18.     button:hover{  
  19.       border-color: rgba(0,0,0,0);  
  20.     }  
  21.   }  
  22. }  
  23.   
  24. .customWebpart {  
  25.   input[type=password], input[type=text], input[type=file], input:not([type]), select, textarea, .sp-peoplepicker-topLevel, .sp-peoplepicker-topLevelDisabled, .sp-peoplepicker-autoFillContainer, .ms-inputBox {  
  26.     border:initial;  
  27. }  
  28. input[type=button], input[type=reset], input[type=submit], button {  
  29.   min-width: initial;  
  30.   margin-left: initial;  
  31. }  
  32. input, select, label, textarea, button, option {  
  33.    vertical-align: initial;  
  34. }  
  35.    
  36. input[type=button]:hover , input[type=reset]:hover, input[type=submit]:hover, button:hover,  
  37. input[type=button]:active, input[type=reset]:active, input[type=submit]:active, button:active,  
  38. :not(:global(.ms-Button:hover)),:not(:global(.ms-Button:active))  {  
  39.   border-color: initial;  
  40.   background-color:initial;  
  41.     
  42. }  
  43. }  
By default, you would only want to target the CSS for the controls which is inside your webpart, not the whole page due to which I have overridden CSS inside the class. Few of them are global because callouts are at body level so to fix those you must have globally.
 
The issues got fixed but I started getting below warning. Due to this warning, I was not able to package my solution.
  1. Warning - [sass] The local CSS class 'ms-Callout-container' is not camelCase and will not be type-safe.  
This warning is because the class names defined are not according to tslint standard. One side there is these CSS class names and another side is warning which prevents me in creating a package. I cannot change the CSS class name as it is SharePoint CSS, so we must fix the warning part.
 
To fix the warning, open the "gulpfile.js” from the project. In the file you will see below line:
  1. build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);  
As you see SPFx guys are also trying to suppress one of the warnings. We do the same thing we add our own suppression and add below line:
  1. build.addSuppression(/^.*The local CSS class(.*)is not camelCase and will not be type-safe\.$/);  
If you read the above line, we have suppressed all CSS warnings of similar nature by passing a regex expression. You can pass a regex expression or pass a string in the "add Suppression" method. Once the warnings are gone, I was able to create my package.
 
I will come up with more, but please let me know in comments how it was and how can I make it better.