/
Tile.Media.Example.tsx
186 lines (173 loc) · 4.47 KB
/
Tile.Media.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import * as React from 'react';
import { Checkbox, css, ISize, fitContentToBounds, Icon } from 'office-ui-fabric-react';
import {
SignalField,
Signal,
NewSignal,
SharedSignal,
MentionSignal,
Tile,
getTileLayout,
renderTileWithLayout
} from '@uifabric/experiments';
import { lorem } from '@uifabric/example-app-base';
import * as TileExampleStylesModule from './Tile.Example.scss';
const ITEMS: { name: string; activity: string }[] = [
{
name: lorem(2),
activity: lorem(6)
},
{
name: lorem(2),
activity: lorem(6)
},
{
name: lorem(2),
activity: lorem(6)
},
{
name: lorem(2),
activity: lorem(6)
}
];
// tslint:disable-next-line:no-any
const TileExampleStyles = TileExampleStylesModule as any;
interface IImageTileProps {
tileSize: ISize;
originalImageSize: ISize;
showBackground: boolean;
item: typeof ITEMS[0];
}
const ImageTile: React.StatelessComponent<IImageTileProps> = (props: IImageTileProps): JSX.Element => {
const tile = (
<Tile
contentSize={props.tileSize}
itemName={<SignalField before={<NewSignal />}>{props.item.name}</SignalField>}
itemActivity={
<SignalField
before={[
<Signal key={0}>
<Icon iconName="play" />
</Signal>,
<MentionSignal key={1} />
]}
>
{props.item.activity}
</SignalField>
}
background={
<span /> // Placeholder content
}
hideBackground={!props.showBackground}
showBackgroundFrame={true}
/>
);
const { backgroundSize } = getTileLayout(tile);
const imageSize = fitContentToBounds({
contentSize: props.originalImageSize,
boundsSize: backgroundSize || { width: 0, height: 0 },
mode: 'cover'
});
return (
<div
className={css(TileExampleStyles.tile)}
// tslint:disable-next-line:jsx-ban-props
style={{
width: `${props.tileSize.width}px`,
height: `${props.tileSize.height}px`
}}
>
{renderTileWithLayout(tile, {
background: (
<img
className={css(TileExampleStyles.tileImage)}
src={`//placehold.it/${Math.round(imageSize.width)}x${Math.round(imageSize.height)}`}
/>
)
})}
</div>
);
};
export interface ITileMediaExampleState {
imagesLoaded: boolean;
}
export class TileMediaExample extends React.Component<{}, ITileMediaExampleState> {
constructor(props: {}) {
super(props);
this.state = {
imagesLoaded: true
};
}
public render(): JSX.Element {
const { imagesLoaded } = this.state;
return (
<div>
<Checkbox label="Show images as loaded" checked={imagesLoaded} onChange={this._onImagesLoadedChanged} />
<h3>Landscape</h3>
<ImageTile
tileSize={{
width: 250,
height: 200
}}
item={ITEMS[0]}
originalImageSize={{
width: 400,
height: 300
}}
showBackground={imagesLoaded}
/>
<h3>Portrait</h3>
<ImageTile
tileSize={{
width: 200,
height: 250
}}
item={ITEMS[1]}
originalImageSize={{
width: 300,
height: 400
}}
showBackground={imagesLoaded}
/>
<h3>Small Image</h3>
<ImageTile
tileSize={{
width: 200,
height: 200
}}
item={ITEMS[2]}
originalImageSize={{
width: 16,
height: 16
}}
showBackground={imagesLoaded}
/>
<h3>No preview</h3>
<div className={css(TileExampleStyles.tile, TileExampleStyles.largeTile)}>
<Tile
itemName={<SignalField before={<NewSignal />}>{ITEMS[3].name}</SignalField>}
itemActivity={
<SignalField
before={[
<Signal key={0}>
<Icon iconName="play" />
</Signal>,
<SharedSignal key={1} />
]}
>
{ITEMS[3].name}
</SignalField>
}
foreground={<Icon iconName="play" style={{ margin: '11px', fontSize: '40px' }} />}
showBackgroundFrame={true}
/>
</div>
</div>
);
}
private _onImagesLoadedChanged = (event: React.FormEvent<HTMLInputElement>, checked: boolean): void => {
this.setState({
imagesLoaded: checked
});
};
}