Skip to content

Commit

Permalink
Add animated auto transition from hours to minutes in TimePicker
Browse files Browse the repository at this point in the history
  • Loading branch information
javivelasco committed Dec 12, 2015
1 parent a88868a commit 211d542
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 15 deletions.
2 changes: 2 additions & 0 deletions components/animations/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export SlideLeft from './slide-left';
export SlideRight from './slide-right';
export ZoomIn from './zoom-in';
export ZoomOut from './zoom-out';
2 changes: 0 additions & 2 deletions components/animations/slide-left.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@import "../base";

.enter, .leave {
position: absolute;
transition-timing-function: ease-in-out;
Expand Down
15 changes: 8 additions & 7 deletions components/animations/slide-right.scss
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
@import "../base";

.enter, .leave {
position: absolute;
}

.enterActive, .leaveActive {
transition-timing-function: ease-in-out;
transition-duration: .35s;
transition-duration: 350ms;
transition-property: transform, opacity;
}

.enter {
opacity: 0;
transform: translate3d(100%, 0, 0);
transform: translateX(100%);

&.enterActive {
opacity: 1;
transform: translate3d(0, 0, 0);
transform: translateX(0);
}
}

.leave {
opacity: 1;
transform: translate3d(0, 0, 0);
transform: translateX(0);

&.leaveActive {
opacity: 0;
transform: translate3d(-100%, 0, 0);
transform: translateX(-100%);
}
}
31 changes: 31 additions & 0 deletions components/animations/zoom-in.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@import "../base";

.enter, .leave {
position: absolute;
}

.enterActive, .leaveActive {
transition-timing-function: $animation-curve-fast-out-slow-in;
transition-duration: 500ms;
transition-property: transform, opacity;
}

.enter {
opacity: 0;
transform: scale(0.85);

&.enterActive {
opacity: 1;
transform: scale(1);
}
}

.leave {
opacity: 1;
transform: scale(1);

&.leaveActive {
opacity: 0;
transform: scale(1.25);
}
}
31 changes: 31 additions & 0 deletions components/animations/zoom-out.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@import "../base";

.enter, .leave {
position: absolute;
}

.enterActive, .leaveActive {
transition-timing-function: $animation-curve-fast-out-slow-in;
transition-duration: 500ms;
transition-property: transform, opacity;
}

.enter {
opacity: 0;
transform: scale(1.25);

&.enterActive {
opacity: 1;
transform: scale(1);
}
}

.leave {
opacity: 1;
transform: scale(1);

&.leaveActive {
opacity: 0;
transform: scale(0.85);
}
}
18 changes: 14 additions & 4 deletions components/time_picker/Clock.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from 'react';
import CssTransitionGroup from 'react-addons-css-transition-group';
import { ZoomIn, ZoomOut } from '../animations';
import style from './style.clock';
import time from '../utils/time';
import Hours from './ClockHours';
Expand All @@ -10,6 +12,7 @@ class Clock extends React.Component {
display: React.PropTypes.oneOf(['hours', 'minutes']),
format: React.PropTypes.oneOf(['24hr', 'ampm']),
onChange: React.PropTypes.func,
onHandMoved: React.PropTypes.func,
time: React.PropTypes.object
};

Expand Down Expand Up @@ -47,7 +50,7 @@ class Clock extends React.Component {
};

handleCalculateShape = () => {
const { top, left, width } = this.refs.wrapper.getBoundingClientRect();
const { top, left, width } = this.refs.placeholder.getBoundingClientRect();
this.setState({
center: { x: left + width / 2, y: top + width / 2 },
radius: width / 2
Expand Down Expand Up @@ -75,6 +78,7 @@ class Clock extends React.Component {
radius={this.state.radius}
selected={this.props.time.getHours()}
spacing={this.state.radius * 0.18}
onHandMoved={this.props.onHandMoved}
/>
);
}
Expand All @@ -87,16 +91,22 @@ class Clock extends React.Component {
radius={this.state.radius}
selected={this.props.time.getMinutes()}
spacing={this.state.radius * 0.18}
onHandMoved={this.props.onHandMoved}
/>
);
}

render () {
const animation = this.props.display === 'hours' ? ZoomOut : ZoomIn;
return (
<div data-react-toolbox='clock' className={style.root}>
<div ref='wrapper' className={style.wrapper} style={{height: this.state.radius * 2}}>
{this.props.display === 'hours' ? this.renderHours() : null}
{this.props.display === 'minutes' ? this.renderMinutes() : null}
<div ref='placeholder' className={style.placeholder} style={{height: this.state.radius * 2}}>
<CssTransitionGroup transitionName={animation} transitionEnterTimeout={500} transitionLeaveTimeout={500}>
<div key={this.props.display} className={style.wrapper} style={{height: this.state.radius * 2}}>
{this.props.display === 'hours' ? this.renderHours() : null}
{this.props.display === 'minutes' ? this.renderMinutes() : null}
</div>
</CssTransitionGroup>
</div>
</div>
);
Expand Down
7 changes: 6 additions & 1 deletion components/time_picker/TimePickerDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class TimePickerDialog extends React.Component {
this.setState({displayTime: time.toggleTimeMode(this.state.displayTime)});
};

handleHandMoved = () => {
if (this.state.display === 'hours') this.setState({display: 'minutes'});
};

switchDisplay = (display) => {
this.setState({display});
};
Expand Down Expand Up @@ -90,8 +94,9 @@ class TimePickerDialog extends React.Component {
ref='clock'
display={this.state.display}
format={this.props.format}
time={this.state.displayTime}
onChange={this.handleClockChange}
onHandMoved={this.handleHandMoved}
time={this.state.displayTime}
/>
</Dialog>
);
Expand Down
7 changes: 6 additions & 1 deletion components/time_picker/style.clock.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
padding: $clock-padding;
}

.wrapper {
.placeholder {
position: relative;
z-index: $z-index-high;
}

.wrapper {
position: absolute;
width: 100%;
background-color: $color-divider;
border-radius: 50%;
}
Expand Down
1 change: 1 addition & 0 deletions components/time_picker/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
width: $timepicker-dialog-width;
> [role="body"] {
padding: 0;
overflow-y: visible;
}
> [role="navigation"] > .button {
color: $timepicker-primary-color;
Expand Down

0 comments on commit 211d542

Please sign in to comment.