Login
Support multiple common ways of login with built-in controls. You can choose your own combinations and use with your custom controls.
Usage:
import Login from 'ant-design-pro/lib/Login';
Learning more to visit: Using Pro Components Alone
Examples
import Login from 'ant-design-pro/lib/Login';
import { Alert, Checkbox } from 'antd';
const { Tab, UserName, Password, Mobile, Captcha, Submit } = Login;
class LoginDemo extends React.Component {
state = {
notice: '',
type: 'tab2',
autoLogin: true,
};
onSubmit = (err, values) => {
console.log('value collected ->', {
...values,
autoLogin: this.state.autoLogin,
});
if (this.state.type === 'tab1') {
this.setState(
{
notice: '',
},
() => {
if (!err && (values.username !== 'admin' || values.password !== '888888')) {
setTimeout(() => {
this.setState({
notice: 'The combination of username and password is incorrect!',
});
}, 500);
}
}
);
}
};
onTabChange = key => {
this.setState({
type: key,
});
};
changeAutoLogin = e => {
this.setState({
autoLogin: e.target.checked,
});
};
render() {
return (
<div className="login-warp">
<Login
defaultActiveKey={this.state.type}
onTabChange={this.onTabChange}
onSubmit={this.onSubmit}
>
<Tab key="tab1" tab="Account">
{this.state.notice && (
<Alert
style={{ marginBottom: 24 }}
message={this.state.notice}
type="error"
showIcon
closable
/>
)}
<UserName name="username" />
<Password name="password" />
</Tab>
<Tab key="tab2" tab="Mobile">
<Mobile name="mobile" />
<Captcha onGetCaptcha={() => console.log('Get captcha!')} name="captcha" />
</Tab>
<div>
<Checkbox checked={this.state.autoLogin} onChange={this.changeAutoLogin}>
Keep me logged in
</Checkbox>
<a style={{ float: 'right' }} href="">
Forgot password
</a>
</div>
<Submit>Login</Submit>
<div>
Other login methods
<span className="icon icon-alipay" />
<span className="icon icon-taobao" />
<span className="icon icon-weibo" />
<a style={{ float: 'right' }} href="">
Register
</a>
</div>
</Login>
</div>
);
}
}
ReactDOM.render(<LoginDemo />, mountNode);
API#
Login#
Property | Description | Type | Default |
---|---|---|---|
defaultActiveKey | default key to activate the tab panel | String | - |
onTabChange | callback on changing tabs | (key) => void | - |
onSubmit | callback on submit | (err, values) => void | - |
Login.Tab#
Property | Description | Type | Default |
---|---|---|---|
key | key of the tab | String | - |
tab | displayed text of the tab | ReactNode | - |
Login.UserName#
Property | Description | Type | Default |
---|---|---|---|
name | name of the control, also the key of the submitted data | String | - |
rules | validation rules, same with option.rules in Form getFieldDecorator(id, options) | object[] | - |
Apart from the above properties, Login.Username also support all properties of antd.Input, together with the default values of basic settings, such as placeholder, size and prefix. All of these default values can be over-written.
Login.Password, Login.Mobile are the same as Login.UserName#
Login.Captcha#
Property | Description | Type | Default |
---|---|---|---|
onGetCaptcha | callback on getting a new Captcha | () => (void | false | Promise) | - |
countDown | count down | number | - |
buttonText | text on getting a new Captcha | ReactNode | '获取验证码' |
Apart from the above properties, Login.Captcha support the same properties with Login.UserName.
Login.Submit#
Support all properties of antd.Button.