@dmsi/wedgekit-react 0.0.29 → 0.0.31

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 (43) hide show
  1. package/dist/{chunk-57WRM337.js → chunk-5POWRPIO.js} +3 -2
  2. package/dist/{chunk-S5KPS4IQ.js → chunk-HXEPUO5W.js} +189 -95
  3. package/dist/chunk-KHQX42T7.js +127 -0
  4. package/dist/{chunk-OUSNH76S.js → chunk-PCCJ7L3N.js} +29 -6
  5. package/dist/{chunk-PDDZ5PMY.js → chunk-S46RZBT4.js} +3 -2
  6. package/dist/components/CalendarRange.cjs +28 -5
  7. package/dist/components/CalendarRange.js +1 -1
  8. package/dist/components/DataGrid.cjs +490 -217
  9. package/dist/components/DataGrid.js +303 -122
  10. package/dist/components/DataGridCell.cjs +192 -96
  11. package/dist/components/DataGridCell.js +4 -2
  12. package/dist/components/DateInput.cjs +231 -30
  13. package/dist/components/DateInput.js +101 -27
  14. package/dist/components/DateRangeInput.cjs +550 -37
  15. package/dist/components/DateRangeInput.js +413 -34
  16. package/dist/components/MenuOption.cjs +3 -2
  17. package/dist/components/MenuOption.js +1 -1
  18. package/dist/components/MobileDataGrid.cjs +3 -2
  19. package/dist/components/MobileDataGrid.js +1 -1
  20. package/dist/components/NestedMenu.cjs +3 -2
  21. package/dist/components/NestedMenu.js +1 -1
  22. package/dist/components/Notification.cjs +3 -2
  23. package/dist/components/Notification.js +1 -1
  24. package/dist/components/SideMenuGroup.cjs +3 -2
  25. package/dist/components/SideMenuGroup.js +1 -1
  26. package/dist/components/SideMenuItem.cjs +3 -2
  27. package/dist/components/SideMenuItem.js +1 -1
  28. package/dist/components/Stack.cjs +3 -2
  29. package/dist/components/Stack.js +1 -1
  30. package/dist/components/Swatch.cjs +3 -2
  31. package/dist/components/Swatch.js +1 -1
  32. package/dist/components/Time.cjs +3 -2
  33. package/dist/components/Time.js +1 -1
  34. package/dist/index.css +9 -0
  35. package/package.json +1 -1
  36. package/src/components/CalendarRange.tsx +37 -6
  37. package/src/components/DataGrid.tsx +284 -48
  38. package/src/components/DataGridCell.tsx +122 -35
  39. package/src/components/DateInput.tsx +118 -25
  40. package/src/components/DateRangeInput.tsx +544 -30
  41. package/src/components/MenuOption.tsx +18 -14
  42. package/src/components/Stack.tsx +4 -2
  43. package/src/utils/date.ts +206 -0
@@ -46,7 +46,7 @@ export interface FlexProps {
46
46
  flexShrink?: string | number;
47
47
  }
48
48
 
49
- const useFlexClassNames = ({ items, justify, grow }: FlexProps) =>
49
+ const getFlexClassNames = ({ items, justify, grow }: FlexProps) =>
50
50
  clsx(
51
51
  "flex",
52
52
  items === "start" && "items-start",
@@ -93,7 +93,7 @@ export const Stack = ({
93
93
  id,
94
94
  ...props
95
95
  }: StackProps) => {
96
- const flexClassNames = useFlexClassNames({ items, justify, grow });
96
+ const flexClassNames = getFlexClassNames({ items, justify, grow });
97
97
 
98
98
  return (
99
99
  <div
@@ -127,6 +127,8 @@ export const Stack = ({
127
127
  }}
128
128
  className={clsx(
129
129
  "scrollbar-thin",
130
+ "max-w-screen",
131
+
130
132
  width !== "fit" && "w-full",
131
133
  width === "full" && "w-full",
132
134
  centered && "mx-auto",
@@ -0,0 +1,206 @@
1
+ /**
2
+ * Shared date utility functions for DateInput and DateRangeInput components
3
+ */
4
+
5
+ /**
6
+ * Parse MM/DD/YYYY format to YYYY-MM-DD format
7
+ */
8
+ export function parseInputDate(input: string): string | null {
9
+ const match = input.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);
10
+ if (!match) {
11
+ return null;
12
+ }
13
+
14
+ const [, month, day, year] = match;
15
+
16
+ // Pad with zeros if necessary
17
+ const paddedMonth = month.padStart(2, "0");
18
+ const paddedDay = day.padStart(2, "0");
19
+
20
+ return `${year}-${paddedMonth}-${paddedDay}`;
21
+ }
22
+
23
+ /**
24
+ * Validate if a date string is a valid date
25
+ */
26
+ export function isValidDate(dateString: string): boolean {
27
+ const date = new Date(dateString);
28
+ return date instanceof Date && !isNaN(date.getTime()) && dateString === date.toISOString().split("T")[0];
29
+ }
30
+
31
+ /**
32
+ * Format input value with slashes (MM/DD/YYYY)
33
+ */
34
+ export function formatInputValue(value: string): string {
35
+ // Remove all non-digits
36
+ const digits = value.replace(/\D/g, "");
37
+
38
+ // Return digits as-is if less than 2
39
+ if (digits.length < 2) {
40
+ return digits;
41
+ }
42
+
43
+ // Format with full MM/DD/YYYY pattern if 4 or more digits
44
+ if (digits.length >= 4) {
45
+ return `${digits.slice(0, 2)}/${digits.slice(2, 4)}/${digits.slice(4, 8)}`;
46
+ }
47
+
48
+ // Format with MM/DD pattern for 2-3 digits
49
+ return `${digits.slice(0, 2)}/${digits.slice(2)}`;
50
+ }
51
+
52
+ /**
53
+ * Check if character is a digit
54
+ */
55
+ export function isDigit(character: string): boolean {
56
+ return /\d/.test(character);
57
+ }
58
+
59
+ /**
60
+ * Check if character is a slash
61
+ */
62
+ export function isSlash(character: string): boolean {
63
+ return character === "/";
64
+ }
65
+
66
+ /**
67
+ * Count digits up to cursor position
68
+ */
69
+ export function countDigitsUpToCursor(value: string, cursorPosition: number): number {
70
+ let digitCount = 0;
71
+
72
+ for (let i = 0; i < cursorPosition && i < value.length; i++) {
73
+ if (!isDigit(value[i])) {
74
+ continue;
75
+ }
76
+
77
+ digitCount++;
78
+ }
79
+
80
+ return digitCount;
81
+ }
82
+
83
+ /**
84
+ * Find position after specific digit count
85
+ */
86
+ export function findPositionAfterDigitCount(formattedValue: string, targetDigitCount: number): number {
87
+ let currentDigitCount = 0;
88
+
89
+ for (let i = 0; i < formattedValue.length; i++) {
90
+ if (!isDigit(formattedValue[i])) {
91
+ continue;
92
+ }
93
+
94
+ currentDigitCount++;
95
+
96
+ if (currentDigitCount !== targetDigitCount) {
97
+ continue;
98
+ }
99
+
100
+ const positionAfterDigit = i + 1;
101
+ const nextCharacter = formattedValue[positionAfterDigit];
102
+
103
+ // Place cursor after slash if it follows the target digit
104
+ if (nextCharacter && isSlash(nextCharacter)) {
105
+ return positionAfterDigit + 1;
106
+ }
107
+
108
+ return positionAfterDigit;
109
+ }
110
+
111
+ return formattedValue.length;
112
+ }
113
+
114
+ /**
115
+ * Calculate cursor position after formatting
116
+ */
117
+ export function calculateCursorPosition(originalValue: string, formattedValue: string, originalPosition: number): number {
118
+ const targetDigitCount = countDigitsUpToCursor(originalValue, originalPosition);
119
+ const newPosition = findPositionAfterDigitCount(formattedValue, targetDigitCount);
120
+
121
+ return Math.min(newPosition, formattedValue.length);
122
+ }
123
+
124
+ /**
125
+ * Parse date parts from YYYY-MM-DD format
126
+ */
127
+ export function parseDateParts(dateString: string): { year: number; month: number; day: number } | null {
128
+ const [yearStr, monthStr, dayStr] = dateString.split("-");
129
+
130
+ if (!yearStr || !monthStr || !dayStr) {
131
+ return null;
132
+ }
133
+
134
+ const year = parseInt(yearStr, 10);
135
+ const month = parseInt(monthStr, 10);
136
+ const day = parseInt(dayStr, 10);
137
+
138
+ if (isNaN(year) || isNaN(month) || isNaN(day)) {
139
+ return null;
140
+ }
141
+
142
+ return { year, month, day };
143
+ }
144
+
145
+ /**
146
+ * Check if date range is valid (month 1-12, day 1-31)
147
+ */
148
+ export function isValidDateRange(month: number, day: number): boolean {
149
+ if (month < 1 || month > 12) {
150
+ return false;
151
+ }
152
+ if (day < 1 || day > 31) {
153
+ return false;
154
+ }
155
+ return true;
156
+ }
157
+
158
+ /**
159
+ * Format date parts to display format (MM/DD/YYYY)
160
+ */
161
+ export function formatDatePartsToDisplay(year: number, month: number, day: number): string {
162
+ const paddedMonth = month.toString().padStart(2, "0");
163
+ const paddedDay = day.toString().padStart(2, "0");
164
+
165
+ return `${paddedMonth}/${paddedDay}/${year}`;
166
+ }
167
+
168
+ /**
169
+ * Format date string to display format
170
+ */
171
+ export function formatDate(date: string): string {
172
+ if (!date) {
173
+ return "";
174
+ }
175
+
176
+ try {
177
+ const dateParts = parseDateParts(date);
178
+ if (!dateParts) {
179
+ return "";
180
+ }
181
+
182
+ const { year, month, day } = dateParts;
183
+
184
+ if (!isValidDateRange(month, day)) {
185
+ return "";
186
+ }
187
+
188
+ return formatDatePartsToDisplay(year, month, day);
189
+ } catch (error) {
190
+ return "";
191
+ }
192
+ }
193
+
194
+ /**
195
+ * Validate if date range is valid (to >= from)
196
+ */
197
+ export function isValidDateRangeOrder(fromDate: string, toDate: string): boolean {
198
+ if (!fromDate || !toDate || !isValidDate(fromDate) || !isValidDate(toDate)) {
199
+ return false;
200
+ }
201
+
202
+ // Check if 'to' date is not earlier than 'from' date
203
+ const from = new Date(fromDate);
204
+ const to = new Date(toDate);
205
+ return to >= from;
206
+ }