ToolJet/frontend/src/Editor/Components/TextInput.jsx
Sherfin Shamsudeen 4bd2fd74d0
Add support for ListView inside ListView (#3454)
* Add support for ListView inside ListView

* Remove unnecessary triggering mechanism for useEffect in ListView

* Remove unnecessary extraProps param
2022-07-02 18:00:30 +05:30

35 lines
1.2 KiB
JavaScript

import React, { useEffect, useState } from 'react';
export const TextInput = function TextInput({ height, validate, properties, styles, setExposedVariable, fireEvent }) {
const [value, setValue] = useState(properties.value);
const { isValid, validationError } = validate(value);
useEffect(() => {
setExposedVariable('isValid', isValid);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isValid]);
useEffect(() => {
setValue(properties.value);
setExposedVariable('value', properties.value);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [properties.value]);
return (
<div className="text-input">
<input
disabled={styles.disabledState}
onChange={(e) => {
setValue(e.target.value);
setExposedVariable('value', e.target.value);
fireEvent('onChange');
}}
type="text"
className={`form-control ${!isValid ? 'is-invalid' : ''} validation-without-icon`}
placeholder={properties.placeholder}
style={{ height, display: styles.visibility ? '' : 'none', borderRadius: `${styles.borderRadius}px` }}
value={value}
/>
<div className="invalid-feedback">{validationError}</div>
</div>
);
};