From 54db25152bba48a27efb0d76cbad91289da03f6c Mon Sep 17 00:00:00 2001 From: Ty Date: Fri, 23 Oct 2015 15:31:09 +0100 Subject: [PATCH] Inline Date Picker --- .../pages/components/date-picker.jsx | 15 +++++ .../components/raw-code/date-picker-code.txt | 9 +++ src/date-picker/date-picker-dialog.jsx | 23 ++++++-- src/date-picker/date-picker-inline.jsx | 56 +++++++++++++++++++ src/date-picker/date-picker.jsx | 5 +- 5 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 src/date-picker/date-picker-inline.jsx diff --git a/docs/src/app/components/pages/components/date-picker.jsx b/docs/src/app/components/pages/components/date-picker.jsx index bab5121b19ad12..98698b1357fa66 100644 --- a/docs/src/app/components/pages/components/date-picker.jsx +++ b/docs/src/app/components/pages/components/date-picker.jsx @@ -29,6 +29,12 @@ export default class DatePickerPage extends React.Component { { name: 'Props', infoArray: [ + { + name: 'container', + type: 'one of: dialog, container', + header: 'default: dialog', + desc: 'The date pickers container type', + }, { name: 'DateTimeFormat', type: 'func', @@ -204,6 +210,15 @@ export default class DatePickerPage extends React.Component { hintText="Landscape Dialog" mode="landscape" /> + + + + +//Inline Picker + +//Inline Picker (AutoOk) + diff --git a/src/date-picker/date-picker-dialog.jsx b/src/date-picker/date-picker-dialog.jsx index 6800a1eee12615..d18bb981130b3d 100644 --- a/src/date-picker/date-picker-dialog.jsx +++ b/src/date-picker/date-picker-dialog.jsx @@ -7,6 +7,7 @@ const CssEvent = require('../utils/css-event'); const KeyCode = require('../utils/key-code'); const Calendar = require('./calendar'); const Dialog = require('../dialog'); +const DatePickerInline = require('./date-picker-inline'); const FlatButton = require('../flat-button'); const DefaultRawTheme = require('../styles/raw-themes/light-raw-theme'); const ThemeManager = require('../styles/theme-manager'); @@ -39,6 +40,7 @@ const DatePickerDialog = React.createClass({ }, propTypes: { + container: React.PropTypes.oneOf(['dialog', 'inline']), DateTimeFormat: React.PropTypes.func, locale: React.PropTypes.string, wordings: React.PropTypes.object, @@ -68,6 +70,7 @@ const DatePickerDialog = React.createClass({ getDefaultProps: function() { return { DateTimeFormat: DateTime.DateTimeFormat, + container: 'dialog', locale: 'en-US', wordings: { ok: 'OK', @@ -82,6 +85,7 @@ const DatePickerDialog = React.createClass({ getInitialState() { return { + open: false, isCalendarActive: false, muiTheme: this.context.muiTheme ? this.context.muiTheme : ThemeManager.getMuiTheme(DefaultRawTheme), }; @@ -102,6 +106,7 @@ const DatePickerDialog = React.createClass({ initialDate, onAccept, style, + container, ...other, } = this.props; @@ -148,9 +153,11 @@ const DatePickerDialog = React.createClass({ onTouchTap={this._handleOKTouchTap} /> ); } - + // will change later when Popover is available. + const Container = (container === 'inline' ? DatePickerInline : Dialog); return ( - + repositionOnUpdate={false} + open={this.state.open} + > - + ); }, show() { + if (this.props.container === 'inline') { + return this.setState({'open': true}); + } this.refs.dialog.show(); }, dismiss() { + if (this.props.container === 'inline') { + return this.setState({'open': false}); + } this.refs.dialog.dismiss(); }, diff --git a/src/date-picker/date-picker-inline.jsx b/src/date-picker/date-picker-inline.jsx new file mode 100644 index 00000000000000..22beb97f9983ef --- /dev/null +++ b/src/date-picker/date-picker-inline.jsx @@ -0,0 +1,56 @@ +const React = require('react'); +const Paper = require('../paper'); + +const DatePickerInline = React.createClass({ + + propTypes: { + open: React.PropTypes.bool, + }, + + getDefaultProps: function() { + return { + open: false, + }; + }, + + render() { + let { + style, + actions, + open, + ...other, + } = this.props; + + let styles = { + actions: { + marginRight: 8, + textAlign: 'right', + }, + container: { + zIndex: 100, + width: '100%', + position: 'relative', + display: (open === true ? 'block' : 'none'), + }, + subContainer: { + position:'absolute', + height: 'auto', + }, + }; + return ( +
+
+ + {this.props.children} +
+ {actions} +
+
+
+
+ ); + }, + +}); + +module.exports = DatePickerInline; diff --git a/src/date-picker/date-picker.jsx b/src/date-picker/date-picker.jsx index 211a0f25bd77d2..7c1153f2d9c20a 100644 --- a/src/date-picker/date-picker.jsx +++ b/src/date-picker/date-picker.jsx @@ -28,6 +28,7 @@ const DatePicker = React.createClass({ }, propTypes: { + container: React.PropTypes.oneOf(['dialog', 'inline']), DateTimeFormat: React.PropTypes.func, locale: React.PropTypes.string, wordings: React.PropTypes.object, @@ -37,7 +38,7 @@ const DatePicker = React.createClass({ hideToolbarYearChange: React.PropTypes.bool, maxDate: React.PropTypes.object, minDate: React.PropTypes.object, - mode: React.PropTypes.oneOf(['portrait', 'landscape', 'inline']), + mode: React.PropTypes.oneOf(['portrait', 'landscape']), onDismiss: React.PropTypes.func, onChange: React.PropTypes.func, onFocus: React.PropTypes.func, @@ -83,6 +84,7 @@ const DatePicker = React.createClass({ render() { let { + container, DateTimeFormat, locale, wordings, @@ -113,6 +115,7 @@ const DatePicker = React.createClass({ onFocus={this._handleInputFocus} onTouchTap={this._handleInputTouchTap}/>