@exmg/exm-date-picker 1.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.rollup.cache/Users/tylerpepper/Development/@exmg/exm-web-components/packages/exm-date-picker/dist/exm-date-picker-base.d.ts +31 -0
- package/.rollup.cache/Users/tylerpepper/Development/@exmg/exm-web-components/packages/exm-date-picker/dist/exm-date-picker-base.js +152 -0
- package/.rollup.cache/Users/tylerpepper/Development/@exmg/exm-web-components/packages/exm-date-picker/dist/exm-date-picker-input-base.d.ts +57 -0
- package/.rollup.cache/Users/tylerpepper/Development/@exmg/exm-web-components/packages/exm-date-picker/dist/exm-date-picker-input-base.js +245 -0
- package/.rollup.cache/Users/tylerpepper/Development/@exmg/exm-web-components/packages/exm-date-picker/dist/exm-date-picker-input.d.ts +18 -0
- package/.rollup.cache/Users/tylerpepper/Development/@exmg/exm-web-components/packages/exm-date-picker/dist/exm-date-picker-input.js +21 -0
- package/.rollup.cache/Users/tylerpepper/Development/@exmg/exm-web-components/packages/exm-date-picker/dist/exm-date-picker-year-grid.d.ts +14 -0
- package/.rollup.cache/Users/tylerpepper/Development/@exmg/exm-web-components/packages/exm-date-picker/dist/exm-date-picker-year-grid.js +74 -0
- package/.rollup.cache/Users/tylerpepper/Development/@exmg/exm-web-components/packages/exm-date-picker/dist/exm-date-picker.d.ts +18 -0
- package/.rollup.cache/Users/tylerpepper/Development/@exmg/exm-web-components/packages/exm-date-picker/dist/exm-date-picker.js +21 -0
- package/.rollup.cache/Users/tylerpepper/Development/@exmg/exm-web-components/packages/exm-date-picker/dist/index.d.ts +8 -0
- package/.rollup.cache/Users/tylerpepper/Development/@exmg/exm-web-components/packages/exm-date-picker/dist/index.js +9 -0
- package/.rollup.cache/Users/tylerpepper/Development/@exmg/exm-web-components/packages/exm-date-picker/dist/styles/exm-date-picker-input-styles-css.d.ts +1 -0
- package/.rollup.cache/Users/tylerpepper/Development/@exmg/exm-web-components/packages/exm-date-picker/dist/styles/exm-date-picker-input-styles-css.js +23 -0
- package/.rollup.cache/Users/tylerpepper/Development/@exmg/exm-web-components/packages/exm-date-picker/dist/styles/exm-date-picker-styles-css.d.ts +1 -0
- package/.rollup.cache/Users/tylerpepper/Development/@exmg/exm-web-components/packages/exm-date-picker/dist/styles/exm-date-picker-styles-css.js +122 -0
- package/.rollup.cache/Users/tylerpepper/Development/@exmg/exm-web-components/packages/exm-date-picker/dist/styles/exm-date-picker-year-grid-styles-css.d.ts +1 -0
- package/.rollup.cache/Users/tylerpepper/Development/@exmg/exm-web-components/packages/exm-date-picker/dist/styles/exm-date-picker-year-grid-styles-css.js +31 -0
- package/README.md +0 -0
- package/dist/exm-date-picker-base.d.ts +31 -0
- package/dist/exm-date-picker-base.js +155 -0
- package/dist/exm-date-picker-input-base.d.ts +57 -0
- package/dist/exm-date-picker-input-base.js +248 -0
- package/dist/exm-date-picker-input.d.ts +18 -0
- package/dist/exm-date-picker-input.js +23 -0
- package/dist/exm-date-picker-year-grid.d.ts +14 -0
- package/dist/exm-date-picker-year-grid.js +76 -0
- package/dist/exm-date-picker.d.ts +18 -0
- package/dist/exm-date-picker.js +23 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +9 -0
- package/dist/styles/exm-date-picker-input-styles-css.d.ts +1 -0
- package/dist/styles/exm-date-picker-input-styles-css.js +26 -0
- package/dist/styles/exm-date-picker-styles-css.d.ts +1 -0
- package/dist/styles/exm-date-picker-styles-css.js +125 -0
- package/dist/styles/exm-date-picker-year-grid-styles-css.d.ts +1 -0
- package/dist/styles/exm-date-picker-year-grid-styles-css.js +34 -0
- package/package.json +47 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { css } from 'lit';
|
|
2
|
+
export const style = css `
|
|
3
|
+
:host {
|
|
4
|
+
--md-menu-container-shape: 1rem;
|
|
5
|
+
--md-menu-container-elevation: 0;
|
|
6
|
+
--md-menu-top-space: 1.25rem;
|
|
7
|
+
--md-menu-bottom-space: 0.75rem;
|
|
8
|
+
--exm-date-picker-inline-padding: 0.75rem;
|
|
9
|
+
|
|
10
|
+
display: block;
|
|
11
|
+
width: 100%;
|
|
12
|
+
padding-inline: 0.75rem;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
md-outlined-text-field {
|
|
16
|
+
width: 100%;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.icon {
|
|
20
|
+
cursor: pointer;
|
|
21
|
+
}
|
|
22
|
+
`;
|
|
23
|
+
//# sourceMappingURL=exm-date-picker-input-styles-css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const style: import("lit").CSSResult;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { css } from 'lit';
|
|
2
|
+
export const style = css `
|
|
3
|
+
:host {
|
|
4
|
+
display: block;
|
|
5
|
+
padding-inline: var(--exm-date-picker-inline-padding, 0);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
calendar-month {
|
|
9
|
+
width: calc(40px * 7);
|
|
10
|
+
margin: 0 auto;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.year,
|
|
14
|
+
.arrow {
|
|
15
|
+
color: var(--md-sys-color-on-surface);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.heading {
|
|
19
|
+
display: flex;
|
|
20
|
+
align-items: center;
|
|
21
|
+
justify-content: center;
|
|
22
|
+
width: 100%;
|
|
23
|
+
color: var(--md-sys-color-on-surface);
|
|
24
|
+
font-size: 14px;
|
|
25
|
+
font-weight: 500;
|
|
26
|
+
line-height: 20px;
|
|
27
|
+
text-transform: uppercase;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.month-year {
|
|
31
|
+
flex: 1;
|
|
32
|
+
margin-inline-start: 48px;
|
|
33
|
+
text-align: center;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
calendar-month::part(heading) {
|
|
37
|
+
display: none;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
calendar-month::part(day) {
|
|
41
|
+
color: var(--md-sys-color-on-surface-variant);
|
|
42
|
+
font-weight: bold;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
calendar-month::part(button) {
|
|
46
|
+
box-sizing: border-box;
|
|
47
|
+
width: 40px;
|
|
48
|
+
height: 40px;
|
|
49
|
+
margin: 0;
|
|
50
|
+
border: 1px solid transparent;
|
|
51
|
+
border-radius: 50%;
|
|
52
|
+
background: transparent;
|
|
53
|
+
color: var(--md-sys-color-on-surface);
|
|
54
|
+
font-weight: 400;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
calendar-month::part(button):hover,
|
|
58
|
+
calendar-month::part(button):focus-visible {
|
|
59
|
+
background: var(--md-sys-color-surface-container-highest);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
calendar-month::part(button):focus-visible {
|
|
63
|
+
outline: none;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
calendar-month::part(today) {
|
|
67
|
+
color: var(--md-sys-color-on-surface);
|
|
68
|
+
border-color: var(--md-sys-color-primary);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
calendar-month::part(selected) {
|
|
72
|
+
background: var(--md-sys-color-primary);
|
|
73
|
+
color: var(--md-sys-color-on-primary);
|
|
74
|
+
border-color: transparent;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
calendar-month::part(selected):hover {
|
|
78
|
+
background: var(--md-sys-color-primary);
|
|
79
|
+
color: var(--md-sys-color-on-primary);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
calendar-month::part(today selected) {
|
|
83
|
+
box-shadow: inset 0 0 0 1px var(--md-sys-color-primary);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
calendar-month::part(outside) {
|
|
87
|
+
color: var(--md-sys-color-on-surface-variant);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
calendar-date::part(button) {
|
|
91
|
+
padding: 0.5rem;
|
|
92
|
+
border: none;
|
|
93
|
+
border-radius: 50%;
|
|
94
|
+
background: transparent;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
calendar-date::part(button):hover {
|
|
98
|
+
background: var(--md-sys-color-surface-container-highest);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
calendar-date::part(header) {
|
|
102
|
+
justify-content: flex-start;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
calendar-date::part(heading) {
|
|
106
|
+
order: 1;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
calendar-date::part(previous) {
|
|
110
|
+
order: 2;
|
|
111
|
+
margin-inline-start: auto;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
calendar-date::part(next) {
|
|
115
|
+
order: 3;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.actions {
|
|
119
|
+
text-align: end;
|
|
120
|
+
}
|
|
121
|
+
`;
|
|
122
|
+
//# sourceMappingURL=exm-date-picker-styles-css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const style: import("lit").CSSResult;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { css } from 'lit';
|
|
2
|
+
export const style = css `
|
|
3
|
+
:host {
|
|
4
|
+
display: block;
|
|
5
|
+
width: 100%;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.grid {
|
|
9
|
+
display: grid;
|
|
10
|
+
grid-template-columns: repeat(4, 1fr);
|
|
11
|
+
gap: 8px 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
md-text-button.selected {
|
|
15
|
+
background: var(--md-sys-color-primary);
|
|
16
|
+
--md-text-button-label-text-color: var(--md-sys-color-on-primary);
|
|
17
|
+
|
|
18
|
+
.year {
|
|
19
|
+
color: var(--md-sys-color-on-primary);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
md-text-button.current {
|
|
24
|
+
border: 1px solid var(--md-sys-color-primary);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.year {
|
|
28
|
+
color: var(--md-sys-color-on-surface);
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
//# sourceMappingURL=exm-date-picker-year-grid-styles-css.js.map
|
package/README.md
ADDED
|
File without changes
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ExmgElement } from '@exmg/lit-base';
|
|
2
|
+
import 'cally';
|
|
3
|
+
import '@material/web/icon/icon.js';
|
|
4
|
+
import '@material/web/button/text-button.js';
|
|
5
|
+
import './exm-date-picker-year-grid.js';
|
|
6
|
+
export interface CalendarDateElement extends HTMLInputElement {
|
|
7
|
+
value: string;
|
|
8
|
+
focusedDate: string;
|
|
9
|
+
focus(options?: unknown): void;
|
|
10
|
+
}
|
|
11
|
+
export declare class ExmDatePickerBase extends ExmgElement {
|
|
12
|
+
locale?: string;
|
|
13
|
+
value: string;
|
|
14
|
+
min?: number;
|
|
15
|
+
max?: number;
|
|
16
|
+
confirmInput: boolean;
|
|
17
|
+
firstDayOfWeek: number;
|
|
18
|
+
showYears: boolean;
|
|
19
|
+
focusedDate: any;
|
|
20
|
+
yearPage: any;
|
|
21
|
+
calendarDate: CalendarDateElement;
|
|
22
|
+
handleFocusDay(event: CustomEvent<Date>): void;
|
|
23
|
+
handleYearChange(event: CustomEvent<number>): void;
|
|
24
|
+
handleDateChange(): void;
|
|
25
|
+
focusDate(): void;
|
|
26
|
+
handleYearsShift(event: Event, direction: 'next' | 'previous'): void;
|
|
27
|
+
handleYearToggle(): Promise<void>;
|
|
28
|
+
handleConfirmClick(): void;
|
|
29
|
+
handleCancelClick(): void;
|
|
30
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { __decorate } from 'tslib';
|
|
2
|
+
import { nothing, html } from 'lit';
|
|
3
|
+
import { ExmgElement } from '@exmg/lit-base';
|
|
4
|
+
import { property, state, query } from 'lit/decorators.js';
|
|
5
|
+
import { DateTime } from 'luxon';
|
|
6
|
+
import 'cally';
|
|
7
|
+
import '@material/web/icon/icon.js';
|
|
8
|
+
import '@material/web/button/text-button.js';
|
|
9
|
+
import './exm-date-picker-year-grid.js';
|
|
10
|
+
|
|
11
|
+
// TODO: Implement form association / validation
|
|
12
|
+
class ExmDatePickerBase extends ExmgElement {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments);
|
|
15
|
+
this.value = '';
|
|
16
|
+
this.confirmInput = true;
|
|
17
|
+
this.firstDayOfWeek = 0;
|
|
18
|
+
this.showYears = false;
|
|
19
|
+
this.focusedDate = DateTime.now();
|
|
20
|
+
this.yearPage = this.focusedDate.year;
|
|
21
|
+
}
|
|
22
|
+
handleFocusDay(event) {
|
|
23
|
+
this.focusedDate = DateTime.fromJSDate(event.detail);
|
|
24
|
+
}
|
|
25
|
+
handleYearChange(event) {
|
|
26
|
+
this.focusedDate = this.focusedDate.set({
|
|
27
|
+
year: event.detail,
|
|
28
|
+
day: 1,
|
|
29
|
+
});
|
|
30
|
+
this.showYears = false;
|
|
31
|
+
}
|
|
32
|
+
handleDateChange() {
|
|
33
|
+
this.value = this.calendarDate.value;
|
|
34
|
+
if (!this.confirmInput) {
|
|
35
|
+
this.fire('date-change', this.value, true);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
focusDate() {
|
|
39
|
+
const date = DateTime.fromISO(this.value);
|
|
40
|
+
if (!date.isValid) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
this.focusedDate = date;
|
|
44
|
+
this.calendarDate.focusedDate = this.value;
|
|
45
|
+
this.calendarDate.focus({ target: 'day' });
|
|
46
|
+
}
|
|
47
|
+
handleYearsShift(event, direction) {
|
|
48
|
+
if (!this.showYears)
|
|
49
|
+
return;
|
|
50
|
+
event.stopPropagation();
|
|
51
|
+
this.yearPage += direction === 'next' ? 24 : -24;
|
|
52
|
+
}
|
|
53
|
+
async handleYearToggle() {
|
|
54
|
+
if (this.showYears) {
|
|
55
|
+
this.yearPage = this.focusedDate.year;
|
|
56
|
+
}
|
|
57
|
+
await this.updateComplete;
|
|
58
|
+
this.showYears = !this.showYears;
|
|
59
|
+
}
|
|
60
|
+
handleConfirmClick() {
|
|
61
|
+
this.fire('date-change', this.value, true);
|
|
62
|
+
}
|
|
63
|
+
handleCancelClick() {
|
|
64
|
+
this.fire('date-cancel', this.value, true);
|
|
65
|
+
}
|
|
66
|
+
render() {
|
|
67
|
+
const year = this.focusedDate.year;
|
|
68
|
+
const heading = this.focusedDate.setLocale(this.locale).toFormat('LLL yyyy');
|
|
69
|
+
const focusedDate = this.focusedDate.toISODate();
|
|
70
|
+
// Cally only supports ISO date string
|
|
71
|
+
const min = this.min ? DateTime.fromMillis(this.min).toISODate() : undefined;
|
|
72
|
+
const max = this.max ? DateTime.fromMillis(this.max).toISODate() : undefined;
|
|
73
|
+
return html `
|
|
74
|
+
<calendar-date
|
|
75
|
+
.locale=${this.locale}
|
|
76
|
+
.value=${this.value}
|
|
77
|
+
.focusedDate=${focusedDate}
|
|
78
|
+
.min=${min}
|
|
79
|
+
.max=${max}
|
|
80
|
+
@focusday=${this.handleFocusDay}
|
|
81
|
+
@change=${this.handleDateChange}
|
|
82
|
+
first-day-of-week=${this.firstDayOfWeek}
|
|
83
|
+
show-outside-days
|
|
84
|
+
>
|
|
85
|
+
<md-text-button slot="heading" @click=${this.handleYearToggle}>
|
|
86
|
+
<span class="heading">
|
|
87
|
+
${heading}
|
|
88
|
+
<md-icon> ${this.showYears ? 'arrow_drop_up' : 'arrow_drop_down'} </md-icon>
|
|
89
|
+
</span>
|
|
90
|
+
</md-text-button>
|
|
91
|
+
|
|
92
|
+
<md-icon class="arrow" slot="previous" @click=${(event) => this.handleYearsShift(event, 'previous')}>
|
|
93
|
+
chevron_left
|
|
94
|
+
</md-icon>
|
|
95
|
+
|
|
96
|
+
<md-icon class="arrow" slot="next" @click=${(event) => this.handleYearsShift(event, 'next')}>
|
|
97
|
+
chevron_right
|
|
98
|
+
</md-icon>
|
|
99
|
+
|
|
100
|
+
${this.showYears
|
|
101
|
+
? html `
|
|
102
|
+
<exm-date-picker-year-grid
|
|
103
|
+
.year=${year}
|
|
104
|
+
.min=${this.min}
|
|
105
|
+
.max=${this.max}
|
|
106
|
+
.displayYear=${this.yearPage}
|
|
107
|
+
@year-change=${this.handleYearChange}
|
|
108
|
+
></exm-date-picker-year-grid>
|
|
109
|
+
`
|
|
110
|
+
: html ` <calendar-month></calendar-month> `}
|
|
111
|
+
${this.confirmInput
|
|
112
|
+
? html `
|
|
113
|
+
<div class="actions">
|
|
114
|
+
<md-text-button @click="${this.handleCancelClick}">Cancel</md-text-button>
|
|
115
|
+
<md-text-button @click="${this.handleConfirmClick}">Ok</md-text-button>
|
|
116
|
+
</div>
|
|
117
|
+
`
|
|
118
|
+
: nothing}
|
|
119
|
+
</calendar-date>
|
|
120
|
+
`;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
__decorate([
|
|
124
|
+
property({ type: String })
|
|
125
|
+
], ExmDatePickerBase.prototype, "locale", void 0);
|
|
126
|
+
__decorate([
|
|
127
|
+
property({ type: String })
|
|
128
|
+
], ExmDatePickerBase.prototype, "value", void 0);
|
|
129
|
+
__decorate([
|
|
130
|
+
property({ type: Number })
|
|
131
|
+
], ExmDatePickerBase.prototype, "min", void 0);
|
|
132
|
+
__decorate([
|
|
133
|
+
property({ type: Number })
|
|
134
|
+
], ExmDatePickerBase.prototype, "max", void 0);
|
|
135
|
+
__decorate([
|
|
136
|
+
property({ type: Boolean, attribute: 'confirm-input' })
|
|
137
|
+
], ExmDatePickerBase.prototype, "confirmInput", void 0);
|
|
138
|
+
__decorate([
|
|
139
|
+
property({ type: Number })
|
|
140
|
+
], ExmDatePickerBase.prototype, "firstDayOfWeek", void 0);
|
|
141
|
+
__decorate([
|
|
142
|
+
state()
|
|
143
|
+
], ExmDatePickerBase.prototype, "showYears", void 0);
|
|
144
|
+
__decorate([
|
|
145
|
+
state()
|
|
146
|
+
], ExmDatePickerBase.prototype, "focusedDate", void 0);
|
|
147
|
+
__decorate([
|
|
148
|
+
state()
|
|
149
|
+
], ExmDatePickerBase.prototype, "yearPage", void 0);
|
|
150
|
+
__decorate([
|
|
151
|
+
query('calendar-date')
|
|
152
|
+
], ExmDatePickerBase.prototype, "calendarDate", void 0);
|
|
153
|
+
|
|
154
|
+
export { ExmDatePickerBase };
|
|
155
|
+
//# sourceMappingURL=exm-date-picker-base.js.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { PropertyValues } from 'lit';
|
|
2
|
+
import { ExmgElement } from '@exmg/lit-base';
|
|
3
|
+
import '@material/web/textfield/outlined-text-field.js';
|
|
4
|
+
import '@material/web/menu/menu.js';
|
|
5
|
+
import '@material/web/icon/icon.js';
|
|
6
|
+
export declare class ExmDatePickerInputBase extends ExmgElement {
|
|
7
|
+
static formAssociated: boolean;
|
|
8
|
+
private internals;
|
|
9
|
+
static shadowRootOptions: {
|
|
10
|
+
delegatesFocus: boolean;
|
|
11
|
+
clonable?: boolean;
|
|
12
|
+
customElementRegistry?: CustomElementRegistry;
|
|
13
|
+
mode: ShadowRootMode;
|
|
14
|
+
serializable?: boolean;
|
|
15
|
+
slotAssignment?: SlotAssignmentMode;
|
|
16
|
+
};
|
|
17
|
+
label: string;
|
|
18
|
+
value?: number;
|
|
19
|
+
name?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Display/input format.
|
|
22
|
+
*/
|
|
23
|
+
format: string;
|
|
24
|
+
locale: string;
|
|
25
|
+
/**
|
|
26
|
+
* Timezone as IANA timezone string
|
|
27
|
+
*/
|
|
28
|
+
timezone: string;
|
|
29
|
+
closeOnSelect: boolean;
|
|
30
|
+
disabled: boolean;
|
|
31
|
+
required: boolean;
|
|
32
|
+
supportingText: string;
|
|
33
|
+
min?: number;
|
|
34
|
+
max?: number;
|
|
35
|
+
private menu;
|
|
36
|
+
private input;
|
|
37
|
+
private datePickers;
|
|
38
|
+
get dateTime(): any;
|
|
39
|
+
get displayValue(): any;
|
|
40
|
+
get datePickerValue(): any;
|
|
41
|
+
constructor();
|
|
42
|
+
protected firstUpdated(): void;
|
|
43
|
+
protected updated(changedProperties: PropertyValues<this>): void;
|
|
44
|
+
validate(): void;
|
|
45
|
+
private updateFormValue;
|
|
46
|
+
private formatTimestamp;
|
|
47
|
+
private updateDatePickerValue;
|
|
48
|
+
private handleDatePickerToggle;
|
|
49
|
+
private handleDateChange;
|
|
50
|
+
private handleDateCancel;
|
|
51
|
+
private handleInputChange;
|
|
52
|
+
syncDatePicker(): void;
|
|
53
|
+
checkValidity(): boolean;
|
|
54
|
+
reportValidity(): boolean;
|
|
55
|
+
private setValidity;
|
|
56
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
57
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { __decorate } from 'tslib';
|
|
2
|
+
import { html } from 'lit';
|
|
3
|
+
import { property, query, queryAssignedElements } from 'lit/decorators.js';
|
|
4
|
+
import { ExmgElement } from '@exmg/lit-base';
|
|
5
|
+
import { DateTime } from 'luxon';
|
|
6
|
+
import '@material/web/textfield/outlined-text-field.js';
|
|
7
|
+
import '@material/web/menu/menu.js';
|
|
8
|
+
import '@material/web/icon/icon.js';
|
|
9
|
+
|
|
10
|
+
class ExmDatePickerInputBase extends ExmgElement {
|
|
11
|
+
get dateTime() {
|
|
12
|
+
if (this.value === undefined) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
const date = DateTime.fromMillis(this.value, {
|
|
16
|
+
zone: this.timezone,
|
|
17
|
+
locale: this.locale,
|
|
18
|
+
});
|
|
19
|
+
return date.isValid ? date : undefined;
|
|
20
|
+
}
|
|
21
|
+
get displayValue() {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
return (_b = (_a = this.dateTime) === null || _a === void 0 ? void 0 : _a.toFormat(this.format)) !== null && _b !== void 0 ? _b : '';
|
|
24
|
+
}
|
|
25
|
+
get datePickerValue() {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
return (_b = (_a = this.dateTime) === null || _a === void 0 ? void 0 : _a.toISODate()) !== null && _b !== void 0 ? _b : '';
|
|
28
|
+
}
|
|
29
|
+
constructor() {
|
|
30
|
+
super();
|
|
31
|
+
this.internals = this.attachInternals();
|
|
32
|
+
this.label = 'Select Date';
|
|
33
|
+
/**
|
|
34
|
+
* Display/input format.
|
|
35
|
+
*/
|
|
36
|
+
this.format = 'dd-MM-yyyy';
|
|
37
|
+
this.locale = 'en-US';
|
|
38
|
+
/**
|
|
39
|
+
* Timezone as IANA timezone string
|
|
40
|
+
*/
|
|
41
|
+
this.timezone = 'local';
|
|
42
|
+
this.closeOnSelect = true;
|
|
43
|
+
this.disabled = false;
|
|
44
|
+
this.required = false;
|
|
45
|
+
this.supportingText = '';
|
|
46
|
+
this.addEventListener('invalid', (event) => {
|
|
47
|
+
// NOTE: Prevent browser ui
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
this.input.error = true;
|
|
50
|
+
this.input.errorText = this.internals.validationMessage;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
firstUpdated() {
|
|
54
|
+
this.syncDatePicker();
|
|
55
|
+
}
|
|
56
|
+
updated(changedProperties) {
|
|
57
|
+
if (changedProperties.has('value') || changedProperties.has('required')) {
|
|
58
|
+
this.updateFormValue();
|
|
59
|
+
}
|
|
60
|
+
if (changedProperties.has('value') || changedProperties.has('timezone')) {
|
|
61
|
+
this.updateDatePickerValue();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
validate() {
|
|
65
|
+
if (this.required && this.value === undefined) {
|
|
66
|
+
this.setValidity({ valueMissing: true }, 'Please select a date');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// Min validation
|
|
70
|
+
if (this.value !== undefined && this.min !== undefined && this.value < this.min) {
|
|
71
|
+
this.setValidity({ rangeUnderflow: true }, `Date must be on or after ${this.formatTimestamp(this.min)}`);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
// Max validation
|
|
75
|
+
if (this.value !== undefined && this.max !== undefined && this.value > this.max) {
|
|
76
|
+
this.setValidity({ rangeOverflow: true }, `Date must be on or before ${this.formatTimestamp(this.max)}`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
this.setValidity();
|
|
80
|
+
}
|
|
81
|
+
updateFormValue() {
|
|
82
|
+
this.internals.setFormValue(this.value !== undefined ? String(this.value) : null);
|
|
83
|
+
this.validate();
|
|
84
|
+
}
|
|
85
|
+
formatTimestamp(timestamp) {
|
|
86
|
+
return DateTime.fromMillis(timestamp, {
|
|
87
|
+
zone: this.timezone,
|
|
88
|
+
locale: this.locale,
|
|
89
|
+
}).toFormat(this.format);
|
|
90
|
+
}
|
|
91
|
+
updateDatePickerValue() {
|
|
92
|
+
const picker = this.datePickers[0];
|
|
93
|
+
if (!picker) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const value = this.datePickerValue;
|
|
97
|
+
if (picker.value !== value) {
|
|
98
|
+
picker.value = value;
|
|
99
|
+
if (value) {
|
|
100
|
+
picker.focusDate();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
handleDatePickerToggle(event) {
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
if (this.disabled) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
this.menu.open = !this.menu.open;
|
|
110
|
+
}
|
|
111
|
+
handleDateChange(event) {
|
|
112
|
+
const date = DateTime.fromISO(event.detail, {
|
|
113
|
+
zone: this.timezone,
|
|
114
|
+
locale: this.locale,
|
|
115
|
+
}).startOf('day');
|
|
116
|
+
if (!date.isValid) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
this.value = date.toMillis();
|
|
120
|
+
if (this.closeOnSelect) {
|
|
121
|
+
this.menu.open = false;
|
|
122
|
+
}
|
|
123
|
+
this.fire('change', this.value);
|
|
124
|
+
}
|
|
125
|
+
handleDateCancel() {
|
|
126
|
+
this.menu.open = false;
|
|
127
|
+
}
|
|
128
|
+
handleInputChange(event) {
|
|
129
|
+
const input = event.currentTarget;
|
|
130
|
+
const date = DateTime.fromFormat(input.value, this.format, {
|
|
131
|
+
locale: this.locale,
|
|
132
|
+
zone: this.timezone,
|
|
133
|
+
}).startOf('day');
|
|
134
|
+
if (!date.isValid) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
this.value = date.toMillis();
|
|
138
|
+
this.fire('change', this.value);
|
|
139
|
+
}
|
|
140
|
+
syncDatePicker() {
|
|
141
|
+
const picker = this.datePickers[0];
|
|
142
|
+
if (!picker) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
picker.min = this.min;
|
|
146
|
+
picker.max = this.max;
|
|
147
|
+
picker.locale = this.locale;
|
|
148
|
+
}
|
|
149
|
+
checkValidity() {
|
|
150
|
+
const valid = this.internals.checkValidity();
|
|
151
|
+
return valid;
|
|
152
|
+
}
|
|
153
|
+
reportValidity() {
|
|
154
|
+
const valid = this.internals.reportValidity();
|
|
155
|
+
if (valid) {
|
|
156
|
+
this.input.error = false;
|
|
157
|
+
this.input.errorText = '';
|
|
158
|
+
}
|
|
159
|
+
return valid;
|
|
160
|
+
}
|
|
161
|
+
// NOTE: To sync validity with the input field
|
|
162
|
+
setValidity(flags = {}, message = '') {
|
|
163
|
+
this.internals.setValidity(flags, message);
|
|
164
|
+
if (!message) {
|
|
165
|
+
this.input.error = false;
|
|
166
|
+
this.input.errorText = '';
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (this.input.error) {
|
|
170
|
+
this.input.errorText = message;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// TODO: Option for supporting different inputs
|
|
174
|
+
render() {
|
|
175
|
+
return html `
|
|
176
|
+
<md-outlined-text-field
|
|
177
|
+
id="date-input"
|
|
178
|
+
label=${this.label}
|
|
179
|
+
.value=${this.displayValue}
|
|
180
|
+
?disabled=${this.disabled}
|
|
181
|
+
?required=${this.required}
|
|
182
|
+
@change=${this.handleInputChange}
|
|
183
|
+
supporting-text=${this.supportingText}
|
|
184
|
+
>
|
|
185
|
+
<md-icon class="icon" slot="trailing-icon" @click=${this.handleDatePickerToggle}>calendar_month</md-icon>
|
|
186
|
+
</md-outlined-text-field>
|
|
187
|
+
|
|
188
|
+
<!-- NOTE: Might need some position tweaking -->
|
|
189
|
+
<md-menu anchor="date-input" positioning="popover">
|
|
190
|
+
<slot @date-change=${this.handleDateChange} @date-cancel=${this.handleDateCancel}></slot>
|
|
191
|
+
</md-menu>
|
|
192
|
+
`;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
ExmDatePickerInputBase.formAssociated = true;
|
|
196
|
+
// NOTE: For an issue where the browser don't know what to focus on if invalid, might need another solution after testing
|
|
197
|
+
ExmDatePickerInputBase.shadowRootOptions = {
|
|
198
|
+
...ExmgElement.shadowRootOptions,
|
|
199
|
+
delegatesFocus: true,
|
|
200
|
+
};
|
|
201
|
+
__decorate([
|
|
202
|
+
property({ type: String })
|
|
203
|
+
], ExmDatePickerInputBase.prototype, "label", void 0);
|
|
204
|
+
__decorate([
|
|
205
|
+
property({ type: Number })
|
|
206
|
+
], ExmDatePickerInputBase.prototype, "value", void 0);
|
|
207
|
+
__decorate([
|
|
208
|
+
property({ type: String })
|
|
209
|
+
], ExmDatePickerInputBase.prototype, "name", void 0);
|
|
210
|
+
__decorate([
|
|
211
|
+
property({ type: String })
|
|
212
|
+
], ExmDatePickerInputBase.prototype, "format", void 0);
|
|
213
|
+
__decorate([
|
|
214
|
+
property({ type: String })
|
|
215
|
+
], ExmDatePickerInputBase.prototype, "locale", void 0);
|
|
216
|
+
__decorate([
|
|
217
|
+
property({ type: String, reflect: true })
|
|
218
|
+
], ExmDatePickerInputBase.prototype, "timezone", void 0);
|
|
219
|
+
__decorate([
|
|
220
|
+
property({ type: Boolean, attribute: 'close-on-select' })
|
|
221
|
+
], ExmDatePickerInputBase.prototype, "closeOnSelect", void 0);
|
|
222
|
+
__decorate([
|
|
223
|
+
property({ type: Boolean, reflect: true })
|
|
224
|
+
], ExmDatePickerInputBase.prototype, "disabled", void 0);
|
|
225
|
+
__decorate([
|
|
226
|
+
property({ type: Boolean })
|
|
227
|
+
], ExmDatePickerInputBase.prototype, "required", void 0);
|
|
228
|
+
__decorate([
|
|
229
|
+
property({ type: String, attribute: 'supporting-text' })
|
|
230
|
+
], ExmDatePickerInputBase.prototype, "supportingText", void 0);
|
|
231
|
+
__decorate([
|
|
232
|
+
property({ type: Number })
|
|
233
|
+
], ExmDatePickerInputBase.prototype, "min", void 0);
|
|
234
|
+
__decorate([
|
|
235
|
+
property({ type: Number })
|
|
236
|
+
], ExmDatePickerInputBase.prototype, "max", void 0);
|
|
237
|
+
__decorate([
|
|
238
|
+
query('md-menu')
|
|
239
|
+
], ExmDatePickerInputBase.prototype, "menu", void 0);
|
|
240
|
+
__decorate([
|
|
241
|
+
query('md-outlined-text-field')
|
|
242
|
+
], ExmDatePickerInputBase.prototype, "input", void 0);
|
|
243
|
+
__decorate([
|
|
244
|
+
queryAssignedElements({ selector: 'exm-date-picker' })
|
|
245
|
+
], ExmDatePickerInputBase.prototype, "datePickers", void 0);
|
|
246
|
+
|
|
247
|
+
export { ExmDatePickerInputBase };
|
|
248
|
+
//# sourceMappingURL=exm-date-picker-input-base.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import '@material/web/progress/circular-progress.js';
|
|
2
|
+
import { ExmDatePickerInputBase } from './exm-date-picker-input-base.js';
|
|
3
|
+
/**
|
|
4
|
+
* exm-date-picker-input
|
|
5
|
+
*
|
|
6
|
+
* Material 3 styled date picker with input, form associated.
|
|
7
|
+
*
|
|
8
|
+
* @customElement exm-date-picker-input
|
|
9
|
+
* @extends ExmDatePickerInputBase
|
|
10
|
+
*/
|
|
11
|
+
export declare class ExmDatePickerInput extends ExmDatePickerInputBase {
|
|
12
|
+
static styles: import("lit").CSSResult[];
|
|
13
|
+
}
|
|
14
|
+
declare global {
|
|
15
|
+
interface HTMLElementTagNameMap {
|
|
16
|
+
'exm-date-picker-input': ExmDatePickerInput;
|
|
17
|
+
}
|
|
18
|
+
}
|