2016-01-04 02:48:42 +05:30
import React , { Component } from 'react' ;
2016-01-18 10:58:43 +05:30
import { connect } from 'react-redux' ;
import { TransitionMotion , spring } from 'react-motion' ;
2016-01-04 02:48:42 +05:30
import AppInfo from 'components/auth/AppInfo' ;
import styles from './auth.scss' ;
2016-01-19 10:46:03 +05:30
const springConfig = [ 200 , 20 ] ;
2016-01-18 10:58:43 +05:30
class AuthPage extends Component {
2016-01-16 17:36:22 +05:30
displayName = 'AuthPage' ;
2016-01-04 02:48:42 +05:30
render ( ) {
var appInfo = {
name : 'TLauncher' ,
2016-01-04 11:32:13 +05:30
description : ` Лучший альтернативный лаунчер для Minecraft с большим количеством версий и их модификаций, а также возмоностью входа как с лицензионным аккаунтом, так и без него. `
2016-01-04 02:48:42 +05:30
} ;
2016-01-18 10:58:43 +05:30
var { path , children } = this . props ;
2016-01-04 02:48:42 +05:30
return (
< div >
< div className = { styles . sidebar } >
< AppInfo { ...appInfo } / >
< / div >
< div className = { styles . content } >
2016-01-18 10:58:43 +05:30
< TransitionMotion
willEnter = { this . willEnter }
willLeave = { this . willLeave }
styles = { {
[ path ] : {
children ,
2016-01-19 10:46:03 +05:30
x : spring ( 0 , springConfig )
2016-01-18 10:58:43 +05:30
}
} }
>
{ ( items ) => (
2016-01-21 11:59:35 +05:30
< div style = { { position : 'relative' , overflow : 'hidden' , width : '100%' , height : '500px' } } >
2016-01-18 10:58:43 +05:30
{ Object . keys ( items ) . map ( ( path ) => {
const { children , x } = items [ path ] ;
const style = {
position : 'absolute' ,
top : 0 ,
2016-01-19 11:51:02 +05:30
left : 0 ,
2016-01-18 10:58:43 +05:30
width : '100%' ,
2016-01-19 11:51:02 +05:30
transform : ` translateX( ${ x } %) `
2016-01-18 10:58:43 +05:30
} ;
return (
< div key = { path } style = { style } >
{ children }
< / div >
) ;
} ) }
< / div >
) }
< / TransitionMotion >
2016-01-21 11:59:35 +05:30
< TheDemo / >
2016-01-04 02:48:42 +05:30
< / div >
< / div >
) ;
}
2016-01-18 10:58:43 +05:30
willEnter ( key , styles ) {
return {
... styles ,
2016-01-19 10:46:03 +05:30
x : spring ( 100 , springConfig )
2016-01-18 10:58:43 +05:30
} ;
}
willLeave ( key , styles ) {
return {
... styles ,
2016-01-19 10:46:03 +05:30
x : spring ( - 100 , springConfig )
2016-01-18 10:58:43 +05:30
} ;
}
2016-01-04 02:48:42 +05:30
}
2016-01-18 10:58:43 +05:30
2016-01-21 11:59:35 +05:30
import { FormattedMessage as Message } from 'react-intl' ;
import Helmet from 'react-helmet' ;
2016-01-27 10:34:03 +05:30
import ReactHeight from 'react-height' ;
2016-01-21 11:59:35 +05:30
import panelStyles from 'components/ui/panel.scss' ;
import buttons from 'components/ui/buttons.scss' ;
import icons from 'components/ui/icons.scss' ;
import { Panel , PanelBody , PanelFooter , PanelHeader } from 'components/ui/Panel' ;
import { Input , Checkbox } from 'components/ui/Form' ;
import messages from 'components/auth/Login.messages' ;
import regMessages from 'components/auth/Register.messages' ;
import { helpLinks as helpLinksStyles } from 'components/auth/helpLinks.scss' ;
import passwordMessages from 'components/auth/Password.messages' ;
2016-01-23 14:51:02 +05:30
const opacitySpringConfig = [ 200 , 20 ] ;
const heightSpringConfig = [ 200 , 18 ] ;
const transformSpringConfig = [ 500 , 20 ] ;
2016-01-21 11:59:35 +05:30
2016-01-23 14:51:02 +05:30
// TODO: сделать более быстрый фейд на горизонтальном скролле
2016-01-21 11:59:35 +05:30
class TheDemo extends Component {
state = {
2016-01-27 10:34:03 +05:30
isFirstPage : true ,
height : { }
2016-01-21 11:59:35 +05:30
} ;
render ( ) {
var { isFirstPage } = this . state ;
2016-01-27 10:34:03 +05:30
var path = ` page ${ isFirstPage ? '1' : '2' } ` ;
2016-01-21 11:59:35 +05:30
return (
< TransitionMotion
styles = { {
2016-01-27 10:34:03 +05:30
[ path ] : {
2016-01-21 11:59:35 +05:30
isFirstPage ,
transformSpring : spring ( 0 ) ,
opacitySpring : spring ( 1 )
} ,
common : {
2016-01-27 10:34:03 +05:30
heightSpring : spring ( this . state . height [ path ] || 0 , heightSpringConfig )
2016-01-21 11:59:35 +05:30
}
} }
willEnter = { this . willEnter }
willLeave = { this . willLeave }
>
{ ( items ) => {
var keys = Object . keys ( items ) . filter ( ( key ) => key !== 'common' ) ;
return (
2016-01-27 10:34:03 +05:30
< div >
2016-01-21 11:59:35 +05:30
< Panel >
< PanelHeader >
< div style = { {
position : 'relative' ,
height : '59px' ,
overflow : 'hidden'
} } >
{ keys . map ( ( key ) => this . getHeader ( key , items [ key ] ) ) }
< / div >
< / PanelHeader >
2016-01-23 14:51:02 +05:30
< PanelBody style = { {
overflow : 'hidden'
} } >
2016-01-21 11:59:35 +05:30
< div style = { {
position : 'relative' ,
2016-01-23 14:51:02 +05:30
height : ` ${ items . common . heightSpring } px `
2016-01-21 11:59:35 +05:30
} } >
{ keys . map ( ( key ) => this . getBody ( key , items [ key ] ) ) }
< / div >
< / PanelBody >
< PanelFooter >
< div style = { {
position : 'relative' ,
height : '50px' ,
overflow : 'hidden'
} } >
{ keys . map ( ( key ) => this . getFooter ( key , items [ key ] ) ) }
< / div >
< / PanelFooter >
< / Panel >
< div className = { helpLinksStyles } style = { { position : 'relative' , height : '20px' } } >
{ keys . map ( ( key ) => this . getLinks ( key , items [ key ] ) ) }
< / div >
< / div >
) ;
} }
< / TransitionMotion >
) ;
}
willEnter = ( key , styles ) => {
var sign = this . state . isFirstPage ? - 1 : 1 ;
return {
... styles ,
transformSpring : spring ( sign * 100 , transformSpringConfig ) ,
opacitySpring : spring ( 1 , opacitySpringConfig )
} ;
} ;
willLeave = ( key , styles ) => {
var sign = this . state . isFirstPage ? - 1 : 1 ;
return {
... styles ,
transformSpring : spring ( sign * - 100 , transformSpringConfig ) ,
opacitySpring : spring ( 0 , opacitySpringConfig )
} ;
} ;
getBody ( key , props ) {
var { isFirstPage , transformSpring , opacitySpring } = props ;
var style = {
position : 'absolute' ,
top : 0 ,
left : 0 ,
width : '100%' ,
2016-01-23 14:51:02 +05:30
WebkitTransform : ` translateX( ${ transformSpring } %) ` ,
2016-01-21 11:59:35 +05:30
transform : ` translateX( ${ transformSpring } %) ` ,
opacity : opacitySpring
} ;
return ( isFirstPage ? (
2016-01-27 10:34:03 +05:30
< ReactHeight key = { ` body ${ key } ` } style = { style } onHeightReady = { this . updateHeight } >
2016-01-21 11:59:35 +05:30
< Input icon = "envelope" type = "email" placeholder = { messages . emailOrUsername } / >
2016-01-27 10:34:03 +05:30
< / ReactHeight >
2016-01-21 11:59:35 +05:30
) : (
2016-01-27 10:34:03 +05:30
< ReactHeight key = { ` body ${ key } ` } style = { style } onHeightReady = { this . updateHeight } >
2016-01-21 11:59:35 +05:30
< Input icon = "user" color = "blue" type = "text" placeholder = { regMessages . yourNickname } / >
< Input icon = "envelope" color = "blue" type = "email" placeholder = { regMessages . yourEmail } / >
< Input icon = "key" color = "blue" type = "password" placeholder = { regMessages . accountPassword } / >
< Input icon = "key" color = "blue" type = "password" placeholder = { regMessages . repeatPassword } / >
< Checkbox color = "blue" label = {
< Message { ...regMessages.acceptRules } values = { {
link : (
< a href = "#" >
< Message { ...regMessages.termsOfService } / >
< / a >
)
} } / >
} / >
2016-01-27 10:34:03 +05:30
< / ReactHeight >
2016-01-21 11:59:35 +05:30
) ) ;
}
2016-01-27 10:34:03 +05:30
updateHeight = ( height ) => {
this . setState ( {
height : {
... this . state . height ,
[ ` page ${ this . state . isFirstPage ? '1' : '2' } ` ] : height
}
} ) ;
} ;
2016-01-21 11:59:35 +05:30
getFooter ( key , props ) {
var { isFirstPage , opacitySpring } = props ;
var style = {
position : 'absolute' ,
top : 0 ,
left : 0 ,
width : '100%' ,
opacity : opacitySpring
} ;
return ( isFirstPage ? (
< button key = { ` footer ${ key } ` } style = { style } onClick = { this . onSwitchViews } className = { buttons . green } >
< Message { ...messages.next } / >
< / button >
) : (
< button key = { ` footer ${ key } ` } style = { style } onClick = { this . onSwitchViews } className = { buttons . blue } >
< Message { ...regMessages.signUpButton } / >
< / button >
) ) ;
}
getHeader ( key , props ) {
var { isFirstPage , transformSpring } = props ;
var style = {
position : 'absolute' ,
top : 0 ,
left : 0 ,
width : '100%'
} ;
var scrollStyle = {
2016-01-23 14:51:02 +05:30
WebkitTransform : ` translateY( ${ transformSpring } %) ` ,
2016-01-21 11:59:35 +05:30
transform : ` translateY( ${ transformSpring } %) `
} ;
var sideScrollStyle = {
position : 'relative' ,
zIndex : 2 ,
2016-01-23 14:51:02 +05:30
WebkitTransform : ` translateX( ${ - Math . abs ( transformSpring ) } %) ` ,
2016-01-21 11:59:35 +05:30
transform : ` translateX( ${ - Math . abs ( transformSpring ) } %) `
} ;
return ( isFirstPage ? (
< div key = { ` header ${ key } ` } style = { style } >
< Message { ...messages.loginTitle } >
{ ( msg ) => < div style = { scrollStyle } > { msg } < Helmet title = { msg } / > < / div > }
< / Message >
< / div >
) : (
< div key = { ` header ${ key } ` } style = { style } >
< button style = { sideScrollStyle } onClick = { this . onSwitchViews } className = { panelStyles . headerControl } >
< span className = { icons . arrowLeft } / >
< / button >
< Message { ...regMessages.registerTitle } >
{ ( msg ) => < div style = { scrollStyle } > { msg } < Helmet title = { msg } / > < / div > }
< / Message >
< / div >
) ) ;
}
getLinks ( key , props ) {
var { isFirstPage , opacitySpring } = props ;
var style = {
position : 'absolute' ,
top : 0 ,
left : 0 ,
width : '100%' ,
opacity : opacitySpring
} ;
return ( isFirstPage ? (
< div key = { ` links ${ key } ` } style = { style } >
< a href = "#" >
< Message { ...passwordMessages.forgotPassword } / >
< / a >
< / div >
) : (
< div key = { ` links ${ key } ` } style = { style } >
< a href = "#" >
{ 'test 123' }
< / a >
< / div >
) ) ;
}
onSwitchViews = ( event ) => {
event . preventDefault ( ) ;
this . setState ( {
isFirstPage : ! this . state . isFirstPage
} ) ;
} ;
}
2016-01-18 10:58:43 +05:30
export default connect ( ( state ) => ( {
path : state . routing . location . pathname
} ) ) ( AuthPage ) ;