I have a SharePoint Online site with green theme color currently set. In my SPFx webpart I want to be able to get the current theme color (primary, secondary and tertiary) in TypeScript code. Below are the approaches I tried.
Approach 1
import { getTheme, loadTheme } from '@uifabric/styling'; const theme = getTheme(); const pivotItemStyle: React.CSSProperties = { borderColor: theme.palette.themePrimary, borderWidth: "1px", borderStyle: "solid" }; But theme.palette.themePrimary return blue color rather than green.
Approach 2
I tried using DefaultPalette.themePrimary but it still gives me blue color.
This link gives CSS equivalents like
.button { /* ... */ background-color: "[theme: themePrimary, default: #0078d7]"; border-color: "[theme: themePrimary, default: #0078d7]"; /* ... */ } How can I get current site theme color in SPFx webpart using TypeScript?