rsuite 5.33.1 → 5.34.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.
@@ -8,9 +8,18 @@ export interface TimelineProps extends WithAsProps {
8
8
  align?: 'left' | 'right' | 'alternate';
9
9
  /** Timeline endless **/
10
10
  endless?: boolean;
11
+ /**
12
+ * Whether an item is active (with highlighted dot).
13
+ *
14
+ * @default
15
+ * The last item is marked active.
16
+ */
17
+ isItemActive?: (index: number, totalItemsCount: number) => boolean;
11
18
  }
12
19
  interface TimelineComponent extends RsRefForwardingComponent<'div', TimelineProps> {
13
20
  Item: typeof TimelineItem;
21
+ ACTIVE_FIRST: (index: number, totalItemsCount: number) => boolean;
22
+ ACTIVE_LAST: (index: number, totalItemsCount: number) => boolean;
14
23
  }
15
24
  declare const Timeline: TimelineComponent;
16
25
  export default Timeline;
@@ -15,7 +15,9 @@ var Timeline = /*#__PURE__*/React.forwardRef(function (props, ref) {
15
15
  _props$align = props.align,
16
16
  align = _props$align === void 0 ? 'left' : _props$align,
17
17
  endless = props.endless,
18
- rest = _objectWithoutPropertiesLoose(props, ["children", "as", "classPrefix", "className", "align", "endless"]);
18
+ _props$isItemActive = props.isItemActive,
19
+ isItemActive = _props$isItemActive === void 0 ? Timeline.ACTIVE_LAST : _props$isItemActive,
20
+ rest = _objectWithoutPropertiesLoose(props, ["children", "as", "classPrefix", "className", "align", "endless", "isItemActive"]);
19
21
 
20
22
  var _useClassNames = useClassNames(classPrefix),
21
23
  merge = _useClassNames.merge,
@@ -37,10 +39,20 @@ var Timeline = /*#__PURE__*/React.forwardRef(function (props, ref) {
37
39
  }), ReactChildren.mapCloneElement(children, function (_child, index) {
38
40
  return {
39
41
  last: index + 1 === count,
42
+ INTERNAL_active: isItemActive(index, count),
40
43
  align: align
41
44
  };
42
45
  }));
43
46
  });
47
+
48
+ Timeline.ACTIVE_FIRST = function (index) {
49
+ return index === 0;
50
+ };
51
+
52
+ Timeline.ACTIVE_LAST = function (index, totalItemsCount) {
53
+ return index === totalItemsCount - 1;
54
+ };
55
+
44
56
  Timeline.Item = TimelineItem;
45
57
  Timeline.displayName = 'Timeline';
46
58
  Timeline.propTypes = {
@@ -1,7 +1,18 @@
1
1
  import React from 'react';
2
2
  import { WithAsProps, RsRefForwardingComponent } from '../@types/common';
3
3
  export interface TimelineItemProps extends WithAsProps {
4
- /** Whether the last item */
4
+ /**
5
+ * Whether the last item
6
+ *
7
+ * @internal
8
+ * This props is supposed to be used only by Timeline component internally
9
+ * User should never rely on this prop
10
+ *
11
+ * @deprecated
12
+ * This prop was used to indicate whether an item is the last item so that it gets highlighted.
13
+ * Now we can specify whether an item should be highlighted individually.
14
+ * Use {@link INTERNAL_active} instead
15
+ */
5
16
  last?: boolean;
6
17
  /** Customizing the Timeline item */
7
18
  dot?: React.ReactNode;
@@ -11,6 +22,12 @@ export interface TimelineItemProps extends WithAsProps {
11
22
  as?: React.ElementType;
12
23
  /** Customized time of timeline **/
13
24
  time?: React.ReactNode;
25
+ /**
26
+ * @internal
27
+ * This props is supposed to be used only by Timeline component internally
28
+ * User should never rely on this prop
29
+ */
30
+ INTERNAL_active?: boolean;
14
31
  }
15
32
  declare const TimelineItem: RsRefForwardingComponent<'div', TimelineItemProps>;
16
33
  export default TimelineItem;
@@ -9,11 +9,12 @@ var TimelineItem = /*#__PURE__*/React.forwardRef(function (props, ref) {
9
9
  children = props.children,
10
10
  _props$classPrefix = props.classPrefix,
11
11
  classPrefix = _props$classPrefix === void 0 ? 'timeline-item' : _props$classPrefix,
12
- last = props.last,
12
+ DEPRECATED_last = props.last,
13
13
  className = props.className,
14
14
  dot = props.dot,
15
15
  time = props.time,
16
- rest = _objectWithoutPropertiesLoose(props, ["as", "children", "classPrefix", "last", "className", "dot", "time"]);
16
+ INTERNAL_active = props.INTERNAL_active,
17
+ rest = _objectWithoutPropertiesLoose(props, ["as", "children", "classPrefix", "last", "className", "dot", "time", "INTERNAL_active"]);
17
18
 
18
19
  var _useClassNames = useClassNames(classPrefix),
19
20
  merge = _useClassNames.merge,
@@ -21,7 +22,8 @@ var TimelineItem = /*#__PURE__*/React.forwardRef(function (props, ref) {
21
22
  prefix = _useClassNames.prefix;
22
23
 
23
24
  var classes = merge(className, withClassPrefix({
24
- last: last
25
+ last: DEPRECATED_last,
26
+ active: INTERNAL_active
25
27
  }));
26
28
  return /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
27
29
  ref: ref,
@@ -1,13 +1,14 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- import React, { useRef, useImperativeHandle, useCallback } from 'react';
3
+ import React, { useRef, useImperativeHandle, useCallback, useMemo } from 'react';
4
4
  import { VariableSizeList } from 'react-window';
5
5
  import { useCustom } from '../utils';
6
6
  var List = /*#__PURE__*/React.forwardRef(function (props, ref) {
7
7
  var rowHeight = props.rowHeight,
8
8
  _props$as = props.as,
9
9
  Component = _props$as === void 0 ? VariableSizeList : _props$as,
10
- rest = _objectWithoutPropertiesLoose(props, ["rowHeight", "as"]);
10
+ itemSizeProp = props.itemSize,
11
+ rest = _objectWithoutPropertiesLoose(props, ["rowHeight", "as", "itemSize"]);
11
12
 
12
13
  var listRef = useRef(null);
13
14
 
@@ -43,8 +44,16 @@ var List = /*#__PURE__*/React.forwardRef(function (props, ref) {
43
44
  index: index
44
45
  }) : rowHeight || 0;
45
46
  }, [rowHeight]);
47
+ var itemSize = useMemo(function () {
48
+ if (typeof itemSizeProp === 'function') return itemSizeProp;
49
+ return function () {
50
+ return itemSizeProp;
51
+ };
52
+ }, [itemSizeProp]);
46
53
 
47
- var compatibleProps = _extends({}, rest);
54
+ var compatibleProps = _extends({
55
+ itemSize: itemSize
56
+ }, rest);
48
57
 
49
58
  if (rowHeight) {
50
59
  compatibleProps.itemSize = Component === VariableSizeList ? setRowHeight : rowHeight;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsuite",
3
- "version": "5.33.1",
3
+ "version": "5.34.0",
4
4
  "description": "A suite of react components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",