Coder Social home page Coder Social logo

bernalrs / material-ui-pickers Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mui/material-ui-pickers

0.0 1.0 0.0 706 KB

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

Home Page: https://material-ui-pic.firebaseapp.com/

License: MIT License

JavaScript 100.00%

material-ui-pickers's Introduction

Material-UI pickers

npm package Build Status

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

Recently updated?

Changelog available here

Installation

Available as npm package. Please note that we are using moment as a peer dependency

npm install moment material-ui-pickers -S

We are using material-ui-icons 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 the following props

  • leftArrowIcon - arrow left for datepicker
  • rightArrowIcon - arrow right for datepicker
  • dateRangeIcon - date tab icon for datetimepicker
  • timeIcon - time tab icon for datetimepicker

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

Datepicker

  • date - string, number, Date object, Moment object (anything, that can be parsed by moment)
Prop Type Default Definition
value date new Date() Datepicker value
format string 'MMMM Do' Moment format string for input
autoOk boolean false Auto accept date on selection
disableFuture boolean false Disable future dates
animateYearScrolling boolean false Will animate year selection (note that will work for browser supports scrollIntoView api)
openToYearSelection boolean false Open datepicker from year selection
minDate date '1900-01-01' Minimum selectable date
maxDate date '2100-01-01' Maximum selectable date
onChange func required Callback firing when date accepted
returnMoment boolean true Will return moment object in onChange
invalidLabel string 'Unknown' Displayed string if date cant be parsed (or null)
labelFunc func null Allow to specify dynamic label for text field labelFunc(date, invalidLabel)
renderDay fund null Allow to specify custom renderer for day renderDay(date, selectedDate, dayInCurrentMonth)
leftArrowIcon react node, string 'keyboard_arrow_left' Left arrow icon
rightArrowIcon react node, string 'keyboard_arrow_right' Right arrow icon

Timepicker

Prop Type Default Definition
value date new Date() Timepicker value
format string 'MMMM Do' Moment format string for input
autoOk boolean false Auto accept time on selection
onChange func required Callback firing when date accepted
returnMoment boolean true Will return moment object in onChange
invalidLabel string 'Unknown' Displayed string if date cant be parsed (or null)
labelFunc func null Allow to specify dynamic label for text field labelFunc(date, invalidLabel)
ampm boolean true 12h/24h view for hour selection clock

DateTimepicker

Prop Type Default Definition
value date new Date() Timepicker value
format string 'MMMM Do hh:mm a' Moment format string for input
autoOk boolean false Auto accept time on selection
autoSubmit boolean true On change show next time input (year -> date -> hour -> minute)
showTabs boolean false Show date/time tabs
openTo one of 'year', 'date', 'hour', 'minutes' 'date' Open to particular view
animateYearScrolling boolean false Will animate year selection
minDate date '1900-01-01' Minimum selectable date
maxDate date '2100-01-01' Maximum selectable date
onChange func required Callback firing when date accepted
returnMoment boolean true Will return moment object in onChangeg
invalidLabel string 'Unknown' Displayed string if date cant be parsed (or null)
labelFunc func null Allow to specify dynamic label for text field labelFunc(date, invalidLabel)
renderDay fund null Allow to specify custom renderer for day renderDay(date, selectedDate, dayInCurrentMonth)
leftArrowIcon react node, string 'keyboard_arrow_left' Left arrow icon
rightArrowIcon react node, string 'keyboard_arrow_right' Right arrow icon
dateRangeIcon react node, string 'date_range' Date tab icon
timeIcon react node, string 'access_time' Time tab icon
ampm boolean true 12h/24h view for hour selection clock

l10n

For l10n texts we're currently relying on moment which is stateful. To change the locale you have to import your langauge specific files an change the locale manually via moment.locale(language).

import moment from 'moment'
import 'moment/locale/fr';
 
moment.locale('fr')

Jalali Calendar

We are fully supporting Jalali calendar system and right-to-left material-ui api. Special thanks to @alitaheri. Here is a little example of how to use it

import { TimePicker, DateTimePicker, DatePicker } from 'material-ui-pickers';
import jalaliUtils from 'material-ui-pickers-jalali-utils';

jMoment.loadPersian({ dialect: 'persian-modern', usePersianDigits: true });

<DateTimePicker
  okLabel="تأیید"
  cancelLabel="لغو"
  labelFunc={date => jMoment(date).format('jYYYY/jMM/jDD hh:mm A')}
  value={selectedDate}
  onChange={this.handleDateChange}
  utils={jalaliUtils}
/>

Migrate to date-fns?

If you are interested of using moment or date-fns as the peer of this project, please mention that in this issue, we need to know which library if more useful to be in the peer dependencies of this project. Thank you.

Contributing

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

LICENSE

The project is licensed under the terms of MIT license

material-ui-pickers's People

Contributors

alitaheri avatar bguthriejr avatar dmtrkovalenko avatar garypwhite avatar noah-potter avatar sakulstra avatar tfuqua avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.