packages/client: Use bloomer in login & register forms

This commit is contained in:
Jerko Steiner 2019-03-18 13:47:47 +05:00
parent 63c27328ff
commit 905501e053
3 changed files with 34 additions and 11 deletions

View File

@ -1,4 +1,6 @@
import React from 'react' import React from 'react'
import {Control, Field, Input as I, Label} from 'bloomer'
import {IconType} from 'react-icons'
export interface IInputProps { export interface IInputProps {
name: string name: string
@ -7,6 +9,8 @@ export interface IInputProps {
onChange?: (name: this['name'], value: string) => void onChange?: (name: this['name'], value: string) => void
placeholder?: string placeholder?: string
readOnly?: boolean readOnly?: boolean
label: string
Icon?: IconType
} }
export class Input extends React.PureComponent<IInputProps> { export class Input extends React.PureComponent<IInputProps> {
@ -16,8 +20,13 @@ export class Input extends React.PureComponent<IInputProps> {
} }
} }
render() { render() {
const {Icon} = this.props
return ( return (
<input <Field>
<Label>{this.props.label}</Label>
<Control hasIcons>
<I
className='input'
name={this.props.name} name={this.props.name}
type={this.props.type} type={this.props.type}
value={this.props.value} value={this.props.value}
@ -25,6 +34,11 @@ export class Input extends React.PureComponent<IInputProps> {
placeholder={this.props.placeholder} placeholder={this.props.placeholder}
readOnly={!!this.props.readOnly} readOnly={!!this.props.readOnly}
/> />
{Icon && <span className='icon is-left is-small'>
<Icon />
</span>}
</Control>
</Field>
) )
} }
} }

View File

@ -2,6 +2,7 @@ import React from 'react'
import {ICredentials, IUser} from '@rondo/common' import {ICredentials, IUser} from '@rondo/common'
import {Input} from '../components/Input' import {Input} from '../components/Input'
import {Redirect} from '../components/Redirect' import {Redirect} from '../components/Redirect'
import {FaUser, FaLock} from 'react-icons/fa'
export interface ILoginFormProps { export interface ILoginFormProps {
error?: string error?: string
@ -23,6 +24,8 @@ export class LoginForm extends React.PureComponent<ILoginFormProps> {
<form onSubmit={this.props.onSubmit}> <form onSubmit={this.props.onSubmit}>
<p className='error'>{this.props.error}</p> <p className='error'>{this.props.error}</p>
<Input <Input
Icon={FaUser}
label='Username'
name='username' name='username'
type='text' type='text'
onChange={this.props.onChange} onChange={this.props.onChange}
@ -30,13 +33,16 @@ export class LoginForm extends React.PureComponent<ILoginFormProps> {
placeholder='Username' placeholder='Username'
/> />
<Input <Input
Icon={FaLock}
label='Password'
name='password' name='password'
type='password' type='password'
onChange={this.props.onChange} onChange={this.props.onChange}
value={this.props.data.password} value={this.props.data.password}
placeholder='Password' placeholder='Password'
/> />
<Input <input
className='button is-primary'
name='submit' name='submit'
type='submit' type='submit'
value='Log In' value='Log In'

View File

@ -21,6 +21,7 @@ export class RegisterForm extends React.PureComponent<IRegisterFormProps> {
<form onSubmit={this.props.onSubmit}> <form onSubmit={this.props.onSubmit}>
<p className='error'>{this.props.error}</p> <p className='error'>{this.props.error}</p>
<Input <Input
label='Username'
name='username' name='username'
type='email' type='email'
onChange={this.props.onChange} onChange={this.props.onChange}
@ -28,16 +29,18 @@ export class RegisterForm extends React.PureComponent<IRegisterFormProps> {
placeholder='Email' placeholder='Email'
/> />
<Input <Input
label='Password'
name='password' name='password'
type='password' type='password'
onChange={this.props.onChange} onChange={this.props.onChange}
value={this.props.data.password} value={this.props.data.password}
placeholder='Password' placeholder='Password'
/> />
<Input <input
className='button is-primary'
name='submit' name='submit'
type='submit' type='submit'
value='Register' value='Log In'
/> />
</form> </form>
) )