import * as React from 'react'; import { Shimmer, IShimmerStyleProps, IShimmerStyles, ShimmerElementsGroup, ShimmerElementType, mergeStyleSets, createTheme, ThemeProvider, } from '@fluentui/react'; const customThemeForShimmer = createTheme({ palette: { // palette slot used in Shimmer for main background neutralLight: '#bdd4ed', // palette slot used in Shimmer for tip of the moving wave neutralLighter: '#7AAFE7', // palette slot used in Shimmer for all the space around the shimmering elements white: '#0078D4', }, }); const shimmerElements = [ { type: ShimmerElementType.circle, height: 24 }, { type: ShimmerElementType.gap, width: '2%' }, { type: ShimmerElementType.line, height: 16, width: '20%' }, { type: ShimmerElementType.gap, width: '5%' }, { type: ShimmerElementType.line, height: 16, width: '20%' }, { type: ShimmerElementType.gap, width: '10%' }, { type: ShimmerElementType.line, height: 16, width: '15%' }, { type: ShimmerElementType.gap, width: '10%' }, { type: ShimmerElementType.line, height: 16 }, ]; const classNames = mergeStyleSets({ wrapper: { selectors: { '& > .ms-Shimmer-container': { margin: '10px 0', }, }, }, themedBackgroundWrapper: { padding: 20, margin: '10px 0', height: 100, boxSizing: 'border-box', display: 'flex', alignItems: 'center', justifyContent: 'stretch', // using the palette color to match the gaps and borders of the shimmer. background: customThemeForShimmer.palette.white, selectors: { '& > .ms-Shimmer-container': { flexGrow: 1, }, }, }, themedBackgroundWrapper2: { width: 400, height: 100, margin: '10px 0', display: 'flex', alignItems: 'center', justifyContent: 'center', // using the palette color to match the gaps and borders of the shimmer. background: customThemeForShimmer.palette.white, outline: `1px solid ${customThemeForShimmer.palette.neutralPrimary}`, outlineOffset: '-10px', }, indent: { paddingLeft: 18, }, }); // Passing a color to match the background color of the containing div. const getCustomElements = (backgroundColor?: string) => { return (
); }; const getShimmerStyles = (props: IShimmerStyleProps): IShimmerStyles => { return { shimmerWrapper: [ { backgroundColor: '#deecf9', }, ], shimmerGradient: [ { backgroundColor: '#deecf9', backgroundImage: 'linear-gradient(to right, rgba(255, 255, 255, 0) 0%, #c7e0f4 50%, rgba(255, 255, 255, 0) 100%)', }, ], }; }; export const ShimmerStylingExample: React.FunctionComponent = () => { return ( <>
Style overrides of shimmering wave and space around in cases where Shimmer is placed on backgrounds different than the main background of the app. There are several scenarios that can be considered bellow:
1. The recommended way by using the shimmerColors prop which in turn has 2 sub-scenarios:
a. When using shimmerElements prop to build the placeholder you can pass all 3 possible colors to shimmerColors prop.
b. When using customElementsGroup prop to build the placeholder:
2. Another way of doing it by using Customizer component wrapper.
3. Style overrides of shimmering wave using styles prop.
); };