@idealyst/datepicker 1.1.3 → 1.1.5

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 (80) hide show
  1. package/package.json +6 -5
  2. package/src/DateInput.native.tsx +155 -0
  3. package/src/DateInput.tsx +2 -0
  4. package/src/DateInput.web.tsx +146 -0
  5. package/src/DatePicker.tsx +276 -0
  6. package/src/DateTimePicker.tsx +89 -0
  7. package/src/TimeInput.native.tsx +175 -0
  8. package/src/TimeInput.tsx +2 -0
  9. package/src/TimeInput.web.tsx +171 -0
  10. package/src/TimePicker.tsx +106 -0
  11. package/src/examples/DatePickerExamples.tsx +113 -149
  12. package/src/examples/index.ts +1 -1
  13. package/src/index.native.ts +15 -20
  14. package/src/index.ts +14 -19
  15. package/src/styles.ts +127 -0
  16. package/src/types.ts +56 -0
  17. package/src/DateInput/DateInput.native.tsx +0 -61
  18. package/src/DateInput/DateInput.styles.tsx +0 -26
  19. package/src/DateInput/DateInput.web.tsx +0 -61
  20. package/src/DateInput/DateInputBase.tsx +0 -228
  21. package/src/DateInput/index.native.ts +0 -2
  22. package/src/DateInput/index.ts +0 -2
  23. package/src/DateInput/types.ts +0 -60
  24. package/src/DatePicker/Calendar.native.tsx +0 -261
  25. package/src/DatePicker/Calendar.styles.tsx +0 -230
  26. package/src/DatePicker/Calendar.web.tsx +0 -159
  27. package/src/DatePicker/DatePicker.native.tsx +0 -51
  28. package/src/DatePicker/DatePicker.styles.tsx +0 -76
  29. package/src/DatePicker/DatePicker.web.tsx +0 -31
  30. package/src/DatePicker/index.native.ts +0 -3
  31. package/src/DatePicker/index.ts +0 -3
  32. package/src/DatePicker/types.ts +0 -78
  33. package/src/DateRangePicker/DateRangePicker.native.tsx +0 -39
  34. package/src/DateRangePicker/DateRangePicker.styles.tsx +0 -83
  35. package/src/DateRangePicker/DateRangePicker.web.tsx +0 -40
  36. package/src/DateRangePicker/RangeCalendar.native.tsx +0 -355
  37. package/src/DateRangePicker/RangeCalendar.styles.tsx +0 -200
  38. package/src/DateRangePicker/RangeCalendar.web.tsx +0 -384
  39. package/src/DateRangePicker/index.native.ts +0 -3
  40. package/src/DateRangePicker/index.ts +0 -3
  41. package/src/DateRangePicker/types.ts +0 -107
  42. package/src/DateTimePicker/DateTimePicker.native.tsx +0 -24
  43. package/src/DateTimePicker/DateTimePicker.styles.tsx +0 -104
  44. package/src/DateTimePicker/DateTimePicker.tsx +0 -21
  45. package/src/DateTimePicker/DateTimePickerBase.tsx +0 -185
  46. package/src/DateTimePicker/TimePicker.native.tsx +0 -17
  47. package/src/DateTimePicker/TimePicker.styles.tsx +0 -115
  48. package/src/DateTimePicker/TimePicker.tsx +0 -14
  49. package/src/DateTimePicker/TimePickerBase.tsx +0 -232
  50. package/src/DateTimePicker/index.native.ts +0 -3
  51. package/src/DateTimePicker/index.ts +0 -3
  52. package/src/DateTimePicker/primitives/ClockFace.native.tsx +0 -195
  53. package/src/DateTimePicker/primitives/ClockFace.web.tsx +0 -168
  54. package/src/DateTimePicker/primitives/TimeInput.native.tsx +0 -53
  55. package/src/DateTimePicker/primitives/TimeInput.web.tsx +0 -66
  56. package/src/DateTimePicker/primitives/index.native.ts +0 -2
  57. package/src/DateTimePicker/primitives/index.ts +0 -2
  58. package/src/DateTimePicker/primitives/index.web.ts +0 -2
  59. package/src/DateTimePicker/types.ts +0 -80
  60. package/src/DateTimePicker/utils/dimensions.native.ts +0 -9
  61. package/src/DateTimePicker/utils/dimensions.ts +0 -9
  62. package/src/DateTimePicker/utils/dimensions.web.ts +0 -33
  63. package/src/DateTimeRangePicker/DateTimeRangePicker.native.tsx +0 -24
  64. package/src/DateTimeRangePicker/DateTimeRangePicker.styles.tsx +0 -118
  65. package/src/DateTimeRangePicker/DateTimeRangePicker.web.tsx +0 -21
  66. package/src/DateTimeRangePicker/DateTimeRangePickerBase.tsx +0 -327
  67. package/src/DateTimeRangePicker/index.native.ts +0 -2
  68. package/src/DateTimeRangePicker/index.ts +0 -2
  69. package/src/DateTimeRangePicker/types.ts +0 -70
  70. package/src/primitives/CalendarGrid/CalendarGrid.styles.tsx +0 -51
  71. package/src/primitives/CalendarGrid/CalendarGrid.tsx +0 -146
  72. package/src/primitives/CalendarGrid/index.ts +0 -1
  73. package/src/primitives/CalendarHeader/CalendarHeader.styles.tsx +0 -25
  74. package/src/primitives/CalendarHeader/CalendarHeader.tsx +0 -69
  75. package/src/primitives/CalendarHeader/index.ts +0 -1
  76. package/src/primitives/CalendarOverlay/CalendarOverlay.styles.tsx +0 -86
  77. package/src/primitives/CalendarOverlay/CalendarOverlay.tsx +0 -136
  78. package/src/primitives/CalendarOverlay/index.ts +0 -1
  79. package/src/primitives/Wrapper/Wrapper.web.tsx +0 -33
  80. package/src/primitives/Wrapper/index.ts +0 -1
@@ -1,146 +0,0 @@
1
- import React, { useMemo } from 'react';
2
- import { Text, Button, View } from '@idealyst/components';
3
- import { calendarGridStyles } from './CalendarGrid.styles';
4
-
5
- interface CalendarGridProps {
6
- currentMonth: Date;
7
- selectedDate?: Date;
8
- onDateSelect: (date: Date) => void;
9
- onMonthChange?: (month: Date) => void;
10
- minDate?: Date;
11
- maxDate?: Date;
12
- disabled?: boolean;
13
- }
14
-
15
-
16
- export const CalendarGrid: React.FC<CalendarGridProps> = ({
17
- currentMonth,
18
- selectedDate,
19
- onDateSelect,
20
- onMonthChange,
21
- minDate,
22
- maxDate,
23
- disabled = false,
24
- }) => {
25
- const { calendarDays, startingDayOfWeek, daysInMonth, weekCount } = useMemo(() => {
26
- const monthStart = new Date(currentMonth.getFullYear(), currentMonth.getMonth(), 1);
27
- const monthEnd = new Date(currentMonth.getFullYear(), currentMonth.getMonth() + 1, 0);
28
- const daysInMonth = monthEnd.getDate();
29
- const startingDayOfWeek = monthStart.getDay();
30
-
31
- const calendarDays = [];
32
-
33
- // Add previous month days to fill start of week
34
- const prevMonthEnd = new Date(currentMonth.getFullYear(), currentMonth.getMonth(), 0);
35
- const prevMonthDaysToShow = startingDayOfWeek;
36
- for (let i = prevMonthDaysToShow - 1; i >= 0; i--) {
37
- const day = prevMonthEnd.getDate() - i;
38
- const date = new Date(currentMonth.getFullYear(), currentMonth.getMonth() - 1, day);
39
- calendarDays.push({ date, isCurrentMonth: false });
40
- }
41
-
42
- // Add days of the current month
43
- for (let day = 1; day <= daysInMonth; day++) {
44
- const date = new Date(currentMonth.getFullYear(), currentMonth.getMonth(), day);
45
- calendarDays.push({ date, isCurrentMonth: true });
46
- }
47
-
48
- // Add next month days only to complete partial weeks, never add full weeks of next month
49
- const currentLength = calendarDays.length;
50
- const weeksNeeded = Math.ceil(currentLength / 7);
51
- const maxDays = weeksNeeded * 7;
52
-
53
- // Only add next month days to fill partial week
54
- const remainingDays = maxDays - currentLength;
55
- for (let day = 1; day <= remainingDays; day++) {
56
- const date = new Date(currentMonth.getFullYear(), currentMonth.getMonth() + 1, day);
57
- calendarDays.push({ date, isCurrentMonth: false });
58
- }
59
-
60
- const weekCount = Math.ceil(calendarDays.length / 7);
61
- return { calendarDays, startingDayOfWeek, daysInMonth, weekCount };
62
- }, [currentMonth]);
63
-
64
- const isDateDisabled = (date: Date): boolean => {
65
- if (disabled) return true;
66
- if (minDate && date < minDate) return true;
67
- if (maxDate && date > maxDate) return true;
68
- return false;
69
- };
70
-
71
- const isDateSelected = (date: Date): boolean => {
72
- if (!selectedDate) return false;
73
- return (
74
- date.getDate() === selectedDate.getDate() &&
75
- date.getMonth() === selectedDate.getMonth() &&
76
- date.getFullYear() === selectedDate.getFullYear()
77
- );
78
- };
79
-
80
- const isCurrentMonth = (date: Date): boolean => {
81
- return (
82
- date.getMonth() === currentMonth.getMonth() &&
83
- date.getFullYear() === currentMonth.getFullYear()
84
- );
85
- };
86
-
87
- const handleDateSelect = (date: Date) => {
88
- // If selecting a date from previous/next month, change the current month first
89
- if (!isCurrentMonth(date) && onMonthChange) {
90
- const newMonth = new Date(date.getFullYear(), date.getMonth(), 1);
91
- onMonthChange(newMonth);
92
- }
93
- onDateSelect(date);
94
- };
95
-
96
- return (
97
- <>
98
- {/* Weekday headers */}
99
- <View style={[
100
- calendarGridStyles.weekdayHeader,
101
- { display: 'grid', gridTemplateColumns: 'repeat(7, 1fr)', gap: 2 }
102
- ]}>
103
- {['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'].map((day) => (
104
- <View key={day} style={calendarGridStyles.weekdayCell}>
105
- <Text style={calendarGridStyles.weekdayText}>
106
- {day}
107
- </Text>
108
- </View>
109
- ))}
110
- </View>
111
-
112
- {/* Calendar grid */}
113
- <View
114
- style={[
115
- calendarGridStyles.calendarGrid,
116
- {
117
- display: 'grid',
118
- gridTemplateColumns: 'repeat(7, 1fr)',
119
- gridTemplateRows: `repeat(${weekCount}, 1fr)`,
120
- gap: 2
121
- }
122
- ]}
123
- >
124
- {calendarDays.map((dayData, index) => {
125
- const { date, isCurrentMonth } = dayData;
126
- const isSelected = isDateSelected(date);
127
-
128
- return (
129
- <View key={index} style={calendarGridStyles.dayCell}>
130
- <Button
131
- type={isSelected ? 'contained' : 'text'}
132
- intent={isSelected ? 'primary' : undefined}
133
- disabled={isDateDisabled(date)}
134
- onPress={() => handleDateSelect(date)}
135
- size="sm"
136
- style={calendarGridStyles.dayButton({ isCurrentMonth, isSelected })}
137
- >
138
- {date.getDate()}
139
- </Button>
140
- </View>
141
- );
142
- })}
143
- </View>
144
- </>
145
- );
146
- };
@@ -1 +0,0 @@
1
- export { CalendarGrid } from './CalendarGrid';
@@ -1,25 +0,0 @@
1
- import { StyleSheet } from 'react-native-unistyles';
2
-
3
- export const calendarHeaderStyles = StyleSheet.create((theme) => ({
4
- container: {
5
- flexDirection: 'row',
6
- justifyContent: 'space-between',
7
- alignItems: 'center',
8
- marginBottom: 16,
9
- },
10
- centerSection: {
11
- flexDirection: 'row',
12
- alignItems: 'center',
13
- gap: 8,
14
- },
15
- navButton: {
16
- minWidth: 32,
17
- minHeight: 32,
18
- paddingHorizontal: 8,
19
- paddingVertical: 4,
20
- },
21
- titleButton: {
22
- paddingHorizontal: 8,
23
- paddingVertical: 4,
24
- },
25
- }));
@@ -1,69 +0,0 @@
1
- import React from 'react';
2
- import { Text, Button, View } from '@idealyst/components';
3
- import { calendarHeaderStyles } from './CalendarHeader.styles';
4
-
5
- interface CalendarHeaderProps {
6
- currentMonth: Date;
7
- onPreviousMonth: () => void;
8
- onNextMonth: () => void;
9
- onMonthClick: () => void;
10
- onYearClick: () => void;
11
- disabled?: boolean;
12
- }
13
-
14
-
15
- export const CalendarHeader: React.FC<CalendarHeaderProps> = ({
16
- currentMonth,
17
- onPreviousMonth,
18
- onNextMonth,
19
- onMonthClick,
20
- onYearClick,
21
- disabled = false,
22
- }) => {
23
- const monthName = currentMonth.toLocaleDateString('en-US', { month: 'long' });
24
- const year = currentMonth.getFullYear();
25
-
26
- return (
27
- <View style={calendarHeaderStyles.container}>
28
- <Button
29
- type="text"
30
- size="sm"
31
- onPress={onPreviousMonth}
32
- disabled={disabled}
33
- style={calendarHeaderStyles.navButton}
34
- >
35
-
36
- </Button>
37
-
38
- <View style={calendarHeaderStyles.centerSection}>
39
- <Button
40
- type="text"
41
- onPress={onMonthClick}
42
- disabled={disabled}
43
- style={calendarHeaderStyles.titleButton}
44
- >
45
- <Text weight="semibold">{monthName}</Text>
46
- </Button>
47
-
48
- <Button
49
- type="text"
50
- onPress={onYearClick}
51
- disabled={disabled}
52
- style={calendarHeaderStyles.titleButton}
53
- >
54
- <Text weight="semibold">{year}</Text>
55
- </Button>
56
- </View>
57
-
58
- <Button
59
- type="text"
60
- size="sm"
61
- onPress={onNextMonth}
62
- disabled={disabled}
63
- style={calendarHeaderStyles.navButton}
64
- >
65
-
66
- </Button>
67
- </View>
68
- );
69
- };
@@ -1 +0,0 @@
1
- export { CalendarHeader } from './CalendarHeader';
@@ -1,86 +0,0 @@
1
- import { StyleSheet } from 'react-native-unistyles';
2
-
3
- type CalendarOverlayVariants = {
4
- isSelected: boolean;
5
- };
6
-
7
- export const calendarOverlayStyles = StyleSheet.create((theme) => ({
8
- container: {
9
- position: 'absolute',
10
- top: 40,
11
- left: 0,
12
- right: 0,
13
- backgroundColor: theme.colors?.surface?.primary || 'white',
14
- borderRadius: 8,
15
- padding: 12,
16
- borderWidth: 1,
17
- borderColor: theme.colors?.border?.primary || '#e5e7eb',
18
- zIndex: 10,
19
-
20
- _web: {
21
- boxShadow: '0 4px 12px rgba(0, 0, 0, 0.15)',
22
- }
23
- },
24
- header: {
25
- flexDirection: 'row',
26
- justifyContent: 'space-between',
27
- alignItems: 'center',
28
- marginBottom: 12,
29
- },
30
- title: {
31
- fontSize: 14,
32
- fontWeight: '600',
33
- margin: 0,
34
- color: theme.colors?.text?.secondary || '#6b7280',
35
- },
36
- closeButton: {
37
- minWidth: 24,
38
- minHeight: 24,
39
- padding: 2,
40
- fontSize: 12,
41
- },
42
- monthGrid: {
43
- gap: 6,
44
-
45
- _web: {
46
- display: 'grid',
47
- gridTemplateColumns: 'repeat(3, 1fr)',
48
- }
49
- },
50
- yearContainer: {
51
- flexDirection: 'column',
52
- gap: 8,
53
- },
54
- yearNavigation: {
55
- flexDirection: 'row',
56
- justifyContent: 'space-between',
57
- alignItems: 'center',
58
- },
59
- yearGrid: {
60
- gap: 6,
61
-
62
- _web: {
63
- display: 'grid',
64
- gridTemplateColumns: 'repeat(4, 1fr)',
65
- }
66
- },
67
- yearNavButton: {
68
- minWidth: 32,
69
- minHeight: 24,
70
- paddingHorizontal: 8,
71
- paddingVertical: 4,
72
- fontSize: 12,
73
- },
74
- yearRangeText: {
75
- fontSize: 13,
76
- fontWeight: '500',
77
- color: theme.colors?.text?.primary || '#374151',
78
- },
79
- gridButton: ({ isSelected }: CalendarOverlayVariants) => ({
80
- minHeight: 28,
81
- paddingHorizontal: 8,
82
- paddingVertical: 4,
83
- fontSize: 12,
84
- color: isSelected ? undefined : theme.colors.text.primary,
85
- }),
86
- }));
@@ -1,136 +0,0 @@
1
- import React, { useState } from 'react';
2
- import { Button, View, Text } from '@idealyst/components';
3
- import { calendarOverlayStyles } from './CalendarOverlay.styles';
4
-
5
- type OverlayMode = 'month' | 'year';
6
-
7
- interface CalendarOverlayProps {
8
- mode: OverlayMode;
9
- currentMonth: number;
10
- currentYear: number;
11
- onMonthSelect: (month: number) => void;
12
- onYearSelect: (year: number) => void;
13
- onClose: () => void;
14
- disabled?: boolean;
15
- }
16
-
17
- const months = [
18
- 'January', 'February', 'March', 'April', 'May', 'June',
19
- 'July', 'August', 'September', 'October', 'November', 'December'
20
- ];
21
-
22
-
23
- export const CalendarOverlay: React.FC<CalendarOverlayProps> = ({
24
- mode,
25
- currentMonth,
26
- currentYear,
27
- onMonthSelect,
28
- onYearSelect,
29
- onClose,
30
- disabled = false,
31
- }) => {
32
- const [yearRangeStart, setYearRangeStart] = useState(currentYear - 10);
33
- const years = Array.from({ length: 20 }, (_, i) => yearRangeStart + i);
34
-
35
-
36
- const handleMonthSelect = (monthIndex: number) => {
37
- onMonthSelect(monthIndex);
38
- onClose();
39
- };
40
-
41
- const handleYearSelect = (year: number) => {
42
- onYearSelect(year);
43
- onClose();
44
- };
45
-
46
- const goToPreviousYearRange = () => {
47
- setYearRangeStart(yearRangeStart - 20);
48
- };
49
-
50
- const goToNextYearRange = () => {
51
- setYearRangeStart(yearRangeStart + 20);
52
- };
53
-
54
- return (
55
- <View style={calendarOverlayStyles.container}>
56
- <View style={calendarOverlayStyles.header}>
57
- <Text style={calendarOverlayStyles.title}>
58
- Select {mode === 'month' ? 'Month' : 'Year'}
59
- </Text>
60
- <Button
61
- type="text"
62
- size="sm"
63
- onPress={onClose}
64
- style={calendarOverlayStyles.closeButton}
65
- >
66
-
67
- </Button>
68
- </View>
69
-
70
- {mode === 'month' ? (
71
- <View style={calendarOverlayStyles.monthGrid}>
72
- {months.map((month, index) => {
73
- const isSelected = index === currentMonth;
74
- return (
75
- <Button
76
- key={month}
77
- type={isSelected ? 'contained' : 'text'}
78
- intent={isSelected ? 'primary' : undefined}
79
- size="sm"
80
- onPress={() => handleMonthSelect(index)}
81
- disabled={disabled}
82
- style={calendarOverlayStyles.gridButton({ isSelected })}
83
- >
84
- {month.slice(0, 3)}
85
- </Button>
86
- );
87
- })}
88
- </View>
89
- ) : (
90
- <View style={calendarOverlayStyles.yearContainer}>
91
- <View style={calendarOverlayStyles.yearNavigation}>
92
- <Button
93
- type="text"
94
- size="sm"
95
- onPress={goToPreviousYearRange}
96
- disabled={disabled}
97
- style={calendarOverlayStyles.yearNavButton}
98
- >
99
-
100
- </Button>
101
- <Text style={calendarOverlayStyles.yearRangeText}>
102
- {yearRangeStart} - {yearRangeStart + 19}
103
- </Text>
104
- <Button
105
- type="text"
106
- size="sm"
107
- onPress={goToNextYearRange}
108
- disabled={disabled}
109
- style={calendarOverlayStyles.yearNavButton}
110
- >
111
-
112
- </Button>
113
- </View>
114
- <View style={calendarOverlayStyles.yearGrid}>
115
- {years.map((year) => {
116
- const isSelected = year === currentYear;
117
- return (
118
- <Button
119
- key={year}
120
- type={isSelected ? 'contained' : 'text'}
121
- intent={isSelected ? 'primary' : undefined}
122
- size="sm"
123
- onPress={() => handleYearSelect(year)}
124
- disabled={disabled}
125
- style={calendarOverlayStyles.gridButton({ isSelected })}
126
- >
127
- {year}
128
- </Button>
129
- );
130
- })}
131
- </View>
132
- </View>
133
- )}
134
- </View>
135
- );
136
- };
@@ -1 +0,0 @@
1
- export { CalendarOverlay } from './CalendarOverlay';
@@ -1,33 +0,0 @@
1
- import React from 'react';
2
- import { getWebProps } from 'react-native-unistyles/web';
3
-
4
- interface WrapperProps {
5
- style?: any;
6
- children?: React.ReactNode;
7
- onClick?: () => void;
8
- 'data-testid'?: string;
9
- ref?: React.Ref<HTMLDivElement>;
10
- }
11
-
12
- export const Wrapper = React.forwardRef<HTMLDivElement, WrapperProps>(({
13
- style,
14
- children,
15
- onClick,
16
- 'data-testid': testID,
17
- ...props
18
- }, ref) => {
19
- return (
20
- <div
21
- ref={ref}
22
- style={style}
23
- onClick={onClick}
24
- data-testid={testID}
25
- {...getWebProps(style)}
26
- {...props}
27
- >
28
- {children}
29
- </div>
30
- );
31
- });
32
-
33
- Wrapper.displayName = 'Wrapper';
@@ -1 +0,0 @@
1
- export { Wrapper } from './Wrapper.web';