@snapdragonsnursery/react-components 1.19.5 → 1.19.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snapdragonsnursery/react-components",
3
- "version": "1.19.5",
3
+ "version": "1.19.7",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -92,48 +92,47 @@ export function DateRangePicker({
92
92
  const hasCompleteCurrentRange = Boolean(
93
93
  internalRange?.from && internalRange?.to
94
94
  );
95
+ const isInProgressRange = Boolean(
96
+ internalRange?.from && !internalRange?.to
97
+ );
95
98
 
96
- let newRange = normalizedRange;
97
-
98
- if (normalizedRange.from && normalizedRange.to) {
99
- if (hasCompleteCurrentRange && !isSelectingRange.current) {
100
- const sameStart = datesEqual(normalizedRange.from, internalRange.from);
99
+ let newRange;
101
100
 
102
- if (sameStart) {
103
- // Adjusting end date on an existing range
104
- newRange = {
105
- from: internalRange.from,
106
- to: normalizedRange.to,
107
- };
108
- } else {
109
- // Starting a new range selection cycle
110
- newRange = {
111
- from: normalizedSelectedDay ?? normalizedRange.from,
112
- to: null,
113
- };
114
- }
115
- } else if (internalRange?.from && !internalRange?.to) {
116
- // Completing an in-progress range
101
+ // If we're in the middle of selecting a range (start date set, end date not set)
102
+ if (isInProgressRange) {
103
+ // Completing an in-progress range - set the clicked date as the end date
104
+ if (normalizedRange.to) {
117
105
  newRange = {
118
106
  from: internalRange.from,
119
107
  to: normalizedRange.to,
120
108
  };
121
- }
122
- } else if (normalizedRange.from && !normalizedRange.to) {
123
- if (hasCompleteCurrentRange && !isSelectingRange.current) {
124
- // New cycle starting from the selected day
109
+ } else if (normalizedRange.from) {
110
+ // Use the clicked date as end date
125
111
  newRange = {
126
- from: normalizedSelectedDay ?? normalizedRange.from,
127
- to: null,
112
+ from: internalRange.from,
113
+ to: normalizedSelectedDay ?? normalizedRange.from,
128
114
  };
129
115
  } else {
116
+ newRange = internalRange; // Keep current state
117
+ }
118
+ } else if (hasCompleteCurrentRange) {
119
+ // We have a complete range - clicking ANY date should start a new range
120
+ // Use the clicked date as the new start date
121
+ newRange = {
122
+ from:
123
+ normalizedSelectedDay ?? normalizedRange.from ?? normalizedRange.to,
124
+ to: null,
125
+ };
126
+ } else {
127
+ // No range selected or only partial - start a new range
128
+ if (normalizedRange.from) {
130
129
  newRange = {
131
130
  from: normalizedRange.from,
132
- to: null,
131
+ to: normalizedRange.to || null,
133
132
  };
133
+ } else {
134
+ newRange = null;
134
135
  }
135
- } else {
136
- newRange = null;
137
136
  }
138
137
 
139
138
  setInternalRange(newRange);
@@ -291,6 +290,7 @@ export function DatePicker({
291
290
  placeholder = "Select a date",
292
291
  disabled,
293
292
  disableFuture = false,
293
+ displayFormat = "PPP",
294
294
  ...props
295
295
  }) {
296
296
  const [isOpen, setIsOpen] = useState(false);
@@ -315,7 +315,7 @@ export function DatePicker({
315
315
  >
316
316
  <CalendarIcon className="mr-2 h-4 w-4" />
317
317
  {selectedDate ? (
318
- format(selectedDate, "PPP")
318
+ format(selectedDate, displayFormat)
319
319
  ) : (
320
320
  <span>{placeholder}</span>
321
321
  )}
package/src/index.d.ts CHANGED
@@ -43,6 +43,7 @@ export interface DatePickerProps {
43
43
  placeholder?: string
44
44
  disabled?: boolean
45
45
  disableFuture?: boolean
46
+ displayFormat?: string
46
47
  }
47
48
  export const DatePicker: React.ComponentType<DatePickerProps>
48
49
  export const Calendar: React.ComponentType<any>