@topconsultnpm/sdkui-react-beta 6.5.57 → 6.5.59
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/lib/components/editors/TMEditorStyled.d.ts +9 -0
- package/lib/components/editors/TMEditorStyled.js +42 -0
- package/lib/components/editors/TMTextArea.d.ts +19 -0
- package/lib/components/editors/TMTextArea.js +71 -0
- package/lib/components/index.d.ts +1 -0
- package/lib/components/index.js +1 -0
- package/package.json +1 -1
|
@@ -28,3 +28,12 @@ export declare const StyledEditorButtonIcon: import("styled-components/dist/type
|
|
|
28
28
|
$index: number;
|
|
29
29
|
$transform: string;
|
|
30
30
|
}>> & string;
|
|
31
|
+
export declare const StyledTextareaEditor: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, {
|
|
32
|
+
$vil: ValidationItem[];
|
|
33
|
+
$width: string;
|
|
34
|
+
$isModified: boolean;
|
|
35
|
+
$fontSize: string;
|
|
36
|
+
$disabled: boolean;
|
|
37
|
+
$isMobile?: boolean;
|
|
38
|
+
$maxHeight?: string;
|
|
39
|
+
}>> & string;
|
|
@@ -73,3 +73,45 @@ export const StyledEditorButtonIcon = styled.div `
|
|
|
73
73
|
border-bottom-color: ${TMColors.primary};
|
|
74
74
|
}
|
|
75
75
|
`;
|
|
76
|
+
export const StyledTextareaEditor = styled.textarea `
|
|
77
|
+
width: ${props => props.$width};
|
|
78
|
+
padding: 8px 13px;
|
|
79
|
+
border: 1px solid;
|
|
80
|
+
border-color: ${props => props.$isModified ? TMColors.isModified : TMColors.border_normal};
|
|
81
|
+
border-bottom: ${props => (props.$vil.length > 0) ? '3px' : '1px'} solid;
|
|
82
|
+
border-bottom-color: ${props => props.$vil.length === 0
|
|
83
|
+
? !props.$isModified
|
|
84
|
+
? TMColors.border_normal
|
|
85
|
+
: TMColors.isModified
|
|
86
|
+
: editorColorManager(props.$vil)};
|
|
87
|
+
color: ${props => !props.$disabled
|
|
88
|
+
? props.$vil.length === 0
|
|
89
|
+
? !props.$isModified
|
|
90
|
+
? 'black'
|
|
91
|
+
: TMColors.isModified
|
|
92
|
+
: editorColorManager(props.$vil)
|
|
93
|
+
: TMColors.disabled};
|
|
94
|
+
border-radius: 4px; /* Slightly increased radius for smoother corners */
|
|
95
|
+
min-width: ${props => (props.$isMobile ? '70px' : '100%')}; /* Adjust for mobile */
|
|
96
|
+
max-height: ${props => props.$maxHeight || 'auto'};
|
|
97
|
+
&:focus {
|
|
98
|
+
outline: none;
|
|
99
|
+
background-image: linear-gradient(white, #E4E9F7);
|
|
100
|
+
border: ${props => props.$isModified
|
|
101
|
+
? `1px solid ${TMColors.isModified}`
|
|
102
|
+
: '1px solid rgb(180,180,180)'};
|
|
103
|
+
border-bottom: 2px solid;
|
|
104
|
+
border-bottom-color: ${props => props.$vil.length === 0
|
|
105
|
+
? !props.$isModified
|
|
106
|
+
? TMColors.primary
|
|
107
|
+
: TMColors.isModified
|
|
108
|
+
: editorColorManager(props.$vil)};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
font-size: ${props => props.$fontSize};
|
|
112
|
+
|
|
113
|
+
&::placeholder {
|
|
114
|
+
color: ${props => (props.$vil.length === 0) ? 'gray' : editorColorManager(props.$vil)};
|
|
115
|
+
font-size: ${props => props.$fontSize};
|
|
116
|
+
}
|
|
117
|
+
`;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React, { ChangeEvent } from 'react';
|
|
2
|
+
import { ITMEditorBase } from '../base/TMEditorBase';
|
|
3
|
+
export type TMTextAreaButtonData = {
|
|
4
|
+
icon: any;
|
|
5
|
+
text?: string;
|
|
6
|
+
onClick?: () => void;
|
|
7
|
+
};
|
|
8
|
+
interface ITMTextArea extends ITMEditorBase {
|
|
9
|
+
value: string;
|
|
10
|
+
onValueChanged: ((e: ChangeEvent<HTMLTextAreaElement>) => void) | undefined;
|
|
11
|
+
formulaItems?: Array<string>;
|
|
12
|
+
buttons?: Array<TMTextAreaButtonData>;
|
|
13
|
+
onBlur?: (value: string | undefined) => void;
|
|
14
|
+
autoFocus?: boolean;
|
|
15
|
+
maxValue?: number;
|
|
16
|
+
maxHeight?: string;
|
|
17
|
+
}
|
|
18
|
+
declare const TMTextArea: React.FunctionComponent<ITMTextArea>;
|
|
19
|
+
export default TMTextArea;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect, useRef } from 'react';
|
|
3
|
+
import { StyledEditorButtonIcon, StyledEditorContainer, StyledEditorIcon, StyledEditorLabel, StyledTextareaEditor } from './TMEditorStyled';
|
|
4
|
+
import { FontSize } from '../../utils/theme';
|
|
5
|
+
import { useWindowWidth } from '../../helper';
|
|
6
|
+
import TMContextMenu, { useContextMenu } from '../base/TMContextMenu';
|
|
7
|
+
import { TMExceptionBoxManager } from '../base/TMPopUp';
|
|
8
|
+
import TMLayoutContainer, { TMLayoutItem } from '../base/TMLayout';
|
|
9
|
+
import TMVilViewer from '../base/TMVilViewer';
|
|
10
|
+
import TMTooltip from '../base/TMTooltip';
|
|
11
|
+
const TMTextArea = (props) => {
|
|
12
|
+
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' } = props;
|
|
13
|
+
const inputRef = useRef(null);
|
|
14
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
15
|
+
const [currentValue, setCurrentValue] = useState(value);
|
|
16
|
+
const [formulaMenuItems, setFormulaMenuItems] = useState([]);
|
|
17
|
+
const { clicked, setClicked, points, setPoints } = useContextMenu();
|
|
18
|
+
let screenWidth = useWindowWidth();
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
setCurrentValue(value);
|
|
21
|
+
}, [value]);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (formulaItems && formulaItems.length > 0) {
|
|
24
|
+
let menuItems = [];
|
|
25
|
+
for (const formula of formulaItems) {
|
|
26
|
+
menuItems.push({ text: formula });
|
|
27
|
+
}
|
|
28
|
+
setFormulaMenuItems(menuItems);
|
|
29
|
+
}
|
|
30
|
+
}, [formulaItems]);
|
|
31
|
+
const insertText = (textToInsert) => {
|
|
32
|
+
if (inputRef?.current == null)
|
|
33
|
+
return;
|
|
34
|
+
try {
|
|
35
|
+
let cursorposition = inputRef.current?.selectionStart;
|
|
36
|
+
let textbeforecursorposition = inputRef.current?.value.substring(0, cursorposition);
|
|
37
|
+
let textaftercursorposition = inputRef.current?.value.substring(cursorposition, inputRef.current?.value.length);
|
|
38
|
+
let newValue = textbeforecursorposition + textToInsert + textaftercursorposition;
|
|
39
|
+
inputRef.current.value = newValue;
|
|
40
|
+
onValueChanged?.({ target: { value: newValue } });
|
|
41
|
+
inputRef.current.focus();
|
|
42
|
+
inputRef.current.selectionStart = inputRef.current.selectionEnd = cursorposition + textToInsert.length;
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
TMExceptionBoxManager.show({ exception: e });
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const renderTextArea = () => {
|
|
49
|
+
return _jsxs(_Fragment, { children: [_jsx(StyledTextareaEditor, { ref: inputRef, autoFocus: autoFocus, readOnly: readOnly, disabled: disabled, value: currentValue, placeholder: placeHolder, onFocus: () => setIsFocused(true), onBlur: (e) => { setIsFocused(false); if (currentValue != value)
|
|
50
|
+
onBlur?.(currentValue); }, onChange: (e) => { setCurrentValue(e.target.value); onValueChanged?.(e); }, onContextMenu: (e) => {
|
|
51
|
+
if (formulaItems.length <= 0)
|
|
52
|
+
return;
|
|
53
|
+
// prevent default right click behavior
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
// set our click state to true when a user right clicks
|
|
56
|
+
setClicked(true);
|
|
57
|
+
const bounds = e.currentTarget.getBoundingClientRect();
|
|
58
|
+
const x = e.clientX - bounds.left;
|
|
59
|
+
const y = e.clientY - bounds.top;
|
|
60
|
+
// set the x and y coordinates of our users right click
|
|
61
|
+
setPoints({ x, y });
|
|
62
|
+
}, "$isMobile": screenWidth < 640, "$maxHeight": maxHeight, "$disabled": disabled, "$vil": validationItems, "$isModified": isModifiedWhen, "$fontSize": fontSize, "$width": width }), buttons.map((buttonItem, index) => {
|
|
63
|
+
return (_jsx(StyledEditorButtonIcon, { onClick: buttonItem.onClick, "$index": index, "$transform": '-26px', children: _jsx(TMTooltip, { content: buttonItem.text, children: buttonItem.icon }) }, index));
|
|
64
|
+
}), formulaItems.length > 0 && clicked && (_jsx(TMContextMenu, { menuData: formulaMenuItems, top: points.y, left: points.x, onMenuItemClick: (formula) => insertText(formula) })), _jsx(TMVilViewer, { vil: validationItems })] });
|
|
65
|
+
};
|
|
66
|
+
const renderedLeftLabelTextArea = () => {
|
|
67
|
+
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, "$fontSize": fontSize, children: label ?? '' }), renderTextArea()] }) })] }));
|
|
68
|
+
};
|
|
69
|
+
return (_jsx("div", { style: elementStyle, children: renderedLeftLabelTextArea() }));
|
|
70
|
+
};
|
|
71
|
+
export default TMTextArea;
|
|
@@ -18,6 +18,7 @@ export { default as TMVilViewer } from './base/TMVilViewer';
|
|
|
18
18
|
export { default as TMDropDown } from './editors/TMDropDown';
|
|
19
19
|
export { default as TMSummary } from './editors/TMSummary';
|
|
20
20
|
export { default as TMTextBox } from './editors/TMTextBox';
|
|
21
|
+
export { default as TMTextArea } from './editors/TMTextArea';
|
|
21
22
|
export { default as TMCheckBox } from './editors/TMCheckBox';
|
|
22
23
|
export { default as TMRadioButton } from './editors/TMRadioButton';
|
|
23
24
|
export { default as TMDateBox } from './editors/TMDateBox';
|
package/lib/components/index.js
CHANGED
|
@@ -21,6 +21,7 @@ export { default as TMVilViewer } from './base/TMVilViewer';
|
|
|
21
21
|
export { default as TMDropDown } from './editors/TMDropDown';
|
|
22
22
|
export { default as TMSummary } from './editors/TMSummary';
|
|
23
23
|
export { default as TMTextBox } from './editors/TMTextBox';
|
|
24
|
+
export { default as TMTextArea } from './editors/TMTextArea';
|
|
24
25
|
export { default as TMCheckBox } from './editors/TMCheckBox';
|
|
25
26
|
export { default as TMRadioButton } from './editors/TMRadioButton';
|
|
26
27
|
export { default as TMDateBox } from './editors/TMDateBox';
|