Material-UI Pickers
by John Vincent
Posted on May 29, 2018
This article describes basic usage of Material-UI Pickers.
General
Install the package
npm i material-ui-pickers --save
Date and Time Pickers
An example of using the DateTime
Picker using the Moment package.
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import Moment from 'moment';
import MomentUtils from 'material-ui-pickers/utils/moment-utils';
import MuiPickersUtilsProvider from 'material-ui-pickers/utils/MuiPickersUtilsProvider';
import DateTimePicker from 'material-ui-pickers/DateTimePicker';
class TaskDateTimePicker extends PureComponent {
constructor(props) {
super(props);
this.state = {
selectedMoment: this.props.value
};
}
handleDateChange = moment => {
this.setState({ selectedMoment: moment });
this.props.onSubmit(moment);
};
render() {
return (
<MuiPickersUtilsProvider utils={MomentUtils}>
<DateTimePicker value={this.state.selectedMoment} onChange={this.handleDateChange} />
</MuiPickersUtilsProvider>
);
}
}
TaskDateTimePicker.propTypes = {
value: PropTypes.instanceOf(Moment),
onSubmit: PropTypes.func.isRequired
};
TaskDateTimePicker.defaultProps = {
value: null
};
export default TaskDateTimePicker;
called by
import React from 'react';
import PropTypes from 'prop-types';
import { TaskDateTimePicker } from './';
handleEndDate = moment => {
this.setState({
workingEnd: moment
});
};
<FormControl className={classes.FormControl}>
<InputLabel>Due Date</InputLabel>
<TaskDateTimePicker value={this.state.workingEnd} onSubmit={this.handleEndDate} />
</FormControl>
Material-ui
React
- Basic React
- Basic React Patterns
- Basic React Redux
- Basic React Redux App
- Basic React Testing with Jest and Enzyme
- Building and deploying MyTunes to johnvincent.io
- Building and deploying React Github Helper App to johnvincent.io
- Deploy React App to Heroku using Travis Continuous Integration
- Deploy TaskMuncher React App to AWS
- First time deploy TaskMuncher React App to Digital Ocean
- Gatsby and Client Only Components
- Gatsby Getting Started
- Gatsby React Icons
- Mac Visual Studio Code
- Material-UI
- Material-UI Pickers
- Material-UI Styling
- Optimizing TaskMuncher with Webpack 4
- Overview of React Gomoku
- Overview of React Hangman
- Overview of React Lights Out
- Overview of React Yahtzee
- React Material-UI
- React Production Issues
- React PropTypes
- React/Redux Node/Express Ecosystem
- Redux Dev Tools
- Responsive Material-UI
- Styling Material-UI components using Styled-Components
- TaskMuncher Performance
- Transforming Html with Webpack
- Update TaskMuncher for Lighthouse Findings
- Update TaskMuncher to be a Progressive Web App
- Update TaskMuncher to use React BrowserRouter
- Update TaskMuncher to Webpack v4, Babel v7, Material-UI v3
- Upgrading Babel and ESLint to use React Advanced Language Features
- Webpack Bundle Analyzer