Example
<div class="display--flex justify-content-center">
<wui-datepicker />
</div>
Unfortunately, the design page you are looking for is not ready yet. But you might want to switch to the implementation tab. There you will find the corresponding Vue component and a description of the different use cases and what to consider when implementing it.
If you have any questions, suggestions or ideas for improvement right now, please feel free to contact us directly.
via Slack: #wescale-wui-public
via Mail: wescale-wui@wescale.com
Stay tuned!
The
<wui-datepicker>
is wrapper component built on top ofvue2-datepicker
plugin. It extends plugin functionality to fit WeScale requirements regarding functionality and style guide.
Description
To simplify implementation <wui-datepicker>
follows similar logic as an old plugin wui-datepicker in terms of formatting and available properties. Datepicker consists of input group (input and trigger button) and calendar.
<wui-datepicker
v-model="value"
locale="en-US"
placeholder="Input placeholder"
:input-attr="{
id: 'input-id-attribute',
name: 'input-name-attribute',
required: true,
}"
show-week-number
/>
export default { data() { return { value: "2022-08-21", }; }, }
v-model
binding
If you bind a variable to the v-model
prop, value will be the currently selected date. v-model value type depends on prop outputFormat
.
Output format
Developers can set the format of binding value with prop outputFormat
. Default output format is ISO 8601 string token "YYYY-MM-DD"
, other available options are:
Value | Description |
---|---|
"date" | return a Date object |
"timestamp" | return a timestamp number |
"format" | returns a string formatted using pattern of format prop |
token(MM/DD/YYYY) | returns a string formatted using this pattern |
<wui-datepicker value-type="timestamp" v-model="new Date().getTime()" />
Locale
Set locale
property to use user locale for translations and formatting settings. Default locale
is en-US
. Datepicker supports all locales that are supported by old datepicker plugin. All locale formats contain values required by datepicker plugin.
<wui-datepicker locale="de-DE" placeholder="DD.MM.YYYY" show-week-number />
First day of week and some other properties are included in locale object. Example for de-DE
:
{
formatLocale: {
months: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
monthsShort: ['Jan', 'Feb', 'März', 'Apr', 'Mai', 'Juni', 'Juli', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'],
weekdays: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
weekdaysShort: ['So.', 'Mo.', 'Di.', 'Mi.', 'Do.', 'Fr.', 'Sa.'],
weekdaysMin: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
firstDayOfWeek: 1,
firstWeekContainsDate: 4,
},
yearFormat: 'YYYY',
monthFormat: 'MMMM',
monthBeforeYear: true,
valueType: 'DD.MM.YYYY',
}
Range selection
Range selection is supported via range
property. If range is used datepicker will display two calendar side by side.
<wui-datepicker
locale="de-DE"
placeholder="Input in de-DE locale DD.MM.YYYY - DD.MM.YYYY"
range
show-week-number
/>
Formatting
Developers can set custom time formatting for input element using date tokens. Users can type in, or paste text in defined format. If format
is not used default formatting will be locale
format.
<wui-datepicker format="DD-MM-YY" placeholder="DD-MM-YY" />
Unit | Token | Output |
---|---|---|
Year | YY | 70 71 ... 10 11 |
YYYY | 1970 1971 ... 2010 2011 | |
Y | -1000 ...20 ... 1970 ... 9999 +10000 | |
Month | M | 1 2 ... 11 12 |
MM | 01 02 ... 11 12 | |
MMM | Jan Feb ... Nov Dec | |
MMMM | January February ... November December | |
Day of Month | D | 1 2 ... 30 31 |
DD | 01 02 ... 30 31 | |
Day of Week | d | 0 1 ... 5 6 |
dd | Su Mo ... Fr Sa | |
ddd | Sun Mon ... Fri Sat | |
dddd | Sunday Monday ... Friday Saturday | |
AM/PM | A | AM PM |
a | am pm | |
Hour | H | 0 1 ... 22 23 |
HH | 00 01 ... 22 23 | |
h | 1 2 ... 12 | |
hh | 01 02 ... 12 | |
Minute | m | 0 1 ... 58 59 |
mm | 00 01 ... 58 59 | |
Second | s | 0 1 ... 58 59 |
ss | 00 01 ... 58 59 | |
Fractional Second | S | 0 1 ... 8 9 |
SS | 00 01 ... 98 99 | |
SSS | 000 001 ... 998 999 | |
Time Zone | Z | -07:00 -06:00 ... +06:00 +07:00 |
ZZ | -0700 -0600 ... +0600 +0700 | |
Week of Year | w | 1 2 ... 52 53 |
ww | 01 02 ... 52 53 | |
Unix Timestamp | X | 1360013296 |
Unix Millisecond Timestamp | x | 1360013296123 |
User input
User can type in, or paste text in input element, and if that value is in correct user locale format it will be displayed in calendar and emitted as ISO 8601 string. e.g. user locale is de-DE
user can type in or paste in 21072022
or 21.07.2022
and value will be formatted and used as date by plugin. In case input value is in different format than user locale plugin will simply ignore that value. For range datepicker user can also type value in locale format separated by dash -
but it must follow strict locale format e.g. for de-DE
correct user input should be 11.07.2022 - 20.07.2022
Set date
Use v-model
property to set date. Accepted value depends on outputFormat
prop, default is ISO 8601 string "YYYY-MM-DD"
.
If range
prop is used value will be Array of ISO strings e.g. or date object if output-format="date"
<wui-datepicker :v-model="value" format="DD.MM.YYYY" />
export default { data() { return { value: null, }; }, }
Or use value
e.g. for "readonly" or "disabled".
<wui-datepicker value="2022-06-21T12:00:00Z" :editable="false" disabled />
In case range
option is used then value is Array of ISO 8601 formatted strings:
<wui-datepicker
:value="['2022-07-21T12:00:00Z', '2022-07-28T12:00:00Z']"
:editable="false"
disabled
/>
Date selection
To set minimum required date selection use minDate
property. It can be ISO 8601 string or JS Date object.
<wui-datepicker min-date="2022-07-14T12:00:00Z" show-week-number />
Or use allowPastDates
property to allow selection of dates starting from today.
<wui-datepicker :allow-past-dates="false" show-week-number />
Calendar
Datepicker will be appended to body element by default as workaround to overflow issue, also positioning will depend on available space in browser window. Use open
prop to immediately display calendar. In case range
property is used calendar will not close on selection by default, user needs to confirm selection via click on check button or by outside click.
Component reference
<wui-datepicker>
<wui-datepicker>
Properties<wui-datepicker>
Events<wui-datepicker>
Slots
Properties
Property | Type | Default | Description |
---|---|---|---|
locale | String | "en-US" | Set value for user locale |
outputFormat | String | "YYYY-MM-DD" | Check section Output format |
value | String, Object, Array | "" | value prop type depends on outputFormat |
format | String | Based on locale property | Set specific input value format using Formatting tokens |
range | Boolean | false | Use range date picker |
allowPastDates | Boolean | true | Allow user selection of past dates |
minDate | String, Date | "" | Use to set minimum allowed selection date |
showWeekNumber | Boolean | false | Display ISO week numbers in calendar next to days row |
inline | Boolean | false | Display inline datepicker |
open | Boolean | false | Set calendar visibility to open |
disabled | Boolean | false | Use to disable input and calendar |
placeholder | String | "" | Set input element placeholder attribute |
editable | Boolean | true | Set input element to readonly i.e. disable user input |
customPopupClass | String | "" | Set popup element class |
inputClass | String | "" | Set input element class |
inputAttr | Object | null | Set input element attributes eg: { name: 'input-name', id: 'input-id'} |
multiple | Boolean | false | Option to select multiple dates |
appendToBody | Boolean | true | Append calendar popup to body |
rangeSeparator | String | " - " | Text of range separator |
Events
Event | Arguments | Description |
---|---|---|
input | "YYYY-MM-DD" | When the value change (v-model event) |
change | "YYYY-MM-DD" , type('date','hour','minute','second','ampm') | When the value change (same as input) |
open | When panel opening | |
close | When panel closing | |
focus | When input focus | |
blur | When input blur |
Slots
Name | Scoped | Description |
---|---|---|
input | Yes (see package.json) | Replace input |
header | Yes (see package.json) | Popup header |
footer | Yes (see package.json) | Popup footer |
sidebar | Yes (see package.json) | Popup sidebar |