@itwin/itwinui-react 1.44.0 → 1.45.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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.45.0](https://www.github.com/iTwin/iTwinUI-react/compare/v1.44.0...v1.45.0) (2022-08-25)
4
+
5
+ ### What's new
6
+
7
+ * **MiddleTextTruncation:** Add text renderer for customizing rendered content ([#787](https://www.github.com/iTwin/iTwinUI-react/issues/787)) ([293ebea](https://www.github.com/iTwin/iTwinUI-react/commit/293ebeac844eb540c1d5c7f999e176f3be377d8e))
8
+ * **Table:** Add `Cell` and `Row` status. Icons support in `DefaultCell` ([#788](https://www.github.com/iTwin/iTwinUI-react/issues/788)) ([9b0282e](https://www.github.com/iTwin/iTwinUI-react/commit/9b0282e610434301ff69e296086304afc5648034))
9
+
3
10
  ## [1.44.0](https://www.github.com/iTwin/iTwinUI-react/compare/v1.43.1...v1.44.0) (2022-08-23)
4
11
 
5
12
  ### What's new
package/README.md CHANGED
@@ -14,7 +14,7 @@
14
14
  ## What is iTwinUI-react?
15
15
 
16
16
  iTwinUI-react is a library built on top of the [iTwinUI](https://github.com/iTwin/iTwinUI) library.
17
- The goal of this project is to provide React components for using the styles and components from the core `iTwinUI` project. Check out the [demo website](https://itwin.github.io/iTwinUI-react/?path=/story/overview--overview) to see the components in action.
17
+ The goal of this project is to provide React components for using the styles and components from the core `iTwinUI` project. Check out the [demo website](https://itwin.github.io/iTwinUI-react) to see the components in action.
18
18
 
19
19
  ---
20
20
 
@@ -102,4 +102,4 @@ Please read our [CONTRIBUTING.md](https://github.com/iTwin/iTwinUI-react/blob/ma
102
102
 
103
103
  ## Changelog
104
104
 
105
- Read our [CHANGELOG.md](https://github.com/iTwin/iTwinUI-react/blob/main/CHANGELOG.md) to find recent changes.
105
+ Read our [CHANGELOG.md](https://github.com/iTwin/iTwinUI-react/blob/main/packages/iTwinUI-react/CHANGELOG.md) to find recent changes.
@@ -129,7 +129,9 @@ export declare type TableProps<T extends Record<string, unknown> = Record<string
129
129
  * Function that should return custom props passed to the each row.
130
130
  * Must be memoized.
131
131
  */
132
- rowProps?: (row: Row<T>) => React.ComponentPropsWithRef<'div'>;
132
+ rowProps?: (row: Row<T>) => React.ComponentPropsWithRef<'div'> & {
133
+ status?: 'positive' | 'warning' | 'negative';
134
+ };
133
135
  /**
134
136
  * Modify the density of the table (adjusts the row height).
135
137
  * @default 'default'
@@ -8,7 +8,11 @@ import { CellProps, Row, TableInstance, TableState } from 'react-table';
8
8
  */
9
9
  export declare const TableRow: <T extends Record<string, unknown>>(props: {
10
10
  row: Row<T>;
11
- rowProps?: ((row: Row<T>) => React.ComponentPropsWithRef<'div'>) | undefined;
11
+ rowProps?: ((row: Row<T>) => Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & {
12
+ ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
13
+ } & {
14
+ status?: "positive" | "warning" | "negative" | undefined;
15
+ }) | undefined;
12
16
  isLast: boolean;
13
17
  onRowInViewport: React.MutableRefObject<((rowData: T) => void) | undefined>;
14
18
  onBottomReached: React.MutableRefObject<(() => void) | undefined>;
@@ -25,7 +29,11 @@ export declare const TableRow: <T extends Record<string, unknown>>(props: {
25
29
  }) => JSX.Element;
26
30
  export declare const TableRowMemoized: <T extends Record<string, unknown>>(props: {
27
31
  row: Row<T>;
28
- rowProps?: ((row: Row<T>) => React.ComponentPropsWithRef<'div'>) | undefined;
32
+ rowProps?: ((row: Row<T>) => Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & {
33
+ ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
34
+ } & {
35
+ status?: "positive" | "warning" | "negative" | undefined;
36
+ }) | undefined;
29
37
  isLast: boolean;
30
38
  onRowInViewport: React.MutableRefObject<((rowData: T) => void) | undefined>;
31
39
  onBottomReached: React.MutableRefObject<(() => void) | undefined>;
@@ -10,6 +10,17 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
13
24
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
25
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
26
  };
@@ -30,6 +41,8 @@ var TableCell_1 = require("./TableCell");
30
41
  * When adding new features check whether it changes state that affects row. If it does then add equality check to `React.memo`.
31
42
  */
32
43
  var TableRow = function (props) {
44
+ var _a;
45
+ var _b;
33
46
  var row = props.row, rowProps = props.rowProps, isLast = props.isLast, onRowInViewport = props.onRowInViewport, onBottomReached = props.onBottomReached, intersectionMargin = props.intersectionMargin, onClick = props.onClick, subComponent = props.subComponent, isDisabled = props.isDisabled, tableHasSubRows = props.tableHasSubRows, tableInstance = props.tableInstance, expanderCell = props.expanderCell, bodyRef = props.bodyRef, tableRowRef = props.tableRowRef;
34
47
  var onIntersect = react_1.default.useCallback(function () {
35
48
  var _a, _b;
@@ -50,13 +63,16 @@ var TableRow = function (props) {
50
63
  rootMargin: "".concat(intersectionMargin, "px"),
51
64
  root: intersectionRoot,
52
65
  });
53
- var userRowProps = rowProps === null || rowProps === void 0 ? void 0 : rowProps(row);
54
- var mergedProps = __assign(__assign(__assign({}, row.getRowProps({ style: { flex: "0 0 auto", minWidth: '100%' } })), userRowProps), {
55
- className: (0, classnames_1.default)('iui-row', {
56
- 'iui-selected': row.isSelected,
57
- 'iui-row-expanded': row.isExpanded && subComponent,
58
- 'iui-disabled': isDisabled,
59
- }, userRowProps === null || userRowProps === void 0 ? void 0 : userRowProps.className),
66
+ var userRowProps = (_b = rowProps === null || rowProps === void 0 ? void 0 : rowProps(row)) !== null && _b !== void 0 ? _b : {};
67
+ var status = userRowProps.status, restUserRowProps = __rest(userRowProps, ["status"]);
68
+ var mergedProps = __assign(__assign(__assign({}, row.getRowProps({ style: { flex: "0 0 auto", minWidth: '100%' } })), restUserRowProps), {
69
+ className: (0, classnames_1.default)('iui-row', (_a = {
70
+ 'iui-selected': row.isSelected,
71
+ 'iui-row-expanded': row.isExpanded && subComponent,
72
+ 'iui-disabled': isDisabled
73
+ },
74
+ _a["iui-".concat(status)] = !!status,
75
+ _a), userRowProps === null || userRowProps === void 0 ? void 0 : userRowProps.className),
60
76
  });
61
77
  var refs = (0, utils_1.useMergedRefs)(intersectionRef, mergedProps.ref, tableRowRef);
62
78
  return (react_1.default.createElement(react_1.default.Fragment, null,
@@ -1,6 +1,19 @@
1
1
  import React from 'react';
2
2
  import { CellRendererProps } from 'react-table';
3
- export declare type DefaultCellProps<T extends Record<string, unknown>> = CellRendererProps<T> & React.ComponentPropsWithoutRef<'div'>;
3
+ export declare type DefaultCellProps<T extends Record<string, unknown>> = {
4
+ /**
5
+ * Custom icon to be displayed at the beginning of the cell.
6
+ */
7
+ startIcon?: JSX.Element;
8
+ /**
9
+ * Custom icon to be displayed at the end of the cell.
10
+ */
11
+ endIcon?: JSX.Element;
12
+ /**
13
+ * Status of the cell.
14
+ */
15
+ status?: 'positive' | 'negative' | 'warning';
16
+ } & CellRendererProps<T> & React.ComponentPropsWithoutRef<'div'>;
4
17
  /**
5
18
  * Default cell.
6
19
  * It should be passed to `cellRenderer`.
@@ -44,12 +44,18 @@ var classnames_1 = __importDefault(require("classnames"));
44
44
  * }
45
45
  */
46
46
  var DefaultCell = function (props) {
47
+ var _a;
47
48
  // Omitting `cellProps`
48
49
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
49
- var _a = props.cellElementProps, cellElementClassName = _a.className, cellElementStyle = _a.style, cellElementProps = __rest(_a, ["className", "style"]), children = props.children, cellProps = props.cellProps, isDisabled = props.isDisabled, className = props.className, style = props.style, rest = __rest(props, ["cellElementProps", "children", "cellProps", "isDisabled", "className", "style"]);
50
- return (react_1.default.createElement("div", __assign({}, cellElementProps, rest, { className: (0, classnames_1.default)(cellElementClassName, className, {
51
- 'iui-disabled': isDisabled === null || isDisabled === void 0 ? void 0 : isDisabled(cellProps.row.original),
52
- }), style: __assign(__assign({}, cellElementStyle), style) }), children));
50
+ var _b = props.cellElementProps, cellElementClassName = _b.className, cellElementStyle = _b.style, cellElementProps = __rest(_b, ["className", "style"]), children = props.children, startIcon = props.startIcon, endIcon = props.endIcon, cellProps = props.cellProps, isDisabled = props.isDisabled, className = props.className, style = props.style, status = props.status, rest = __rest(props, ["cellElementProps", "children", "startIcon", "endIcon", "cellProps", "isDisabled", "className", "style", "status"]);
51
+ return (react_1.default.createElement("div", __assign({}, cellElementProps, rest, { className: (0, classnames_1.default)(cellElementClassName, className, (_a = {
52
+ 'iui-disabled': isDisabled === null || isDisabled === void 0 ? void 0 : isDisabled(cellProps.row.original)
53
+ },
54
+ _a["iui-".concat(status)] = !!status,
55
+ _a)), style: __assign(__assign({}, cellElementStyle), style) }),
56
+ startIcon && react_1.default.createElement("div", { className: 'iui-cell-start-icon' }, startIcon),
57
+ children,
58
+ endIcon && react_1.default.createElement("div", { className: 'iui-cell-end-icon' }, endIcon)));
53
59
  };
54
60
  exports.DefaultCell = DefaultCell;
55
61
  exports.default = exports.DefaultCell;
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import { CommonProps } from '../props';
3
3
  export declare type MiddleTextTruncationProps = {
4
4
  /**
@@ -10,12 +10,26 @@ export declare type MiddleTextTruncationProps = {
10
10
  * @default 6
11
11
  */
12
12
  endCharsCount?: number;
13
+ /**
14
+ * Custom renderer for the truncated text.
15
+ */
16
+ textRenderer?: (truncatedText: string, originalText: string) => React.ReactNode;
13
17
  } & CommonProps;
14
18
  /**
15
19
  * Truncates text with the ellipsis in the middle,
16
20
  * leaving defined number of chars at the end.
17
21
  * @example
18
22
  * <MiddleTextTruncation text='ThisIsMyVeryLongFileName.dgn' />
23
+ * @example
24
+ * <MiddleTextTruncation text='ThisIsMyVeryLongFileName.dgn' endCharsCount={10} />
25
+ * @example
26
+ * <MiddleTextTruncation
27
+ * text='ThisIsMyVeryLongFileName.dgn'
28
+ * textRenderer={React.useCallback(
29
+ * (truncatedText) => <b>{truncatedText}</b>,
30
+ * []
31
+ * )}
32
+ * />
19
33
  */
20
34
  export declare const MiddleTextTruncation: (props: MiddleTextTruncationProps) => JSX.Element;
21
35
  export default MiddleTextTruncation;
@@ -38,10 +38,21 @@ var ELLIPSIS_CHAR = '…';
38
38
  * leaving defined number of chars at the end.
39
39
  * @example
40
40
  * <MiddleTextTruncation text='ThisIsMyVeryLongFileName.dgn' />
41
+ * @example
42
+ * <MiddleTextTruncation text='ThisIsMyVeryLongFileName.dgn' endCharsCount={10} />
43
+ * @example
44
+ * <MiddleTextTruncation
45
+ * text='ThisIsMyVeryLongFileName.dgn'
46
+ * textRenderer={React.useCallback(
47
+ * (truncatedText) => <b>{truncatedText}</b>,
48
+ * []
49
+ * )}
50
+ * />
41
51
  */
42
52
  var MiddleTextTruncation = function (props) {
43
- var text = props.text, _a = props.endCharsCount, endCharsCount = _a === void 0 ? 6 : _a, style = props.style, rest = __rest(props, ["text", "endCharsCount", "style"]);
44
- var _b = (0, useOverflow_1.useOverflow)(text), ref = _b[0], visibleCount = _b[1];
53
+ var _a;
54
+ var text = props.text, _b = props.endCharsCount, endCharsCount = _b === void 0 ? 6 : _b, textRenderer = props.textRenderer, style = props.style, rest = __rest(props, ["text", "endCharsCount", "textRenderer", "style"]);
55
+ var _c = (0, useOverflow_1.useOverflow)(text), ref = _c[0], visibleCount = _c[1];
45
56
  var truncatedText = react_1.default.useMemo(function () {
46
57
  if (visibleCount < text.length) {
47
58
  return "".concat(text.substring(0, visibleCount - endCharsCount - ELLIPSIS_CHAR.length)).concat(ELLIPSIS_CHAR).concat(text.substring(text.length - endCharsCount));
@@ -50,7 +61,7 @@ var MiddleTextTruncation = function (props) {
50
61
  return text;
51
62
  }
52
63
  }, [endCharsCount, text, visibleCount]);
53
- return (react_1.default.createElement("span", __assign({ style: __assign({ display: 'flex', minWidth: 0, flexGrow: 1, whiteSpace: 'nowrap' }, style), ref: ref }, rest), truncatedText));
64
+ return (react_1.default.createElement("span", __assign({ style: __assign({ display: 'flex', minWidth: 0, flexGrow: 1, whiteSpace: 'nowrap' }, style), ref: ref }, rest), (_a = textRenderer === null || textRenderer === void 0 ? void 0 : textRenderer(truncatedText, text)) !== null && _a !== void 0 ? _a : truncatedText));
54
65
  };
55
66
  exports.MiddleTextTruncation = MiddleTextTruncation;
56
67
  exports.default = exports.MiddleTextTruncation;
@@ -129,7 +129,9 @@ export declare type TableProps<T extends Record<string, unknown> = Record<string
129
129
  * Function that should return custom props passed to the each row.
130
130
  * Must be memoized.
131
131
  */
132
- rowProps?: (row: Row<T>) => React.ComponentPropsWithRef<'div'>;
132
+ rowProps?: (row: Row<T>) => React.ComponentPropsWithRef<'div'> & {
133
+ status?: 'positive' | 'warning' | 'negative';
134
+ };
133
135
  /**
134
136
  * Modify the density of the table (adjusts the row height).
135
137
  * @default 'default'
@@ -8,7 +8,11 @@ import { CellProps, Row, TableInstance, TableState } from 'react-table';
8
8
  */
9
9
  export declare const TableRow: <T extends Record<string, unknown>>(props: {
10
10
  row: Row<T>;
11
- rowProps?: ((row: Row<T>) => React.ComponentPropsWithRef<'div'>) | undefined;
11
+ rowProps?: ((row: Row<T>) => Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & {
12
+ ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
13
+ } & {
14
+ status?: "positive" | "warning" | "negative" | undefined;
15
+ }) | undefined;
12
16
  isLast: boolean;
13
17
  onRowInViewport: React.MutableRefObject<((rowData: T) => void) | undefined>;
14
18
  onBottomReached: React.MutableRefObject<(() => void) | undefined>;
@@ -25,7 +29,11 @@ export declare const TableRow: <T extends Record<string, unknown>>(props: {
25
29
  }) => JSX.Element;
26
30
  export declare const TableRowMemoized: <T extends Record<string, unknown>>(props: {
27
31
  row: Row<T>;
28
- rowProps?: ((row: Row<T>) => React.ComponentPropsWithRef<'div'>) | undefined;
32
+ rowProps?: ((row: Row<T>) => Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & {
33
+ ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
34
+ } & {
35
+ status?: "positive" | "warning" | "negative" | undefined;
36
+ }) | undefined;
29
37
  isLast: boolean;
30
38
  onRowInViewport: React.MutableRefObject<((rowData: T) => void) | undefined>;
31
39
  onBottomReached: React.MutableRefObject<(() => void) | undefined>;
@@ -9,6 +9,17 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
12
23
  /*---------------------------------------------------------------------------------------------
13
24
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
14
25
  * See LICENSE.md in the project root for license terms and full copyright notice.
@@ -24,6 +35,8 @@ import { TableCell } from './TableCell';
24
35
  * When adding new features check whether it changes state that affects row. If it does then add equality check to `React.memo`.
25
36
  */
26
37
  export var TableRow = function (props) {
38
+ var _a;
39
+ var _b;
27
40
  var row = props.row, rowProps = props.rowProps, isLast = props.isLast, onRowInViewport = props.onRowInViewport, onBottomReached = props.onBottomReached, intersectionMargin = props.intersectionMargin, onClick = props.onClick, subComponent = props.subComponent, isDisabled = props.isDisabled, tableHasSubRows = props.tableHasSubRows, tableInstance = props.tableInstance, expanderCell = props.expanderCell, bodyRef = props.bodyRef, tableRowRef = props.tableRowRef;
28
41
  var onIntersect = React.useCallback(function () {
29
42
  var _a, _b;
@@ -44,13 +57,16 @@ export var TableRow = function (props) {
44
57
  rootMargin: "".concat(intersectionMargin, "px"),
45
58
  root: intersectionRoot,
46
59
  });
47
- var userRowProps = rowProps === null || rowProps === void 0 ? void 0 : rowProps(row);
48
- var mergedProps = __assign(__assign(__assign({}, row.getRowProps({ style: { flex: "0 0 auto", minWidth: '100%' } })), userRowProps), {
49
- className: cx('iui-row', {
50
- 'iui-selected': row.isSelected,
51
- 'iui-row-expanded': row.isExpanded && subComponent,
52
- 'iui-disabled': isDisabled,
53
- }, userRowProps === null || userRowProps === void 0 ? void 0 : userRowProps.className),
60
+ var userRowProps = (_b = rowProps === null || rowProps === void 0 ? void 0 : rowProps(row)) !== null && _b !== void 0 ? _b : {};
61
+ var status = userRowProps.status, restUserRowProps = __rest(userRowProps, ["status"]);
62
+ var mergedProps = __assign(__assign(__assign({}, row.getRowProps({ style: { flex: "0 0 auto", minWidth: '100%' } })), restUserRowProps), {
63
+ className: cx('iui-row', (_a = {
64
+ 'iui-selected': row.isSelected,
65
+ 'iui-row-expanded': row.isExpanded && subComponent,
66
+ 'iui-disabled': isDisabled
67
+ },
68
+ _a["iui-".concat(status)] = !!status,
69
+ _a), userRowProps === null || userRowProps === void 0 ? void 0 : userRowProps.className),
54
70
  });
55
71
  var refs = useMergedRefs(intersectionRef, mergedProps.ref, tableRowRef);
56
72
  return (React.createElement(React.Fragment, null,
@@ -1,6 +1,19 @@
1
1
  import React from 'react';
2
2
  import { CellRendererProps } from 'react-table';
3
- export declare type DefaultCellProps<T extends Record<string, unknown>> = CellRendererProps<T> & React.ComponentPropsWithoutRef<'div'>;
3
+ export declare type DefaultCellProps<T extends Record<string, unknown>> = {
4
+ /**
5
+ * Custom icon to be displayed at the beginning of the cell.
6
+ */
7
+ startIcon?: JSX.Element;
8
+ /**
9
+ * Custom icon to be displayed at the end of the cell.
10
+ */
11
+ endIcon?: JSX.Element;
12
+ /**
13
+ * Status of the cell.
14
+ */
15
+ status?: 'positive' | 'negative' | 'warning';
16
+ } & CellRendererProps<T> & React.ComponentPropsWithoutRef<'div'>;
4
17
  /**
5
18
  * Default cell.
6
19
  * It should be passed to `cellRenderer`.
@@ -38,11 +38,17 @@ import cx from 'classnames';
38
38
  * }
39
39
  */
40
40
  export var DefaultCell = function (props) {
41
+ var _a;
41
42
  // Omitting `cellProps`
42
43
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
43
- var _a = props.cellElementProps, cellElementClassName = _a.className, cellElementStyle = _a.style, cellElementProps = __rest(_a, ["className", "style"]), children = props.children, cellProps = props.cellProps, isDisabled = props.isDisabled, className = props.className, style = props.style, rest = __rest(props, ["cellElementProps", "children", "cellProps", "isDisabled", "className", "style"]);
44
- return (React.createElement("div", __assign({}, cellElementProps, rest, { className: cx(cellElementClassName, className, {
45
- 'iui-disabled': isDisabled === null || isDisabled === void 0 ? void 0 : isDisabled(cellProps.row.original),
46
- }), style: __assign(__assign({}, cellElementStyle), style) }), children));
44
+ var _b = props.cellElementProps, cellElementClassName = _b.className, cellElementStyle = _b.style, cellElementProps = __rest(_b, ["className", "style"]), children = props.children, startIcon = props.startIcon, endIcon = props.endIcon, cellProps = props.cellProps, isDisabled = props.isDisabled, className = props.className, style = props.style, status = props.status, rest = __rest(props, ["cellElementProps", "children", "startIcon", "endIcon", "cellProps", "isDisabled", "className", "style", "status"]);
45
+ return (React.createElement("div", __assign({}, cellElementProps, rest, { className: cx(cellElementClassName, className, (_a = {
46
+ 'iui-disabled': isDisabled === null || isDisabled === void 0 ? void 0 : isDisabled(cellProps.row.original)
47
+ },
48
+ _a["iui-".concat(status)] = !!status,
49
+ _a)), style: __assign(__assign({}, cellElementStyle), style) }),
50
+ startIcon && React.createElement("div", { className: 'iui-cell-start-icon' }, startIcon),
51
+ children,
52
+ endIcon && React.createElement("div", { className: 'iui-cell-end-icon' }, endIcon)));
47
53
  };
48
54
  export default DefaultCell;
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import { CommonProps } from '../props';
3
3
  export declare type MiddleTextTruncationProps = {
4
4
  /**
@@ -10,12 +10,26 @@ export declare type MiddleTextTruncationProps = {
10
10
  * @default 6
11
11
  */
12
12
  endCharsCount?: number;
13
+ /**
14
+ * Custom renderer for the truncated text.
15
+ */
16
+ textRenderer?: (truncatedText: string, originalText: string) => React.ReactNode;
13
17
  } & CommonProps;
14
18
  /**
15
19
  * Truncates text with the ellipsis in the middle,
16
20
  * leaving defined number of chars at the end.
17
21
  * @example
18
22
  * <MiddleTextTruncation text='ThisIsMyVeryLongFileName.dgn' />
23
+ * @example
24
+ * <MiddleTextTruncation text='ThisIsMyVeryLongFileName.dgn' endCharsCount={10} />
25
+ * @example
26
+ * <MiddleTextTruncation
27
+ * text='ThisIsMyVeryLongFileName.dgn'
28
+ * textRenderer={React.useCallback(
29
+ * (truncatedText) => <b>{truncatedText}</b>,
30
+ * []
31
+ * )}
32
+ * />
19
33
  */
20
34
  export declare const MiddleTextTruncation: (props: MiddleTextTruncationProps) => JSX.Element;
21
35
  export default MiddleTextTruncation;
@@ -32,10 +32,21 @@ var ELLIPSIS_CHAR = '…';
32
32
  * leaving defined number of chars at the end.
33
33
  * @example
34
34
  * <MiddleTextTruncation text='ThisIsMyVeryLongFileName.dgn' />
35
+ * @example
36
+ * <MiddleTextTruncation text='ThisIsMyVeryLongFileName.dgn' endCharsCount={10} />
37
+ * @example
38
+ * <MiddleTextTruncation
39
+ * text='ThisIsMyVeryLongFileName.dgn'
40
+ * textRenderer={React.useCallback(
41
+ * (truncatedText) => <b>{truncatedText}</b>,
42
+ * []
43
+ * )}
44
+ * />
35
45
  */
36
46
  export var MiddleTextTruncation = function (props) {
37
- var text = props.text, _a = props.endCharsCount, endCharsCount = _a === void 0 ? 6 : _a, style = props.style, rest = __rest(props, ["text", "endCharsCount", "style"]);
38
- var _b = useOverflow(text), ref = _b[0], visibleCount = _b[1];
47
+ var _a;
48
+ var text = props.text, _b = props.endCharsCount, endCharsCount = _b === void 0 ? 6 : _b, textRenderer = props.textRenderer, style = props.style, rest = __rest(props, ["text", "endCharsCount", "textRenderer", "style"]);
49
+ var _c = useOverflow(text), ref = _c[0], visibleCount = _c[1];
39
50
  var truncatedText = React.useMemo(function () {
40
51
  if (visibleCount < text.length) {
41
52
  return "".concat(text.substring(0, visibleCount - endCharsCount - ELLIPSIS_CHAR.length)).concat(ELLIPSIS_CHAR).concat(text.substring(text.length - endCharsCount));
@@ -44,6 +55,6 @@ export var MiddleTextTruncation = function (props) {
44
55
  return text;
45
56
  }
46
57
  }, [endCharsCount, text, visibleCount]);
47
- return (React.createElement("span", __assign({ style: __assign({ display: 'flex', minWidth: 0, flexGrow: 1, whiteSpace: 'nowrap' }, style), ref: ref }, rest), truncatedText));
58
+ return (React.createElement("span", __assign({ style: __assign({ display: 'flex', minWidth: 0, flexGrow: 1, whiteSpace: 'nowrap' }, style), ref: ref }, rest), (_a = textRenderer === null || textRenderer === void 0 ? void 0 : textRenderer(truncatedText, text)) !== null && _a !== void 0 ? _a : truncatedText));
48
59
  };
49
60
  export default MiddleTextTruncation;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/itwinui-react",
3
- "version": "1.44.0",
3
+ "version": "1.45.0",
4
4
  "author": "Bentley Systems",
5
5
  "license": "MIT",
6
6
  "main": "cjs/index.js",