npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

semantic-ui-daterangepicker-canjs

v0.1.0

Published

CanJS wrapper around SemanticUI Date Range Picker component

Downloads

7

Readme

semantic-ui-daterangepicker-canjs

CanJS wrapper around SemanticUI Date Range Picker component

A can.view.attr wrapper around the SemanticUI Date Range Picker. With can.view.attr you can add custom behavior to elements that contain a specified html attribute. Since SemanticUI is a set of jQuery plugins, can.view.attr is a natural way to invoke them in a CanJS or DoneJS application.

This wrapper allows you to use SemanticUI Date Range Picker with just html, no need to run jQuery plugin yourself.

SemanticUI's CSS should be imported separately. You can use semantic-ui-less package as in this demo.

Demo

See the included demo /demo/demo.html (run npm install, then http-server in the project root and browse /demo/demo.html).

Date Range Picker

Installation

npm install semantic-ui-daterangepicker-canjs --save

Usage

<input type="text" semantic-daterangepicker />

<!-- As a single-calendar date-picker -->
<input type="text" semantic-daterangepicker single="true"/>

<!-- Specify start and end dates -->
<input type="text" semantic-daterangepicker
  start-date="6/23/2016"
  end-date="9/23/2016"/>

<!-- Specify date string format -->
<input type="text" semantic-daterangepicker
  start-date="Jun 23 2016"
  end-date="Sep 23 2016"
  format="MMM D Y"/>

Use as a single date picker with live binding

Use a template like this:

<input type="text" semantic-daterangepicker
  single="true"
  {($value)}="formattedDate"
  format="MMM D Y"/>

And this example viewModel:

import Map from 'can/map/';
import 'can/map/define/';
import moment from 'moment';

let DateMap = Map.extend({
  define: {
    date: {
      value: new Date()
    },

    formattedDate: {
      get(){
        let date = this.attr('date');
        return moment(date).format('MMM D Y');
      },
      set(val){
        let date = moment(val);
        // If an invalid date is set, set it to today's date.
        if (date.toString() === 'Invalid date') {
          return this.attr('formattedDate', moment());
        }
        this.attr('date', date);
        return val;
      }
    }
  }
});

let dateMap = new DateMap();

$('#demo').viewModel(dateMap).attr(dateMap);

API

Attributes:

  • semantic-daterangepicker - main attribute to invoke the wrapper
  • start-date - (Date object, moment object or string) The start of the initially selected date range
  • end-date - (Date object, moment object or string) The end of the initially selected date range
  • min-date - (Date object, moment object or string) The earliest date a user may select
  • max-date - (Date object, moment object or string) The latest date a user may select
  • format - (Moment.js format string) Specifies the expected format for parsing the text input's value.
  • date-limit - (A JSON-parseable string starting with a space) The maximum span between the selected start and end dates. Can have any property you can add to a moment object (i.e. days, months)
  • show-dropdowns - (boolean) Show year and month select boxes above calendars to jump to a specific month and year
  • show-week-numbers - (boolean) Show localized week numbers at the start of each week on the calendars
  • show-iso-week-numbers - (boolean) Show ISO week numbers at the start of each week on the calendars
  • time-picker - (boolean) Allow selection of dates with times, not just dates
  • time-picker-increment - (number) Increment of the minutes selection list for times (i.e. 30 to allow only selection of times ending in 0 or 30)
  • time-picker-24-hour - (boolean) Use 24-hour instead of 12-hour times, removing the AM/PM selection
  • time-picker-seconds - (boolean) Show seconds in the timePicker
  • ranges - (A JSON-parseable string beginning with a space) Set predefined date ranges the user can select from. Each key is the label for the range, and its value an array with two dates representing the bounds of the range
  • opens - (string: 'left'/'right'/'center') Whether the picker appears aligned to the left, to the right, or centered under the HTML element it's attached to
  • drops - (string: 'down' or 'up') Whether the picker appears below (default) or above the HTML element it's attached to
  • button-classes - (comma-separated string) CSS class names that will be added to all buttons in the picker
  • apply-class - (string) CSS class string that will be added to the apply button
  • cancel-class - (string) CSS class string that will be added to the cancel button
  • single-date-picker - (boolean) Show only a single calendar to choose one date, instead of a range picker with two calendars; the start and end dates provided to your callback will be the same single date chosen
  • auto-apply - (boolean) Hide the apply and cancel buttons, and automatically apply a new date range as soon as two dates or a predefined range is selected
  • linked-calendars - (boolean) When enabled, the two calendars displayed will always be for two sequential months (i.e. January and February), and both will be advanced when clicking the left or right arrows above the calendars. When disabled, the two calendars can be individually advanced and display any month/year.
  • parent-el - (string) jQuery selector of the parent element that the date range picker will be added to, if not provided this will be 'body'
  • is-invalid-date-fn - (function) A function that is passed each date in the two calendars before they are displayed, and may return true or false to indicate whether that date should be available for selection or not.
  • is-custom-date-fn - (function) A function that is passed each date in the two calendars before they are displayed, and may return a string or array of CSS class names to apply to that date's calendar cell.
  • auto-update-input - (boolean) Indicates whether the date range picker should automatically update the value of an element it's attached to at initialization and when the selected dates change.
  • always-show-calendars - (boolean) Normally, if you use the ranges option to specify pre-defined date ranges, calendars for choosing a custom date range are not shown until the user clicks "Custom Range". When this option is set to true, the calendars for choosing a custom date range are always shown instead.
  • locale-separator - (string) in multiple calendar mode, allows for customizing the separator between the two dates in the text input.
  • locale-apply-label - (string) allows customizing the text in the apply button.
  • locale-cancel-label - (string) allows customizing the text in the cancel button.
  • locale-from-label - (string) allows customizing the 'from' label.
  • locale-to-label - (string) allows customizing the 'to' label.
  • locale-custom-range-label - (string) allows customizing the name of the last range in the list. (when the ranges are turned on.)
  • locale-week-label - (string) allows customizing the label that appears when show-week-numbers is set to true.
  • locale-days-of-week - (comma-separated string) allows customizing the labels for the days of the week in the calendar.
  • locale-month-names - (comma-separated string) allows customizing the month names.
  • locale-first-day - (integer)

Contributing

Pull requests are welcome.

Authors