All Projects → adopted-ember-addons → Ember Pikaday

adopted-ember-addons / Ember Pikaday

Licence: mit
A datepicker component for Ember CLI projects.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Ember Pikaday

Ember Basic Dropdown
The basic dropdown you ember app needs
Stars: ✭ 140 (-7.28%)
Mutual labels:  addon, ember
ember-links-with-follower
Render a set of links with a "follower" line underneath. The follower moves to the active link, matching size and position on the page.
Stars: ✭ 43 (-71.52%)
Mutual labels:  ember, addon
ember-app-scheduler
An Ember addon to schedule work until after the initial render.
Stars: ✭ 67 (-55.63%)
Mutual labels:  ember, addon
Ember Web App
NOTICE: official repository moved to https://github.com/zonkyio/ember-web-app
Stars: ✭ 143 (-5.3%)
Mutual labels:  addon, ember
Ember Searchable Select
Data-down, actions up select-like menu with searching and tagging capabilities.
Stars: ✭ 38 (-74.83%)
Mutual labels:  addon, ember
ember-ref-bucket
This is list of handy ember primitives, created to simplify class-based dom workflow
Stars: ✭ 31 (-79.47%)
Mutual labels:  ember, addon
ember-cli-daterangepicker
Just a simple component to use bootstrap-daterangepicker.
Stars: ✭ 32 (-78.81%)
Mutual labels:  ember, addon
ember-audio
An Ember addon that makes working with the Web Audio API super EZ.
Stars: ✭ 33 (-78.15%)
Mutual labels:  ember, addon
Ember Cli Updater
ember-cli addon to help you update your ember-cli application or addon.
Stars: ✭ 32 (-78.81%)
Mutual labels:  addon, ember
Ember Can
Simple authorisation addon for Ember apps
Stars: ✭ 262 (+73.51%)
Mutual labels:  addon, ember
ember-best-language
🏳 A FastBoot-enabled addon to detect the best language for your user.
Stars: ✭ 18 (-88.08%)
Mutual labels:  ember, addon
Ember Socket Guru
Addon for easy integration with Pusher.js, ActionCable, Socket.io and Phoenix Channels
Stars: ✭ 119 (-21.19%)
Mutual labels:  addon, ember
ember-app-shell
No description or website provided.
Stars: ✭ 23 (-84.77%)
Mutual labels:  ember, addon
ember-legit-forms
Component for creating flexible forms along with validations.
Stars: ✭ 41 (-72.85%)
Mutual labels:  ember, addon
ember-contextual-services
Services in Ember are scoped to the app as a whole and are singletons. Sometimes you don't want that. :) This addon provides ephemeral route-based services.
Stars: ✭ 20 (-86.75%)
Mutual labels:  ember, addon
ember-formly
JavaScript powered forms for Ember
Stars: ✭ 24 (-84.11%)
Mutual labels:  ember, addon
ember-vertical-timeline
A Vertical Timeline for Ember.js apps 🚀
Stars: ✭ 19 (-87.42%)
Mutual labels:  ember, addon
ember-right-click-menu
An easy and flexible addon to add context menus anywhere in your application
Stars: ✭ 14 (-90.73%)
Mutual labels:  ember, addon
ember-eui
Ember Components for Elastic Eui
Stars: ✭ 22 (-85.43%)
Mutual labels:  ember, addon
Ember Attacher
Native tooltips and popovers for Ember.js
Stars: ✭ 69 (-54.3%)
Mutual labels:  addon, ember

ember-pikaday

Build Status Ember Observer Score NPM

ember-pikaday is an addon that can be installed with Ember CLI. It gives you a datepicker input component that can be used in your Ember.js application. ember-cli-moment-shim is used in the background so it is added as NPM dependencies to your application.

The component provided by ember-pikaday is fully acceptance tested. It also provides test helpers to interact with the datepicker in your own acceptance tests. It works in Ember 1.13.1+ or 2.0+, including beta and canary.

Installation

  • Ember.js v3.12 or above
  • Ember CLI v2.13 or above
  • Node.js v10 or above
cd your-project-directory
ember install ember-pikaday

This README is for the new 2.X release of ember-pikaday. You can find the 1.X README in the stable-1 branch.

Usage

While the input shows a formatted date to the user, the value attribute can be any valid JavaScript date including Date object. If the application sets the attribute without a user interaction the datepicker updates accordingly.

<label>
  Start date:
  <PikadayInput @onSelection={{action 'doSomethingWithSelectedValue'}}/>
</label>

You can also pass in other closure actions to handle onOpen, onClose and onDraw events.

<label>
  Start date:
  <PikadayInput 
    @onOpen={{action 'doSomethingOnOpen'}} 
    @onClose={{action 'doSomethingOnClose'}}
    @onDraw={{action 'doSomethingOnDraw'}}
  />
</label>

You can also change the default format from DD.MM.YYYY to any format string supported by Moment.js.

<label>
  Start date:
  <PikadayInput @format={{"MM/DD/YYYY"}}/>
</label>

You can define a theme which will be a CSS class that can be used as a hook for styling different themes.

<label>
  Start date:
  <PikadayInput @theme={{"dark-theme"}} />
</label>

You can change the yearRange. It defaults to 10. the yearRange can be a single number or two comma separated years.

<label>
  Start date:
  <PikadayInput @yearRange={{"4"}}/>
</label>
<label>
  Start date:
  <PikadayInput @yearRange={{"2004,2008"}}/>
</label>

If the second year of the comma separated years is set to currentYear, it sets the maximum selectable year to the current year.

<label>
  Start date:
  <PikadayInput @yearRange={{"2004,currentYear"}}/>
</label>

The readonly attribute is supported as binding so you can make the input readonly for mobile or other usecases.

<label>
  Start date:
  <PikadayInput @readonly={{"readonly"}}/>
</label>

The placeholder attribute is supported as binding so you can improve the user experience of your interface.

<label>
  Due date:
  <PikadayInput @placeholder={{"Due date of invoice"}}/>
</label>

The disabled attribute is supported as binding so you can disabled the datepicker entirely. If the datepicker is shown to the user and it gets disabled it will close the datepicker itself.

<label>
  Due date:
  <PikadayInput @disabled={{isDisabled}}/>
</label>

The firstDay attribute is supported as a binding so you can set the first day of the calendar week. Defaults to Monday.

  • 0 = Sunday
  • 1 = Monday
  • etc...
<label>
  Due date:
  <PikadayInput @firstDay={{0}}/>
</label>

The minDate attribute is supported as a binding so you can set the earliest date that can be selected.

<label>
  Due Date:
  <PikadayInput @minDate={{minDate}}/>
</label>

The maxDate attribute is supported as a binding so you can set the latest date that can be selected.

<label>
  Due Date:
  <PikadayInput @maxDate={{maxDate}}/>
</label>

Return dates in UTC time zone

The date returned by ember-pikaday is in your local time zone due to the JavaScript default behaviour of new Date(). This can lead to problems when your application converts the date to UTC. In additive time zones (e.g. +0010) the resulting converted date could be yesterdays date. You can force the component to return a date with the UTC time zone by passing useUTC=true to it.

<label>
  Start date:
  <PikadayInput @useUTC={{true}}/>
</label>

ember-pikaday will not automatically convert the date to UTC if your application is setting the datepicker value directly!

Using pikaday specific options

You can pass any custom pikaday option through the component like this

<label>
  <PikadayInput @options={{hash numberOfMonths=2 disableWeekends=true disableDayFn=(action 'someAction')}}/>
</label>

Please refer to pikaday configuration

Inputless pikaday

If you don't want to show an input field, you can use the pikaday-inputless component instead of pikaday-input. It has the same API, but doesn't support onOpen and onClose. When disabled=true on a pikaday-inputless, the datepicker gets hidden.

Localization

Localizing the datepicker is possible in two steps. To localize the output of the datepicker, this is the formatted string visible in the input field, you simply include all the locales by following the ember-cli-moment-shim instructions and include the following in your ember-cli-build.js

app.import('node_modules/moment/locale/de.js');

To localize the datepicker itself, this is the popup you see after clicking the input, a little more work is necessary. The prefered way to do this is writting a custom initializer to inject a localized i18n object into the datepicker component. Naturally you can use your own localized strings instead of the ones provided by Moment.js.

// app/initializers/setup-pikaday-i18n.js

import EmberObject from '@ember/object';
import moment from 'moment';

export default {
  name: 'setup-pikaday-i18n',
  initialize: function(application) {
    let i18n = EmberObject.extend({
      previousMonth: 'Vorheriger Monat',
      nextMonth: 'Nächster Monat',
      months: moment.localeData().months(),
      weekdays: moment.localeData().weekdays(),
      weekdaysShort: moment.localeData().weekdaysShort()
    });

    application.register('pikaday-i18n:main', i18n, { singleton: true });
    application.inject('component:pikaday-input', 'i18n', 'pikaday-i18n:main');
  }
};

Examples

Show ember-pikaday when clicking on a button:

<button {{action "togglePika"}}>Show Pika</button>
{{#if showPika}}
    <PikadayInputless @value={{"2017-07-07"}}/>
{{/if}}
// app/controller/index.js
import Ember from 'ember';
export default Ember.Controller.extend({
  actions: {
    togglePika() {
      this.toggleProperty('showPika');
    }
  }
});

Show ember-pikaday when hovering over a div:

<div {{action "showPika" on="mouseEnter"}} {{action "hidePika" on="mouseLeave"}}>
  Hover me to pika
  {{#if showPika}}
    <PikadayInputless @value={{"2017-07-07"}}/>
  {{/if}}
</div>
// app/controller/index.js

import Controller from '@ember/controller';
export default Controller.extend({
  actions: {
    showPika() {
      this.set('showPika', true);
    },
    hidePika() {
      this.set('showPika', false);
    }
  }
});

Test Helpers

The test helpers provided by ember-pikaday allow you to interact with the datepicker in your integration and acceptance tests.

Opening Pikaday

To open the datepicker use click from the @ember/test-helpers package:

import { click } from '@ember/test-helpers';

await click('.my-pikaday-input');

Closing Pikaday

Pikaday can be closed with the provided close helper:

import { close as closePikaday } from 'ember-pikaday/test-support';

await closePikaday('.my-pikaday-input');

Interacting with Pikaday

An Interactor, like a page object, provides helpers for getting and setting dates in a date picker:

import { click } from '@ember/test-helpers';
import { Interactor as Pikaday } from 'ember-pikaday/test-support';

await click('#my-datepicker');
await Pikaday.selectDate(new Date(1989, 3, 28));

There are also methods available to check if a specific day, month or year is selected:

await Interactor.selectDate(new Date(1989, 3, 28));

assert.equal(Interactor.selectedYear(), 1989);
assert.equal(Interactor.selectedMonth(), 3);
assert.equal(Interactor.selectedDay(), 28);

Excluding assets

By default, ember-pikaday will load for you the needed pikaday assets. If you need to use a custom version, you can now disable auto assests importing like this:

// ember-cli-build.js
let app = new EmberApp(defaults, {
  emberPikaday: {
    excludePikadayAssets: true
  }
});

Other Resources

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].