Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Datepicker] Redesign datepicker as per material spec #3739

Merged
merged 14 commits into from
May 6, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions src/DatePicker/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import CalendarToolbar from './CalendarToolbar';
import DateDisplay from './DateDisplay';
import SlideInTransitionGroup from '../internal/SlideIn';
import ClearFix from '../internal/ClearFix';
import deprecated from '../utils/deprecatedPropType';

import {
addDays,
Expand All @@ -26,9 +27,7 @@ import {

const daysArray = [...Array(7)];


class Calendar extends React.Component {

class Calendar extends Component {
static propTypes = {
DateTimeFormat: PropTypes.func.isRequired,
autoOk: PropTypes.bool,
Expand All @@ -47,7 +46,7 @@ class Calendar extends React.Component {
open: PropTypes.bool,
shouldDisableDate: PropTypes.func,
showActionButtons: PropTypes.bool,
wordings: PropTypes.object,
wordings: deprecated(PropTypes.object, 'Instead, use `cancelLabel` and `okLabel`.'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should only need the warning in DatePicker, otherwise the warning will fire multiple times as the value propagates down the component tree.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

};

static defaultProps = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually put the defaultProps directly below the propTypes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted.

Expand All @@ -69,7 +68,6 @@ class Calendar extends React.Component {
selectedDate: undefined,
transitionDirection: 'left',
transitionEnter: true,
open: true,
};

componentWillMount() {
Expand Down Expand Up @@ -256,22 +254,21 @@ class Calendar extends React.Component {
flexDirection: 'column',
},
calendarContainer: {
alignContent: 'space-between',
display: 'flex',
alignContent: 'space-between',
justifyContent: 'space-between',
flexDirection: 'column',
fontSize: 12,
fontWeight: 400,
height: 'auto',
justifyContent: 'space-between',
padding: '0px 8px 0px 8px',
padding: '0px 8px',
transition: transitions.easeOut(),
width: isLandscape ? 294 : 'auto',
},
yearContainer: {
display: 'flex',
justifyContent: 'space-between',
flexDirection: 'column',
height: 272,
justifyContent: 'space-between',
marginTop: 10,
overflow: 'hidden',
width: 310,
Expand All @@ -285,9 +282,9 @@ class Calendar extends React.Component {
weekTitle: {
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
fontWeight: '500',
height: 20,
justifyContent: 'space-between',
lineHeight: '15px',
opacity: '0.5',
textAlign: 'center',
Expand Down Expand Up @@ -358,7 +355,7 @@ class Calendar extends React.Component {
key={this.state.displayDate.toDateString()}
minDate={this.props.minDate}
maxDate={this.props.maxDate}
onTouchTapDay={this.handleTouchTapDay}
onDayTouchTap={this.handleTouchTapDay}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this changed? These were all consistently onTouchTapXXX...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this because CalendarMonth had onDayTouchTap: PropTypes.func, so I kept it to be the same as I was getting issue while changing dates after this.

I thought the naming convention was changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbrookes Fixed.

ref="calendar"
selectedDate={this.state.selectedDate}
shouldDisableDate={this.props.shouldDisableDate}
Expand Down
17 changes: 8 additions & 9 deletions src/DatePicker/CalendarActionButtons.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react';
import React, {Component, PropTypes} from 'react';
import FlatButton from '../FlatButton';
import deprecated from '../utils/deprecatedPropType';

class CalendarActionButton extends React.Component {
class CalendarActionButton extends Component {
static propTypes = {
cancelLabel: React.PropTypes.node,
okLabel: React.PropTypes.node,
onTouchTapCancel: React.PropTypes.func,
onTouchTapOk: React.PropTypes.func,
wordings: React.PropTypes.object,
cancelLabel: PropTypes.node,
okLabel: PropTypes.node,
onTouchTapCancel: PropTypes.func,
onTouchTapOk: PropTypes.func,
wordings: deprecated(PropTypes.object, 'Instead, use `cancelLabel` and `okLabel`.'),
Copy link
Member

@mbrookes mbrookes May 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

};

render() {
Expand All @@ -34,15 +35,13 @@ class CalendarActionButton extends React.Component {
return (
<div style={styles.root} >
<FlatButton
key={0}
label={wordings ? wordings.cancel : cancelLabel}
onTouchTap={this.props.onTouchTapCancel}
primary={true}
style={styles.flatButtons}
/>
<FlatButton
disabled={this.refs.calendar !== undefined && this.refs.calendar.isSelectedDateDisabled()}
key={1}
label={wordings ? wordings.ok : okLabel}
onTouchTap={this.props.onTouchTapOk}
primary={true}
Expand Down
13 changes: 5 additions & 8 deletions src/DatePicker/CalendarMonth.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, {Component, PropTypes} from 'react';
import {isBetweenDates, isEqualDate, getWeekArray} from './dateUtils';
import DayButton from './DayButton';
import ClearFix from '../internal/ClearFix';

class CalendarMonth extends Component {
static propTypes = {
Expand All @@ -20,7 +19,7 @@ class CalendarMonth extends Component {
}

handleTouchTapDay = (event, date) => {
if (this.props.onTouchTapDay) this.props.onTouchTapDay(event, date);
if (this.props.onDayTouchTap) this.props.onDayTouchTap(event, date);
};

shouldDisableDate(day) {
Expand All @@ -36,9 +35,9 @@ class CalendarMonth extends Component {

return weekArray.map((week, i) => {
return (
<ClearFix key={i} style={this.styles.week}>
<div key={i} style={this.styles.week}>
{this.getDayElements(week, i)}
</ClearFix>
</div>
);
}, this);
}
Expand Down Expand Up @@ -69,22 +68,20 @@ class CalendarMonth extends Component {
root: {
display: 'flex',
flexDirection: 'column',
justifyContent: 'flex-start',
fontWeight: 400,
height: 228,
justifyContent: 'flex-start',
lineHeight: 2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need line-height if we're using flexbox?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

position: 'relative',
textAlign: 'center',
MozPaddingStart: 0,
// backgroundColor: 'cyan',
},
week: {
display: 'flex',
flexDirection: 'row',
height: 34,
justifyContent: 'space-around',
height: 34,
marginBottom: 2,
// backgroundColor: 'yellow',
},
};

Expand Down
27 changes: 9 additions & 18 deletions src/DatePicker/CalendarToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,20 @@ import SlideInTransitionGroup from '../internal/SlideIn';

const styles = {
root: {
position: 'relative',
display: 'flex',
justifyContent: 'space-between',
backgroundColor: 'inherit',
height: 48,
},
title: {
titleDiv: {
fontSize: 14,
fontWeight: '500',
lineHeight: '20px',
position: 'relative',
textAlign: 'center',
paddingTop: 12,
width: '100%',
},
button: {
padding: 0,
paddingTop: 12,
margin: 0,
titleText: {
height: 'inherit',
textAlign: 'center',
paddingTop: 12,
},
};

Expand Down Expand Up @@ -78,30 +71,28 @@ class CalendarToolbar extends Component {
year: 'numeric',
}).format(displayDate);

const nextButtonIcon = this.context.muiTheme.isRtl ? <NavigationChevronRight /> : <NavigationChevronLeft />;
const prevButtonIcon = this.context.muiTheme.isRtl ? <NavigationChevronLeft /> : <NavigationChevronRight />;
const nextButtonIcon = this.context.muiTheme.isRtl ? <NavigationChevronLeft /> : <NavigationChevronRight />;
const prevButtonIcon = this.context.muiTheme.isRtl ? <NavigationChevronRight /> : <NavigationChevronLeft />;

return (
<div style={styles.root}>
<IconButton
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ripple circle is messed up on these buttons:

img

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

disabled={!this.props.prevMonth}
onTouchTap={this.handleTouchTapPrevMonth}
style={styles.button}
>
{nextButtonIcon}
{prevButtonIcon}
</IconButton>
<SlideInTransitionGroup
direction={this.state.transitionDirection}
style={styles.title}
style={styles.titleDiv}
>
<div key={dateTimeFormatted} style={{paddingTop: 13}}>{dateTimeFormatted}</div>
<div key={dateTimeFormatted} style={styles.titleText}>{dateTimeFormatted}</div>
</SlideInTransitionGroup>
<IconButton
disabled={!this.props.nextMonth}
onTouchTap={this.handleTouchTapNextMonth}
style={styles.button}
>
{prevButtonIcon}
{nextButtonIcon}
</IconButton>
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions src/DatePicker/CalendarYear.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ class CalendarYear extends Component {
displayDate: PropTypes.object.isRequired,
maxDate: PropTypes.object,
minDate: PropTypes.object,
onYearTouchTap: PropTypes.func,
onTouchTapYear: PropTypes.func,
selectedDate: PropTypes.object.isRequired,
wordings: PropTypes.object,
};

static contextTypes = {
Expand Down Expand Up @@ -81,7 +82,6 @@ class CalendarYear extends Component {
overflowX: 'hidden',
overflowY: 'scroll',
position: 'relative',
textAlign: 'center',
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
Expand Down
5 changes: 3 additions & 2 deletions src/DatePicker/DateDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function getStyles(props, context, state) {
width: isLandscape ? 125 : 270,
height: isLandscape ? 290 : 'auto',
float: isLandscape ? 'left' : 'none',
fontWeight: 'bolder',
fontWeight: 700,
display: 'inline-block',
backgroundColor: datePicker.selectColor,
borderTopLeftRadius: 2,
Expand Down Expand Up @@ -121,6 +121,7 @@ class DateDisplay extends Component {
DateTimeFormat,
locale,
selectedDate,
style,
...other,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we remove style if it's being used in getStyles()? May as well throw it out here instead of spreading it with {...other} on the root node.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

} = this.props;

Expand All @@ -135,7 +136,7 @@ class DateDisplay extends Component {
}).format(selectedDate);

return (
<div {...other} style={prepareStyles(styles.root)}>
<div {...other} style={prepareStyles(styles.root, style)}>
<SlideInTransitionGroup
style={styles.year}
direction={this.state.transitionDirection}
Expand Down
6 changes: 2 additions & 4 deletions src/DatePicker/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,12 @@ class DatePicker extends Component {
};

state = {
date: null,
dialogDate: null,
date: undefined,
};

componentWillMount() {
this.setState({
date: this.isControlled() ? this.getControlledDate() : this.props.defaultDate,
dialogDate: new Date(),
});
}

Expand Down Expand Up @@ -283,7 +281,7 @@ class DatePicker extends Component {
onTouchTap={this.handleTouchTap}
ref="input"
style={textFieldStyle}
value={this.state.date ? formatDate(this.state.date) : undefined}
value={this.state.date ? formatDate(this.state.date) : ''}
/>
<DatePickerDialog
DateTimeFormat={DateTimeFormat}
Expand Down
9 changes: 5 additions & 4 deletions src/DatePicker/DatePickerDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Calendar from './Calendar';
import Dialog from '../Dialog';
import Popover from '../Popover/Popover';
import PopoverAnimationFromTop from '../Popover/PopoverAnimationVertical';
import deprecated from '../utils/deprecatedPropType';
import {dateTimeFormat} from './dateUtils';

class DatePickerDialog extends Component {
Expand All @@ -24,9 +25,10 @@ class DatePickerDialog extends Component {
onAccept: PropTypes.func,
onDismiss: PropTypes.func,
onShow: PropTypes.func,
open: PropTypes.bool,
shouldDisableDate: PropTypes.func,
style: PropTypes.object,
wordings: PropTypes.object,
wordings: deprecated(PropTypes.object, 'Instead, use `cancelLabel` and `okLabel`.'),
};

static defaultProps = {
Expand Down Expand Up @@ -117,8 +119,7 @@ class DatePickerDialog extends Component {
width: mode === 'landscape' ? 479 : 310,
},
dialogBodyContent: {
paddingLeft: 0,
paddingBottom: 0,
padding: 0,
minHeight: mode === 'landscape' ? 330 : 434,
minWidth: mode === 'landscape' ? 479 : 310,
},
Expand All @@ -134,7 +135,7 @@ class DatePickerDialog extends Component {
bodyStyle={styles.dialogBodyContent}
contentStyle={styles.dialogContent}
ref="dialog"
repositionOnUpdate={false}
repositionOnUpdate={true}
open={open}
onRequestClose={this.handleRequestClose}
style={styles.dialogBodyContent}
Expand Down
1 change: 1 addition & 0 deletions src/DatePicker/YearButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function getStyles(props, context, state) {
margin: '0 auto',
position: 'relative',
textAlign: 'center',
lineHeight: 'inherit',
WebkitTapHighlightColor: 'rgba(0,0,0,0)', // Remove mobile color flashing (deprecated)
},
label: {
Expand Down
2 changes: 0 additions & 2 deletions src/Dialog/Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ function getStyles(props, context) {
color: dialog.bodyColor,
padding: `${props.title ? 0 : gutter}px ${gutter}px ${gutter}px`,
boxSizing: 'border-box',
/* padding: gutter,
paddingTop: 0,*/
overflowY: autoScrollBodyContent ? 'auto' : 'hidden',
},
};
Expand Down