@atlaskit/image 0.2.0

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 ADDED
@@ -0,0 +1,11 @@
1
+ # @atlaskit/image
2
+
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`8ab96dfc824`](https://bitbucket.org/atlassian/atlassian-frontend/commits/8ab96dfc824) - Adds a new Image primitive that works like the native HTML img element, with the added functionality of being theme-aware.
8
+
9
+ ## 0.1.0
10
+
11
+ - Create Image component with theme functionality.
package/LICENSE.md ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2022 Atlassian Pty Ltd
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # Image
2
+
3
+ An image component with additional features, such as support for themes.
4
+
5
+ ## Usage
6
+
7
+ `import Image from '@atlaskit/image';`
8
+
9
+ Detailed docs and example usage can be found [here](https://atlaskit.atlassian.com/packages/design-system/image).
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ Object.defineProperty(exports, "default", {
9
+ enumerable: true,
10
+ get: function get() {
11
+ return _image.default;
12
+ }
13
+ });
14
+
15
+ var _image = _interopRequireDefault(require("./ui/image"));
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = Image;
9
+
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+
12
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
+
14
+ var _react = require("react");
15
+
16
+ var _react2 = require("@emotion/react");
17
+
18
+ var _tokens = require("@atlaskit/tokens");
19
+
20
+ var _excluded = ["src", "srcDark", "alt", "testId"];
21
+ var imageStyles = (0, _react2.css)({
22
+ maxWidth: '100%',
23
+ height: 'auto'
24
+ });
25
+ /**
26
+ * __Image__
27
+ *
28
+ * This component can be used interchangeably with the native `img` element. It includes additional functionality, such as theme support.
29
+ *
30
+ * - [Examples](https://atlassian.design/components/image/examples)
31
+ * - [Code](https://atlassian.design/components/image/code)
32
+ * - [Usage](https://atlassian.design/components/image/usage)
33
+ */
34
+
35
+ function Image(_ref) {
36
+ var src = _ref.src,
37
+ srcDark = _ref.srcDark,
38
+ alt = _ref.alt,
39
+ testId = _ref.testId,
40
+ props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
41
+ var imgRef = (0, _react.useRef)(null);
42
+ var theme = (0, _tokens.useThemeObserver)();
43
+ (0, _react.useEffect)(function () {
44
+ if (imgRef === null || imgRef.current === null) {
45
+ return;
46
+ }
47
+
48
+ if (srcDark && theme === 'dark') {
49
+ imgRef.current.src = srcDark;
50
+ } else if (src) {
51
+ imgRef.current.src = src;
52
+ }
53
+ }, [src, srcDark, theme]);
54
+ return (0, _react2.jsx)("picture", null, srcDark && (0, _react2.jsx)("source", {
55
+ srcSet: srcDark,
56
+ media: "(prefers-color-scheme: dark)"
57
+ }), (0, _react2.jsx)("img", (0, _extends2.default)({
58
+ alt: alt,
59
+ css: imageStyles,
60
+ "data-testid": testId,
61
+ src: src,
62
+ ref: imgRef // The spread operator is necessary since the component can accept all the props of an `img` element.
63
+ // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
64
+
65
+ }, props)));
66
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "@atlaskit/image",
3
+ "version": "0.2.0",
4
+ "sideEffects": false
5
+ }
@@ -0,0 +1 @@
1
+ export { default } from './ui/image';
@@ -0,0 +1,53 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+
3
+ /** @jsx jsx */
4
+ import { useEffect, useRef } from 'react';
5
+ import { css, jsx } from '@emotion/react';
6
+ import { useThemeObserver } from '@atlaskit/tokens';
7
+ const imageStyles = css({
8
+ maxWidth: '100%',
9
+ height: 'auto'
10
+ });
11
+ /**
12
+ * __Image__
13
+ *
14
+ * This component can be used interchangeably with the native `img` element. It includes additional functionality, such as theme support.
15
+ *
16
+ * - [Examples](https://atlassian.design/components/image/examples)
17
+ * - [Code](https://atlassian.design/components/image/code)
18
+ * - [Usage](https://atlassian.design/components/image/usage)
19
+ */
20
+
21
+ export default function Image({
22
+ src,
23
+ srcDark,
24
+ alt,
25
+ testId,
26
+ ...props
27
+ }) {
28
+ const imgRef = useRef(null);
29
+ const theme = useThemeObserver();
30
+ useEffect(() => {
31
+ if (imgRef === null || imgRef.current === null) {
32
+ return;
33
+ }
34
+
35
+ if (srcDark && theme === 'dark') {
36
+ imgRef.current.src = srcDark;
37
+ } else if (src) {
38
+ imgRef.current.src = src;
39
+ }
40
+ }, [src, srcDark, theme]);
41
+ return jsx("picture", null, srcDark && jsx("source", {
42
+ srcSet: srcDark,
43
+ media: "(prefers-color-scheme: dark)"
44
+ }), jsx("img", _extends({
45
+ alt: alt,
46
+ css: imageStyles,
47
+ "data-testid": testId,
48
+ src: src,
49
+ ref: imgRef // The spread operator is necessary since the component can accept all the props of an `img` element.
50
+ // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
51
+
52
+ }, props)));
53
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "@atlaskit/image",
3
+ "version": "0.2.0",
4
+ "sideEffects": false
5
+ }
@@ -0,0 +1 @@
1
+ export { default } from './ui/image';
@@ -0,0 +1,55 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ var _excluded = ["src", "srcDark", "alt", "testId"];
4
+
5
+ /** @jsx jsx */
6
+ import { useEffect, useRef } from 'react';
7
+ import { css, jsx } from '@emotion/react';
8
+ import { useThemeObserver } from '@atlaskit/tokens';
9
+ var imageStyles = css({
10
+ maxWidth: '100%',
11
+ height: 'auto'
12
+ });
13
+ /**
14
+ * __Image__
15
+ *
16
+ * This component can be used interchangeably with the native `img` element. It includes additional functionality, such as theme support.
17
+ *
18
+ * - [Examples](https://atlassian.design/components/image/examples)
19
+ * - [Code](https://atlassian.design/components/image/code)
20
+ * - [Usage](https://atlassian.design/components/image/usage)
21
+ */
22
+
23
+ export default function Image(_ref) {
24
+ var src = _ref.src,
25
+ srcDark = _ref.srcDark,
26
+ alt = _ref.alt,
27
+ testId = _ref.testId,
28
+ props = _objectWithoutProperties(_ref, _excluded);
29
+
30
+ var imgRef = useRef(null);
31
+ var theme = useThemeObserver();
32
+ useEffect(function () {
33
+ if (imgRef === null || imgRef.current === null) {
34
+ return;
35
+ }
36
+
37
+ if (srcDark && theme === 'dark') {
38
+ imgRef.current.src = srcDark;
39
+ } else if (src) {
40
+ imgRef.current.src = src;
41
+ }
42
+ }, [src, srcDark, theme]);
43
+ return jsx("picture", null, srcDark && jsx("source", {
44
+ srcSet: srcDark,
45
+ media: "(prefers-color-scheme: dark)"
46
+ }), jsx("img", _extends({
47
+ alt: alt,
48
+ css: imageStyles,
49
+ "data-testid": testId,
50
+ src: src,
51
+ ref: imgRef // The spread operator is necessary since the component can accept all the props of an `img` element.
52
+ // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
53
+
54
+ }, props)));
55
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "@atlaskit/image",
3
+ "version": "0.2.0",
4
+ "sideEffects": false
5
+ }
@@ -0,0 +1 @@
1
+ export { default } from './ui/image';
@@ -0,0 +1,26 @@
1
+ /// <reference types="react" />
2
+ import { jsx } from '@emotion/react';
3
+ interface ImageProps extends React.ImgHTMLAttributes<HTMLImageElement> {
4
+ /**
5
+ * Image URL to use for dark mode. This overrides `src` when the user
6
+ * has selected dark mode either in the app or on their operating system.
7
+ */
8
+ srcDark?: string;
9
+ /**
10
+ * A `testId` prop is provided for specified elements, which is a unique
11
+ * string that appears as a data attribute `data-testid` in the rendered code,
12
+ * serving as a hook for automated tests.
13
+ */
14
+ testId?: string;
15
+ }
16
+ /**
17
+ * __Image__
18
+ *
19
+ * This component can be used interchangeably with the native `img` element. It includes additional functionality, such as theme support.
20
+ *
21
+ * - [Examples](https://atlassian.design/components/image/examples)
22
+ * - [Code](https://atlassian.design/components/image/code)
23
+ * - [Usage](https://atlassian.design/components/image/usage)
24
+ */
25
+ export default function Image({ src, srcDark, alt, testId, ...props }: ImageProps): jsx.JSX.Element;
26
+ export {};
package/package.json ADDED
@@ -0,0 +1,84 @@
1
+ {
2
+ "name": "@atlaskit/image",
3
+ "version": "0.2.0",
4
+ "description": "Image component with additional functionality.",
5
+ "author": "Atlassian Pty Ltd",
6
+ "license": "Apache-2.0",
7
+ "publishConfig": {
8
+ "registry": "https://registry.npmjs.org/"
9
+ },
10
+ "homepage": "https://atlassian.design/components/image/",
11
+ "atlassian": {
12
+ "team": "Design System Team",
13
+ "inPublicMirror": true,
14
+ "releaseModel": "continuous",
15
+ "website": {
16
+ "name": "Image",
17
+ "category": "Components"
18
+ }
19
+ },
20
+ "repository": "https://bitbucket.org/atlassian/atlassian-frontend-mirror",
21
+ "main": "dist/cjs/index.js",
22
+ "module": "dist/esm/index.js",
23
+ "module:es2019": "dist/es2019/index.js",
24
+ "types": "dist/types/index.d.ts",
25
+ "sideEffects": false,
26
+ "atlaskit:src": "src/index.tsx",
27
+ "af:exports": {
28
+ ".": "./src/index.tsx"
29
+ },
30
+ "dependencies": {
31
+ "@atlaskit/tokens": "^0.11.2",
32
+ "@babel/runtime": "^7.0.0",
33
+ "@emotion/react": "^11.7.1"
34
+ },
35
+ "peerDependencies": {
36
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
37
+ },
38
+ "devDependencies": {
39
+ "@atlaskit/docs": "*",
40
+ "@atlaskit/ds-lib": "^2.1.1",
41
+ "@atlaskit/section-message": "*",
42
+ "@atlaskit/ssr": "*",
43
+ "@atlaskit/visual-regression": "*",
44
+ "@atlaskit/webdriver-runner": "*",
45
+ "@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
46
+ "@testing-library/react": "^12.1.5",
47
+ "react-dom": "^16.8.0",
48
+ "typescript": "4.5.5",
49
+ "wait-for-expect": "^1.2.0"
50
+ },
51
+ "techstack": {
52
+ "@atlassian/frontend": {
53
+ "code-structure": [
54
+ "tangerine-next"
55
+ ],
56
+ "import-structure": [
57
+ "atlassian-conventions"
58
+ ],
59
+ "circular-dependencies": [
60
+ "file-and-folder-level"
61
+ ]
62
+ },
63
+ "@repo/internal": {
64
+ "design-system": "v1",
65
+ "analytics": [
66
+ "analytics-next"
67
+ ],
68
+ "theming": [
69
+ "tokens"
70
+ ],
71
+ "ui-components": [
72
+ "lite-mode"
73
+ ],
74
+ "deprecation": [
75
+ "no-deprecated-imports"
76
+ ],
77
+ "styling": [
78
+ "static",
79
+ "emotion"
80
+ ]
81
+ }
82
+ },
83
+ "prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.0"
84
+ }
package/report.api.md ADDED
@@ -0,0 +1,40 @@
1
+ <!-- API Report Version: 2.3 -->
2
+
3
+ ## API Report File for "@atlaskit/image"
4
+
5
+ > Do not edit this file. This report is auto-generated using [API Extractor](https://api-extractor.com/).
6
+ > [Learn more about API reports](https://hello.atlassian.net/wiki/spaces/UR/pages/1825484529/Package+API+Reports)
7
+
8
+ ### Table of contents
9
+
10
+ - [Main Entry Types](#main-entry-types)
11
+
12
+ ### Main Entry Types
13
+
14
+ <!--SECTION START: Main Entry Types-->
15
+
16
+ ```ts
17
+ /// <reference types="react" />
18
+
19
+ import { jsx } from '@emotion/react';
20
+
21
+ // @public
22
+ function Image_2({
23
+ src,
24
+ srcDark,
25
+ alt,
26
+ testId,
27
+ ...props
28
+ }: ImageProps): jsx.JSX.Element;
29
+ export default Image_2;
30
+
31
+ // @public (undocumented)
32
+ interface ImageProps extends React.ImgHTMLAttributes<HTMLImageElement> {
33
+ srcDark?: string;
34
+ testId?: string;
35
+ }
36
+
37
+ // (No @packageDocumentation comment for this package)
38
+ ```
39
+
40
+ <!--SECTION END: Main Entry Types-->
@@ -0,0 +1,23 @@
1
+ ## API Report File for "@atlaskit/image"
2
+
3
+ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4
+
5
+ ```ts
6
+
7
+ /// <reference types="react" />
8
+
9
+ import { jsx } from '@emotion/react';
10
+
11
+ // @public
12
+ function Image_2({ src, srcDark, alt, testId, ...props }: ImageProps): jsx.JSX.Element;
13
+ export default Image_2;
14
+
15
+ // @public (undocumented)
16
+ interface ImageProps extends React.ImgHTMLAttributes<HTMLImageElement> {
17
+ srcDark?: string;
18
+ testId?: string;
19
+ }
20
+
21
+ // (No @packageDocumentation comment for this package)
22
+
23
+ ```