web: Components: Added onValidateInput and onCopyToClipboard callback`s for PasswordInput component. Fixed story, README and some console warnings.
This commit is contained in:
parent
13674843d5
commit
d08461db20
@ -9,7 +9,9 @@ import Link from '../link'
|
||||
import { Text } from '../text'
|
||||
import DropDown from '../drop-down'
|
||||
|
||||
const StyledInput = styled.div`
|
||||
const SimpleInput = ({ onValidateInput, onCopyToClipboard, ...props }) => <div {...props}></div>;
|
||||
|
||||
const StyledInput = styled(SimpleInput)`
|
||||
display: flex;
|
||||
align-items: center;
|
||||
line-height: 32px;
|
||||
@ -120,7 +122,7 @@ class PasswordInput extends React.PureComponent {
|
||||
digits: digits,
|
||||
capital: capital,
|
||||
special: special,
|
||||
length: value.length >= passwordSettings.minLength
|
||||
length: value.trim().length >= passwordSettings.minLength
|
||||
};
|
||||
}
|
||||
|
||||
@ -132,13 +134,15 @@ class PasswordInput extends React.PureComponent {
|
||||
&& passwordValidation.capital
|
||||
&& passwordValidation.special
|
||||
&& passwordValidation.length;
|
||||
const progressWidth = value.length * 100 / this.props.passwordSettings.minLength;
|
||||
const progressWidth = value.trim().length * 100 / this.props.passwordSettings.minLength;
|
||||
const progressColor = progressScore
|
||||
? greenColor
|
||||
: (value.length === 0)
|
||||
? 'transparent'
|
||||
: redColor;
|
||||
|
||||
this.props.onValidateInput && this.props.onValidateInput(progressScore);
|
||||
|
||||
this.setState({
|
||||
progressColor: progressColor,
|
||||
progressWidth: progressWidth > 100 ? 100 : progressWidth,
|
||||
@ -183,12 +187,12 @@ class PasswordInput extends React.PureComponent {
|
||||
|
||||
if (passwordSettings.upperCase) {
|
||||
hold = (password.length % 2 == 0)
|
||||
? (hold.toUpperCase())
|
||||
: (hold);
|
||||
? (hold.toUpperCase())
|
||||
: (hold);
|
||||
}
|
||||
|
||||
character += hold;
|
||||
|
||||
|
||||
if (passwordSettings.digits) {
|
||||
character += numeric.charAt(b);
|
||||
}
|
||||
@ -196,7 +200,7 @@ class PasswordInput extends React.PureComponent {
|
||||
if (passwordSettings.specSymbols) {
|
||||
character += special.charAt(c);
|
||||
}
|
||||
|
||||
|
||||
password = character;
|
||||
}
|
||||
|
||||
@ -209,23 +213,26 @@ class PasswordInput extends React.PureComponent {
|
||||
}
|
||||
|
||||
copyToClipboard = emailInputName => {
|
||||
const { clipEmailResource, clipPasswordResource, isDisabled } = this.props;
|
||||
const { clipEmailResource, clipPasswordResource, isDisabled, onCopyToClipboard } = this.props;
|
||||
|
||||
if (isDisabled)
|
||||
return event.preventDefault();
|
||||
|
||||
const textField = document.createElement('textarea');
|
||||
const emailValue = document.getElementsByName(emailInputName)[0].value;
|
||||
const formattedText = clipEmailResource + emailValue + ' | ' + clipPasswordResource + this.state.inputValue;
|
||||
|
||||
textField.innerText = clipEmailResource + emailValue + ' | ' + clipPasswordResource + this.state.inputValue;
|
||||
|
||||
textField.innerText = formattedText;
|
||||
document.body.appendChild(textField);
|
||||
textField.select();
|
||||
document.execCommand('copy');
|
||||
textField.remove();
|
||||
|
||||
onCopyToClipboard && onCopyToClipboard(formattedText);
|
||||
}
|
||||
|
||||
render() {
|
||||
//console.log('PasswordInput render()');
|
||||
const {
|
||||
inputName,
|
||||
isDisabled,
|
||||
@ -244,7 +251,8 @@ class PasswordInput extends React.PureComponent {
|
||||
hasWarning,
|
||||
placeholder,
|
||||
tabIndex,
|
||||
maxLength
|
||||
maxLength,
|
||||
onValidateInput
|
||||
} = this.props;
|
||||
const {
|
||||
type,
|
||||
@ -272,20 +280,20 @@ class PasswordInput extends React.PureComponent {
|
||||
</StyledTooltipItem>
|
||||
}
|
||||
{passwordSettings.upperCase &&
|
||||
<StyledTooltipItem forwardedAs='div' title={tooltipPasswordCapital} valid={validCapital} >
|
||||
{tooltipPasswordCapital}
|
||||
</StyledTooltipItem>
|
||||
<StyledTooltipItem forwardedAs='div' title={tooltipPasswordCapital} valid={validCapital} >
|
||||
{tooltipPasswordCapital}
|
||||
</StyledTooltipItem>
|
||||
}
|
||||
{passwordSettings.specSymbols &&
|
||||
<StyledTooltipItem forwardedAs='div' title={tooltipPasswordSpecial} valid={validSpecial} >
|
||||
{tooltipPasswordSpecial}
|
||||
</StyledTooltipItem>
|
||||
<StyledTooltipItem forwardedAs='div' title={tooltipPasswordSpecial} valid={validSpecial} >
|
||||
{tooltipPasswordSpecial}
|
||||
</StyledTooltipItem>
|
||||
}
|
||||
</StyledTooltipContainer>
|
||||
);
|
||||
|
||||
return (
|
||||
<StyledInput>
|
||||
<StyledInput onValidateInput={onValidateInput}>
|
||||
<PasswordProgress inputWidth={inputWidth}>
|
||||
<InputBlock
|
||||
name={inputName}
|
||||
@ -363,21 +371,24 @@ PasswordInput.propTypes = {
|
||||
tooltipPasswordSpecial: PropTypes.string,
|
||||
|
||||
generatorSpecial: PropTypes.string,
|
||||
passwordSettings: PropTypes.object.isRequired
|
||||
passwordSettings: PropTypes.object.isRequired,
|
||||
|
||||
onValidateInput: PropTypes.func,
|
||||
onCopyToClipboard: PropTypes.func
|
||||
}
|
||||
|
||||
PasswordInput.defaultProps = {
|
||||
inputType: 'password',
|
||||
inputName: 'passwordInput',
|
||||
|
||||
isDisabled: false,
|
||||
size: 'base',
|
||||
scale: true,
|
||||
|
||||
clipEmailResource: 'E-mail',
|
||||
clipPasswordResource: 'Password',
|
||||
clipEmailResource: 'E-mail ',
|
||||
clipPasswordResource: 'Password ',
|
||||
|
||||
generatorSpecial: '!@#$%^&*'
|
||||
|
||||
}
|
||||
|
||||
export default PasswordInput;
|
@ -19,7 +19,7 @@ Check for compliance with settings is carried out on fly. As you type in require
|
||||
|
||||
Depending on screen width of device, input will change location of elements.
|
||||
|
||||
When setting focus to input, tooltip will be shown with progress in fulfilling conditions specified in settings. When unfocused, tooltip disappears.
|
||||
When setting focus to input, tooltip will be shown with progress in fulfilling conditions specified in settings. When unfocused, tooltip disappears.
|
||||
|
||||
You can apply all the parameters of the InputBlock component to the component.
|
||||
|
||||
@ -53,27 +53,32 @@ const settings = {
|
||||
generatorSpecial="!@#$%^&*"
|
||||
passwordSettings={settings}
|
||||
isDisabled={false}
|
||||
placeholder="password"
|
||||
onValidateInput={a => console.log(a)}
|
||||
onCopyToClipboard={b => console.log("Data " + b + " copied to clipboard")}
|
||||
/>;
|
||||
```
|
||||
|
||||
#### Properties
|
||||
|
||||
| Props | Type | Required | Values | Default | Description |
|
||||
| ------------------- | --------- | :------: | ------------------ | --------- | --------------------------------------------------------- |
|
||||
| `inputType` | `array` | - | `text`, `password` | `password`| It is necessary for correct display of values inside input|
|
||||
| `inputName` | `string` | - | - | `passwordInput`| Input name |
|
||||
| `emailInputName` | `string` | ✅ | - | - | Required to associate password field with email field |
|
||||
| `inputValue` | `string` | - | - | - | Input value |
|
||||
| `onChange` | `func` | - | - | - | Will be triggered whenever an PasswordInput typing |
|
||||
| `clipActionResource`| `string` | - | - | - | Translation of text for copying email data and password |
|
||||
| `clipEmailResource` | `string` | - | - | `E-mail` | Text translation email to copy |
|
||||
| `clipPasswordResource`| `string` | - | - | `Password`| Text translation password to copy |
|
||||
| `tooltipPasswordTitle`| `string` | - | - | - | Text translation tooltip |
|
||||
| `tooltipPasswordLength`| `string` | - | - | - | Password text translation is long tooltip |
|
||||
| `tooltipPasswordDigits`| `string` | - | - | - | Digit text translation tooltip |
|
||||
| `tooltipPasswordCapital`| `string` |- | - | - | Capital text translation tooltip |
|
||||
| `tooltipPasswordSpecial`| `string` |- | - | - | Special text translation tooltip |
|
||||
| `generatorSpecial` | `string` | - | - | `!@#$%^&*`| Set of special characters for password generator and validator|
|
||||
| `passwordSettings` | `object` | ✅ | - | - | Set of settings for password generator and validator |
|
||||
| `isDisabled` | `bool` | - | - | `false` | Set input disabled |
|
||||
| `inputWidth` | `string` | - | - | - | If you need to set input width manually |
|
||||
| Props | Type | Required | Values | Default | Description |
|
||||
| ------------------------ | -------- | :------: | ------------------ | --------------- | -------------------------------------------------------------- |
|
||||
| `inputType` | `array` | - | `text`, `password` | `password` | It is necessary for correct display of values inside input |
|
||||
| `inputName` | `string` | - | - | `passwordInput` | Input name |
|
||||
| `emailInputName` | `string` | ✅ | - | - | Required to associate password field with email field |
|
||||
| `inputValue` | `string` | - | - | - | Input value |
|
||||
| `onChange` | `func` | - | - | - | Will be triggered whenever an PasswordInput typing |
|
||||
| `clipActionResource` | `string` | - | - | - | Translation of text for copying email data and password |
|
||||
| `clipEmailResource` | `string` | - | - | `E-mail` | Text translation email to copy |
|
||||
| `clipPasswordResource` | `string` | - | - | `Password` | Text translation password to copy |
|
||||
| `tooltipPasswordTitle` | `string` | - | - | - | Text translation tooltip |
|
||||
| `tooltipPasswordLength` | `string` | - | - | - | Password text translation is long tooltip |
|
||||
| `tooltipPasswordDigits` | `string` | - | - | - | Digit text translation tooltip |
|
||||
| `tooltipPasswordCapital` | `string` | - | - | - | Capital text translation tooltip |
|
||||
| `tooltipPasswordSpecial` | `string` | - | - | - | Special text translation tooltip |
|
||||
| `generatorSpecial` | `string` | - | - | `!@#$%^&*` | Set of special characters for password generator and validator |
|
||||
| `passwordSettings` | `object` | ✅ | - | - | Set of settings for password generator and validator |
|
||||
| `isDisabled` | `bool` | - | - | `false` | Set input disabled |
|
||||
| `inputWidth` | `string` | - | - | - | If you need to set input width manually |
|
||||
| `onValidateInput` | `func` | - | - | - | Will be triggered whenever an PasswordInput typing, return bool value|
|
||||
| `onCopyToClipboard` | `func` | - | - | - | Will be triggered if you press copy button, return formatted value|
|
@ -60,6 +60,8 @@ storiesOf('Components|Input', module)
|
||||
isDisabled={isDisabled}
|
||||
placeholder='password'
|
||||
maxLength={30}
|
||||
onValidateInput={(a) => console.log(a)}
|
||||
onCopyToClipboard={(b) => console.log('Data ' + b + ' copied to clipboard')}
|
||||
/>
|
||||
)}
|
||||
</StringValue>
|
||||
|
Loading…
Reference in New Issue
Block a user