-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathTextBox.tsx
124 lines (120 loc) · 3.34 KB
/
TextBox.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// SPDX-FileCopyrightText: Meta Platforms, Inc. and its affiliates
// SPDX-FileCopyrightText: TNG Technology Consulting GmbH <https://www.tngtech.com>
//
// SPDX-License-Identifier: Apache-2.0
import { SxProps } from '@mui/material';
import MuiBox from '@mui/material/Box';
import MuiInputAdornment from '@mui/material/InputAdornment';
import MuiTextField, { TextFieldProps } from '@mui/material/TextField';
import { OpossumColors } from '../../shared-styles';
import { ensureArray } from '../../util/ensure-array';
export const classes = {
textField: {
width: '100%',
'& div': {
backgroundColor: OpossumColors.white,
borderRadius: '0px',
},
'& label': {
backgroundColor: OpossumColors.white,
padding: '1px 3px',
fontSize: '13px',
},
'& span': {
padding: '0px',
},
'& legend': {
'& span': {
display: 'none',
},
},
'& .MuiOutlinedInput-notchedOutline': {
borderColor: 'rgb(192, 192, 192)',
},
'& .Mui-readOnly:hover:not(.Mui-focused) fieldset': {
borderColor: 'rgb(192, 192, 192)',
},
},
defaultHighlightedTextField: {
'& div': {
backgroundColor: OpossumColors.lightOrange,
borderRadius: '0px',
},
'& label': {
backgroundColor: OpossumColors.lightOrange,
padding: '1px 3px',
},
},
endAdornmentRoot: {
position: 'absolute',
right: 0,
marginRight: '14px',
height: 0,
},
} satisfies SxProps;
export interface TextBoxProps {
color?: TextFieldProps['color'];
placeholder?: string;
disabled?: boolean;
expanded?: boolean;
focused?: boolean;
handleChange?: (
event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
) => void;
error?: boolean;
maxRows?: number;
minRows?: number;
multiline?: boolean;
readOnly?: boolean;
sx?: SxProps;
text?: string;
title: string;
endIcon?: React.ReactElement | Array<React.ReactElement>;
}
export function TextBox(props: TextBoxProps) {
return (
<MuiBox sx={props.sx}>
<MuiTextField
disabled={props.disabled}
placeholder={props.placeholder}
sx={{
...classes.textField,
...(props.error && classes.defaultHighlightedTextField),
}}
label={props.title}
focused={props.focused}
color={props.color}
InputLabelProps={{
shrink: !!props.placeholder || !!props.text,
}}
InputProps={{
readOnly: props.readOnly,
slotProps: { root: { sx: { padding: 0 } } },
inputProps: {
'aria-label': props.title,
sx: {
overflowX: 'hidden',
textOverflow: 'ellipsis',
paddingTop: '8.5px',
paddingBottom: '8.5px',
paddingLeft: '14px',
paddingRight: `calc(14px + ${ensureArray(props.endIcon).length} * 28px)`,
},
},
endAdornment: props.endIcon && (
<MuiInputAdornment sx={classes.endAdornmentRoot} position="end">
{props.endIcon}
</MuiInputAdornment>
),
}}
multiline={props.multiline}
minRows={props.expanded ? props.maxRows : props.minRows}
maxRows={props.maxRows}
variant="outlined"
size="small"
value={props.text || ''}
onChange={props.handleChange}
/>
</MuiBox>
);
}