Pivot Link Font size in SPFX web part (hipstertabs)

%3CLINGO-SUB%20id%3D%22lingo-sub-1936154%22%20slang%3D%22en-US%22%3EPivot%20Link%20Font%20size%20in%20SPFX%20web%20part%20(hipstertabs)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1936154%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20folks%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EReally%20simplistic%20request%20from%20client%20but%20frankly%20I'm%20lacking%20on%20the%20react%20side%20of%20things%20so%20its%20a%20bit%20tricky!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWe're%20using%20the%20HipsterTabs%20webpart%20found%20here%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmrackley%2FModernHillbillyTabs%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Emrackley%2FModernHillbillyTabs%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20client%20has%20requested%20we%20adjust%20the%20font%20size%20of%20the%20pivot%20link%20headers%20(where%20the%20names%20of%20the%20tabs%20go)%20or%20even%20allow%20the%20option%20to%20flick%20between%20the%20default%20sizes%20(normal%2C%20large)%20and%20a%20third%20new%20size%20(larger%2C%20font-size%2022).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20the%20font%20settings%20are%20imported%20from%20the%20Office-ui-fabric-react%20package%2C%20I%20haven't%20been%20able%20to%20figure%20out%20a%20simple%20method%20around%20using%20a%20CSS%20custom%20class%20or%20something%2C%20I%20think%20I'd%20really%20need%20to%20delve%20into%20the%20react%20framework%20and%20do%20something%20with%20the%20pivotstyles%20modules..%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20web%20part%20is%20a%20couple%20of%20years%20old%20and%20its%20a%20bit%20of%20a%20nightmare%20getting%20all%20the%20node%20dependencies%20to%20the%20right%20versions%20in%20the%20first%20place%20for%20even%20basic%20compilation%20(we%20used%20the%20pre-packaged%20sppkg%20in%20the%20test%20tenant)%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eso%20while%20I'd%20love%20to%20spend%20time%20learning%20and%20understanding%20the%20framework%20to%20create%20a%20newer%20alternative%2C%20I%20was%20hoping%20maybe%20someone%20might%26nbsp%3B%3CSPAN%3Ehave%20a%20quick%20look%20and%20point%20us%20in%20the%20right%20direction%3F%20%3A)%3C%2Fimg%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EMany%20thanks!%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1940953%22%20slang%3D%22en-US%22%3ERe%3A%20Pivot%20Link%20Font%20size%20in%20SPFX%20web%20part%20(hipstertabs)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1940953%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F883589%22%20target%3D%22_blank%22%3E%40jlan927%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20think%20the%20easiest%20way%20to%20customize%20the%20webpart%20as%20you%20wish%20would%20be%20to%20add%20classnames%20to%20the%20components%20you%20are%20using%20and%20edit%20the%20class%20in%20the%20.scss%20file.%20So%2C%20for%20example%2C%20to%20edit%20the%20pivot%20links%20you%20could%20add%20a%20class%20to%20you%20.scss%20file%20-%20let's%20say%20'.myPivot'%20-%20and%20then%20work%20your%20way%20into%20the%20header%20tag%20to%20customize%20it.%3C%2FP%3E%3CP%3EI%20took%20a%20quick%20look%20at%20the%20Pivot%20component%20-%20you%20can%20see%20the%20reference%20%3CA%20href%3D%22https%3A%2F%2Fdeveloper.microsoft.com%2Fen-us%2Ffluentui%23%2Fcontrols%2Fweb%2Fpivot%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Ehere%3C%2FA%3E%20-%20and%20realized%20that%20they%20use%20the%20PivotItem%20to%20render%20the%20link%20headers%2C%20so%20you%20can%20add%20a%20'className%3D%7Bstyles.myHeader%7D'%20property%20to%20this%20component%2C%20and%20inside%20your%20.scss%20file%20you%20and%20something%20like%20'.myHeader%7B%20font-size%3A%2014px%20%7D'%20to%20adjust%20it.%3C%2FP%3E%3CP%3EI%20hope%20you%20can%20understand%20what%20I%20mean%20by%20those%202%20examples%2C%20but%20let%20me%20know%20if%20you%20need%20any%20help.%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

Hi folks

 

Really simplistic request from client but frankly I'm lacking on the react side of things so its a bit tricky!

 

We're using the HipsterTabs webpart found here: mrackley/ModernHillbillyTabs

 

The client has requested we adjust the font size of the pivot link headers (where the names of the tabs go) or even allow the option to flick between the default sizes (normal, large) and a third new size (larger, font-size 22).

 

As the font settings are imported from the Office-ui-fabric-react package, I haven't been able to figure out a simple method around using a CSS custom class or something, I think I'd really need to delve into the react framework and do something with the pivotstyles modules..

 

The web part is a couple of years old and its a bit of a nightmare getting all the node dependencies to the right versions in the first place for even basic compilation (we used the pre-packaged sppkg in the test tenant),

 

so while I'd love to spend time learning and understanding the framework to create a newer alternative, I was hoping maybe someone might have a quick look and point us in the right direction? :)

 

Many thanks!

 

 

3 Replies

Hello, @jlan927 

 

I think the easiest way to customize the webpart as you wish would be to add classnames to the components you are using and edit the class in the .scss file. So, for example, to edit the pivot links you could add a class to you .scss file - let's say '.myPivot' - and then work your way into the header tag to customize it.

I took a quick look at the Pivot component - you can see the reference here - and realized that they use the PivotItem to render the link headers, so you can add a 'className={styles.myHeader}' property to this component, and inside your .scss file you and something like '.myHeader{ font-size: 14px }' to adjust it.

I hope you can understand what I mean by those 2 examples, but let me know if you need any help.

@Carlos_Marinsthanks for your reply, much appreciated!

 

This is kind of what was looking into, seeing as there's a clear couple of custom styles being applied already (.Hidden and .Instructions). However please excuse my complete ignorance but I can't for the life of me get it to work with my own class against pivotitems!!

 

Inside hipstertabs.module.css I added:

 

  .myheader {
    font-size22px;
  }
}
 
Also inside hipstertabs.module.css.ts I had to add:
 
/* tslint:disable */
require('./HipsterTabs.module.css');
const styles = {
  hipsterTabs: 'hipsterTabs_02e133bf',
  instructions: 'instructions_02e133bf',
  hidden: 'hidden_02e133bf',
  myheader: 'myheader_02e133bf',
};
 
Then inside the TSX file I tried to apply the class to the pivotitem component but I get the feeling I'm either approaching the wrong component or just making a mess of the syntax. Or perhaps it's being overridden by the default choices "normal" / "large" being set earlier in the pivot?
Also (perhap unrelated) I get errors on running gulp serve relating back to index.d.ts ....Strange, but the server does load and I can still run a workbench. Not sure whats up with that.

 

 

 

 

<div>
            <Pivot
              selectedKey={this.state.selectedTab}
              headersOnly={true}
              getTabId={this.getTabId}
              onLinkClick={this.onTabClick}
              linkFormat={this.props.showAsLinks ? PivotLinkFormat.links : PivotLinkFormat.tabs}
              linkSize={this.props.normalSize ? PivotLinkSize.normal : PivotLinkSize.large}
              >
              {tabNames.map((tabName:string) => {
                return (
                  <PivotItem className={styles.myheader} linkText={tabName} itemKey={tabName}>
                  </PivotItem>
                );
              })}
            </Pivot>

 

 

 

 

 

Any further wisdom much appreciated, and then I'll go back to my JS101 classes to make better head or tail of whats going on :lol:

Hello @jlan927,

 

I think you're heading into the right direction. Just a couple notes to add.

 

FIrst, when you add a class to the module.scss file, the SharePoint Framework automatically adds a reference to the .module.scss.ts file, so you should never touch it. Just adding your class to the .scss file should be enough.

Second, I recommend you to not touch the dev's .scss file, insteading creating your own 'myStyle.module.scss' file and adding styles to it, then importing a myStyles property just like you import the styles property into your code. This way you can always go back to the original version, as well as compare the changes with the ones you made. 

 

Regarding errors with gulp serve, maybe you could upload an image displaying the error so I could take a look. Probably the error is keeping your changes from being saved, since the SharePoint Framework stops compiling your webpart for most of the errors it bumps into.

 

You could also take a look at Microsoft's SPFx doc here.