UNPKG

5.07 kBJavaScriptView Raw
1import { AnimationClassNames, getGlobalClassNames } from '../../Styling';
2import { getWindow } from '../../Utilities';
3var GlobalClassNames = {
4 root: 'ms-Image',
5 rootMaximizeFrame: 'ms-Image--maximizeFrame',
6 image: 'ms-Image-image',
7 imageCenter: 'ms-Image-image--center',
8 imageContain: 'ms-Image-image--contain',
9 imageCover: 'ms-Image-image--cover',
10 imageCenterContain: 'ms-Image-image--centerContain',
11 imageCenterCover: 'ms-Image-image--centerCover',
12 imageNone: 'ms-Image-image--none',
13 imageLandscape: 'ms-Image-image--landscape',
14 imagePortrait: 'ms-Image-image--portrait',
15};
16export var getStyles = function (props) {
17 var className = props.className, width = props.width, height = props.height, maximizeFrame = props.maximizeFrame, isLoaded = props.isLoaded, shouldFadeIn = props.shouldFadeIn, shouldStartVisible = props.shouldStartVisible, isLandscape = props.isLandscape, isCenter = props.isCenter, isContain = props.isContain, isCover = props.isCover, isCenterContain = props.isCenterContain, isCenterCover = props.isCenterCover, isNone = props.isNone, isError = props.isError, isNotImageFit = props.isNotImageFit, theme = props.theme;
18 var classNames = getGlobalClassNames(GlobalClassNames, theme);
19 var ImageFitStyles = {
20 position: 'absolute',
21 left: '50% /* @noflip */',
22 top: '50%',
23 transform: 'translate(-50%,-50%)',
24 };
25 // Cut the mustard using msMaxTouchPoints to detect IE11 which does not support CSS object-fit
26 var window = getWindow();
27 var supportsObjectFit = window !== undefined && window.navigator.msMaxTouchPoints === undefined;
28 var fallbackObjectFitStyles = (isContain && isLandscape) || (isCover && !isLandscape)
29 ? { width: '100%', height: 'auto' }
30 : { width: 'auto', height: '100%' };
31 return {
32 root: [
33 classNames.root,
34 theme.fonts.medium,
35 {
36 overflow: 'hidden',
37 },
38 maximizeFrame && [
39 classNames.rootMaximizeFrame,
40 {
41 height: '100%',
42 width: '100%',
43 },
44 ],
45 isLoaded && shouldFadeIn && !shouldStartVisible && AnimationClassNames.fadeIn400,
46 (isCenter || isContain || isCover || isCenterContain || isCenterCover) && {
47 position: 'relative',
48 },
49 className,
50 ],
51 image: [
52 classNames.image,
53 {
54 display: 'block',
55 opacity: 0,
56 },
57 isLoaded && [
58 'is-loaded',
59 {
60 opacity: 1,
61 },
62 ],
63 isCenter && [classNames.imageCenter, ImageFitStyles],
64 isContain && [
65 classNames.imageContain,
66 supportsObjectFit && {
67 width: '100%',
68 height: '100%',
69 objectFit: 'contain',
70 },
71 !supportsObjectFit && fallbackObjectFitStyles,
72 ImageFitStyles,
73 ],
74 isCover && [
75 classNames.imageCover,
76 supportsObjectFit && {
77 width: '100%',
78 height: '100%',
79 objectFit: 'cover',
80 },
81 !supportsObjectFit && fallbackObjectFitStyles,
82 ImageFitStyles,
83 ],
84 isCenterContain && [
85 classNames.imageCenterContain,
86 isLandscape && {
87 maxWidth: '100%',
88 },
89 !isLandscape && {
90 maxHeight: '100%',
91 },
92 ImageFitStyles,
93 ],
94 isCenterCover && [
95 classNames.imageCenterCover,
96 isLandscape && {
97 maxHeight: '100%',
98 },
99 !isLandscape && {
100 maxWidth: '100%',
101 },
102 ImageFitStyles,
103 ],
104 isNone && [
105 classNames.imageNone,
106 {
107 width: 'auto',
108 height: 'auto',
109 },
110 ],
111 isNotImageFit && [
112 !!width &&
113 !height && {
114 height: 'auto',
115 width: '100%',
116 },
117 !width &&
118 !!height && {
119 height: '100%',
120 width: 'auto',
121 },
122 !!width &&
123 !!height && {
124 height: '100%',
125 width: '100%',
126 },
127 ],
128 isLandscape && classNames.imageLandscape,
129 !isLandscape && classNames.imagePortrait,
130 !isLoaded && 'is-notLoaded',
131 shouldFadeIn && 'is-fadeIn',
132 isError && 'is-error',
133 ],
134 };
135};
136//# sourceMappingURL=Image.styles.js.map
\No newline at end of file