@atlaskit/image 1.2.0 → 1.2.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @atlaskit/image
2
2
 
3
+ ## 1.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#89307](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/89307)
8
+ [`47cdc66371fb`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/47cdc66371fb) -
9
+ [ux] Fix bug where images flickered in dark mode. Source URLs are now set based on the current
10
+ theme before first paint.
11
+ - Updated dependencies
12
+
3
13
  ## 1.2.0
4
14
 
5
15
  ### Minor Changes
@@ -9,13 +9,21 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
9
9
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
10
  var _react = require("react");
11
11
  var _react2 = require("@emotion/react");
12
+ var _appProvider = require("@atlaskit/app-provider");
12
13
  var _tokens = require("@atlaskit/tokens");
13
14
  var _excluded = ["src", "srcDark", "alt", "testId"];
14
15
  /** @jsx jsx */
15
- var imageStyles = (0, _react2.css)({
16
+ var baseImageStyles = (0, _react2.css)({
16
17
  maxWidth: '100%',
17
18
  height: 'auto'
18
19
  });
20
+ var themedImageStyles = (0, _react2.css)({
21
+ content: "var(--img-source)",
22
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
23
+ 'html[data-color-mode=dark] &': {
24
+ content: "var(--img-source-dark)"
25
+ }
26
+ });
19
27
 
20
28
  /**
21
29
  * __Image__
@@ -33,8 +41,10 @@ function Image(_ref) {
33
41
  testId = _ref.testId,
34
42
  props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
35
43
  var imgRef = (0, _react.useRef)(null);
44
+ var providedColorMode = (0, _appProvider.UNSAFE_useColorModeForMigration)();
36
45
  var _useThemeObserver = (0, _tokens.useThemeObserver)(),
37
- colorMode = _useThemeObserver.colorMode;
46
+ observedColorMode = _useThemeObserver.colorMode;
47
+ var colorMode = providedColorMode || observedColorMode;
38
48
  (0, _react.useEffect)(function () {
39
49
  if (imgRef === null || imgRef.current === null) {
40
50
  return;
@@ -47,9 +57,13 @@ function Image(_ref) {
47
57
  }, [src, srcDark, colorMode]);
48
58
  return (0, _react2.jsx)("img", (0, _extends2.default)({
49
59
  alt: alt,
50
- css: imageStyles,
51
60
  "data-testid": testId,
52
61
  src: src,
62
+ style: {
63
+ '--img-source': "url(".concat(src, ")"),
64
+ '--img-source-dark': "url(".concat(srcDark || src, ")")
65
+ },
66
+ css: [baseImageStyles, themedImageStyles],
53
67
  ref: imgRef
54
68
  // The spread operator is necessary since the component can accept all the props of an `img` element.
55
69
  // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
@@ -2,11 +2,19 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  /** @jsx jsx */
3
3
  import { useEffect, useRef } from 'react';
4
4
  import { css, jsx } from '@emotion/react';
5
+ import { UNSAFE_useColorModeForMigration } from '@atlaskit/app-provider';
5
6
  import { useThemeObserver } from '@atlaskit/tokens';
6
- const imageStyles = css({
7
+ const baseImageStyles = css({
7
8
  maxWidth: '100%',
8
9
  height: 'auto'
9
10
  });
11
+ const themedImageStyles = css({
12
+ content: `var(--img-source)`,
13
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
14
+ 'html[data-color-mode=dark] &': {
15
+ content: `var(--img-source-dark)`
16
+ }
17
+ });
10
18
 
11
19
  /**
12
20
  * __Image__
@@ -25,9 +33,11 @@ export default function Image({
25
33
  ...props
26
34
  }) {
27
35
  const imgRef = useRef(null);
36
+ const providedColorMode = UNSAFE_useColorModeForMigration();
28
37
  const {
29
- colorMode
38
+ colorMode: observedColorMode
30
39
  } = useThemeObserver();
40
+ const colorMode = providedColorMode || observedColorMode;
31
41
  useEffect(() => {
32
42
  if (imgRef === null || imgRef.current === null) {
33
43
  return;
@@ -40,9 +50,13 @@ export default function Image({
40
50
  }, [src, srcDark, colorMode]);
41
51
  return jsx("img", _extends({
42
52
  alt: alt,
43
- css: imageStyles,
44
53
  "data-testid": testId,
45
54
  src: src,
55
+ style: {
56
+ '--img-source': `url(${src})`,
57
+ '--img-source-dark': `url(${srcDark || src})`
58
+ },
59
+ css: [baseImageStyles, themedImageStyles],
46
60
  ref: imgRef
47
61
  // The spread operator is necessary since the component can accept all the props of an `img` element.
48
62
  // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
@@ -4,11 +4,19 @@ var _excluded = ["src", "srcDark", "alt", "testId"];
4
4
  /** @jsx jsx */
5
5
  import { useEffect, useRef } from 'react';
6
6
  import { css, jsx } from '@emotion/react';
7
+ import { UNSAFE_useColorModeForMigration } from '@atlaskit/app-provider';
7
8
  import { useThemeObserver } from '@atlaskit/tokens';
8
- var imageStyles = css({
9
+ var baseImageStyles = css({
9
10
  maxWidth: '100%',
10
11
  height: 'auto'
11
12
  });
13
+ var themedImageStyles = css({
14
+ content: "var(--img-source)",
15
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
16
+ 'html[data-color-mode=dark] &': {
17
+ content: "var(--img-source-dark)"
18
+ }
19
+ });
12
20
 
13
21
  /**
14
22
  * __Image__
@@ -26,8 +34,10 @@ export default function Image(_ref) {
26
34
  testId = _ref.testId,
27
35
  props = _objectWithoutProperties(_ref, _excluded);
28
36
  var imgRef = useRef(null);
37
+ var providedColorMode = UNSAFE_useColorModeForMigration();
29
38
  var _useThemeObserver = useThemeObserver(),
30
- colorMode = _useThemeObserver.colorMode;
39
+ observedColorMode = _useThemeObserver.colorMode;
40
+ var colorMode = providedColorMode || observedColorMode;
31
41
  useEffect(function () {
32
42
  if (imgRef === null || imgRef.current === null) {
33
43
  return;
@@ -40,9 +50,13 @@ export default function Image(_ref) {
40
50
  }, [src, srcDark, colorMode]);
41
51
  return jsx("img", _extends({
42
52
  alt: alt,
43
- css: imageStyles,
44
53
  "data-testid": testId,
45
54
  src: src,
55
+ style: {
56
+ '--img-source': "url(".concat(src, ")"),
57
+ '--img-source-dark': "url(".concat(srcDark || src, ")")
58
+ },
59
+ css: [baseImageStyles, themedImageStyles],
46
60
  ref: imgRef
47
61
  // The spread operator is necessary since the component can accept all the props of an `img` element.
48
62
  // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/image",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "An image that changes in light or dark themes.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -28,7 +28,8 @@
28
28
  "runReact18": true
29
29
  },
30
30
  "dependencies": {
31
- "@atlaskit/tokens": "^1.45.0",
31
+ "@atlaskit/app-provider": "1.3.2",
32
+ "@atlaskit/tokens": "^1.49.0",
32
33
  "@babel/runtime": "^7.0.0",
33
34
  "@emotion/react": "^11.7.1"
34
35
  },