@archpublicwebsite/rangepicker 1.0.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 +340 -0
- package/dist/Rangepicker.vue.d.ts +58 -0
- package/dist/Rangepicker.vue.d.ts.map +1 -0
- package/dist/RangepickerInput.stories.d.ts +14 -0
- package/dist/RangepickerInput.stories.d.ts.map +1 -0
- package/dist/RangepickerInput.stories.js +117 -0
- package/dist/RangepickerInput.vue.d.ts +47 -0
- package/dist/RangepickerInput.vue.d.ts.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/rangepicker.js +986 -0
- package/dist/rangepicker.js.map +1 -0
- package/dist/rangepicker.umd.cjs +2 -0
- package/dist/rangepicker.umd.cjs.map +1 -0
- package/dist/style.css +1 -0
- package/dist/types.d.ts +46 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/utils/calendar.d.ts +29 -0
- package/dist/utils/calendar.d.ts.map +1 -0
- package/dist/utils/calendar.js +88 -0
- package/dist/utils/date.d.ts +11 -0
- package/dist/utils/date.d.ts.map +1 -0
- package/dist/utils/date.js +31 -0
- package/dist/utils/position.d.ts +8 -0
- package/dist/utils/position.d.ts.map +1 -0
- package/dist/utils/position.js +35 -0
- package/package.json +63 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { dayjs } from './date';
|
|
2
|
+
export function getMonthDays(monthOffset, currentDate = dayjs()) {
|
|
3
|
+
const month = currentDate.add(monthOffset, 'month').startOf('month');
|
|
4
|
+
const firstDayOfMonth = month.day();
|
|
5
|
+
const daysInMonth = month.daysInMonth();
|
|
6
|
+
const daysInPrevMonth = month.subtract(1, 'month').daysInMonth();
|
|
7
|
+
const days = [];
|
|
8
|
+
// Previous month days
|
|
9
|
+
for (let i = firstDayOfMonth - 1; i >= 0; i--) {
|
|
10
|
+
const date = month.subtract(1, 'month').date(daysInPrevMonth - i);
|
|
11
|
+
days.push({
|
|
12
|
+
date,
|
|
13
|
+
isPrevMonth: true,
|
|
14
|
+
isCurrentMonth: false,
|
|
15
|
+
isNextMonth: false,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
// Current month days
|
|
19
|
+
for (let i = 1; i <= daysInMonth; i++) {
|
|
20
|
+
const date = month.date(i);
|
|
21
|
+
days.push({
|
|
22
|
+
date,
|
|
23
|
+
isPrevMonth: false,
|
|
24
|
+
isCurrentMonth: true,
|
|
25
|
+
isNextMonth: false,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
// Next month days to complete the grid
|
|
29
|
+
const remainingDays = 42 - days.length; // 6 weeks * 7 days
|
|
30
|
+
for (let i = 1; i <= remainingDays; i++) {
|
|
31
|
+
const date = month.add(1, 'month').date(i);
|
|
32
|
+
days.push({
|
|
33
|
+
date,
|
|
34
|
+
isPrevMonth: false,
|
|
35
|
+
isCurrentMonth: false,
|
|
36
|
+
isNextMonth: true,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return { month, days };
|
|
40
|
+
}
|
|
41
|
+
export function createCalendarDay(date, isPrevMonth, isCurrentMonth, isNextMonth, options = {}) {
|
|
42
|
+
const { startDate = null, endDate = null, minDate = null, maxDate = null, disabledDates = [], holidays = [], } = options;
|
|
43
|
+
const isDisabled = (minDate && date.isBefore(minDate, 'day'))
|
|
44
|
+
|| (maxDate && date.isAfter(maxDate, 'day'))
|
|
45
|
+
|| disabledDates.some(d => d.isSame(date, 'day'));
|
|
46
|
+
const isHoliday = holidays.some(h => h.isSame(date, 'day'));
|
|
47
|
+
const isSelected = (startDate && date.isSame(startDate, 'day'))
|
|
48
|
+
|| (endDate && date.isSame(endDate, 'day'));
|
|
49
|
+
const isInRange = startDate
|
|
50
|
+
&& endDate
|
|
51
|
+
&& date.isAfter(startDate, 'day')
|
|
52
|
+
&& date.isBefore(endDate, 'day');
|
|
53
|
+
const isToday = date.isSame(dayjs(), 'day');
|
|
54
|
+
const isWeekend = date.day() === 0 || date.day() === 6;
|
|
55
|
+
return {
|
|
56
|
+
date,
|
|
57
|
+
isPrevMonth,
|
|
58
|
+
isCurrentMonth,
|
|
59
|
+
isNextMonth,
|
|
60
|
+
isDisabled,
|
|
61
|
+
isHoliday,
|
|
62
|
+
isWeekend,
|
|
63
|
+
isSelected,
|
|
64
|
+
isInRange,
|
|
65
|
+
isToday,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export function generateCalendarMonths(numberOfMonths, startOffset = 0, options = {}) {
|
|
69
|
+
const months = [];
|
|
70
|
+
for (let i = 0; i < numberOfMonths; i++) {
|
|
71
|
+
const { month, days } = getMonthDays(startOffset + i);
|
|
72
|
+
const calendarDays = days.map(day => createCalendarDay(day.date, day.isPrevMonth, day.isCurrentMonth, day.isNextMonth, options));
|
|
73
|
+
months.push({
|
|
74
|
+
month,
|
|
75
|
+
days: calendarDays,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return months;
|
|
79
|
+
}
|
|
80
|
+
export function getWeekDays(locale = 'en', format = 'short') {
|
|
81
|
+
const weekStart = dayjs().startOf('week');
|
|
82
|
+
const days = [];
|
|
83
|
+
for (let i = 0; i < 7; i++) {
|
|
84
|
+
const day = weekStart.add(i, 'day');
|
|
85
|
+
days.push(format === 'short' ? day.format('ddd') : day.format('dd'));
|
|
86
|
+
}
|
|
87
|
+
return days;
|
|
88
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Dayjs } from 'dayjs';
|
|
2
|
+
import dayjs from 'dayjs';
|
|
3
|
+
export { dayjs };
|
|
4
|
+
export type { Dayjs };
|
|
5
|
+
export declare function parseDate(date: string | Date | Dayjs, format?: string): Dayjs;
|
|
6
|
+
export declare function formatDate(date: Dayjs, format?: string): string;
|
|
7
|
+
export declare function isDateInRange(date: Dayjs, start: Dayjs, end: Dayjs): boolean;
|
|
8
|
+
export declare function getDaysBetween(start: Dayjs, end: Dayjs): number;
|
|
9
|
+
export declare function isWeekend(date: Dayjs): boolean;
|
|
10
|
+
export declare function isToday(date: Dayjs): boolean;
|
|
11
|
+
//# sourceMappingURL=date.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/utils/date.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAClC,OAAO,KAAK,MAAM,OAAO,CAAA;AAWzB,OAAO,EAAE,KAAK,EAAE,CAAA;AAChB,YAAY,EAAE,KAAK,EAAE,CAAA;AAErB,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,KAAK,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,CAI7E;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,GAAE,MAAqB,GAAG,MAAM,CAE7E;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,GAAG,OAAO,CAE5E;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,GAAG,MAAM,CAE/D;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,KAAK,GAAG,OAAO,CAG9C;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,KAAK,GAAG,OAAO,CAE5C"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import isBetween from 'dayjs/plugin/isBetween';
|
|
3
|
+
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
|
|
4
|
+
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
|
|
5
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
6
|
+
dayjs.extend(isBetween);
|
|
7
|
+
dayjs.extend(isSameOrAfter);
|
|
8
|
+
dayjs.extend(isSameOrBefore);
|
|
9
|
+
dayjs.extend(customParseFormat);
|
|
10
|
+
export { dayjs };
|
|
11
|
+
export function parseDate(date, format) {
|
|
12
|
+
if (dayjs.isDayjs(date))
|
|
13
|
+
return date;
|
|
14
|
+
return format ? dayjs(date, format) : dayjs(date);
|
|
15
|
+
}
|
|
16
|
+
export function formatDate(date, format = 'YYYY-MM-DD') {
|
|
17
|
+
return date.format(format);
|
|
18
|
+
}
|
|
19
|
+
export function isDateInRange(date, start, end) {
|
|
20
|
+
return date.isBetween(start, end, 'day', '[]');
|
|
21
|
+
}
|
|
22
|
+
export function getDaysBetween(start, end) {
|
|
23
|
+
return end.diff(start, 'day');
|
|
24
|
+
}
|
|
25
|
+
export function isWeekend(date) {
|
|
26
|
+
const day = date.day();
|
|
27
|
+
return day === 0 || day === 6; // Sunday or Saturday
|
|
28
|
+
}
|
|
29
|
+
export function isToday(date) {
|
|
30
|
+
return date.isSame(dayjs(), 'day');
|
|
31
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface PositionResult {
|
|
2
|
+
top?: number;
|
|
3
|
+
bottom?: number;
|
|
4
|
+
left: number;
|
|
5
|
+
transform?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function calculatePosition(triggerElement: HTMLElement | null, calendarElement: HTMLElement | null, preferredPosition?: 'auto' | 'top' | 'bottom'): PositionResult;
|
|
8
|
+
//# sourceMappingURL=position.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../../src/utils/position.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,iBAAiB,CAC/B,cAAc,EAAE,WAAW,GAAG,IAAI,EAClC,eAAe,EAAE,WAAW,GAAG,IAAI,EACnC,iBAAiB,GAAE,MAAM,GAAG,KAAK,GAAG,QAAiB,GACpD,cAAc,CAyChB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export function calculatePosition(triggerElement, calendarElement, preferredPosition = 'auto') {
|
|
2
|
+
if (!triggerElement || !calendarElement)
|
|
3
|
+
return { left: 0 };
|
|
4
|
+
const triggerRect = triggerElement.getBoundingClientRect();
|
|
5
|
+
const calendarRect = calendarElement.getBoundingClientRect();
|
|
6
|
+
const viewportHeight = window.innerHeight;
|
|
7
|
+
const viewportWidth = window.innerWidth;
|
|
8
|
+
// Calculate available space
|
|
9
|
+
const spaceAbove = triggerRect.top;
|
|
10
|
+
const spaceBelow = viewportHeight - triggerRect.bottom;
|
|
11
|
+
// Determine vertical position
|
|
12
|
+
const position = { left: triggerRect.left };
|
|
13
|
+
if (preferredPosition === 'auto') {
|
|
14
|
+
if (spaceBelow >= calendarRect.height || spaceBelow > spaceAbove) {
|
|
15
|
+
// Position below
|
|
16
|
+
position.top = triggerRect.bottom + 8;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
// Position above
|
|
20
|
+
position.bottom = viewportHeight - triggerRect.top + 8;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else if (preferredPosition === 'top') {
|
|
24
|
+
position.bottom = viewportHeight - triggerRect.top + 8;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
position.top = triggerRect.bottom + 8;
|
|
28
|
+
}
|
|
29
|
+
// Adjust horizontal position to keep within viewport
|
|
30
|
+
if (position.left + calendarRect.width > viewportWidth)
|
|
31
|
+
position.left = viewportWidth - calendarRect.width - 16;
|
|
32
|
+
if (position.left < 16)
|
|
33
|
+
position.left = 16;
|
|
34
|
+
return position;
|
|
35
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@archpublicwebsite/rangepicker",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Custom date range picker component for PBA Hotel Apps",
|
|
5
|
+
"author": "Archipelago International",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/rangepicker.umd.cjs",
|
|
9
|
+
"module": "./dist/rangepicker.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/rangepicker.js",
|
|
15
|
+
"require": "./dist/rangepicker.umd.cjs"
|
|
16
|
+
},
|
|
17
|
+
"./style.css": "./dist/style.css"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/ArchipelagoInternational/archi-ui.git",
|
|
27
|
+
"directory": "packages/rangepicker"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"vue",
|
|
31
|
+
"vue3",
|
|
32
|
+
"date-picker",
|
|
33
|
+
"range-picker",
|
|
34
|
+
"date-range",
|
|
35
|
+
"litepicker",
|
|
36
|
+
"component"
|
|
37
|
+
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"dev": "vite",
|
|
40
|
+
"build": "vite build && tsc",
|
|
41
|
+
"preview": "vite preview",
|
|
42
|
+
"type-check": "tsc --noEmit"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@vueuse/core": "^11.0.0",
|
|
46
|
+
"dayjs": "^1.11.10",
|
|
47
|
+
"terser": "^5.44.1"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@vitejs/plugin-vue": "^5.0.0",
|
|
51
|
+
"autoprefixer": "^10.4.0",
|
|
52
|
+
"postcss": "^8.4.0",
|
|
53
|
+
"tailwindcss": "^3.4.0",
|
|
54
|
+
"typescript": "^5.3.3",
|
|
55
|
+
"vite": "^6.0.7",
|
|
56
|
+
"vite-plugin-dts": "^4.3.0",
|
|
57
|
+
"vue": "3.5.22"
|
|
58
|
+
},
|
|
59
|
+
"private": false,
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "public"
|
|
62
|
+
}
|
|
63
|
+
}
|