2021-12-14 11:18:25 +00:00
|
|
|
import React from 'react';
|
2021-10-21 16:23:11 +00:00
|
|
|
|
2022-11-03 14:04:37 +00:00
|
|
|
export const PasswordInput = ({
|
|
|
|
|
height,
|
|
|
|
|
validate,
|
|
|
|
|
properties,
|
|
|
|
|
styles,
|
|
|
|
|
setExposedVariable,
|
|
|
|
|
darkMode,
|
|
|
|
|
component,
|
|
|
|
|
fireEvent,
|
|
|
|
|
}) => {
|
2022-10-26 04:35:23 +00:00
|
|
|
const { visibility, disabledState, borderRadius, backgroundColor } = styles;
|
2022-11-03 11:32:38 +00:00
|
|
|
|
2021-12-14 11:18:25 +00:00
|
|
|
const placeholder = properties.placeholder;
|
2021-10-21 16:23:11 +00:00
|
|
|
|
2022-09-12 07:04:27 +00:00
|
|
|
const [passwordValue, setPasswordValue] = React.useState('');
|
|
|
|
|
const { isValid, validationError } = validate(passwordValue);
|
2021-10-21 16:23:11 +00:00
|
|
|
|
2022-09-12 07:04:27 +00:00
|
|
|
React.useEffect(() => {
|
2021-12-14 11:18:25 +00:00
|
|
|
setExposedVariable('isValid', isValid);
|
2022-09-12 07:04:27 +00:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, [passwordValue, isValid]);
|
2021-10-21 16:23:11 +00:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<input
|
2021-12-14 11:18:25 +00:00
|
|
|
disabled={disabledState}
|
2021-10-21 16:23:11 +00:00
|
|
|
onChange={(e) => {
|
2022-09-12 07:04:27 +00:00
|
|
|
setPasswordValue(e.target.value);
|
2022-11-03 14:04:37 +00:00
|
|
|
setExposedVariable('value', e.target.value).then(() => fireEvent('onChange'));
|
2021-10-21 16:23:11 +00:00
|
|
|
}}
|
|
|
|
|
type={'password'}
|
2022-09-12 03:48:46 +00:00
|
|
|
className={`form-control ${!isValid ? 'is-invalid' : ''} validation-without-icon ${
|
|
|
|
|
darkMode && 'dark-theme-placeholder'
|
|
|
|
|
}`}
|
2021-10-21 16:23:11 +00:00
|
|
|
placeholder={placeholder}
|
2022-09-12 07:04:27 +00:00
|
|
|
value={passwordValue}
|
2022-10-26 04:35:23 +00:00
|
|
|
style={{
|
|
|
|
|
height,
|
|
|
|
|
display: visibility ? '' : 'none',
|
|
|
|
|
borderRadius: `${borderRadius}px`,
|
|
|
|
|
backgroundColor,
|
|
|
|
|
}}
|
2022-10-14 11:46:09 +00:00
|
|
|
data-cy={`draggable-widget-${String(component.name).toLowerCase()}`}
|
2021-10-21 16:23:11 +00:00
|
|
|
/>
|
2022-10-14 11:46:09 +00:00
|
|
|
<div className="invalid-feedback" data-cy={`${String(component.name).toLowerCase()}-invalid-feedback`}>
|
|
|
|
|
{validationError}
|
|
|
|
|
</div>
|
2021-10-21 16:23:11 +00:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|