@micromag/element-image 0.3.803 → 0.3.811

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.
Files changed (2) hide show
  1. package/es/index.js +24 -7
  2. package/package.json +3 -3
package/es/index.js CHANGED
@@ -4,8 +4,9 @@ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
4
  import { getSizeWithinBounds } from '@folklore/size';
5
5
  import classNames from 'classnames';
6
6
  import PropTypes from 'prop-types';
7
- import React, { useState, useRef, useCallback } from 'react';
7
+ import React, { forwardRef, useState, useRef, useCallback } from 'react';
8
8
  import { PropTypes as PropTypes$1 } from '@micromag/core';
9
+ import { useSupportsWebp } from '@micromag/core/hooks';
9
10
  import { getOptimalImageUrl } from '@micromag/core/utils';
10
11
 
11
12
  var styles = {"container":"micromag-element-image-container","img":"micromag-element-image-img"};
@@ -23,7 +24,10 @@ var propTypes = {
23
24
  imageClassName: PropTypes.string,
24
25
  onLoaded: PropTypes.func,
25
26
  loadingMode: PropTypes.string,
26
- shouldLoad: PropTypes.bool
27
+ shouldLoad: PropTypes.bool,
28
+ containerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
29
+ current: PropTypes.any
30
+ })])
27
31
  };
28
32
  var defaultProps = {
29
33
  media: null,
@@ -39,7 +43,8 @@ var defaultProps = {
39
43
  imageClassName: null,
40
44
  onLoaded: null,
41
45
  loadingMode: 'lazy',
42
- shouldLoad: true
46
+ shouldLoad: true,
47
+ containerRef: null
43
48
  };
44
49
  var Image = function Image(_ref) {
45
50
  var media = _ref.media,
@@ -54,7 +59,8 @@ var Image = function Image(_ref) {
54
59
  imageClassName = _ref.imageClassName,
55
60
  onLoaded = _ref.onLoaded,
56
61
  loadingMode = _ref.loadingMode,
57
- shouldLoad = _ref.shouldLoad;
62
+ shouldLoad = _ref.shouldLoad,
63
+ containerRef = _ref.containerRef;
58
64
  var _ref2 = media || {},
59
65
  _ref2$metadata = _ref2.metadata,
60
66
  metadata = _ref2$metadata === void 0 ? null : _ref2$metadata;
@@ -170,20 +176,26 @@ var Image = function Image(_ref) {
170
176
  }
171
177
  finalContainerStyle = _objectSpread(_objectSpread({}, finalContainerStyle), containerStyle);
172
178
  finalImageStyle = _objectSpread(_objectSpread({}, finalImageStyle), imageStyle);
179
+ var supportsWebp = useSupportsWebp();
180
+ console.log({
181
+ supportsWebp: supportsWebp
182
+ });
173
183
  var _finalImageStyle = finalImageStyle,
174
184
  _finalImageStyle$widt = _finalImageStyle.width,
175
185
  finalWidth = _finalImageStyle$widt === void 0 ? null : _finalImageStyle$widt,
176
186
  _finalImageStyle$heig = _finalImageStyle.height,
177
187
  finalHeight = _finalImageStyle$heig === void 0 ? null : _finalImageStyle$heig;
178
188
  var finalUrl = getOptimalImageUrl(media, finalWidth, finalHeight || finalWidth, {
179
- resolution: resolution
189
+ resolution: resolution,
190
+ supportsWebp: supportsWebp
180
191
  });
181
192
 
182
193
  // console.log('image finalWidth, finalHeight, resolution', finalImageStyle, resolution, finalUrl);
183
194
 
184
195
  return /*#__PURE__*/React.createElement("div", {
185
196
  className: classNames([styles.container, _defineProperty({}, className, className !== null)]),
186
- style: finalContainerStyle
197
+ style: finalContainerStyle,
198
+ ref: containerRef
187
199
  }, finalUrl !== null && finalShouldLoad ? /*#__PURE__*/React.createElement("img", {
188
200
  src: finalUrl,
189
201
  alt: alt || description,
@@ -195,5 +207,10 @@ var Image = function Image(_ref) {
195
207
  };
196
208
  Image.propTypes = propTypes;
197
209
  Image.defaultProps = defaultProps;
210
+ var Image_default = /*#__PURE__*/forwardRef(function (props, ref) {
211
+ return /*#__PURE__*/React.createElement(Image, Object.assign({
212
+ containerRef: ref
213
+ }, props));
214
+ });
198
215
 
199
- export { Image as default };
216
+ export { Image_default as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/element-image",
3
- "version": "0.3.803",
3
+ "version": "0.3.811",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [
@@ -60,7 +60,7 @@
60
60
  "dependencies": {
61
61
  "@babel/runtime": "^7.13.10",
62
62
  "@folklore/size": "^0.1.20",
63
- "@micromag/core": "^0.3.803",
63
+ "@micromag/core": "^0.3.811",
64
64
  "classnames": "^2.2.6",
65
65
  "prop-types": "^15.7.2",
66
66
  "react-intl": "^6.6.4",
@@ -70,5 +70,5 @@
70
70
  "access": "public",
71
71
  "registry": "https://registry.npmjs.org/"
72
72
  },
73
- "gitHead": "b8d7486367da5144fa0824e48527c44aa4123ddf"
73
+ "gitHead": "80a754e5a50e86fa1e195015112ea0ff39008da8"
74
74
  }