@enact/ui 5.2.1 → 5.3.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
@@ -2,6 +2,18 @@
2
2
 
3
3
  The following is a curated list of changes in the Enact ui module, newest changes on the top.
4
4
 
5
+ ## [5.3.1] - 2025-10-14
6
+
7
+ ### Fixed
8
+
9
+ - `ui/Scroller` to calculate correctly targetX and targetY when scrolling to a position
10
+
11
+ ## [5.3.0] - 2025-09-24
12
+
13
+ ### Added
14
+
15
+ - `ui/Card` `fitImage` prop to allow developers to center the image
16
+
5
17
  ## [5.2.1] - 2025-09-02
6
18
 
7
19
  No significant changes.
package/Card/Card.d.ts CHANGED
@@ -29,6 +29,10 @@ corresponding internal elements and states of this component.
29
29
  * The following classes are supported.
30
30
  */
31
31
  css?: object;
32
+ /**
33
+ * Fits the image to its height and width and positions it on the center of the Card
34
+ */
35
+ fitImage?: boolean;
32
36
  /**
33
37
  * The component used to render the image component.
34
38
  */
package/Card/Card.js CHANGED
@@ -85,6 +85,13 @@ var CardBase = exports.CardBase = (0, _kind["default"])({
85
85
  * @public
86
86
  */
87
87
  css: _propTypes2["default"].object,
88
+ /**
89
+ * Fits the image to its height and width and positions it on the center of the Card
90
+ *
91
+ * @type {Boolean}
92
+ * @public
93
+ */
94
+ fitImage: _propTypes2["default"].bool,
88
95
  /**
89
96
  * The component used to render the image component.
90
97
  *
@@ -137,12 +144,14 @@ var CardBase = exports.CardBase = (0, _kind["default"])({
137
144
  computed: {
138
145
  className: function className(_ref2) {
139
146
  var captionOverlay = _ref2.captionOverlay,
147
+ fitImage = _ref2.fitImage,
140
148
  orientation = _ref2.orientation,
141
149
  selected = _ref2.selected,
142
150
  styler = _ref2.styler;
143
151
  return styler.append({
144
152
  captionOverlay: captionOverlay && orientation === 'vertical',
145
153
  selected: selected,
154
+ fitImage: fitImage,
146
155
  horizontal: orientation === 'horizontal',
147
156
  vertical: orientation === 'vertical'
148
157
  });
@@ -158,6 +167,7 @@ var CardBase = exports.CardBase = (0, _kind["default"])({
158
167
  placeholder = _ref3.placeholder,
159
168
  src = _ref3.src,
160
169
  rest = _objectWithoutProperties(_ref3, _excluded2);
170
+ delete rest.fitImage;
161
171
  var isHorizontal = orientation === 'horizontal';
162
172
  var isCaptionOverlay = captionOverlay && !isHorizontal;
163
173
  var Component = isHorizontal ? _Layout.Row : _Layout.Column;
@@ -5,6 +5,10 @@
5
5
  display: block;
6
6
  margin: 0;
7
7
  }
8
+ .card.fitImage .image {
9
+ background-size: contain;
10
+ background-repeat: no-repeat;
11
+ }
8
12
  .card .children,
9
13
  .card.selected {
10
14
  /* Public Class Names */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enact/ui",
3
- "version": "5.2.1",
3
+ "version": "5.3.1",
4
4
  "description": "A collection of simplified unstyled cross-platform UI components for Enact",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,16 +32,16 @@
32
32
  }
33
33
  },
34
34
  "dependencies": {
35
- "@enact/core": "^5.2.1",
36
- "@enact/i18n": "^5.2.1",
35
+ "@enact/core": "^5.3.1",
36
+ "@enact/i18n": "^5.3.1",
37
37
  "classnames": "^2.5.1",
38
38
  "ilib": "^14.21.1",
39
39
  "invariant": "^2.2.4",
40
40
  "prop-types": "^15.8.1",
41
41
  "ramda": "^0.31.3",
42
- "react": "^19.1.0",
43
- "react-dom": "^19.1.0",
44
- "react-is": "^19.1.0",
42
+ "react": "^19.1.1",
43
+ "react-dom": "^19.1.1",
44
+ "react-is": "^19.1.1",
45
45
  "warning": "^4.0.3"
46
46
  }
47
47
  }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ require("@testing-library/jest-dom");
4
+ describe('useScroll', function () {
5
+ describe('Rounding target scroll position', function () {
6
+ beforeEach(function () {
7
+ jest.resetModules(); // important! clears cached modules
8
+ });
9
+ test('should round target position upwards when target is bigger than current position', function () {
10
+ jest.doMock('@enact/core/platform', function () {
11
+ return {
12
+ __esModule: true,
13
+ platform: {
14
+ chrome: 132
15
+ }
16
+ };
17
+ });
18
+ var _require = require('../useScroll'),
19
+ roundTarget = _require.roundTarget;
20
+ var currentPosition = {
21
+ scrollPos: {
22
+ left: 100,
23
+ top: 100
24
+ }
25
+ };
26
+ var _roundTarget = roundTarget(currentPosition, 120.5, 120.4),
27
+ roundedTargetX = _roundTarget.roundedTargetX,
28
+ roundedTargetY = _roundTarget.roundedTargetY;
29
+ expect(roundedTargetX).toEqual(121);
30
+ expect(roundedTargetY).toEqual(121);
31
+ });
32
+ test('should round target position downwards when target is bigger than current position', function () {
33
+ jest.doMock('@enact/core/platform', function () {
34
+ return {
35
+ __esModule: true,
36
+ platform: {
37
+ chrome: 132
38
+ }
39
+ };
40
+ });
41
+ var _require2 = require('../useScroll'),
42
+ roundTarget = _require2.roundTarget;
43
+ var currentPosition = {
44
+ scrollPos: {
45
+ left: 100,
46
+ top: 100
47
+ }
48
+ };
49
+ var _roundTarget2 = roundTarget(currentPosition, 90.4, 80.8),
50
+ roundedTargetX = _roundTarget2.roundedTargetX,
51
+ roundedTargetY = _roundTarget2.roundedTargetY;
52
+ expect(roundedTargetX).toEqual(90);
53
+ expect(roundedTargetY).toEqual(80);
54
+ });
55
+ test('should not round target position when chrome <= 120', function () {
56
+ jest.doMock('@enact/core/platform', function () {
57
+ return {
58
+ __esModule: true,
59
+ platform: {
60
+ chrome: 119
61
+ }
62
+ };
63
+ });
64
+ var _require3 = require('../useScroll'),
65
+ roundTarget = _require3.roundTarget;
66
+ var currentPosition = {
67
+ scrollPos: {
68
+ left: 100,
69
+ top: 100
70
+ }
71
+ };
72
+ var _roundTarget3 = roundTarget(currentPosition, 90.4, 80.8),
73
+ roundedTargetX = _roundTarget3.roundedTargetX,
74
+ roundedTargetY = _roundTarget3.roundedTargetY;
75
+ expect(roundedTargetX).toEqual(90.4);
76
+ expect(roundedTargetY).toEqual(80.8);
77
+ });
78
+ });
79
+ });
@@ -3,7 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useScrollBase = exports.useScroll = exports["default"] = exports.constants = exports.assignPropertiesOf = void 0;
6
+ exports["default"] = exports.constants = exports.assignPropertiesOf = void 0;
7
+ exports.roundTarget = roundTarget;
8
+ exports.useScrollBase = exports.useScroll = void 0;
7
9
  var _classnames = _interopRequireDefault(require("classnames"));
8
10
  var _handle = require("@enact/core/handle");
9
11
  var _keymap = require("@enact/core/keymap");
@@ -95,6 +97,21 @@ var useForceUpdate = function useForceUpdate() {
95
97
  return x + 1;
96
98
  }, 0);
97
99
  };
100
+ function roundTarget(currentPosition, targetX, targetY) {
101
+ var roundedTargetX, roundedTargetY;
102
+ if (currentPosition !== null && currentPosition !== void 0 && currentPosition.scrollPos && _platform.platform.chrome > 120) {
103
+ var _currentPosition$scro, _currentPosition$scro2;
104
+ roundedTargetX = (currentPosition === null || currentPosition === void 0 || (_currentPosition$scro = currentPosition.scrollPos) === null || _currentPosition$scro === void 0 ? void 0 : _currentPosition$scro.left) < targetX ? Math.ceil(targetX) : Math.floor(targetX);
105
+ roundedTargetY = (currentPosition === null || currentPosition === void 0 || (_currentPosition$scro2 = currentPosition.scrollPos) === null || _currentPosition$scro2 === void 0 ? void 0 : _currentPosition$scro2.top) < targetY ? Math.ceil(targetY) : Math.floor(targetY);
106
+ } else {
107
+ roundedTargetX = targetX;
108
+ roundedTargetY = targetY;
109
+ }
110
+ return {
111
+ roundedTargetX: roundedTargetX,
112
+ roundedTargetY: roundedTargetY
113
+ };
114
+ }
98
115
 
99
116
  /**
100
117
  * A custom hook that passes scrollable behavior information as its render prop.
@@ -1126,10 +1143,13 @@ var useScrollBase = exports.useScrollBase = function useScrollBase(props) {
1126
1143
  }
1127
1144
  } else {
1128
1145
  // scrollMode 'native'
1146
+ var _roundTarget = roundTarget(scrollContentHandle.current, targetX, targetY),
1147
+ roundedTargetX = _roundTarget.roundedTargetX,
1148
+ roundedTargetY = _roundTarget.roundedTargetY;
1129
1149
  if (animate) {
1130
- scrollContentHandle.current.scrollToPosition(targetX, targetY, 'smooth');
1150
+ scrollContentHandle.current.scrollToPosition(roundedTargetX, roundedTargetY, 'smooth');
1131
1151
  } else {
1132
- scrollContentHandle.current.scrollToPosition(targetX, targetY, 'instant');
1152
+ scrollContentHandle.current.scrollToPosition(roundedTargetX, roundedTargetY, 'instant');
1133
1153
  }
1134
1154
  if (props.start) {
1135
1155
  props.start(animate);