A simple mobile UI widget for picking a date within a period.
npm
npm install week-view
ES2015 module import
import WeekView from 'week-view'
Load it via a link tag and a script tag
<!-- css is included in js -->
<script src="/path/to/week-view.js"></script>
new WeekView(element[, options])
- element
- Type:
CSS selector
orHTMLElement
- The container for the widget, normally a div at the top of the page
- Type:
- options (optional)
- Type:
Object
- See Options below.
- Type:
- Type:
Number
- Default: 7
Length of the period. Restricted in [1, 14].
- Type:
Date
- Default:
new Date()
Initial start date of the period.
- Type:
Date
- Default:
new Date()
Minimum date. If given is later than startDate
, it'll be set to startDate
.
- Type:
Date
ornull
- Default:
null
Maximum date. If given is earlier than minDate
, it'll be set to null
.
- Type:
function
- Default:
date => {}
Function to be called when a date is selected.
Param: Date
- the date selected.
- Type:
function
- Default:
(oldStart, currentStart) => {}
Function to be called when the period is changed.
Params:
oldStart
- the old period's start datecurrentStart
- current period's start date
- Type:
Boolean
- Default:
true
Whether to show the header, which contains header text and prev/next buttons.
- Type:
function
- Default:
date => date.toLocaleDateString()
Header text.
Param: Date
- the date selected.
- Type:
Object
- Default:
{}
A set of key-value pairs where key is your custom css class, and value is a function who receives a Date
and returns Boolean
. The class will be added to corresponding cell element when the function returns true
.
e.g.
{
'week-end': date => return [6,0].includes(date.getDay())
}
will add 'week-end' on weekend cells.
- Type:
Array
- Default:
['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
Day texts from Sunday to Saturday.
- start
- Type:
Date
- Type:
- offset (optional)
- Type:
Number
- Type:
- (return value)
- Type:
this
- Type:
Set the period starting from start
, set offset
th date in the period selected.
- (return value)
- Type:
this
- Type:
Re-render current period, e.g. new options set.
- options
- Type:
Object
- Type:
- (return value)
- Type:
this
- Type:
Set new options for the instance, automatically refresh.
num
,startDate
,minDate
,maxDate
are not supported.
- date
- Type:
Date
- Type:
- (return value)
- Type:
this
- Type:
Try to set the given date selected.
Destroy the instance.
- Type:
Array
Dates within the current period.
- Type:
Date
Selected date.
- Chrome latest
- Firefox latest
- QQ Browser latest
MIT.