simon-void / pikaday_datepicker

Provides an Angular2 datepicker component by wrapping the lightweight pikaday js-library.
Other
4 stars 0 forks source link

PikadayDatepicker

A Dart Datepicker usable (with dart:html)

screenshot

If you do find bugs or have feature requests please submit them to the issues Also see the changelog

Usage

html-file config

Link to the Pikaday-js library (with it's css file) and the optional but highly advisable Moment.js library (for advanced date formating) in your index.html-file:

<link rel="stylesheet" href="https://github.com/simon-void/pikaday_datepicker/blob/master/pikaday.css">
<script src="https://github.com/simon-void/pikaday_datepicker/raw/master/moment.js"></script>
<script src="https://github.com/simon-void/pikaday_datepicker/raw/master/pikaday.js"></script>

Download a local copy of those libs, put them in or under the directory your index.html file is in, an link accordingly.

dart-file usage

Check out the example under web.

Import and use PikadayParams and upgradeInputToDatepicker(...) into your dart code:

import 'dart:html';
import 'package:intl/intl.dart';
import 'package:pikaday_datepicker/pikaday_datepicker.dart';

void main() {
  final inputElem = new InputElement() ..placeholder="select a day";
  final outputElem = new DivElement();

  final params = new PikadayParams()
    ..defaultDay = new DateTime(2015, 2, 1)
    ..format="DD-MM-YYYY"
    ..firstDay="1"
    ..minDate="2010-1-1"
    ..maxDate="2025-12-31"
    ..showDayOnInit="false";

  final dayFormatter = new DateFormat('MMM dd, yyyy');
  updateOutput(DateTime selectedDay){
    outputElem.text = "selectedDay: ${dayFormatter.format(selectedDay)}";
  }

  // make the input a pikaday-datepicker
  upgradeInputToDatepicker(inputElem, updateOutput, params);

  // wire the elements to the page
  final appDiv = querySelector("#datepickerShowcase");
  appDiv.text = "";
  appDiv.children
    ..add(inputElem)
    ..add(outputElem);
}

Configuration

PikadayParams has many useful options, which can be provided as instance of type String or their real type (int/bool/DateTime with format yyyy-mm-dd):

Common problems

The Dart-Wrapper can't access the Pikaday-JS-constructor. You probably forgot to link to the js-lib itself in index.html:

<link rel="stylesheet" href="https://github.com/simon-void/pikaday_datepicker/blob/master/pikaday.css">
<script src="https://github.com/simon-void/pikaday_datepicker/raw/master/moment.js"></script>
<script src="https://github.com/simon-void/pikaday_datepicker/raw/master/pikaday.js"></script>

Authors

Thanks to David Bushell for writing Pikaday.

Copyright © 2017 Stephan Schröder | BSD & MIT license