-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrange-date-picker.js
97 lines (81 loc) · 2.12 KB
/
range-date-picker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { html, css, LitElement } from 'https://unpkg.com/lit-element?module';
class RangeDatePicker extends LitElement {
static styles = css`
:host {
display: block;
font-family: Arial, sans-serif;
}
.datepicker {
display: inline-block;
border: 1px solid #ccc;
padding: 8px;
}
.calendar {
display: grid;
grid-template-columns: repeat(7, 1fr);
gap: 4px;
}
.header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
}
.prev-month,
.next-month {
cursor: pointer;
}
.days {
display: grid;
grid-template-columns: repeat(7, 1fr);
gap: 4px;
}
.day {
display: flex;
align-items: center;
justify-content: center;
height: 32px;
cursor: pointer;
border-radius: 4px;
}
.day:hover {
background-color: #f2f2f2;
}
.day.selected {
background-color: #007bff;
color: #fff;
}
`;
static get properties() {
return {
startDate: { type: String },
endDate: { type: String },
};
}
constructor() {
super();
this.startDate = localStorage.getItem('start-date') || '';
this.endDate = localStorage.getItem('end-date') || '';
}
render() {
return html`
<div class="datepicker">
<label>Start Date:</label>
<input type="date" .value="${this.startDate}" @change="${this.handleStartDateChange}" />
<label>End Date:</label>
<input type="date" .value="${this.endDate}" @change="${this.handleEndDateChange}" />
</div>
`;
}
handleStartDateChange(event) {
this.startDate = event.target.value;
localStorage.setItem('start-date', this.startDate);
this.dispatchEvent(new CustomEvent('start-date-selected', { detail: this.startDate }));
}
handleEndDateChange(event) {
this.endDate = event.target.value;
localStorage.setItem('end-date', this.endDate);
this.dispatchEvent(new CustomEvent('end-date-selected', { detail: this.endDate }));
}
}
customElements.define('range-date-picker', RangeDatePicker);