2016-07-31 19:23:16 +05:30
|
|
|
import React, { PropTypes } from 'react';
|
|
|
|
|
2016-08-05 11:28:24 +05:30
|
|
|
import classNames from 'classnames';
|
|
|
|
|
2016-07-31 19:23:16 +05:30
|
|
|
import captcha from 'services/captcha';
|
|
|
|
import { skins, SKIN_DARK } from 'components/ui';
|
2016-08-14 14:29:23 +05:30
|
|
|
import { ComponentLoader } from 'components/ui/loader';
|
2016-07-31 19:23:16 +05:30
|
|
|
|
|
|
|
import styles from './form.scss';
|
|
|
|
import FormInputComponent from './FormInputComponent';
|
|
|
|
|
|
|
|
export default class Captcha extends FormInputComponent {
|
|
|
|
static displayName = 'Captcha';
|
|
|
|
|
|
|
|
static propTypes = {
|
2016-08-14 14:29:23 +05:30
|
|
|
skin: PropTypes.oneOf(skins),
|
|
|
|
delay: PropTypes.number
|
2016-07-31 19:23:16 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
static defaultProps = {
|
2016-08-14 14:29:23 +05:30
|
|
|
skin: SKIN_DARK,
|
|
|
|
delay: 0
|
2016-07-31 19:23:16 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
componentDidMount() {
|
2016-08-14 14:29:23 +05:30
|
|
|
setTimeout(() => captcha.render(this.el, {
|
2016-07-31 19:23:16 +05:30
|
|
|
skin: this.props.skin,
|
|
|
|
onSetCode: this.setCode
|
2016-08-14 14:29:23 +05:30
|
|
|
}), this.props.delay);
|
2016-07-31 19:23:16 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-08-05 11:28:24 +05:30
|
|
|
const {skin} = this.props;
|
|
|
|
|
2016-07-31 19:23:16 +05:30
|
|
|
return (
|
2016-08-14 14:29:23 +05:30
|
|
|
<div className={styles.captchaContainer}>
|
|
|
|
<div className={styles.captchaLoader}>
|
|
|
|
<ComponentLoader />
|
|
|
|
</div>
|
2016-08-05 11:28:24 +05:30
|
|
|
<div ref={this.setEl} className={classNames(
|
|
|
|
styles.captcha,
|
|
|
|
styles[`${skin}Captcha`]
|
|
|
|
)} />
|
2016-08-05 11:11:33 +05:30
|
|
|
{this.renderError()}
|
|
|
|
</div>
|
2016-07-31 19:23:16 +05:30
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
getValue() {
|
|
|
|
return this.state && this.state.code;
|
|
|
|
}
|
|
|
|
|
|
|
|
setCode = (code) => this.setState({code});
|
|
|
|
}
|