@instructure/ui-img 11.7.2-snapshot-45 → 11.7.2-snapshot-47

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
@@ -3,9 +3,19 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [11.7.2-snapshot-45](https://github.com/instructure/instructure-ui/compare/v11.7.1...v11.7.2-snapshot-45) (2026-04-10)
6
+ ## [11.7.2-snapshot-47](https://github.com/instructure/instructure-ui/compare/v11.7.1...v11.7.2-snapshot-47) (2026-04-16)
7
7
 
8
- **Note:** Version bump only for package @instructure/ui-img
8
+
9
+ ### Features
10
+
11
+ * **ui-img:** rework Img ([5e7a355](https://github.com/instructure/instructure-ui/commit/5e7a3556401ac3155a8ff58baad9359095f654ff))
12
+
13
+
14
+ ### BREAKING CHANGES
15
+
16
+ * **ui-img:** contains breaking changes due to component using the new theming system
17
+
18
+ INSTUI-4970
9
19
 
10
20
 
11
21
 
@@ -0,0 +1,126 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
+ const _excluded = ["src", "alt", "margin", "display", "overlay", "withGrayscale", "withBlur", "constrain", "width", "height", "elementRef", "styles", "loading"];
3
+ var _dec, _class, _Img;
4
+ /*
5
+ * The MIT License (MIT)
6
+ *
7
+ * Copyright (c) 2015 - present Instructure, Inc.
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ * of this software and associated documentation files (the "Software"), to deal
11
+ * in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ * copies of the Software, and to permit persons to whom the Software is
14
+ * furnished to do so, subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in all
17
+ * copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ * SOFTWARE.
26
+ */
27
+
28
+ import { Component } from 'react';
29
+ import { View } from '@instructure/ui-view/latest';
30
+ import { passthroughProps } from '@instructure/ui-react-utils';
31
+ import { withStyle } from '@instructure/emotion';
32
+ import generateStyle from "./styles.js";
33
+ import { allowedProps } from "./props.js";
34
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
35
+ /**
36
+ ---
37
+ category: components
38
+ ---
39
+ **/
40
+ let Img = (_dec = withStyle(generateStyle), _dec(_class = (_Img = class Img extends Component {
41
+ constructor(...args) {
42
+ super(...args);
43
+ this.ref = null;
44
+ this.handleRef = el => {
45
+ const elementRef = this.props.elementRef;
46
+ this.ref = el;
47
+ if (typeof elementRef === 'function') {
48
+ elementRef(el);
49
+ }
50
+ };
51
+ }
52
+ componentDidMount() {
53
+ var _this$props$makeStyle, _this$props;
54
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
55
+ }
56
+ componentDidUpdate() {
57
+ var _this$props$makeStyle2, _this$props2;
58
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
59
+ }
60
+ render() {
61
+ const _this$props3 = this.props,
62
+ src = _this$props3.src,
63
+ alt = _this$props3.alt,
64
+ margin = _this$props3.margin,
65
+ display = _this$props3.display,
66
+ overlay = _this$props3.overlay,
67
+ withGrayscale = _this$props3.withGrayscale,
68
+ withBlur = _this$props3.withBlur,
69
+ constrain = _this$props3.constrain,
70
+ width = _this$props3.width,
71
+ height = _this$props3.height,
72
+ elementRef = _this$props3.elementRef,
73
+ styles = _this$props3.styles,
74
+ loading = _this$props3.loading,
75
+ props = _objectWithoutProperties(_this$props3, _excluded);
76
+ const a11yProps = {
77
+ alt: alt || ''
78
+ };
79
+ const imageProps = {
80
+ css: styles === null || styles === void 0 ? void 0 : styles.img,
81
+ src,
82
+ loading
83
+ };
84
+ const containerProps = {
85
+ ...passthroughProps(props),
86
+ width,
87
+ height,
88
+ margin,
89
+ display,
90
+ elementRef: this.handleRef
91
+ };
92
+ if (overlay) {
93
+ // if a background image is rendered we add the a11y props on the container element
94
+ const rootProps = {
95
+ ...containerProps
96
+ };
97
+ return _jsxs(View, {
98
+ ...rootProps,
99
+ as: "span",
100
+ css: styles === null || styles === void 0 ? void 0 : styles.container,
101
+ "data-cid": "Img",
102
+ children: [_jsx("img", {
103
+ ...imageProps,
104
+ ...a11yProps
105
+ }), overlay && _jsx("span", {
106
+ css: styles === null || styles === void 0 ? void 0 : styles.overlay
107
+ })]
108
+ });
109
+ } else {
110
+ return _jsx(View, {
111
+ ...containerProps,
112
+ ...imageProps,
113
+ ...a11yProps,
114
+ as: "img",
115
+ "data-cid": "Img"
116
+ });
117
+ }
118
+ }
119
+ }, _Img.displayName = "Img", _Img.componentId = 'Img', _Img.allowedProps = allowedProps, _Img.defaultProps = {
120
+ alt: '',
121
+ display: 'inline-block',
122
+ withGrayscale: false,
123
+ withBlur: false
124
+ }, _Img)) || _class);
125
+ export default Img;
126
+ export { Img };
@@ -0,0 +1,26 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ const allowedProps = ['src', 'alt', 'display', 'loading', 'margin', 'overlay', 'withGrayscale', 'withBlur', 'constrain', 'elementRef', 'height', 'width'];
26
+ export { allowedProps };
@@ -0,0 +1,132 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ /**
26
+ * ---
27
+ * private: true
28
+ * ---
29
+ * Generates the style object from the theme and provided additional information
30
+ * @param {Object} componentTheme The theme variable object.
31
+ * @param {Object} props the props of the component, the style is applied to
32
+ * @param {Object} state the state of the component, the style is applied to
33
+ * @return {Object} The final style object, which will be used in the component
34
+ */
35
+ const generateStyle = (componentTheme, props) => {
36
+ const overlay = props.overlay,
37
+ withBlur = props.withBlur,
38
+ withGrayscale = props.withGrayscale,
39
+ constrain = props.constrain;
40
+ const isCover = constrain === 'cover';
41
+ const isContain = constrain === 'contain';
42
+
43
+ // if overlay or filters are updated via props,
44
+ // make the transition look smooth
45
+ const transitionStyle = {
46
+ transition: `all ${componentTheme.effectTransitionDuration}`
47
+ };
48
+ const getFilterStyle = () => {
49
+ const filters = [];
50
+ withBlur && filters.push(`blur(${componentTheme.imageBlurAmount})`);
51
+ withGrayscale && filters.push('grayscale(1)');
52
+ return filters.length > 0 ? {
53
+ ...transitionStyle,
54
+ filter: filters.join(' ')
55
+ } : {
56
+ filter: 'none'
57
+ };
58
+ };
59
+ const fillContainer = {
60
+ width: '100%',
61
+ height: '100%'
62
+ };
63
+ const imgCoverStyle = {
64
+ objectFit: 'cover',
65
+ ...fillContainer
66
+ };
67
+ const imgContainStyle = {
68
+ objectFit: 'contain',
69
+ ...fillContainer,
70
+ ...(overlay && {
71
+ width: 'auto',
72
+ height: 'auto',
73
+ maxWidth: '100%',
74
+ maxHeight: '100%'
75
+ })
76
+ };
77
+ return {
78
+ overlay: {
79
+ label: 'img__overlay',
80
+ position: 'absolute',
81
+ top: '0px',
82
+ left: '0px',
83
+ width: '100%',
84
+ height: '100%',
85
+ ...transitionStyle,
86
+ ...(overlay && {
87
+ backgroundColor: overlay.color,
88
+ opacity: overlay.opacity * 0.1,
89
+ mixBlendMode: overlay.blend ? overlay.blend : void 0
90
+ })
91
+ },
92
+ container: {
93
+ label: 'img__container',
94
+ ...(overlay && {
95
+ position: 'relative',
96
+ overflow: 'hidden' /* stops blurred images extending past overlay borders */
97
+ }),
98
+ ...(isCover && fillContainer),
99
+ ...(isContain && {
100
+ height: 'inherit'
101
+ })
102
+ },
103
+ img: {
104
+ label: 'img',
105
+ // reset image styles (initial: all was causing conflicts
106
+ // View's CSS and overriding height/width attrs)
107
+ margin: '0',
108
+ padding: '0',
109
+ float: 'none',
110
+ top: 'auto',
111
+ bottom: 'auto',
112
+ left: 'auto',
113
+ right: 'auto',
114
+ lineHeight: 'normal',
115
+ position: 'static',
116
+ transform: 'none',
117
+ maxHeight: 'none',
118
+ minHeight: '0',
119
+ minWidth: '0',
120
+ maxWidth: '100%',
121
+ ...getFilterStyle(),
122
+ ...(overlay && {
123
+ // when image is contained in overlay,
124
+ // avoid extra space at bottom from inline/line-height
125
+ display: 'block'
126
+ }),
127
+ ...(isCover && imgCoverStyle),
128
+ ...(isContain && imgContainStyle)
129
+ }
130
+ };
131
+ };
132
+ export default generateStyle;
@@ -0,0 +1,24 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ export { Img } from "../Img/v2/index.js";
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = exports.Img = void 0;
8
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
9
+ var _react = require("react");
10
+ var _latest = require("@instructure/ui-view/latest");
11
+ var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
12
+ var _emotion = require("@instructure/emotion");
13
+ var _styles = _interopRequireDefault(require("./styles"));
14
+ var _props = require("./props");
15
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
16
+ const _excluded = ["src", "alt", "margin", "display", "overlay", "withGrayscale", "withBlur", "constrain", "width", "height", "elementRef", "styles", "loading"];
17
+ var _dec, _class, _Img;
18
+ /*
19
+ * The MIT License (MIT)
20
+ *
21
+ * Copyright (c) 2015 - present Instructure, Inc.
22
+ *
23
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
24
+ * of this software and associated documentation files (the "Software"), to deal
25
+ * in the Software without restriction, including without limitation the rights
26
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27
+ * copies of the Software, and to permit persons to whom the Software is
28
+ * furnished to do so, subject to the following conditions:
29
+ *
30
+ * The above copyright notice and this permission notice shall be included in all
31
+ * copies or substantial portions of the Software.
32
+ *
33
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39
+ * SOFTWARE.
40
+ */
41
+ /**
42
+ ---
43
+ category: components
44
+ ---
45
+ **/
46
+ let Img = exports.Img = (_dec = (0, _emotion.withStyle)(_styles.default), _dec(_class = (_Img = class Img extends _react.Component {
47
+ constructor(...args) {
48
+ super(...args);
49
+ this.ref = null;
50
+ this.handleRef = el => {
51
+ const elementRef = this.props.elementRef;
52
+ this.ref = el;
53
+ if (typeof elementRef === 'function') {
54
+ elementRef(el);
55
+ }
56
+ };
57
+ }
58
+ componentDidMount() {
59
+ var _this$props$makeStyle, _this$props;
60
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
61
+ }
62
+ componentDidUpdate() {
63
+ var _this$props$makeStyle2, _this$props2;
64
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
65
+ }
66
+ render() {
67
+ const _this$props3 = this.props,
68
+ src = _this$props3.src,
69
+ alt = _this$props3.alt,
70
+ margin = _this$props3.margin,
71
+ display = _this$props3.display,
72
+ overlay = _this$props3.overlay,
73
+ withGrayscale = _this$props3.withGrayscale,
74
+ withBlur = _this$props3.withBlur,
75
+ constrain = _this$props3.constrain,
76
+ width = _this$props3.width,
77
+ height = _this$props3.height,
78
+ elementRef = _this$props3.elementRef,
79
+ styles = _this$props3.styles,
80
+ loading = _this$props3.loading,
81
+ props = (0, _objectWithoutProperties2.default)(_this$props3, _excluded);
82
+ const a11yProps = {
83
+ alt: alt || ''
84
+ };
85
+ const imageProps = {
86
+ css: styles === null || styles === void 0 ? void 0 : styles.img,
87
+ src,
88
+ loading
89
+ };
90
+ const containerProps = {
91
+ ...(0, _passthroughProps.passthroughProps)(props),
92
+ width,
93
+ height,
94
+ margin,
95
+ display,
96
+ elementRef: this.handleRef
97
+ };
98
+ if (overlay) {
99
+ // if a background image is rendered we add the a11y props on the container element
100
+ const rootProps = {
101
+ ...containerProps
102
+ };
103
+ return (0, _jsxRuntime.jsxs)(_latest.View, {
104
+ ...rootProps,
105
+ as: "span",
106
+ css: styles === null || styles === void 0 ? void 0 : styles.container,
107
+ "data-cid": "Img",
108
+ children: [(0, _jsxRuntime.jsx)("img", {
109
+ ...imageProps,
110
+ ...a11yProps
111
+ }), overlay && (0, _jsxRuntime.jsx)("span", {
112
+ css: styles === null || styles === void 0 ? void 0 : styles.overlay
113
+ })]
114
+ });
115
+ } else {
116
+ return (0, _jsxRuntime.jsx)(_latest.View, {
117
+ ...containerProps,
118
+ ...imageProps,
119
+ ...a11yProps,
120
+ as: "img",
121
+ "data-cid": "Img"
122
+ });
123
+ }
124
+ }
125
+ }, _Img.displayName = "Img", _Img.componentId = 'Img', _Img.allowedProps = _props.allowedProps, _Img.defaultProps = {
126
+ alt: '',
127
+ display: 'inline-block',
128
+ withGrayscale: false,
129
+ withBlur: false
130
+ }, _Img)) || _class);
131
+ var _default = exports.default = Img;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.allowedProps = void 0;
7
+ /*
8
+ * The MIT License (MIT)
9
+ *
10
+ * Copyright (c) 2015 - present Instructure, Inc.
11
+ *
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ * of this software and associated documentation files (the "Software"), to deal
14
+ * in the Software without restriction, including without limitation the rights
15
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ * copies of the Software, and to permit persons to whom the Software is
17
+ * furnished to do so, subject to the following conditions:
18
+ *
19
+ * The above copyright notice and this permission notice shall be included in all
20
+ * copies or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ * SOFTWARE.
29
+ */
30
+
31
+ const allowedProps = exports.allowedProps = ['src', 'alt', 'display', 'loading', 'margin', 'overlay', 'withGrayscale', 'withBlur', 'constrain', 'elementRef', 'height', 'width'];
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ /*
8
+ * The MIT License (MIT)
9
+ *
10
+ * Copyright (c) 2015 - present Instructure, Inc.
11
+ *
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ * of this software and associated documentation files (the "Software"), to deal
14
+ * in the Software without restriction, including without limitation the rights
15
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ * copies of the Software, and to permit persons to whom the Software is
17
+ * furnished to do so, subject to the following conditions:
18
+ *
19
+ * The above copyright notice and this permission notice shall be included in all
20
+ * copies or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ * SOFTWARE.
29
+ */
30
+
31
+ /**
32
+ * ---
33
+ * private: true
34
+ * ---
35
+ * Generates the style object from the theme and provided additional information
36
+ * @param {Object} componentTheme The theme variable object.
37
+ * @param {Object} props the props of the component, the style is applied to
38
+ * @param {Object} state the state of the component, the style is applied to
39
+ * @return {Object} The final style object, which will be used in the component
40
+ */
41
+ const generateStyle = (componentTheme, props) => {
42
+ const overlay = props.overlay,
43
+ withBlur = props.withBlur,
44
+ withGrayscale = props.withGrayscale,
45
+ constrain = props.constrain;
46
+ const isCover = constrain === 'cover';
47
+ const isContain = constrain === 'contain';
48
+
49
+ // if overlay or filters are updated via props,
50
+ // make the transition look smooth
51
+ const transitionStyle = {
52
+ transition: `all ${componentTheme.effectTransitionDuration}`
53
+ };
54
+ const getFilterStyle = () => {
55
+ const filters = [];
56
+ withBlur && filters.push(`blur(${componentTheme.imageBlurAmount})`);
57
+ withGrayscale && filters.push('grayscale(1)');
58
+ return filters.length > 0 ? {
59
+ ...transitionStyle,
60
+ filter: filters.join(' ')
61
+ } : {
62
+ filter: 'none'
63
+ };
64
+ };
65
+ const fillContainer = {
66
+ width: '100%',
67
+ height: '100%'
68
+ };
69
+ const imgCoverStyle = {
70
+ objectFit: 'cover',
71
+ ...fillContainer
72
+ };
73
+ const imgContainStyle = {
74
+ objectFit: 'contain',
75
+ ...fillContainer,
76
+ ...(overlay && {
77
+ width: 'auto',
78
+ height: 'auto',
79
+ maxWidth: '100%',
80
+ maxHeight: '100%'
81
+ })
82
+ };
83
+ return {
84
+ overlay: {
85
+ label: 'img__overlay',
86
+ position: 'absolute',
87
+ top: '0px',
88
+ left: '0px',
89
+ width: '100%',
90
+ height: '100%',
91
+ ...transitionStyle,
92
+ ...(overlay && {
93
+ backgroundColor: overlay.color,
94
+ opacity: overlay.opacity * 0.1,
95
+ mixBlendMode: overlay.blend ? overlay.blend : void 0
96
+ })
97
+ },
98
+ container: {
99
+ label: 'img__container',
100
+ ...(overlay && {
101
+ position: 'relative',
102
+ overflow: 'hidden' /* stops blurred images extending past overlay borders */
103
+ }),
104
+ ...(isCover && fillContainer),
105
+ ...(isContain && {
106
+ height: 'inherit'
107
+ })
108
+ },
109
+ img: {
110
+ label: 'img',
111
+ // reset image styles (initial: all was causing conflicts
112
+ // View's CSS and overriding height/width attrs)
113
+ margin: '0',
114
+ padding: '0',
115
+ float: 'none',
116
+ top: 'auto',
117
+ bottom: 'auto',
118
+ left: 'auto',
119
+ right: 'auto',
120
+ lineHeight: 'normal',
121
+ position: 'static',
122
+ transform: 'none',
123
+ maxHeight: 'none',
124
+ minHeight: '0',
125
+ minWidth: '0',
126
+ maxWidth: '100%',
127
+ ...getFilterStyle(),
128
+ ...(overlay && {
129
+ // when image is contained in overlay,
130
+ // avoid extra space at bottom from inline/line-height
131
+ display: 'block'
132
+ }),
133
+ ...(isCover && imgCoverStyle),
134
+ ...(isContain && imgContainStyle)
135
+ }
136
+ };
137
+ };
138
+ var _default = exports.default = generateStyle;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Img", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _v.Img;
10
+ }
11
+ });
12
+ var _v = require("../Img/v2");