@plesk/ui-library 3.38.0 → 3.38.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.
@@ -30,7 +30,9 @@ const calcWidths = node => {
30
30
  */
31
31
  class Carousel extends _react.Component {
32
32
  constructor() {
33
+ var _this;
33
34
  super(...arguments);
35
+ _this = this;
34
36
  (0, _defineProperty2.default)(this, "state", {
35
37
  showControls: false,
36
38
  current: 0,
@@ -83,9 +85,14 @@ class Carousel extends _react.Component {
83
85
  showControls: (bounds?.width || 0) < totalWidth
84
86
  });
85
87
  });
88
+ (0, _defineProperty2.default)(this, "getChildrenCount", () => {
89
+ const {
90
+ children
91
+ } = this.props;
92
+ return Array.isArray(children) ? children?.reduce((prev, curr) => Array.isArray(curr) ? prev + curr.length : prev + 1, 0) : 0;
93
+ });
86
94
  (0, _defineProperty2.default)(this, "renderNavigationDots", () => {
87
95
  const {
88
- children,
89
96
  baseClassName,
90
97
  dots,
91
98
  items
@@ -96,18 +103,17 @@ class Carousel extends _react.Component {
96
103
  const {
97
104
  current
98
105
  } = this.state;
99
- const childrenCount = children?.length ?? 1;
100
- const pages = Math.ceil(childrenCount / items);
101
- if (pages <= 1) {
106
+ const childrenCount = this.getChildrenCount();
107
+ if (childrenCount <= 1) {
102
108
  return null;
103
109
  }
104
110
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
105
111
  className: `${baseClassName}__dots`,
106
112
  children: Array.from({
107
- length: pages
113
+ length: childrenCount
108
114
  }).map((_, idx) => /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
109
115
  role: "button",
110
- className: (0, _classnames.default)(`${baseClassName}__dots--dot`, current === idx ? `${baseClassName}__dots--dot-current` : null),
116
+ className: (0, _classnames.default)(`${baseClassName}__dot`, current === idx ? `${baseClassName}__dot--current` : null),
111
117
  "aria-current": current === idx,
112
118
  onClick: () => this.setCurrentSlide(idx)
113
119
  // eslint-disable-next-line react/no-array-index-key
@@ -154,19 +160,23 @@ class Carousel extends _react.Component {
154
160
  })]
155
161
  });
156
162
  });
157
- (0, _defineProperty2.default)(this, "renderSliderItems", () => {
163
+ (0, _defineProperty2.default)(this, "renderSliderItems", function () {
164
+ let showCurrent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
158
165
  const {
159
166
  children,
160
167
  baseClassName,
161
168
  items
162
- } = this.props;
163
- const childrenCount = children?.length ?? 1;
169
+ } = _this.props;
170
+ const {
171
+ current
172
+ } = _this.state;
173
+ const childrenCount = _this.getChildrenCount();
164
174
  let width = '';
165
175
  if (items) {
166
- width = `calc(100% / ${Math.min(childrenCount, items)})`;
176
+ width = `${Math.ceil(100 / Math.min(childrenCount, items))}%`;
167
177
  }
168
- return _react.Children.map(children, item => item && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
169
- className: `${baseClassName}__item`,
178
+ return _react.Children.map(children, (item, idx) => item && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
179
+ className: (0, _classnames.default)(`${baseClassName}__item`, showCurrent && idx === current ? `${baseClassName}__item--current` : null),
170
180
  style: {
171
181
  width
172
182
  },
@@ -187,23 +197,6 @@ class Carousel extends _react.Component {
187
197
  const {
188
198
  width
189
199
  } = this.rootRef.current.getBoundingClientRect();
190
- const {
191
- items,
192
- children
193
- } = this.props;
194
- if (items) {
195
- const slideItems = items;
196
- const childrenCount = children?.length ?? 1;
197
- const totalWidth = childrenCount * (width / slideItems);
198
- if (this.state.totalWidth !== totalWidth) {
199
- this.setState({
200
- slideWidths: new Array(childrenCount).fill(width),
201
- totalWidth,
202
- showControls: childrenCount > slideItems
203
- });
204
- }
205
- return;
206
- }
207
200
  const {
208
201
  slideWidths,
209
202
  totalWidth
@@ -237,7 +230,7 @@ class Carousel extends _react.Component {
237
230
  if (current >= slideWidths.length) {
238
231
  current = 0;
239
232
  }
240
- this.props.onSlide?.(next);
233
+ this.props.onSlide?.(current);
241
234
  this.setState({
242
235
  current,
243
236
  next,
@@ -323,7 +316,7 @@ class Carousel extends _react.Component {
323
316
  children: [showControls && this.renderSliderItems(), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
324
317
  className: `${baseClassName}__genuine-slides`,
325
318
  ref: this.genuineRef,
326
- children: this.renderSliderItems()
319
+ children: this.renderSliderItems(true)
327
320
  }), showControls && this.renderSliderItems()]
328
321
  }), this.renderNavigationArrows()]
329
322
  }), this.renderNavigationDots()]
package/cjs/index.js CHANGED
@@ -46,5 +46,5 @@ Object.keys(_components).forEach(function (key) {
46
46
  });
47
47
  });
48
48
  // Copyright 1999-2023. Plesk International GmbH. All rights reserved.
49
- const version = exports.version = "3.38.0";
49
+ const version = exports.version = "3.38.1";
50
50
  (0, _svg4everybody.default)();