@nepdatejs/datepicker 0.0.0-bootstrap → 0.1.0
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/LICENSE +21 -0
- package/README.md +109 -1
- package/dist/index.cjs +1325 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +420 -0
- package/dist/index.d.ts +420 -0
- package/dist/index.js +1313 -0
- package/dist/index.js.map +1 -0
- package/dist/nepdate-datepicker.global.js +2 -0
- package/dist/nepdate-datepicker.global.js.map +1 -0
- package/package.json +63 -4
- package/src/base.ts +130 -0
- package/src/datetime.ts +397 -0
- package/src/index.ts +60 -0
- package/src/input.ts +128 -0
- package/src/mask.ts +42 -0
- package/src/multi.ts +318 -0
- package/src/picker.ts +322 -0
- package/src/presets.ts +146 -0
- package/src/range.ts +428 -0
- package/src/types.ts +250 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shishir Rai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,111 @@
|
|
|
1
1
|
# @nepdatejs/datepicker
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Framework-free BS/AD date picker behaviour:
|
|
4
|
+
|
|
5
|
+
- `inline: true` keeps the panel open (`state.inline`) for calendars shown in the page
|
|
6
|
+
- typed text ⇄ value, year first, in ASCII or Devanagari digits; dashes fill in as digits are typed (`mask: false` turns that off, `maskDateText` is exported)
|
|
7
|
+
- validation with English or Nepali messages
|
|
8
|
+
- the BS/AD switch
|
|
9
|
+
- open/close
|
|
10
|
+
- single and range values
|
|
11
|
+
|
|
12
|
+
It renders nothing; the adapters (`@nepdatejs/react`, `@nepdatejs/vanilla`) do.
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @nepdatejs/datepicker
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { createDatePicker } from '@nepdatejs/datepicker';
|
|
20
|
+
|
|
21
|
+
const picker = createDatePicker({
|
|
22
|
+
defaultCalendar: 'BS',
|
|
23
|
+
min: '2026-01-01', // AD "YYYY-MM-DD"
|
|
24
|
+
onChange: (value, detail) => save(value), // value is always AD, e.g. "2026-10-10"
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
picker.actions.type('२०८३-०६-२४');
|
|
28
|
+
picker.getState();
|
|
29
|
+
// { value: '2026-10-10', text: '२०८३-०६-२४', equivalentText: '10 October 2026 AD', error: null, … }
|
|
30
|
+
picker.actions.switchCalendar('AD'); // the text becomes "2026-10-10"; the value does not change
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## The value contract
|
|
34
|
+
|
|
35
|
+
- **Value:** always the AD day as `"YYYY-MM-DD"`, or `""` when empty or invalid. A BS date is never sent as the value.
|
|
36
|
+
- **`onChange(value, detail)`:** called for user actions only (typing, picking, clear, reset). `detail` is `{ ad, bs }` or `null`.
|
|
37
|
+
- **Outside values:** `setValue()` and `setOptions({ value })` never call `onChange`. Passing back the value the user just typed leaves their text alone, so the cursor doesn't jump.
|
|
38
|
+
|
|
39
|
+
## Errors
|
|
40
|
+
|
|
41
|
+
`state.error` is `{ code, message }`, with `code` one of `'format'`, `'range'`, `'disabled'`, `'tooShort'` or `'tooLong'`. The message is already translated, e.g. "Choose 2083-06-15 or later." or "वि.सं. मिति YYYY-MM-DD ढाँचामा लेख्नुहोस्।".
|
|
42
|
+
|
|
43
|
+
## Presets
|
|
44
|
+
|
|
45
|
+
Shortcuts shown beside the calendar. Weeks, months and years count in the calendar on screen, so "This month" is the BS month in BS mode.
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
createDateRangePicker({
|
|
49
|
+
presets: ['last7Days', 'thisMonth', 'lastMonth', 'thisFiscalYear', 'lastFiscalYear'],
|
|
50
|
+
});
|
|
51
|
+
createDatePicker({
|
|
52
|
+
presets: [
|
|
53
|
+
'today',
|
|
54
|
+
'yesterday',
|
|
55
|
+
{ id: 'admission', label: 'Admission day', resolve: () => bsDate(2083, 1, 15) },
|
|
56
|
+
],
|
|
57
|
+
});
|
|
58
|
+
picker.getState().presets; // [{ id, label, isActive, isDisabled }]
|
|
59
|
+
picker.actions.applyPreset('thisFiscalYear'); // 2083-04-01 → 2084-03-32 BS
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
| Picker | Built-in presets |
|
|
63
|
+
| ------ | ------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
64
|
+
| Single | `today`, `yesterday`, `tomorrow` |
|
|
65
|
+
| Range | `today`, `yesterday`, `thisWeek`, `lastWeek`, `last7Days`, `last30Days`, `thisMonth`, `lastMonth`, `thisYear`, `thisFiscalYear`, `lastFiscalYear` |
|
|
66
|
+
|
|
67
|
+
A preset is disabled when its range falls outside `min`/`max` or breaks `minDays`/`maxDays`.
|
|
68
|
+
|
|
69
|
+
## Range picker
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { createDateRangePicker } from '@nepdatejs/datepicker';
|
|
73
|
+
|
|
74
|
+
const range = createDateRangePicker({ minDays: 1, maxDays: 15 });
|
|
75
|
+
range.actions.select(start); // a click in the panel
|
|
76
|
+
range.actions.select(end);
|
|
77
|
+
range.getState().value; // { start: '2026-10-22', end: '2026-10-25' }
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Date and time
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { createDateTimePicker } from '@nepdatejs/datepicker';
|
|
84
|
+
|
|
85
|
+
const picker = createDateTimePicker({
|
|
86
|
+
minuteStep: 15,
|
|
87
|
+
defaultTime: '09:00',
|
|
88
|
+
hour12: true,
|
|
89
|
+
});
|
|
90
|
+
picker.actions.typeDate('2083-06-24');
|
|
91
|
+
picker.actions.typeTime('2:30 pm');
|
|
92
|
+
picker.getState().value; // "2026-10-10T14:30:00+05:45": one instant, with Nepal's offset
|
|
93
|
+
picker.getState().hours; // hour cells for the time column; minutes likewise
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Use `timeZone` to show and store another zone. Values without an offset are taken as wall times in that zone.
|
|
97
|
+
|
|
98
|
+
## Multiple dates
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { createMultiDatePicker } from '@nepdatejs/datepicker';
|
|
102
|
+
|
|
103
|
+
const picker = createMultiDatePicker({ maxDates: 5 });
|
|
104
|
+
picker.actions.select(bsDate(2083, 7, 8)); // a click adds a day, a second click removes it
|
|
105
|
+
picker.actions.type('2083-07-01, 2083-07-05'); // or type them, separated by commas
|
|
106
|
+
picker.getState().value; // ['2026-10-18', '2026-10-22']: sorted AD days
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Every store exposes the panel's calendar store as `.calendar` (see `@nepdatejs/calendar`). The pure helpers `parseInput`, `checkDate`, `formatInput` and `equivalentText` are exported too.
|
|
110
|
+
|
|
111
|
+
MIT © Shishir Rai
|