@korsolutions/ui 0.0.20 → 0.0.22

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.
Files changed (46) hide show
  1. package/dist/components/index.d.mts +50 -2
  2. package/dist/components/index.mjs +177 -4
  3. package/dist/hooks/index.d.mts +32 -2
  4. package/dist/hooks/index.mjs +79 -2
  5. package/dist/{index-CGY0mO6z.d.mts → index-vgnXBa4Z.d.mts} +98 -10
  6. package/dist/index.d.mts +3 -3
  7. package/dist/index.mjs +3 -2
  8. package/dist/primitives/index.d.mts +3 -2
  9. package/dist/primitives/index.mjs +3 -2
  10. package/dist/{primitives-P_8clvQr.mjs → primitives-ApsPS0vU.mjs} +335 -118
  11. package/dist/{toast-manager-DSo9oN8w.mjs → toast-manager-Cdhl1ep0.mjs} +1 -1
  12. package/dist/use-numeric-mask-B9WZG25o.d.mts +33 -0
  13. package/dist/use-numeric-mask-BQlz1Pus.mjs +113 -0
  14. package/dist/use-relative-position-BTKEyT1F.mjs +106 -0
  15. package/dist/use-relative-position-DBzhrBU7.d.mts +61 -0
  16. package/package.json +1 -1
  17. package/src/components/calendar/calendar.tsx +31 -0
  18. package/src/components/calendar/index.ts +1 -0
  19. package/src/components/calendar/variants/default.tsx +127 -0
  20. package/src/components/calendar/variants/index.ts +5 -0
  21. package/src/components/index.ts +2 -1
  22. package/src/components/input/index.ts +2 -0
  23. package/src/components/input/numeric-input.tsx +73 -0
  24. package/src/hooks/index.ts +4 -1
  25. package/src/hooks/use-currency-mask.ts +141 -0
  26. package/src/hooks/use-numeric-mask.ts +202 -0
  27. package/src/primitives/calendar/calendar-day.tsx +64 -0
  28. package/src/primitives/calendar/calendar-header.tsx +21 -0
  29. package/src/primitives/calendar/calendar-nav-button.tsx +60 -0
  30. package/src/primitives/calendar/calendar-root.tsx +41 -0
  31. package/src/primitives/calendar/calendar-title.tsx +23 -0
  32. package/src/primitives/calendar/calendar-week-labels.tsx +45 -0
  33. package/src/primitives/calendar/calendar-weeks.tsx +47 -0
  34. package/src/primitives/calendar/context.ts +23 -0
  35. package/src/primitives/calendar/index.ts +26 -0
  36. package/src/primitives/calendar/types.ts +39 -0
  37. package/src/primitives/dropdown-menu/context.ts +1 -1
  38. package/src/primitives/dropdown-menu/dropdown-menu-content.tsx +1 -1
  39. package/src/primitives/dropdown-menu/dropdown-menu-root.tsx +1 -1
  40. package/src/primitives/index.ts +1 -0
  41. package/src/primitives/popover/context.ts +1 -1
  42. package/src/primitives/popover/popover-content.tsx +1 -1
  43. package/src/primitives/popover/popover-root.tsx +1 -1
  44. package/src/utils/date-utils.ts +113 -0
  45. /package/src/hooks/{useRelativePosition.ts → use-relative-position.ts} +0 -0
  46. /package/src/hooks/{useScreenSize.ts → use-screen-size.ts} +0 -0
@@ -0,0 +1,113 @@
1
+ export const formatDate = (date: Date, format: string): string => {
2
+ const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
3
+
4
+ const day = date.getDate();
5
+ const month = months[date.getMonth()];
6
+ const year = date.getFullYear();
7
+
8
+ if (format === "MMMM yyyy") {
9
+ return `${month} ${year}`;
10
+ }
11
+ if (format === "d") {
12
+ return day.toString();
13
+ }
14
+
15
+ return date.toLocaleDateString();
16
+ };
17
+
18
+ export const isDateSameDay = (date1: Date, date2: Date): boolean => {
19
+ return date1.getFullYear() === date2.getFullYear() && date1.getMonth() === date2.getMonth() && date1.getDate() === date2.getDate();
20
+ };
21
+
22
+ export const isDateToday = (date: Date): boolean => {
23
+ return isDateSameDay(date, new Date());
24
+ };
25
+
26
+ export const isDateBefore = (date1: Date, date2: Date): boolean => {
27
+ const d1 = new Date(date1.getFullYear(), date1.getMonth(), date1.getDate());
28
+ const d2 = new Date(date2.getFullYear(), date2.getMonth(), date2.getDate());
29
+ return d1.getTime() < d2.getTime();
30
+ };
31
+
32
+ export const isDateAfter = (date1: Date, date2: Date): boolean => {
33
+ const d1 = new Date(date1.getFullYear(), date1.getMonth(), date1.getDate());
34
+ const d2 = new Date(date2.getFullYear(), date2.getMonth(), date2.getDate());
35
+ return d1.getTime() > d2.getTime();
36
+ };
37
+
38
+ export const isDateTimeWithinInterval = (date: Date, interval: { start: Date; end: Date }): boolean => {
39
+ const time = date.getTime();
40
+ return time >= interval.start.getTime() && time <= interval.end.getTime();
41
+ };
42
+
43
+ export const addMonths = (date: Date, months: number): Date => {
44
+ const newDate = new Date(date);
45
+ newDate.setMonth(newDate.getMonth() + months);
46
+ return newDate;
47
+ };
48
+
49
+ export const subMonths = (date: Date, months: number): Date => {
50
+ return addMonths(date, -months);
51
+ };
52
+
53
+ export const startOfMonth = (date: Date): Date => {
54
+ return new Date(date.getFullYear(), date.getMonth(), 1);
55
+ };
56
+
57
+ export const endOfMonth = (date: Date): Date => {
58
+ return new Date(date.getFullYear(), date.getMonth() + 1, 0);
59
+ };
60
+
61
+ export const getDaysInMonth = (date: Date): number => {
62
+ return endOfMonth(date).getDate();
63
+ };
64
+
65
+ export const getFirstDayOfMonth = (date: Date): number => {
66
+ return startOfMonth(date).getDay();
67
+ };
68
+
69
+ export const isSameMonth = (date1: Date, date2: Date): boolean => {
70
+ return date1.getFullYear() === date2.getFullYear() && date1.getMonth() === date2.getMonth();
71
+ };
72
+
73
+ export const getWeekDays = (month: number, year: number, week: number): Date[] => {
74
+ const days: Date[] = [];
75
+ const firstDayOfMonth = new Date(year, month, 1).getDay();
76
+ const daysInMonth = getDaysInMonth(new Date(year, month));
77
+
78
+ // Calculate the date of the first day in the week
79
+ const startDay = week * 7 - (firstDayOfMonth === 0 ? 6 : firstDayOfMonth - 1);
80
+
81
+ for (let i = 0; i < 7; i++) {
82
+ const day = startDay + i;
83
+ let date: Date;
84
+
85
+ if (day < 1) {
86
+ // Days from previous month
87
+ const prevMonth = month === 0 ? 11 : month - 1;
88
+ const prevYear = month === 0 ? year - 1 : year;
89
+ const daysInPrevMonth = getDaysInMonth(new Date(prevYear, prevMonth));
90
+ date = new Date(prevYear, prevMonth, daysInPrevMonth + day);
91
+ } else if (day > daysInMonth) {
92
+ // Days from next month
93
+ const nextMonth = month === 11 ? 0 : month + 1;
94
+ const nextYear = month === 11 ? year + 1 : year;
95
+ date = new Date(nextYear, nextMonth, day - daysInMonth);
96
+ } else {
97
+ // Days from current month
98
+ date = new Date(year, month, day);
99
+ }
100
+
101
+ days.push(date);
102
+ }
103
+
104
+ return days;
105
+ };
106
+
107
+ export const getWeeksInMonth = (date: Date): number => {
108
+ const firstDayOfMonth = getFirstDayOfMonth(date);
109
+ const daysInMonth = getDaysInMonth(date);
110
+
111
+ // Calculate total number of weeks
112
+ return Math.ceil((firstDayOfMonth + daysInMonth) / 7);
113
+ };