Step 2.3: Theming and styling with UI Fabric (Exercise)
If you don't already have the app running, start it by running npm start from the root of the frontend-bootcamp folder. Click the "exercise" link under day 2 step 3 to see results.
Fabric theming and styling
Applying Fabric themes
Try applying some predefined themes from UI Fabric packages inside the TodoApp under exercise/src/components/TodoApp.tsx. Do this by replacing:
import { FluentCustomizations } from '@uifabric/fluent-theme';
with:
import { TeamsCustomizations } from '@uifabric/theme-samples';
Applying customized themes
-
Create your own theme using the theme generator and copy the generated code.
-
In
exercise/src/components/TodoApp.tsx, delete theCustomizercomponent. -
Paste in the generated theme code before the
TodoAppcomponent definition. -
Play around with the values and use VS Code's intellisense to discover more properties of the
IThemetype.
Customizing one Fabric control instance
-
Open
exercise/src/components/TodoFooter.tsx -
Find the
<DefaultButton>and insert astylesprop -
Try to customize this with a styles object (let the Intellisense of VS Code guide you on what you can use to customize)
-
Try to customize this with a styles function
Advanced/non-Fabric component styling
CSS-in-JS with mergeStyles
- Try generating a class name using
mergeStylesand use it as aclassNameprop insideTodoApp
import { mergeStyles } from 'office-ui-fabric-react';
const className = mergeStyles({
backgroundColor: 'red',
selectors: {
':hover': {
backgroundColor: 'blue'
}
}
});
- Try to give a few components extra padding