@docusaurus/plugin-ideal-image 3.7.0 → 3.8.0-canary-6324
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +6 -0
- package/lib/theme/IdealImage/index.js +1 -2
- package/lib/theme/IdealImageLegacy/LICENSE +20 -0
- package/lib/theme/IdealImageLegacy/README.md +13 -0
- package/lib/theme/IdealImageLegacy/components/Icon/Download.d.ts +3 -0
- package/lib/theme/IdealImageLegacy/components/Icon/Download.js +15 -0
- package/lib/theme/IdealImageLegacy/components/Icon/Loading.d.ts +3 -0
- package/lib/theme/IdealImageLegacy/components/Icon/Loading.js +15 -0
- package/lib/theme/IdealImageLegacy/components/Icon/Offline.d.ts +3 -0
- package/lib/theme/IdealImageLegacy/components/Icon/Offline.js +15 -0
- package/lib/theme/IdealImageLegacy/components/Icon/Warning.d.ts +3 -0
- package/lib/theme/IdealImageLegacy/components/Icon/Warning.js +15 -0
- package/lib/theme/IdealImageLegacy/components/Icon/index.d.ts +8 -0
- package/lib/theme/IdealImageLegacy/components/Icon/index.js +25 -0
- package/lib/theme/IdealImageLegacy/components/IdealImage/index.d.ts +42 -0
- package/lib/theme/IdealImageLegacy/components/IdealImage/index.js +352 -0
- package/lib/theme/IdealImageLegacy/components/IdealImage/waypoint.d.ts +10 -0
- package/lib/theme/IdealImageLegacy/components/IdealImage/waypoint.js +188 -0
- package/lib/theme/IdealImageLegacy/components/IdealImageWithDefaults/index.d.ts +33 -0
- package/lib/theme/IdealImageLegacy/components/IdealImageWithDefaults/index.js +12 -0
- package/lib/theme/IdealImageLegacy/components/Media/index.d.ts +20 -0
- package/lib/theme/IdealImageLegacy/components/Media/index.js +169 -0
- package/lib/theme/IdealImageLegacy/components/MediaWithDefaults/README.md +89 -0
- package/lib/theme/IdealImageLegacy/components/MediaWithDefaults/index.d.ts +33 -0
- package/lib/theme/IdealImageLegacy/components/MediaWithDefaults/index.js +12 -0
- package/lib/theme/IdealImageLegacy/components/composeStyle.d.ts +5 -0
- package/lib/theme/IdealImageLegacy/components/composeStyle.js +37 -0
- package/lib/theme/IdealImageLegacy/components/constants.d.ts +22 -0
- package/lib/theme/IdealImageLegacy/components/constants.js +24 -0
- package/lib/theme/IdealImageLegacy/components/helpers.d.ts +22 -0
- package/lib/theme/IdealImageLegacy/components/helpers.js +141 -0
- package/lib/theme/IdealImageLegacy/components/icons.d.ts +15 -0
- package/lib/theme/IdealImageLegacy/components/icons.js +16 -0
- package/lib/theme/IdealImageLegacy/components/loaders.d.ts +4 -0
- package/lib/theme/IdealImageLegacy/components/loaders.js +112 -0
- package/lib/theme/IdealImageLegacy/components/theme.d.ts +30 -0
- package/lib/theme/IdealImageLegacy/components/theme.js +26 -0
- package/lib/theme/IdealImageLegacy/components/theme.module.css +35 -0
- package/lib/theme/IdealImageLegacy/components/unfetch.d.ts +7 -0
- package/lib/theme/IdealImageLegacy/components/unfetch.js +74 -0
- package/lib/theme/IdealImageLegacy/index.d.ts +2 -0
- package/lib/theme/IdealImageLegacy/index.js +2 -0
- package/package.json +8 -10
- package/src/index.ts +6 -0
- package/src/plugin-ideal-image.d.ts +121 -0
- package/src/theme/IdealImage/index.tsx +2 -3
- package/src/theme/IdealImageLegacy/LICENSE +20 -0
- package/src/theme/IdealImageLegacy/README.md +13 -0
- package/src/theme/IdealImageLegacy/components/Icon/Download.js +15 -0
- package/src/theme/IdealImageLegacy/components/Icon/Loading.js +15 -0
- package/src/theme/IdealImageLegacy/components/Icon/Offline.js +15 -0
- package/src/theme/IdealImageLegacy/components/Icon/Warning.js +15 -0
- package/src/theme/IdealImageLegacy/components/Icon/index.js +25 -0
- package/src/theme/IdealImageLegacy/components/IdealImage/index.js +352 -0
- package/src/theme/IdealImageLegacy/components/IdealImage/waypoint.tsx +254 -0
- package/src/theme/IdealImageLegacy/components/IdealImageWithDefaults/index.js +12 -0
- package/src/theme/IdealImageLegacy/components/Media/index.js +169 -0
- package/src/theme/IdealImageLegacy/components/MediaWithDefaults/README.md +89 -0
- package/src/theme/IdealImageLegacy/components/MediaWithDefaults/index.js +12 -0
- package/src/theme/IdealImageLegacy/components/composeStyle.js +37 -0
- package/src/theme/IdealImageLegacy/components/constants.js +24 -0
- package/src/theme/IdealImageLegacy/components/helpers.js +141 -0
- package/src/theme/IdealImageLegacy/components/icons.js +16 -0
- package/src/theme/IdealImageLegacy/components/loaders.js +112 -0
- package/src/theme/IdealImageLegacy/components/theme.js +26 -0
- package/src/theme/IdealImageLegacy/components/theme.module.css +35 -0
- package/src/theme/IdealImageLegacy/components/unfetch.js +74 -0
- package/src/theme/IdealImageLegacy/index.tsx +3 -0
- package/src/deps.d.ts +0 -124
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/*
|
|
2
|
+
This is a slimmed down copy of https://github.com/civiccc/react-waypoint
|
|
3
|
+
The MIT License (MIT)
|
|
4
|
+
Copyright (c) 2015 Brigade
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import React, {createRef, ReactNode} from 'react';
|
|
8
|
+
|
|
9
|
+
type ScrollContainer = Window | HTMLElement;
|
|
10
|
+
|
|
11
|
+
function addEventListener(
|
|
12
|
+
element: ScrollContainer,
|
|
13
|
+
type: 'scroll' | 'resize',
|
|
14
|
+
listener: () => void,
|
|
15
|
+
options: AddEventListenerOptions,
|
|
16
|
+
) {
|
|
17
|
+
element.addEventListener(type, listener, options);
|
|
18
|
+
return () => element.removeEventListener(type, listener, options);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Because waypoint may fire before the setState() updates due to batching
|
|
22
|
+
// queueMicrotask is a better option than setTimeout() or React.flushSync()
|
|
23
|
+
// See https://github.com/facebook/docusaurus/issues/11018
|
|
24
|
+
// See https://github.com/civiccc/react-waypoint/blob/0905ac5a073131147c96dd0694bd6f1b6ee8bc97/src/onNextTick.js
|
|
25
|
+
function subscribeMicrotask(callback: () => void) {
|
|
26
|
+
let subscribed = true;
|
|
27
|
+
queueMicrotask(() => {
|
|
28
|
+
if (subscribed) callback();
|
|
29
|
+
});
|
|
30
|
+
return () => (subscribed = false);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type Position = 'above' | 'inside' | 'below' | 'invisible';
|
|
34
|
+
|
|
35
|
+
type Props = {
|
|
36
|
+
topOffset: number;
|
|
37
|
+
bottomOffset: number;
|
|
38
|
+
onEnter: () => void;
|
|
39
|
+
onLeave: () => void;
|
|
40
|
+
children: ReactNode;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export function Waypoint(props: Props) {
|
|
44
|
+
return typeof window !== 'undefined' ? (
|
|
45
|
+
<WaypointClient {...props}>{props.children}</WaypointClient>
|
|
46
|
+
) : (
|
|
47
|
+
props.children
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// TODO maybe replace this with IntersectionObserver later?
|
|
52
|
+
// IntersectionObserver doesn't support the "fast scroll" thing
|
|
53
|
+
// but it's probably not a big deal
|
|
54
|
+
class WaypointClient extends React.Component<Props> {
|
|
55
|
+
static defaultProps = {
|
|
56
|
+
topOffset: 0,
|
|
57
|
+
bottomOffset: 0,
|
|
58
|
+
onEnter() {},
|
|
59
|
+
onLeave() {},
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
scrollableAncestor?: ScrollContainer;
|
|
63
|
+
previousPosition: Position | null = null;
|
|
64
|
+
unsubscribe?: () => void;
|
|
65
|
+
|
|
66
|
+
innerRef = createRef<HTMLElement>();
|
|
67
|
+
|
|
68
|
+
override componentDidMount() {
|
|
69
|
+
this.scrollableAncestor = findScrollableAncestor(this.innerRef.current!);
|
|
70
|
+
|
|
71
|
+
const unsubscribeScroll = addEventListener(
|
|
72
|
+
this.scrollableAncestor!,
|
|
73
|
+
'scroll',
|
|
74
|
+
this._handleScroll,
|
|
75
|
+
{passive: true},
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const unsubscribeResize = addEventListener(
|
|
79
|
+
window,
|
|
80
|
+
'resize',
|
|
81
|
+
this._handleScroll,
|
|
82
|
+
{passive: true},
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const unsubscribeInitialScroll = subscribeMicrotask(() => {
|
|
86
|
+
this._handleScroll();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
this.unsubscribe = () => {
|
|
90
|
+
unsubscribeScroll();
|
|
91
|
+
unsubscribeResize();
|
|
92
|
+
unsubscribeInitialScroll();
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
override componentDidUpdate() {
|
|
97
|
+
this._handleScroll();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
override componentWillUnmount() {
|
|
101
|
+
this.unsubscribe?.();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
_handleScroll = () => {
|
|
105
|
+
const node = this.innerRef.current;
|
|
106
|
+
const {topOffset, bottomOffset, onEnter, onLeave} = this.props;
|
|
107
|
+
|
|
108
|
+
const bounds = getBounds({
|
|
109
|
+
node: node!,
|
|
110
|
+
scrollableAncestor: this.scrollableAncestor!,
|
|
111
|
+
topOffset,
|
|
112
|
+
bottomOffset,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const currentPosition = getCurrentPosition(bounds);
|
|
116
|
+
const previousPosition = this.previousPosition;
|
|
117
|
+
this.previousPosition = currentPosition;
|
|
118
|
+
|
|
119
|
+
if (previousPosition === currentPosition) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (currentPosition === 'inside') {
|
|
124
|
+
onEnter();
|
|
125
|
+
} else if (previousPosition === 'inside') {
|
|
126
|
+
onLeave();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const isRapidScrollDown =
|
|
130
|
+
previousPosition === 'below' && currentPosition === 'above';
|
|
131
|
+
const isRapidScrollUp =
|
|
132
|
+
previousPosition === 'above' && currentPosition === 'below';
|
|
133
|
+
if (isRapidScrollDown || isRapidScrollUp) {
|
|
134
|
+
onEnter();
|
|
135
|
+
onLeave();
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
override render() {
|
|
140
|
+
// @ts-expect-error: fix this implicit API
|
|
141
|
+
return React.cloneElement(this.props.children, {innerRef: this.innerRef});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Traverses up the DOM to find an ancestor container which has an overflow
|
|
147
|
+
* style that allows for scrolling.
|
|
148
|
+
*
|
|
149
|
+
* @return {Object} the closest ancestor element with an overflow style that
|
|
150
|
+
* allows for scrolling. If none is found, the `window` object is returned
|
|
151
|
+
* as a fallback.
|
|
152
|
+
*/
|
|
153
|
+
function findScrollableAncestor(inputNode: HTMLElement): ScrollContainer {
|
|
154
|
+
let node: HTMLElement = inputNode;
|
|
155
|
+
|
|
156
|
+
while (node.parentNode) {
|
|
157
|
+
// @ts-expect-error: it's fine
|
|
158
|
+
node = node.parentNode!;
|
|
159
|
+
|
|
160
|
+
if (node === document.body) {
|
|
161
|
+
// We've reached all the way to the root node.
|
|
162
|
+
return window;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const style = window.getComputedStyle(node);
|
|
166
|
+
const overflow =
|
|
167
|
+
style.getPropertyValue('overflow-y') ||
|
|
168
|
+
style.getPropertyValue('overflow');
|
|
169
|
+
|
|
170
|
+
if (
|
|
171
|
+
overflow === 'auto' ||
|
|
172
|
+
overflow === 'scroll' ||
|
|
173
|
+
overflow === 'overlay'
|
|
174
|
+
) {
|
|
175
|
+
return node;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// A scrollable ancestor element was not found, which means that we need to
|
|
180
|
+
// do stuff on window.
|
|
181
|
+
return window;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
type Bounds = {
|
|
185
|
+
top: number;
|
|
186
|
+
bottom: number;
|
|
187
|
+
viewportTop: number;
|
|
188
|
+
viewportBottom: number;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
function getBounds({
|
|
192
|
+
node,
|
|
193
|
+
scrollableAncestor,
|
|
194
|
+
topOffset,
|
|
195
|
+
bottomOffset,
|
|
196
|
+
}: {
|
|
197
|
+
node: Element;
|
|
198
|
+
scrollableAncestor: ScrollContainer;
|
|
199
|
+
topOffset: number;
|
|
200
|
+
bottomOffset: number;
|
|
201
|
+
}): Bounds {
|
|
202
|
+
const {top, bottom} = node.getBoundingClientRect();
|
|
203
|
+
|
|
204
|
+
let contextHeight;
|
|
205
|
+
let contextScrollTop;
|
|
206
|
+
if (scrollableAncestor === window) {
|
|
207
|
+
contextHeight = window.innerHeight;
|
|
208
|
+
contextScrollTop = 0;
|
|
209
|
+
} else {
|
|
210
|
+
const ancestorElement = scrollableAncestor as HTMLElement;
|
|
211
|
+
contextHeight = ancestorElement.offsetHeight;
|
|
212
|
+
contextScrollTop = ancestorElement.getBoundingClientRect().top;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const contextBottom = contextScrollTop + contextHeight;
|
|
216
|
+
|
|
217
|
+
return {
|
|
218
|
+
top,
|
|
219
|
+
bottom,
|
|
220
|
+
viewportTop: contextScrollTop + topOffset,
|
|
221
|
+
viewportBottom: contextBottom - bottomOffset,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function getCurrentPosition(bounds: Bounds): Position {
|
|
226
|
+
if (bounds.viewportBottom - bounds.viewportTop === 0) {
|
|
227
|
+
return 'invisible';
|
|
228
|
+
}
|
|
229
|
+
// top is within the viewport
|
|
230
|
+
if (bounds.viewportTop <= bounds.top && bounds.top <= bounds.viewportBottom) {
|
|
231
|
+
return 'inside';
|
|
232
|
+
}
|
|
233
|
+
// bottom is within the viewport
|
|
234
|
+
if (
|
|
235
|
+
bounds.viewportTop <= bounds.bottom &&
|
|
236
|
+
bounds.bottom <= bounds.viewportBottom
|
|
237
|
+
) {
|
|
238
|
+
return 'inside';
|
|
239
|
+
}
|
|
240
|
+
// top is above the viewport and bottom is below the viewport
|
|
241
|
+
if (
|
|
242
|
+
bounds.top <= bounds.viewportTop &&
|
|
243
|
+
bounds.viewportBottom <= bounds.bottom
|
|
244
|
+
) {
|
|
245
|
+
return 'inside';
|
|
246
|
+
}
|
|
247
|
+
if (bounds.viewportBottom < bounds.top) {
|
|
248
|
+
return 'below';
|
|
249
|
+
}
|
|
250
|
+
if (bounds.top < bounds.viewportTop) {
|
|
251
|
+
return 'above';
|
|
252
|
+
}
|
|
253
|
+
return 'invisible';
|
|
254
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import IdealImage from '../IdealImage';
|
|
3
|
+
import icons from '../icons';
|
|
4
|
+
import theme from '../theme';
|
|
5
|
+
|
|
6
|
+
const IdealImageWithDefaults = ({
|
|
7
|
+
icons: iconsProp = icons,
|
|
8
|
+
theme: themeProp = theme,
|
|
9
|
+
...props
|
|
10
|
+
}) => <IdealImage {...props} icons={iconsProp} theme={themeProp} />;
|
|
11
|
+
|
|
12
|
+
export default IdealImageWithDefaults;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import React, {PureComponent} from 'react';
|
|
2
|
+
// import PropTypes from 'prop-types'
|
|
3
|
+
import compose from '../composeStyle';
|
|
4
|
+
import {icons as defaultIcons} from '../constants';
|
|
5
|
+
|
|
6
|
+
const {load, loading, loaded, error, noicon, offline} = defaultIcons;
|
|
7
|
+
|
|
8
|
+
export default class Media extends PureComponent {
|
|
9
|
+
/*static propTypes = {
|
|
10
|
+
/!** URL of the image *!/
|
|
11
|
+
src: PropTypes.string.isRequired,
|
|
12
|
+
/!** Width of the image in px *!/
|
|
13
|
+
width: PropTypes.number.isRequired,
|
|
14
|
+
/!** Height of the image in px *!/
|
|
15
|
+
height: PropTypes.number.isRequired,
|
|
16
|
+
placeholder: PropTypes.oneOfType([
|
|
17
|
+
PropTypes.shape({
|
|
18
|
+
/!** Solid color placeholder *!/
|
|
19
|
+
color: PropTypes.string.isRequired,
|
|
20
|
+
}),
|
|
21
|
+
PropTypes.shape({
|
|
22
|
+
/!**
|
|
23
|
+
* [Low Quality Image Placeholder](https://github.com/zouhir/lqip)
|
|
24
|
+
* [SVG-Based Image Placeholder](https://github.com/technopagan/sqip)
|
|
25
|
+
* base64 encoded image of low quality
|
|
26
|
+
*!/
|
|
27
|
+
lqip: PropTypes.string.isRequired,
|
|
28
|
+
}),
|
|
29
|
+
]).isRequired,
|
|
30
|
+
/!** display icon *!/
|
|
31
|
+
icon: PropTypes.oneOf([load, loading, loaded, error, noicon, offline])
|
|
32
|
+
.isRequired,
|
|
33
|
+
/!** Map of icons *!/
|
|
34
|
+
icons: PropTypes.object.isRequired,
|
|
35
|
+
/!** theme object - CSS Modules or React styles *!/
|
|
36
|
+
theme: PropTypes.object.isRequired,
|
|
37
|
+
/!** Alternative text *!/
|
|
38
|
+
alt: PropTypes.string,
|
|
39
|
+
/!** Color of the icon *!/
|
|
40
|
+
iconColor: PropTypes.string,
|
|
41
|
+
/!** Size of the icon in px *!/
|
|
42
|
+
iconSize: PropTypes.number,
|
|
43
|
+
/!** React's style attribute for root element of the component *!/
|
|
44
|
+
style: PropTypes.object,
|
|
45
|
+
/!** React's className attribute for root element of the component *!/
|
|
46
|
+
className: PropTypes.string,
|
|
47
|
+
/!** On click handler *!/
|
|
48
|
+
onClick: PropTypes.func,
|
|
49
|
+
/!** callback to get dimensions of the placeholder *!/
|
|
50
|
+
onDimensions: PropTypes.func,
|
|
51
|
+
/!** message to show below the icon *!/
|
|
52
|
+
message: PropTypes.node,
|
|
53
|
+
/!** reference for Waypoint *!/
|
|
54
|
+
innerRef: PropTypes.func,
|
|
55
|
+
/!** noscript image src *!/
|
|
56
|
+
nsSrc: PropTypes.string,
|
|
57
|
+
/!** noscript image srcSet *!/
|
|
58
|
+
nsSrcSet: PropTypes.string,
|
|
59
|
+
}*/
|
|
60
|
+
|
|
61
|
+
static defaultProps = {
|
|
62
|
+
iconColor: '#fff',
|
|
63
|
+
iconSize: 64,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
constructor(props) {
|
|
67
|
+
super(props);
|
|
68
|
+
this.state = {isMounted: false};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
componentDidMount() {
|
|
72
|
+
this.setState({isMounted: true});
|
|
73
|
+
|
|
74
|
+
if (this.props.onDimensions && this.dimensionElement)
|
|
75
|
+
/* Firefox returns 0 for both clientWidth and clientHeight.
|
|
76
|
+
To fix this we can check the parentNode's clientWidth and clientHeight as a fallback. */
|
|
77
|
+
this.props.onDimensions({
|
|
78
|
+
width:
|
|
79
|
+
this.dimensionElement.clientWidth ||
|
|
80
|
+
this.dimensionElement.parentNode.clientWidth,
|
|
81
|
+
height:
|
|
82
|
+
this.dimensionElement.clientHeight ||
|
|
83
|
+
this.dimensionElement.parentNode.clientHeight,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
renderIcon(props) {
|
|
88
|
+
const {icon, icons, iconColor: fill, iconSize: size, theme} = props;
|
|
89
|
+
const iconToRender = icons[icon];
|
|
90
|
+
if (!iconToRender) return null;
|
|
91
|
+
const styleOrClass = compose(
|
|
92
|
+
{width: size + 100, height: size, color: fill},
|
|
93
|
+
theme.icon,
|
|
94
|
+
);
|
|
95
|
+
return React.createElement('div', styleOrClass, [
|
|
96
|
+
React.createElement(iconToRender, {fill, size, key: 'icon'}),
|
|
97
|
+
React.createElement('br', {key: 'br'}),
|
|
98
|
+
this.props.message,
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
renderImage(props) {
|
|
103
|
+
return props.icon === loaded ? (
|
|
104
|
+
<img
|
|
105
|
+
{...compose(props.theme.img)}
|
|
106
|
+
src={props.src}
|
|
107
|
+
alt={props.alt}
|
|
108
|
+
width={props.width}
|
|
109
|
+
height={props.height}
|
|
110
|
+
/>
|
|
111
|
+
) : (
|
|
112
|
+
<svg
|
|
113
|
+
{...compose(props.theme.img)}
|
|
114
|
+
width={props.width}
|
|
115
|
+
height={props.height}
|
|
116
|
+
ref={(ref) => (this.dimensionElement = ref)}
|
|
117
|
+
/>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
renderNoscript(props) {
|
|
122
|
+
// render noscript in ssr + hydration to avoid hydration mismatch error
|
|
123
|
+
return this.state.isMounted ? null : (
|
|
124
|
+
<noscript>
|
|
125
|
+
<img
|
|
126
|
+
{...compose(props.theme.img, props.theme.noscript)}
|
|
127
|
+
src={props.nsSrc}
|
|
128
|
+
srcSet={props.nsSrcSet}
|
|
129
|
+
alt={props.alt}
|
|
130
|
+
width={props.width}
|
|
131
|
+
height={props.height}
|
|
132
|
+
/>
|
|
133
|
+
</noscript>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
render() {
|
|
138
|
+
const props = this.props;
|
|
139
|
+
const {placeholder, theme} = props;
|
|
140
|
+
let background;
|
|
141
|
+
if (props.icon === loaded) {
|
|
142
|
+
background = {};
|
|
143
|
+
} else if (placeholder.lqip) {
|
|
144
|
+
background = {
|
|
145
|
+
backgroundImage: `url("${placeholder.lqip}")`,
|
|
146
|
+
};
|
|
147
|
+
} else {
|
|
148
|
+
background = {
|
|
149
|
+
backgroundColor: placeholder.color,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
return (
|
|
153
|
+
<div
|
|
154
|
+
{...compose(
|
|
155
|
+
theme.placeholder,
|
|
156
|
+
background,
|
|
157
|
+
props.style,
|
|
158
|
+
props.className,
|
|
159
|
+
)}
|
|
160
|
+
onClick={this.props.onClick}
|
|
161
|
+
onKeyPress={this.props.onClick}
|
|
162
|
+
ref={this.props.innerRef}>
|
|
163
|
+
{this.renderImage(props)}
|
|
164
|
+
{this.renderNoscript(props)}
|
|
165
|
+
{this.renderIcon(props)}
|
|
166
|
+
</div>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
All possible states of the component
|
|
2
|
+
|
|
3
|
+
```js
|
|
4
|
+
const lqip =
|
|
5
|
+
'data:image/jpeg;base64,/9j/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAIAA4DASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAAAAUG/8QAIRAAAQQDAAEFAAAAAAAAAAAAAQIDBREABAYhEjEyQVH/xAAUAQEAAAAAAAAAAAAAAAAAAAAE/8QAGBEBAAMBAAAAAAAAAAAAAAAAAQACIRH/2gAMAwEAAhEDEQA/AMJ2DG+7Dw0nz8gsx+uyhlxnWdLakOlfzpIF3aRf1WT5t96P5+N1ug9Tu7ZWS8q1gG6B8H2FDz+YxhjUrEOdZ//Z';
|
|
6
|
+
|
|
7
|
+
const sqip =
|
|
8
|
+
"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4774 3024'%3e%3cfilter id='b'%3e%3cfeGaussianBlur stdDeviation='12' /%3e%3c/filter%3e%3cpath fill='%23515a57' d='M0 0h4774v3021H0z'/%3e%3cg filter='url(%23b)' transform='translate(9.3 9.3) scale(18.64844)' fill-opacity='.5'%3e%3cellipse fill='whitefef' rx='1' ry='1' transform='matrix(74.55002 60.89891 -21.7939 26.67923 151.8 104.4)'/%3e%3cellipse fill='black80c' cx='216' cy='49' rx='59' ry='59'/%3e%3cellipse fill='black60e' cx='22' cy='60' rx='46' ry='89'/%3e%3cellipse fill='%23ffebd5' cx='110' cy='66' rx='42' ry='28'/%3e%3cellipse fill='whiteff9' rx='1' ry='1' transform='rotate(33.3 -113.2 392.6) scale(42.337 17.49703)'/%3e%3cellipse fill='%23031f1e' rx='1' ry='1' transform='matrix(163.4651 -64.93326 6.77862 17.06471 111 16.4)'/%3e%3cpath fill='whitefea' d='M66 74l9 39 16-44z'/%3e%3cellipse fill='%23a28364' rx='1' ry='1' transform='rotate(-32.4 253.2 -179) scale(30.79511 43.65381)'/%3e%3cpath fill='%231a232c' d='M40 139l61-57 33 95z'/%3e%3cpath fill='%230a222b' d='M249.8 153.3l-48.1-48 32.5-32.6 48.1 48z'/%3e%3c/g%3e%3c/svg%3e";
|
|
9
|
+
<table>
|
|
10
|
+
<tbody>
|
|
11
|
+
<tr>
|
|
12
|
+
<th align="left" width="100">
|
|
13
|
+
load
|
|
14
|
+
</th>
|
|
15
|
+
<td>
|
|
16
|
+
<MediaWithDefaults
|
|
17
|
+
width={3500}
|
|
18
|
+
height={2095}
|
|
19
|
+
placeholder={{lqip: lqip}}
|
|
20
|
+
src="andre-spieker-238-unsplash.jpg"
|
|
21
|
+
style={{maxWidth: 200}}
|
|
22
|
+
icon={'load'}
|
|
23
|
+
/>
|
|
24
|
+
</td>
|
|
25
|
+
<th align="left" width="100">
|
|
26
|
+
noicon
|
|
27
|
+
</th>
|
|
28
|
+
<td>
|
|
29
|
+
<MediaWithDefaults
|
|
30
|
+
width={3500}
|
|
31
|
+
height={2095}
|
|
32
|
+
placeholder={{lqip: lqip}}
|
|
33
|
+
src="andre-spieker-238-unsplash.jpg"
|
|
34
|
+
style={{maxWidth: 200}}
|
|
35
|
+
icon={'noicon'}
|
|
36
|
+
/>
|
|
37
|
+
</td>
|
|
38
|
+
</tr>
|
|
39
|
+
<tr>
|
|
40
|
+
<th align="left">loading</th>
|
|
41
|
+
<td>
|
|
42
|
+
<MediaWithDefaults
|
|
43
|
+
width={3500}
|
|
44
|
+
height={2095}
|
|
45
|
+
placeholder={{lqip: lqip}}
|
|
46
|
+
src="andre-spieker-238-unsplash.jpg"
|
|
47
|
+
style={{maxWidth: 200}}
|
|
48
|
+
icon={'loading'}
|
|
49
|
+
/>
|
|
50
|
+
</td>
|
|
51
|
+
<th align="left">offline</th>
|
|
52
|
+
<td>
|
|
53
|
+
<MediaWithDefaults
|
|
54
|
+
width={3500}
|
|
55
|
+
height={2095}
|
|
56
|
+
placeholder={{lqip: lqip}}
|
|
57
|
+
src="andre-spieker-238-unsplash.jpg"
|
|
58
|
+
style={{maxWidth: 200}}
|
|
59
|
+
icon={'offline'}
|
|
60
|
+
/>
|
|
61
|
+
</td>
|
|
62
|
+
</tr>
|
|
63
|
+
<tr>
|
|
64
|
+
<th align="left">loaded</th>
|
|
65
|
+
<td>
|
|
66
|
+
<MediaWithDefaults
|
|
67
|
+
width={3500}
|
|
68
|
+
height={2095}
|
|
69
|
+
placeholder={{lqip: lqip}}
|
|
70
|
+
src="andre-spieker-238-unsplash.jpg"
|
|
71
|
+
style={{maxWidth: 200}}
|
|
72
|
+
icon={'loaded'}
|
|
73
|
+
/>
|
|
74
|
+
</td>
|
|
75
|
+
<th align="left">error</th>
|
|
76
|
+
<td>
|
|
77
|
+
<MediaWithDefaults
|
|
78
|
+
width={3500}
|
|
79
|
+
height={2095}
|
|
80
|
+
placeholder={{lqip: lqip}}
|
|
81
|
+
src="andre-spieker-238-unsplash.jpg"
|
|
82
|
+
style={{maxWidth: 200}}
|
|
83
|
+
icon={'error'}
|
|
84
|
+
/>
|
|
85
|
+
</td>
|
|
86
|
+
</tr>
|
|
87
|
+
</tbody>
|
|
88
|
+
</table>;
|
|
89
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Media from '../Media';
|
|
3
|
+
import icons from '../icons';
|
|
4
|
+
import theme from '../theme';
|
|
5
|
+
|
|
6
|
+
const MediaWithDefaults = ({
|
|
7
|
+
icons: iconsProp = icons,
|
|
8
|
+
theme: themeProp = theme,
|
|
9
|
+
...props
|
|
10
|
+
}) => <Media {...props} icons={iconsProp} theme={themeProp} />;
|
|
11
|
+
|
|
12
|
+
export default MediaWithDefaults;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composes styles and/or classes
|
|
3
|
+
*
|
|
4
|
+
* For classes it will concat them in in one string
|
|
5
|
+
* and return as `className` property.
|
|
6
|
+
* Alternative is https://github.com/JedWatson/classnames
|
|
7
|
+
*
|
|
8
|
+
* For objects it will merge them in one object
|
|
9
|
+
* and return as `style` property.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* Assume you have `theme` object, which can be css-module
|
|
13
|
+
* or object or other css-in-js compatible with css-module
|
|
14
|
+
*
|
|
15
|
+
* <a {...compose(theme.link, theme.active, {color: "#000"})}>link</a>
|
|
16
|
+
*
|
|
17
|
+
* @returns {{className: string, style: object}} - params for React component
|
|
18
|
+
*/
|
|
19
|
+
export default (...stylesOrClasses) => {
|
|
20
|
+
const classes = [];
|
|
21
|
+
let style;
|
|
22
|
+
for (const obj of stylesOrClasses) {
|
|
23
|
+
if (obj instanceof Object) {
|
|
24
|
+
Object.assign(style || (style = {}), obj);
|
|
25
|
+
} else if (obj === undefined || obj === false) {
|
|
26
|
+
// ignore
|
|
27
|
+
} else if (typeof obj === 'string') {
|
|
28
|
+
classes.push(obj);
|
|
29
|
+
} else {
|
|
30
|
+
throw new Error(`Unexpected value ${obj}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
className: classes.length > 1 ? classes.join(' ') : classes[0],
|
|
35
|
+
style,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const load = 'load';
|
|
2
|
+
const loading = 'loading';
|
|
3
|
+
const loaded = 'loaded';
|
|
4
|
+
const error = 'error';
|
|
5
|
+
const noicon = 'noicon';
|
|
6
|
+
const offline = 'offline';
|
|
7
|
+
|
|
8
|
+
export const icons = {
|
|
9
|
+
load,
|
|
10
|
+
loading,
|
|
11
|
+
loaded,
|
|
12
|
+
error,
|
|
13
|
+
noicon,
|
|
14
|
+
offline,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const initial = 'initial';
|
|
18
|
+
|
|
19
|
+
export const loadStates = {
|
|
20
|
+
initial,
|
|
21
|
+
loading,
|
|
22
|
+
loaded,
|
|
23
|
+
error,
|
|
24
|
+
};
|