Add visibility toggle of password input. Closes #2
parent
a11f6260c0
commit
00c7f514ae
@ -1,19 +1,8 @@
|
|||||||
import usePrevious from './use-previous';
|
|
||||||
import useField from './use-field';
|
import useField from './use-field';
|
||||||
import useForm from './use-form';
|
import useForm from './use-form';
|
||||||
import useSteps from './use-steps';
|
import useSteps from './use-steps';
|
||||||
import useToggle from './use-toggle';
|
|
||||||
import useForceUpdate from './use-force-update';
|
|
||||||
import useClosableForm from './use-closable-form';
|
import useClosableForm from './use-closable-form';
|
||||||
import useDidUpdate from './use-did-update';
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
usePrevious,
|
useField, useForm, useSteps, useClosableForm,
|
||||||
useField,
|
|
||||||
useForm,
|
|
||||||
useSteps,
|
|
||||||
useToggle,
|
|
||||||
useForceUpdate,
|
|
||||||
useClosableForm,
|
|
||||||
useDidUpdate,
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,28 +1,11 @@
|
|||||||
import React from 'react';
|
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import { Input as SemanticUIInput } from 'semantic-ui-react';
|
import { Input as SemanticUIInput } from 'semantic-ui-react';
|
||||||
|
|
||||||
import MaskedInput from './MaskedInput';
|
import InputPassword from './InputPassword';
|
||||||
|
import InputMask from './InputMask';
|
||||||
|
|
||||||
const Input = React.forwardRef(({ mask, maskChar, ...props }, ref) => {
|
const Input = SemanticUIInput;
|
||||||
const nextProps = props;
|
|
||||||
|
|
||||||
if (mask) {
|
Input.Password = InputPassword;
|
||||||
nextProps.input = <MaskedInput mask={mask} maskChar={maskChar} />;
|
Input.Mask = InputMask;
|
||||||
}
|
|
||||||
|
|
||||||
// eslint-disable-next-line react/jsx-props-no-spreading
|
export default Input;
|
||||||
return <SemanticUIInput {...nextProps} ref={ref} />;
|
|
||||||
});
|
|
||||||
|
|
||||||
Input.propTypes = {
|
|
||||||
mask: PropTypes.string,
|
|
||||||
maskChar: PropTypes.string,
|
|
||||||
};
|
|
||||||
|
|
||||||
Input.defaultProps = {
|
|
||||||
mask: undefined,
|
|
||||||
maskChar: undefined,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default React.memo(Input);
|
|
||||||
|
|||||||
@ -0,0 +1,21 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { Input } from 'semantic-ui-react';
|
||||||
|
|
||||||
|
import MaskedInput from './MaskedInput';
|
||||||
|
|
||||||
|
const InputMask = React.forwardRef(({ mask, maskChar, ...props }, ref) => (
|
||||||
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
||||||
|
<Input {...props} ref={ref} input={<MaskedInput mask={mask} maskChar={maskChar} />} />
|
||||||
|
));
|
||||||
|
|
||||||
|
InputMask.propTypes = {
|
||||||
|
mask: PropTypes.string.isRequired,
|
||||||
|
maskChar: PropTypes.string,
|
||||||
|
};
|
||||||
|
|
||||||
|
InputMask.defaultProps = {
|
||||||
|
maskChar: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default React.memo(InputMask);
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
import React, { useCallback } from 'react';
|
||||||
|
import { Icon, Input } from 'semantic-ui-react';
|
||||||
|
import { useToggle } from '../../../hooks';
|
||||||
|
|
||||||
|
const InputPassword = React.forwardRef((props, ref) => {
|
||||||
|
const [isHidden, toggleHidden] = useToggle(true);
|
||||||
|
|
||||||
|
const handleToggleClick = useCallback(() => {
|
||||||
|
toggleHidden();
|
||||||
|
}, [toggleHidden]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Input
|
||||||
|
{...props} // eslint-disable-line react/jsx-props-no-spreading
|
||||||
|
ref={ref}
|
||||||
|
type={isHidden ? 'password' : 'text'}
|
||||||
|
icon={<Icon link name={isHidden ? 'eye slash' : 'eye'} onClick={handleToggleClick} />}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default React.memo(InputPassword);
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
import usePrevious from './use-previous';
|
||||||
|
import useToggle from './use-toggle';
|
||||||
|
import useForceUpdate from './use-force-update';
|
||||||
|
import useDidUpdate from './use-did-update';
|
||||||
|
|
||||||
|
export {
|
||||||
|
usePrevious, useToggle, useForceUpdate, useDidUpdate,
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue