1.0.0-rc.1 • Published 6 years ago

@gyurist/material-ui-pickers v1.0.0-rc.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

Material-UI pickers

npm package npm download Build Status

Components, that implements material design date and time pickers for material-ui v1

Click here for demo

Recently updated?

Changelog available here

Installation

Available as npm package.

npm install material-ui-pickers -S

Now choose the library that pickers will use to work with date. We are providing interfaces for moment and date-fns. If you are not using moment in the project (or dont have it in the bundle already) we suggest using date-fns, because it much more lightweight and will be correctly tree-shaked from the bundle.

Teach pickers how to use one of that library using MuiPickersUtilsProvider. This component takes an utils property, and makes it available down the React tree thanks to React context. It should preferably be used at the root of your component tree.

import { MuiPickersUtilsProvider } from 'material-ui-pickers';
import MomentUtils from 'material-ui-pickers/utils/moment-utils';
import DateFnsUtils from 'material-ui-picker/utils/date-fns-utils'

function App() {
  return ( 
    <MuiPickersUtilsProvider utils={DateFnsUtils}>
      <Root />
    </MuiPickersUtilsProvider>
  );
}

render(<App />, document.querySelector('#app'));

We are using material-ui-icons icon font to display icons. Just add this to your html

<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

If you dont want to use icon font, or you are already use material-ui-icons you can pass any icon to the components with corresponding props

Usage

Here is a quick example of how to use this package

import { TimePicker, DatePicker, DateTimePicker } from 'material-ui-pickers'

class App extends Component {
  state = {
    selectedDate: new Date(),
    selectedTime: new Date(),
    selectedDateTime: new Date()
  }

  handleDateChange = date => {
    this.setState({ selectedDate: date })
  }

  handleTimeChange = time => {
    this.setState({ selectedTime: time })
  }

  handleDateTimeChange = dateTime => {
    this.setState({ selectedDateTime: dateTime })
  }

  render() {
    const { selectedDate, selectedTime, selectedDateTime } = this.state

    return (
      <div>
        <DatePicker
          value={selectedDate}
          onChange={this.handleDateChange}
        />

        <TimePicker
          value={selectedTime}
          onChange={this.handleTimeChange}
        />

        <DateTimePicker
          value={selectedDateTime}
          onChange={this.handleDateTimeChange}
        />
      </div>
    )
  }
}

Props documentation

Here is a list of available props

Note: Any prop not recognized by the pickers and their sub-components are passed down to material-ui TextField component.

Datepicker

  • date - string, number, Date object or Moment object (if you are using moment utils)
PropTypeDefaultDefinition
valuedatenew Date()Datepicker value
formatstring'MMMM Do'Format string for input
autoOkbooleanfalseAuto accept date on selection
disablePastbooleanfalseDisable past dates
disableFuturebooleanfalseDisable future dates
animateYearScrollingbooleanfalseWill animate year selection (note that will work for browser supports scrollIntoView api)
openToYearSelectionbooleanfalseOpen datepicker from year selection
minDatedate'1900-01-01'Minimum selectable date
maxDatedate'2100-01-01'Maximum selectable date
onChangefuncrequiredCallback firing when date accepted
invalidLabelstring'Unknown'Displayed string if date cant be parsed
emptyLabelstring''Displayed string if date is null (e.g. after clear)
okLabelstring'OK'The label for the ok button
cancelLabelstring'Cancel'The label for the cancel button
clearLabelstring'Clear'The label for the clear button
labelFuncfuncnullAllow to specify dynamic label for text field labelFunc(date, invalidLabel). Note, that date equals null after picker is cleared.
renderDayfuncnullAllow to specify custom renderer for day renderDay(date, selectedDate, dayInCurrentMonth)
leftArrowIconreact node<Icon>keyboard_arrow_left</Icon>Left arrow icon
rightArrowIconreact node<Icon>keyboard_arrow_right</Icon>Right arrow icon
shouldDisableDate(date: Moment) => boolean() => falseAllow to disable custom date in calendar
keyboardbooleanfalseAllow to manual input date to the text field
keyboardIconreact node<Icon>event</Icon>Keyboard adornment icon
maxDateMessagestring'Date should not be after maximal date'Maximum date error message for keyboard input
minDateMessagestring'Date should not be before minimal date'Minimum date error message for keyboard input
masktext mask (read more here)undefinedText mask for keyboard-mode
clearablebooleanfalseIf true, clear button will be displayed
TextFieldComponentfunc, stringundefinedComponent that should replace the default Material-UI TextField
InputAdornmentPropsobject{}Props to pass to keyboard input adornment
inputAdornmentPositionenum 'start', 'end''end'Specifies position of keyboard adornment

Timepicker

PropTypeDefaultDefinition
valuedatenew Date()Timepicker value
formatstring'MMMM Do'Moment format string for input
autoOkbooleanfalseAuto accept time on selection
onChangefuncrequiredCallback firing when date accepted
invalidLabelstring'Unknown'Displayed string if date cant be parsed
emptyLabelstring''Displayed string if date is null (e.g. after clear)
okLabelstring'OK'The label for the ok button
cancelLabelstring'Cancel'The label for the cancel button
clearLabelstring'Clear'The label for the clear button
labelFuncfuncnullAllow to specify dynamic label for text field labelFunc(date, invalidLabel). Note, that date equals null after picker is cleared.
ampmbooleantrue12h/24h view for hour selection clock
keyboardbooleanfalseAllow to manual input date to the text field
keyboardIconreact node<Icon>event</Icon>Keyboard adornment icon
masktext mask (read more here)undefinedText mask for keyboard-mode
clearablebooleanfalseIf true, clear button will be displayed
TextFieldComponentfunc, stringundefinedComponent that should replace the default Material-UI TextField
InputAdornmentPropsobject{}Props to pass to keyboard input adornment
inputAdornmentPositionenum 'start', 'end''end'Specifies position of keyboard adornment

DateTimepicker

PropTypeDefaultDefinition
valuedatenew Date()Timepicker value
formatstring'MMMM Do hh:mm a'Moment format string for input
autoOkbooleanfalseAuto accept time on selection
autoSubmitbooleantrueOn change show next time input (year -> date -> hour -> minute)
disablePastbooleanfalseDisable past dates
disableFuturebooleanfalseDisable future dates
showTabsbooleanfalseShow date/time tabs
openToone of 'year', 'date', 'hour', 'minutes''date'Open to particular view
animateYearScrollingbooleanfalseWill animate year selection
minDatedate'1900-01-01'Minimum selectable date
maxDatedate'2100-01-01'Maximum selectable date
onChangefuncrequiredCallback firing when date accepted
invalidLabelstring'Unknown'Displayed string if date cant be parsed
emptyLabelstring''Displayed string if date is null (e.g. after clear)
okLabelstring'OK'The label for the ok button
cancelLabelstring'Cancel'The label for the cancel button
clearLabelstring'Clear'The label for the clear button
labelFuncfuncnullAllow to specify dynamic label for text field labelFunc(date, invalidLabel). Note, that date equals null after picker is cleared.
renderDayfuncnullAllow to specify custom renderer for day renderDay(date, selectedDate, dayInCurrentMonth)
leftArrowIconreact node<Icon>keyboard_arrow_left</Icon>Left arrow icon
rightArrowIconreact node<Icon>keyboard_arrow_right</Icon>Right arrow icon
dateRangeIconreact node<Icon>date_range</Icon>Date tab icon
timeIconreact node<Icon>access_time</Icon>Time tab icon
ampmbooleantrue12h/24h view for hour selection clock
shouldDisableDate(date: MomentDate) => boolean() => falseAllow to disable custom date in calendar
keyboardbooleanfalseAllow to manual input date to the text field
keyboardIconreact node<Icon>event</Icon>Keyboard adornment icon
maxDateMessagestring'Date should not be after maximal date'Maximum date error message for keyboard input
minDateMessagestring'Date should not be before minimal date'Minimum date error message for keyboard input
invalidDateMessagestring'Invalid Date Format'Message, appearing when date cannot be parsed
masktext mask (read more here)undefinedText mask for keyboard-mode
clearablebooleanfalseIf true, clear button will be displayed
TextFieldComponentfunc, stringundefinedComponent that should replace the default Material-UI TextField
InputAdornmentPropsobject{}Props to pass to keyboard input adornment
inputAdornmentPositionenum 'start', 'end''end'Specifies position of keyboard adornment

Contributing

For information about how to contribute, see the CONTRIBUTING file.

LICENSE

The project is licensed under the terms of MIT license