Fluent UI Northstar comes with a color palette. I can find the color names and gradients in the documentation, but how am I supposed to use the names and gradient values (100, 200, etc.) in TypeScript? I couldn't find any documentation or examples.
Asked
Active
Viewed 1,372 times
2 Answers
2
Hi below You have an example for header component:
const Header: React.FC<SegmentProps> = () => {
const styledHeaderWrapper = useCSS((theme) => ({
gridColumn: "span 4",
backgroundColor: theme.siteVariables.colorScheme.brand.background1,
}));
return (
<Flex
gap="gap.small"
hAlign="center"
vAlign="center"
className={styledHeaderWrapper}
>
<Image src="LOGO.svg" />
<Breadcrumb content="main/site1" />
<div style={{ width: "100%" }}>
<Input
icon={<SearchIcon />}
placeholder="Search..."
iconPosition="start"
fluid
style={{ padding: "0 25%" }}
/>
</div>
<HeaderNavigationBar />
</Flex>
);
};
export default Header;

Daniel Noworyta
- 54
- 4
-
Thanks for the example! Would you have a more general reference? I am trying to work with the built-in Northstar themes such as teamsTheme, not necessarily building a theme from scratch. teamsTheme.siteVariables doesn't lead me anywhere. – Christophe Feb 15 '21 at 18:33
-
you should use theme northstar is reading current theme from context – Daniel Noworyta May 13 '21 at 11:47
1
There is more generic example how to use theme. On the global level you have to load and provide theme.
import { Provider, teamsTheme } from "@fluentui/react-northstar";
import { Grid } from "@fluentui/react-northstar";
const Layout: React.FC = ({ children }) => {
return (
<Provider theme={teamsTheme}>
<Grid
columns="minmax(50px, 0.75fr) 1fr 1fr 1fr"
rows="50px 1fr"
style={{ height: "100vh" }}
>
{children}
</Grid>
</Provider>
);
};
export default Layout;
Then by component :
const Header: React.FC<SegmentProps> = ({children}) => {
const styledHeaderWrapper = useCSS((theme) => ({
gridColumn: "span 4",
backgroundColor: theme.siteVariables.colorScheme.brand.white,
}));
return (
<Flex
gap="gap.small"
hAlign="center"
vAlign="center"
className={styledHeaderWrapper}
>
{children}
</Flex>
);
};
export default Header;

Dharman
- 30,962
- 25
- 85
- 135

Daniel Noworyta
- 54
- 4
-
I must still be missing something. I found the useCSS import, however siteVariables only bring up fontSizes, not any other property. interface SiteVariablesPrepared extends SiteVariablesInput {fontSizes: Record
} – Christophe Feb 18 '21 at 02:07 -
Are You importing theme properly and providing this theme in your component three ? – Daniel Noworyta Feb 18 '21 at 11:00
-
Probably not :-) and I don't really know where to start. I didn't even know about useCSS before you posted the sample code. Would you have a link to the documentation, or maybe a CodeSandbox working demo? – Christophe Feb 18 '21 at 17:47
-
https://fluentsite.z22.web.core.windows.net/0.52.0/theming-examples – Daniel Noworyta Feb 19 '21 at 13:09