imx-select-datepicker 0.0.1 → 0.0.2
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/README.md +23 -4
- package/index.js +2 -1
- package/package.json +1 -1
- package/src/InputGroup/InputGroup.js +12 -0
- package/src/InputGroup/utils/Option.js +2 -2
- package/src/InputRange/InputRange.js +40 -0
package/README.md
CHANGED
|
@@ -8,17 +8,24 @@ A component for managing date inputs with separate controls for day and month.
|
|
|
8
8
|
const inputGroup = new InputGroup(startDate, endDate);
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
```javascript
|
|
12
|
+
const inputGroupFrom = new InputGroup();
|
|
13
|
+
const inputGroupTo = new InputGroup();
|
|
14
|
+
|
|
15
|
+
const inputRange = new InputRange(inputGroupFrom, inputGroupTo);
|
|
16
|
+
```
|
|
17
|
+
|
|
11
18
|
**Parameters:**
|
|
12
19
|
- `startDate` (Date, optional) - The start date for the possible select options. Defaults to the current date minus 1 year.
|
|
13
20
|
- `endDate` (Date, optional) - The end date for the possible select options. Defaults to the current date plus 1 year.
|
|
14
21
|
|
|
15
|
-
## Usage as single date picker
|
|
22
|
+
## Usage as single date picker (use InputGroup only)
|
|
16
23
|
|
|
17
24
|
```javascript
|
|
18
25
|
const inputGroup = new InputGroup();
|
|
19
26
|
inputDate.appendChild(inputGroup.markup);
|
|
20
27
|
|
|
21
|
-
inputGroup.update(new Date('2026-
|
|
28
|
+
inputGroup.update(new Date('2026-12-01'));
|
|
22
29
|
```
|
|
23
30
|
|
|
24
31
|
## Usage as range date picker
|
|
@@ -30,17 +37,29 @@ inputDate.appendChild(inputGroupFrom.markup);
|
|
|
30
37
|
const inputGroupTo = new InputGroup();
|
|
31
38
|
inputDate.appendChild(inputGroupTo.markup);
|
|
32
39
|
|
|
40
|
+
const inputRange = new InputRange(inputGroupFrom, inputGroupTo);
|
|
41
|
+
|
|
33
42
|
inputGroupFrom.update(new Date('2026-01-01'));
|
|
34
43
|
inputGroupTo.update(new Date('2026-12-31'));
|
|
35
44
|
```
|
|
36
45
|
|
|
37
46
|
## Properties
|
|
38
47
|
|
|
39
|
-
- **`markup`** - The DOM element of the component that can be inserted into the document
|
|
40
48
|
- **`daySelect.select`** - Select element for day selection, to register a change listener.
|
|
41
49
|
- **`monthSelect.select`** - Select element for month selection, to register a change listener.
|
|
42
50
|
|
|
43
51
|
## Methods
|
|
52
|
+
### `getMarkup()`
|
|
53
|
+
Returns the HTML markup for the input group to append it to the DOM.
|
|
54
|
+
|
|
55
|
+
### `getMonthSelect()`
|
|
56
|
+
Returns the month select element for registering change listeners.
|
|
57
|
+
|
|
58
|
+
### `getDaySelect()`
|
|
59
|
+
Returns the day select element for registering change listeners.
|
|
60
|
+
|
|
61
|
+
### `getValue()`
|
|
62
|
+
Returns the currently selected date as a ISO date string (YYYY-MM-DD).
|
|
44
63
|
|
|
45
64
|
### `update(date)`
|
|
46
65
|
Updates the input fields with a new date.
|
|
@@ -57,7 +76,7 @@ Sets the minimum selectable date for the input fields.
|
|
|
57
76
|
## Events
|
|
58
77
|
|
|
59
78
|
```javascript
|
|
60
|
-
inputGroupFrom.
|
|
79
|
+
inputGroupFrom.getDaySelect().addEventListener('change', (event) => {
|
|
61
80
|
const newDate = new Date(event.target.value);
|
|
62
81
|
console.log('New date:', newDate);
|
|
63
82
|
});
|
package/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { InputGroup } from "./src/InputGroup/InputGroup.js";
|
|
1
|
+
export { InputGroup } from "./src/InputGroup/InputGroup.js";
|
|
2
|
+
export { InputRange } from "./src/InputRange/InputRange.js";
|
package/package.json
CHANGED
|
@@ -33,6 +33,18 @@ export class InputGroup {
|
|
|
33
33
|
return this.daySelect.select.value;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
getMarkup() {
|
|
37
|
+
return this.markup;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getMonthSelect() {
|
|
41
|
+
return this.monthSelect.select;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
getDaySelect() {
|
|
45
|
+
return this.daySelect.select;
|
|
46
|
+
}
|
|
47
|
+
|
|
36
48
|
update(jsDateObject) {
|
|
37
49
|
if(dayjs(jsDateObject).isValid()) {
|
|
38
50
|
this.updateMonth(jsDateObject);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export class Option {
|
|
2
2
|
static createMonthOption(date) {
|
|
3
|
-
const formatted = date.
|
|
3
|
+
const formatted = date.toDate().toLocaleDateString('de-DE', { month: 'long', year: 'numeric' });
|
|
4
4
|
return this.createOption(date.format('YYYY-MM-DD'), formatted);
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
static createDayOption(date) {
|
|
8
|
-
const formatted = date.
|
|
8
|
+
const formatted = date.toDate().toLocaleDateString('de-DE', { weekday: 'short', day: '2-digit' })
|
|
9
9
|
return this.createOption(date.format('YYYY-MM-DD'), formatted);
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
|
|
3
|
+
export class InputRange {
|
|
4
|
+
|
|
5
|
+
constructor(inputGroupFrom, inputGroupTo) {
|
|
6
|
+
this.inputGroupFrom = inputGroupFrom;
|
|
7
|
+
this.inputGroupTo = inputGroupTo;
|
|
8
|
+
|
|
9
|
+
this.registerSync();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
registerSync() {
|
|
13
|
+
const { inputGroupFrom, inputGroupTo } = this;
|
|
14
|
+
|
|
15
|
+
inputGroupFrom.getDaySelect().addEventListener('change', (event) => {
|
|
16
|
+
const newDate = new Date(event.target.value);
|
|
17
|
+
inputGroupTo.setMinDate(newDate);
|
|
18
|
+
|
|
19
|
+
if(dayjs(newDate).isAfter(dayjs(inputGroupTo.getValue()), 'day')) {
|
|
20
|
+
inputGroupTo.update(newDate);
|
|
21
|
+
inputGroupTo.getDaySelect().dispatchEvent(new Event('change'));
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
inputGroupFrom.getMonthSelect().addEventListener('change', (event) => {
|
|
26
|
+
const newDate = new Date(event.target.value);
|
|
27
|
+
inputGroupTo.setMinDate(newDate);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
inputGroupTo.getMonthSelect().addEventListener('change', (event) => {
|
|
31
|
+
const newDate = new Date(event.target.value);
|
|
32
|
+
|
|
33
|
+
if(dayjs(newDate).isSame(dayjs(inputGroupFrom.getValue()), 'month')) {
|
|
34
|
+
const fromDate = new Date(inputGroupFrom.getValue());
|
|
35
|
+
inputGroupTo.update(fromDate);
|
|
36
|
+
inputGroupTo.setMinDate(fromDate);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|