@topconsultnpm/sdkui-react-beta 6.7.99 → 6.7.101
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,28 +8,47 @@ import TMLayoutContainer, { TMLayoutItem } from '../base/TMLayout';
|
|
|
8
8
|
import TMVilViewer from '../base/TMVilViewer';
|
|
9
9
|
import TMTooltip from '../base/TMTooltip';
|
|
10
10
|
import { DeviceType, useDeviceType } from '../base/TMDeviceProvider';
|
|
11
|
+
// Define the TMTextArea component
|
|
11
12
|
const TMTextArea = (props) => {
|
|
13
|
+
// Extract properties from the props object
|
|
12
14
|
const { label = '', value = '', width = '100%', height = 'auto', autoFocus = false, validationItems = [], disabled = false, isModifiedWhen = false, fontSize = FontSize.defaultFontSize, elementStyle = {}, icon = null, labelPosition = 'left', readOnly = false, onValueChanged, onBlur, placeHolder, formulaItems = [], buttons = [], maxHeight = 'auto', rows, maxLength } = props;
|
|
15
|
+
// Reference to the textarea DOM element
|
|
13
16
|
const inputRef = useRef(null);
|
|
17
|
+
// Stores the textarea is focused
|
|
14
18
|
const [isFocused, setIsFocused] = useState(false);
|
|
19
|
+
// Stores the current value of the textarea
|
|
15
20
|
const [currentValue, setCurrentValue] = useState(value);
|
|
21
|
+
// Stores the items for the context menu
|
|
16
22
|
const [formulaMenuItems, setFormulaMenuItems] = useState([]);
|
|
23
|
+
// Stores the calculated number of rows for the textarea
|
|
17
24
|
const [calculatedRows, setCalculatedRows] = useState(rows ?? 1);
|
|
25
|
+
// Manages the state for the custom context menu
|
|
18
26
|
const { clicked, setClicked, points, setPoints } = useContextMenu();
|
|
19
27
|
const deviceType = useDeviceType();
|
|
28
|
+
// Attach a `ResizeObserver` to the textarea to monitor changes in width: dynamically updates rows based on textarea content and width
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const observer = new ResizeObserver(() => { if (currentValue) {
|
|
31
|
+
updateRows();
|
|
32
|
+
} });
|
|
33
|
+
if (inputRef.current) {
|
|
34
|
+
observer.observe(inputRef.current);
|
|
35
|
+
}
|
|
36
|
+
return () => { if (inputRef.current) {
|
|
37
|
+
observer.unobserve(inputRef.current);
|
|
38
|
+
} };
|
|
39
|
+
}, [currentValue]);
|
|
40
|
+
// Update current value whenever the `value` prop changes, synchronize the internal state with the `value` prop
|
|
20
41
|
useEffect(() => {
|
|
21
42
|
setCurrentValue(value);
|
|
22
43
|
}, [value]);
|
|
44
|
+
// Recalculate the number of rows whenever the `currentValue` changes
|
|
23
45
|
useEffect(() => {
|
|
24
46
|
if (currentValue) {
|
|
25
47
|
const newRowCount = calculateRows(currentValue);
|
|
26
48
|
setCalculatedRows(newRowCount);
|
|
27
49
|
}
|
|
28
50
|
}, [currentValue]);
|
|
29
|
-
|
|
30
|
-
const lines = content.split('\n').length;
|
|
31
|
-
return Math.min(lines, 10);
|
|
32
|
-
};
|
|
51
|
+
// Populate the formula menu items whenever the `formulaItems` prop changes
|
|
33
52
|
useEffect(() => {
|
|
34
53
|
if (formulaItems && formulaItems.length > 0) {
|
|
35
54
|
let menuItems = [];
|
|
@@ -39,6 +58,24 @@ const TMTextArea = (props) => {
|
|
|
39
58
|
setFormulaMenuItems(menuItems);
|
|
40
59
|
}
|
|
41
60
|
}, [formulaItems]);
|
|
61
|
+
// Adjust the rows dynamically
|
|
62
|
+
const updateRows = () => {
|
|
63
|
+
const newRowCount = calculateRows(currentValue);
|
|
64
|
+
setCalculatedRows(newRowCount);
|
|
65
|
+
};
|
|
66
|
+
// Calculate the number of rows required to display the content
|
|
67
|
+
const calculateRows = (content) => {
|
|
68
|
+
if (!inputRef.current)
|
|
69
|
+
return rows ?? 1;
|
|
70
|
+
const textareaWidth = inputRef.current.offsetWidth;
|
|
71
|
+
const charWidth = 8;
|
|
72
|
+
const maxCharsPerLine = Math.floor(textareaWidth / charWidth);
|
|
73
|
+
const lines = content.split('\n').reduce((acc, line) => {
|
|
74
|
+
return acc + Math.ceil(line.length / maxCharsPerLine);
|
|
75
|
+
}, 0);
|
|
76
|
+
return Math.min(lines, 10);
|
|
77
|
+
};
|
|
78
|
+
// Inserts text at the cursor position
|
|
42
79
|
const insertText = (textToInsert) => {
|
|
43
80
|
if (inputRef?.current == null)
|
|
44
81
|
return;
|
|
@@ -56,6 +93,7 @@ const TMTextArea = (props) => {
|
|
|
56
93
|
TMExceptionBoxManager.show({ exception: e });
|
|
57
94
|
}
|
|
58
95
|
};
|
|
96
|
+
// Renders the textarea
|
|
59
97
|
const renderTextArea = () => {
|
|
60
98
|
return _jsxs(_Fragment, { children: [_jsx(StyledTextareaEditor, { ref: inputRef, autoFocus: autoFocus, readOnly: readOnly, disabled: disabled, value: currentValue, placeholder: placeHolder, rows: calculatedRows, maxLength: maxLength, onFocus: () => setIsFocused(true), onBlur: (e) => { setIsFocused(false); if (currentValue != value)
|
|
61
99
|
onBlur?.(currentValue); }, onChange: (e) => { setCurrentValue(e.target.value); onValueChanged?.(e); }, onContextMenu: (e) => {
|
|
@@ -74,6 +112,7 @@ const TMTextArea = (props) => {
|
|
|
74
112
|
return (_jsx(StyledEditorButtonIcon, { onClick: buttonItem.onClick, "$index": index, "$transform": '-26px', children: _jsx(TMTooltip, { content: buttonItem.text, children: buttonItem.icon }) }, index));
|
|
75
113
|
}), formulaItems.length > 0 && clicked && (_jsx(TMContextMenu, { menuData: formulaMenuItems, top: points.y, left: points.x, onMenuItemClick: (formula) => insertText(formula) })), _jsx(TMVilViewer, { vil: validationItems })] });
|
|
76
114
|
};
|
|
115
|
+
// Layout for the textarea with a left-aligned label
|
|
77
116
|
const renderedLeftLabelTextArea = () => {
|
|
78
117
|
return (_jsxs(TMLayoutContainer, { direction: 'horizontal', children: [icon && _jsx(TMLayoutItem, { width: '20px', children: _jsx(StyledEditorIcon, { "$disabled": disabled, "$vil": validationItems, "$isModified": isModifiedWhen, children: icon }) }), _jsx(TMLayoutItem, { children: _jsxs(StyledEditorContainer, { "$width": width, children: [label && _jsx(StyledEditorLabel, { "$isFocused": isFocused, "$labelPosition": labelPosition, "$disabled": disabled, children: label ?? '' }), renderTextArea()] }) })] }));
|
|
79
118
|
};
|
|
@@ -9,8 +9,9 @@ interface TMTreeDropDownProps {
|
|
|
9
9
|
}>;
|
|
10
10
|
values: Array<number>;
|
|
11
11
|
setValues: React.Dispatch<React.SetStateAction<Array<number>>>;
|
|
12
|
+
displayExpr: boolean;
|
|
12
13
|
isValidKey?: (key: number) => boolean;
|
|
13
|
-
elementStyle?: React.CSSProperties
|
|
14
|
+
elementStyle?: React.CSSProperties;
|
|
14
15
|
}
|
|
15
16
|
declare const TMTreeDropDown: (props: TMTreeDropDownProps) => import("react/jsx-runtime").JSX.Element;
|
|
16
17
|
export default TMTreeDropDown;
|
|
@@ -7,7 +7,7 @@ import TMTooltip from '../base/TMTooltip';
|
|
|
7
7
|
// The TMTreeDropDown functional component
|
|
8
8
|
const TMTreeDropDown = (props) => {
|
|
9
9
|
// Destructure props for easy access
|
|
10
|
-
const { dataSource, values, setValues, isValidKey, elementStyle } = props;
|
|
10
|
+
const { dataSource, values, setValues, displayExpr, isValidKey, elementStyle } = props;
|
|
11
11
|
// Reference to the TreeView component for programmatic control
|
|
12
12
|
const treeViewRef = useRef(null);
|
|
13
13
|
// Helper function to get a comma-separated string of labels for the selected IDs
|
|
@@ -49,6 +49,11 @@ const TMTreeDropDown = (props) => {
|
|
|
49
49
|
filteredKeys = selectedKeys.filter(isValidKey); // If a validation function is provided, filter the selected keys
|
|
50
50
|
setValues(filteredKeys);
|
|
51
51
|
}, []);
|
|
52
|
-
|
|
52
|
+
const displayValueFormatter = useCallback((value) => {
|
|
53
|
+
if (displayExpr)
|
|
54
|
+
return value.toString();
|
|
55
|
+
return SDKUI_Localizator.Filters;
|
|
56
|
+
}, []);
|
|
57
|
+
return _jsx(TMTooltip, { content: getLabelsByIds(values, 'formatted'), children: _jsx(DropDownBox, { width: "100%", style: elementStyle, valueExpr: "id", displayExpr: "label", displayValueFormatter: displayValueFormatter, value: values, dataSource: dataSource, placeholder: SDKUI_Localizator.SelectDesiredFilters, onContentReady: syncTreeViewSelection, focusStateEnabled: true, contentRender: () => _jsx(TreeView, { ref: treeViewRef, keyExpr: "id", dataSource: dataSource, selectByClick: true, selectNodesRecursive: true, selectionMode: "multiple", displayExpr: "label", parentIdExpr: "categoryId", dataStructure: "plain", showCheckBoxesMode: "normal", onContentReady: syncTreeViewSelection, onItemSelectionChanged: (e) => treeViewItemSelectionChanged(e) }) }) });
|
|
53
58
|
};
|
|
54
59
|
export default TMTreeDropDown;
|