forked from ToolJet/ToolJet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableRowHeightInput.jsx
More file actions
54 lines (47 loc) · 1.62 KB
/
TableRowHeightInput.jsx
File metadata and controls
54 lines (47 loc) · 1.62 KB
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
import React, { useEffect, useState } from 'react';
const MIN_TABLE_ROW_HEIGHT_CONDENSED = 39;
const MIN_TABLE_ROW_HEIGHT_DEFAULT = 45;
const TableRowHeightInput = ({ value, onChange, cyLabel, staticText, styleDefinition }) => {
const [inputValue, setInputValue] = useState(value);
useEffect(() => {
setInputValue(value < minValue ? minValue : value);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [value, styleDefinition.cellSize?.value]);
useEffect(() => {
onChange(
styleDefinition.cellSize?.value === 'condensed' ? MIN_TABLE_ROW_HEIGHT_CONDENSED : MIN_TABLE_ROW_HEIGHT_DEFAULT
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const minValue =
styleDefinition.cellSize?.value === 'condensed' ? MIN_TABLE_ROW_HEIGHT_CONDENSED : MIN_TABLE_ROW_HEIGHT_DEFAULT;
const handleBlur = () => {
const newValue = Math.max(inputValue, minValue);
setInputValue(newValue);
onChange(newValue);
};
const handleChange = (e) => {
setInputValue(e.target.value);
};
return (
<div className="form-text tj-number-input-element">
<input
style={{ width: '142px', height: '32px' }}
data-cy={`${cyLabel}-input`}
type="number"
className="tj-input-element tj-text-xsm"
value={inputValue}
placeholder=""
id="labelId"
min={minValue}
onChange={handleChange}
onBlur={handleBlur}
autoComplete="off"
/>
<label htmlFor="labelId" className="static-value tj-text-xsm">
{staticText ? staticText : 'px'}
</label>
</div>
);
};
export default TableRowHeightInput;