-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Shimmer.LoadData.Example.tsx
105 lines (96 loc) · 3.63 KB
/
Shimmer.LoadData.Example.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import * as React from 'react';
import {
Shimmer,
ShimmerElementsGroup,
ShimmerElementType as ElemType,
ShimmerElementVerticalAlign as ElemVerticalAlign
} from '@uifabric/experiments/lib/Shimmer';
import { Persona, PersonaSize, PersonaPresence, IPersonaProps } from 'office-ui-fabric-react/lib/Persona';
import { Toggle } from 'office-ui-fabric-react/lib/Toggle';
const baseProductionCdnUrl = 'https://static2.sharepointonline.com/files/fabric/office-ui-fabric-react-assets/';
const PersonaDetails = {
imageUrl: baseProductionCdnUrl + 'persona-female.png',
imageInitials: 'AL',
primaryText: 'Annie Lindqvist',
secondaryText: 'Software Engineer'
};
export interface IShimmerLoadDataExampleState {
isDataLoadedOne?: boolean;
isDataLoadedTwo?: boolean;
contentOne?: string;
examplePersona?: IPersonaProps;
}
export class ShimmerLoadDataExample extends React.Component<{}, IShimmerLoadDataExampleState> {
constructor(props: {}) {
super(props);
this.state = {
isDataLoadedOne: false,
isDataLoadedTwo: false,
contentOne: '',
examplePersona: {}
};
}
public render(): JSX.Element {
const { isDataLoadedOne, isDataLoadedTwo, contentOne, examplePersona } = this.state;
return (
<div className="shimmerBasicExample-container">
<Toggle checked={isDataLoadedOne} onChange={this._getContentOne} onText="Toggle to show shimmer" offText="Toggle to load content" />
<Shimmer isDataLoaded={isDataLoadedOne} ariaLabel={'Loading content'}>
<div
// tslint:disable-next-line:jsx-ban-props
style={{
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
lineHeight: '1',
minHeight: '16px' // Default height of Shimmer when no elements being provided.
}}
>
{contentOne}
{contentOne}
{contentOne}
</div>
</Shimmer>
<Toggle checked={isDataLoadedTwo} onChange={this._getContentTwo} onText="Toggle to show shimmer" offText="Toggle to load content" />
<Shimmer customElementsGroup={this._getCustomElements()} widthInPixel={300} isDataLoaded={isDataLoadedTwo}>
<Persona {...examplePersona} size={PersonaSize.size40} presence={PersonaPresence.away} />
</Shimmer>
</div>
);
}
private _getContentOne = (event: React.MouseEvent<HTMLElement>, checked: boolean): void => {
const { isDataLoadedOne } = this.state;
this.setState({
isDataLoadedOne: checked,
contentOne: !isDataLoadedOne ? 'Congratulations!!! You have successfully loaded the content. ' : ''
});
};
private _getContentTwo = (event: React.MouseEvent<HTMLElement>, checked: boolean): void => {
const { isDataLoadedTwo } = this.state;
this.setState({
isDataLoadedTwo: checked,
examplePersona: !isDataLoadedTwo ? { ...PersonaDetails } : {}
});
};
private _getCustomElements = (): JSX.Element => {
return (
<div
// tslint:disable-next-line:jsx-ban-props
style={{ display: 'flex' }}
>
<ShimmerElementsGroup
shimmerElements={[{ type: ElemType.circle, height: 40 }, { type: ElemType.gap, widthInPixel: 16, height: 40 }]}
/>
<ShimmerElementsGroup
flexWrap={true}
width={'100%'}
shimmerElements={[
{ type: ElemType.line, widthInPercentage: 100, height: 10, verticalAlign: ElemVerticalAlign.bottom },
{ type: ElemType.line, widthInPercentage: 90, height: 8 },
{ type: ElemType.gap, widthInPercentage: 10, height: 20 }
]}
/>
</div>
);
};
}