mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-01-16 08:33:15 +05:30
#305: use ScrollMotion for ChangeEmail form
This commit is contained in:
parent
fca73477cc
commit
cdec930b94
@ -3,13 +3,12 @@ import PropTypes from 'prop-types';
|
|||||||
|
|
||||||
import { FormattedMessage as Message } from 'react-intl';
|
import { FormattedMessage as Message } from 'react-intl';
|
||||||
import Helmet from 'react-helmet';
|
import Helmet from 'react-helmet';
|
||||||
import { Motion, spring } from 'react-motion';
|
|
||||||
|
|
||||||
|
import { ScrollMotion } from 'components/ui/motion';
|
||||||
import { Input, Button, Form, FormModel, FormError } from 'components/ui/form';
|
import { Input, Button, Form, FormModel, FormError } from 'components/ui/form';
|
||||||
import { BackButton } from 'components/profile/ProfileForm';
|
import { BackButton } from 'components/profile/ProfileForm';
|
||||||
import styles from 'components/profile/profileForm.scss';
|
import styles from 'components/profile/profileForm.scss';
|
||||||
import helpLinks from 'components/auth/helpLinks.scss';
|
import helpLinks from 'components/auth/helpLinks.scss';
|
||||||
import MeasureHeight from 'components/MeasureHeight';
|
|
||||||
import Stepper from 'components/ui/stepper';
|
import Stepper from 'components/ui/stepper';
|
||||||
|
|
||||||
import changeEmail from './changeEmail.scss';
|
import changeEmail from './changeEmail.scss';
|
||||||
@ -127,58 +126,26 @@ export default class ChangeEmail extends Component {
|
|||||||
const {activeStep, code} = this.state;
|
const {activeStep, code} = this.state;
|
||||||
const isCodeSpecified = !!this.props.code;
|
const isCodeSpecified = !!this.props.code;
|
||||||
|
|
||||||
const activeStepHeight = this.state[`step${activeStep}Height`] || 0;
|
|
||||||
|
|
||||||
// a hack to disable height animation on first render
|
|
||||||
const isHeightMeasured = this.isHeightMeasured;
|
|
||||||
this.isHeightMeasured = isHeightMeasured || activeStepHeight > 0;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Motion
|
<ScrollMotion activeStep={activeStep}>
|
||||||
style={{
|
{(new Array(STEPS_TOTAL)).fill(0).map((_, step) => {
|
||||||
transform: spring(activeStep * 100, {stiffness: 500, damping: 50, precision: 0.5}),
|
const form = this.props.stepForms[step];
|
||||||
height: isHeightMeasured ? spring(activeStepHeight, {stiffness: 500, damping: 20, precision: 0.5}) : activeStepHeight
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{(interpolatingStyle) => (
|
|
||||||
<div style={{
|
|
||||||
overflow: 'hidden',
|
|
||||||
height: `${interpolatingStyle.height}px`
|
|
||||||
}}>
|
|
||||||
<div className={changeEmail.stepForms} style={{
|
|
||||||
WebkitTransform: `translateX(-${interpolatingStyle.transform}%)`,
|
|
||||||
transform: `translateX(-${interpolatingStyle.transform}%)`
|
|
||||||
}}>
|
|
||||||
{(new Array(STEPS_TOTAL)).fill(0).map((_, step) => {
|
|
||||||
const form = this.props.stepForms[step];
|
|
||||||
|
|
||||||
return (
|
return this[`renderStep${step}`]({
|
||||||
<MeasureHeight
|
email,
|
||||||
className={changeEmail.stepForm}
|
code,
|
||||||
onMeasure={this.onStepMeasure(step)}
|
isCodeSpecified,
|
||||||
state={`${step}.${form.hasErrors()}.${this.props.lang}`}
|
form,
|
||||||
key={step}
|
isActiveStep: step === activeStep
|
||||||
>
|
});
|
||||||
{this[`renderStep${step}`]({
|
})}
|
||||||
email,
|
</ScrollMotion>
|
||||||
code,
|
|
||||||
isCodeSpecified,
|
|
||||||
form,
|
|
||||||
isActiveStep: step === activeStep
|
|
||||||
})}
|
|
||||||
</MeasureHeight>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</Motion>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderStep0({email, form}) {
|
renderStep0({email, form}) {
|
||||||
return (
|
return (
|
||||||
<div className={styles.formBody}>
|
<div key="step0" className={styles.formBody}>
|
||||||
<div className={styles.formRow}>
|
<div className={styles.formRow}>
|
||||||
<p className={styles.description}>
|
<p className={styles.description}>
|
||||||
<Message {...messages.currentAccountEmail} />
|
<Message {...messages.currentAccountEmail} />
|
||||||
@ -204,7 +171,7 @@ export default class ChangeEmail extends Component {
|
|||||||
|
|
||||||
renderStep1({email, form, code, isCodeSpecified, isActiveStep}) {
|
renderStep1({email, form, code, isCodeSpecified, isActiveStep}) {
|
||||||
return (
|
return (
|
||||||
<div className={styles.formBody}>
|
<div key="step1" className={styles.formBody}>
|
||||||
<div className={styles.formRow}>
|
<div className={styles.formRow}>
|
||||||
<p className={styles.description}>
|
<p className={styles.description}>
|
||||||
<Message {...messages.enterInitializationCode} values={{
|
<Message {...messages.enterInitializationCode} values={{
|
||||||
@ -248,7 +215,7 @@ export default class ChangeEmail extends Component {
|
|||||||
const {newEmail} = this.state;
|
const {newEmail} = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.formBody}>
|
<div key="step2" className={styles.formBody}>
|
||||||
<div className={styles.formRow}>
|
<div className={styles.formRow}>
|
||||||
<p className={styles.description}>
|
<p className={styles.description}>
|
||||||
{newEmail ? (
|
{newEmail ? (
|
||||||
|
@ -4,14 +4,3 @@
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
line-height: 1.2;
|
line-height: 1.2;
|
||||||
}
|
}
|
||||||
|
|
||||||
.stepForms {
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.stepForm {
|
|
||||||
display: inline-block;
|
|
||||||
white-space: normal;
|
|
||||||
vertical-align: top;
|
|
||||||
max-width: 100%;
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user