@hero-design/rn 8.92.1 → 8.92.2

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.
@@ -1,4 +1,4 @@
1
- (node:3004) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
1
+ (node:3013) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
2
2
  (Use `node --trace-warnings ...` to show where the warning was created)
3
3
  
4
4
  src/index.ts → lib/index.js, es/index.js...
@@ -10,4 +10,4 @@
10
10
     ~~~~~~~~~~~~~~~~~~~
11
11
  
12
12
  (!) [plugin node-resolve] preferring built-in module 'events' over local alternative at '/home/runner/work/hero-design/hero-design/node_modules/events/events.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning.or passing a function to 'preferBuiltins' to provide more fine-grained control over which built-in modules to prefer.
13
- created lib/index.js, es/index.js in 53.1s
13
+ created lib/index.js, es/index.js in 53.6s
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @hero-design/rn
2
2
 
3
+ ## 8.92.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#3733](https://github.com/Thinkei/hero-design/pull/3733) [`3704e47f0103bde351e4820b81f2ebcbafedc6a5`](https://github.com/Thinkei/hero-design/commit/3704e47f0103bde351e4820b81f2ebcbafedc6a5) Thanks [@vinhphan-eh](https://github.com/vinhphan-eh)! - [Calendar] Update selection logic
8
+
3
9
  ## 8.92.1
4
10
 
5
11
  ### Patch Changes
package/es/index.js CHANGED
@@ -13204,11 +13204,11 @@ var setStartOrEndDate = function setStartOrEndDate(_ref2) {
13204
13204
  var date = _ref2.date,
13205
13205
  startDate = _ref2.startDate,
13206
13206
  endDate = _ref2.endDate;
13207
- // Prevent selecting same date when both dates are set
13207
+ // If both dates are set, selecting start or end date will set the same date
13208
13208
  if (startDate && endDate && (isEqDate(date, startDate) || isEqDate(date, endDate))) {
13209
13209
  return {
13210
- startDate: startDate,
13211
- endDate: endDate
13210
+ startDate: date,
13211
+ endDate: date
13212
13212
  };
13213
13213
  }
13214
13214
  // No start date yet - set as start
@@ -13235,13 +13235,10 @@ var setStartOrEndDate = function setStartOrEndDate(_ref2) {
13235
13235
  endDate: undefined
13236
13236
  };
13237
13237
  }
13238
- // Clicking outside range - extend range
13239
- return date < startDate ? {
13238
+ // Clicking outside range - reset range
13239
+ return {
13240
13240
  startDate: date,
13241
- endDate: endDate
13242
- } : {
13243
- startDate: startDate,
13244
- endDate: date
13241
+ endDate: undefined
13245
13242
  };
13246
13243
  };
13247
13244
 
package/lib/index.js CHANGED
@@ -13232,11 +13232,11 @@ var setStartOrEndDate = function setStartOrEndDate(_ref2) {
13232
13232
  var date = _ref2.date,
13233
13233
  startDate = _ref2.startDate,
13234
13234
  endDate = _ref2.endDate;
13235
- // Prevent selecting same date when both dates are set
13235
+ // If both dates are set, selecting start or end date will set the same date
13236
13236
  if (startDate && endDate && (isEqDate(date, startDate) || isEqDate(date, endDate))) {
13237
13237
  return {
13238
- startDate: startDate,
13239
- endDate: endDate
13238
+ startDate: date,
13239
+ endDate: date
13240
13240
  };
13241
13241
  }
13242
13242
  // No start date yet - set as start
@@ -13263,13 +13263,10 @@ var setStartOrEndDate = function setStartOrEndDate(_ref2) {
13263
13263
  endDate: undefined
13264
13264
  };
13265
13265
  }
13266
- // Clicking outside range - extend range
13267
- return date < startDate ? {
13266
+ // Clicking outside range - reset range
13267
+ return {
13268
13268
  startDate: date,
13269
- endDate: endDate
13270
- } : {
13271
- startDate: startDate,
13272
- endDate: date
13269
+ endDate: undefined
13273
13270
  };
13274
13271
  };
13275
13272
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hero-design/rn",
3
- "version": "8.92.1",
3
+ "version": "8.92.2",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -47,17 +47,32 @@ describe('CalendarRange', () => {
47
47
  expect(queryAllByTestId('calendar-disabled-cell')).toHaveLength(0);
48
48
  expect(queryAllByTestId('calendar-date-mark')).toHaveLength(5);
49
49
 
50
- // Test range selection
51
- fireEvent.press(queryAllByText('11')[0]); // Select start date
50
+ // Select outside range
51
+ fireEvent.press(queryAllByText('11')[0]);
52
52
  expect(onChange).toHaveBeenCalledWith({
53
53
  startDate: new Date('2022-10-11'),
54
- endDate: new Date('2022-10-15'),
54
+ endDate: undefined,
55
55
  });
56
56
 
57
- fireEvent.press(queryAllByText('20')[0]); // Select end date
57
+ // Select start date
58
+ fireEvent.press(queryAllByText('12')[0]);
58
59
  expect(onChange).toHaveBeenCalledWith({
59
60
  startDate: new Date('2022-10-12'),
60
- endDate: new Date('2022-10-20'),
61
+ endDate: new Date('2022-10-12'),
62
+ });
63
+
64
+ // Select end date
65
+ fireEvent.press(queryAllByText('15')[0]);
66
+ expect(onChange).toHaveBeenCalledWith({
67
+ startDate: new Date('2022-10-15'),
68
+ endDate: new Date('2022-10-15'),
69
+ });
70
+
71
+ // Select inside range
72
+ fireEvent.press(queryAllByText('13')[0]);
73
+ expect(onChange).toHaveBeenCalledWith({
74
+ startDate: new Date('2022-10-13'),
75
+ endDate: undefined,
61
76
  });
62
77
 
63
78
  fireEvent.press(queryByTestId('previous-icon-button'));
@@ -129,14 +144,14 @@ describe('CalendarRange', () => {
129
144
  // Test range selection within constraints
130
145
  fireEvent.press(getByText('17')); // Select start date
131
146
  expect(onChange).toHaveBeenCalledWith({
132
- startDate: new Date('2022-10-12'),
133
- endDate: new Date('2022-10-17'),
147
+ startDate: new Date('2022-10-17'),
148
+ endDate: undefined,
134
149
  });
135
150
 
136
151
  fireEvent.press(getByText('11')); // Select end date
137
152
  expect(onChange).toHaveBeenCalledWith({
138
153
  startDate: new Date('2022-10-11'),
139
- endDate: new Date('2022-10-15'),
154
+ endDate: undefined,
140
155
  });
141
156
  });
142
157
 
@@ -156,14 +171,14 @@ describe('CalendarRange', () => {
156
171
  fireEvent.press(getByText('11'));
157
172
  expect(onChange).toHaveBeenCalledWith({
158
173
  startDate: new Date('2022-10-11'),
159
- endDate: new Date('2022-10-15'),
174
+ endDate: undefined,
160
175
  });
161
176
 
162
177
  // Select end date
163
178
  fireEvent.press(getByText('20'));
164
179
  expect(onChange).toHaveBeenCalledWith({
165
- startDate: new Date('2022-10-12'),
166
- endDate: new Date('2022-10-20'),
180
+ startDate: new Date('2022-10-20'),
181
+ endDate: undefined,
167
182
  });
168
183
 
169
184
  // Select new start date (should clear end date)
@@ -73,99 +73,106 @@ describe('isDateInRange', () => {
73
73
  });
74
74
 
75
75
  describe('setStartOrEndDate', () => {
76
- // Test case 1: Prevent selecting same date when both dates are set
77
- it('should not change dates when selecting same date as start date and both dates are set', () => {
78
- const date = new Date('2024-03-15');
79
- const startDate = new Date('2024-03-15');
80
- const endDate = new Date('2024-03-20');
81
-
82
- const result = setStartOrEndDate({ date, startDate, endDate });
83
- expect(result).toEqual({ startDate, endDate });
76
+ const today = new Date('2024-01-01');
77
+ const tomorrow = new Date('2024-01-02');
78
+ const nextWeek = new Date('2024-01-08');
79
+
80
+ it('should set start date when no dates are selected', () => {
81
+ const result = setStartOrEndDate({
82
+ date: today,
83
+ });
84
+
85
+ expect(result).toEqual({
86
+ startDate: today,
87
+ endDate: undefined,
88
+ });
84
89
  });
85
90
 
86
- // Test case 2: Allow selecting same date as start date when only start date is set
87
- it('should allow selecting same date as start date when only start date is set', () => {
88
- const date = new Date('2024-03-15');
89
- const startDate = new Date('2024-03-15');
91
+ it('should set end date when only start date is selected', () => {
92
+ const result = setStartOrEndDate({
93
+ date: tomorrow,
94
+ startDate: today,
95
+ });
90
96
 
91
- const result = setStartOrEndDate({ date, startDate });
92
97
  expect(result).toEqual({
93
- startDate: new Date('2024-03-15'),
94
- endDate: new Date('2024-03-15'),
98
+ startDate: today,
99
+ endDate: tomorrow,
95
100
  });
96
101
  });
97
102
 
98
- // Test case 3: Initial selection (no start date)
99
- it('should set start date when no dates are selected', () => {
100
- const date = new Date('2024-03-15');
103
+ it('should set start date when date is before current start date', () => {
104
+ const result = setStartOrEndDate({
105
+ date: today,
106
+ startDate: tomorrow,
107
+ });
101
108
 
102
- const result = setStartOrEndDate({ date });
103
109
  expect(result).toEqual({
104
- startDate: new Date('2024-03-15'),
105
- endDate: undefined,
110
+ startDate: today,
111
+ endDate: tomorrow,
106
112
  });
107
113
  });
108
114
 
109
- // Test case 4: Setting end date after start date
110
- it('should set end date when start date exists and selected date is after', () => {
111
- const date = new Date('2024-03-20');
112
- const startDate = new Date('2024-03-15');
115
+ it('should set end date when date is after current start date', () => {
116
+ const result = setStartOrEndDate({
117
+ date: tomorrow,
118
+ startDate: today,
119
+ });
113
120
 
114
- const result = setStartOrEndDate({ date, startDate });
115
121
  expect(result).toEqual({
116
- startDate: new Date('2024-03-15'),
117
- endDate: new Date('2024-03-20'),
122
+ startDate: today,
123
+ endDate: tomorrow,
118
124
  });
119
125
  });
120
126
 
121
- // Test case 5: Setting end date before start date (should reorder)
122
- it('should reorder dates when end date is selected before start date', () => {
123
- const date = new Date('2024-03-10');
124
- const startDate = new Date('2024-03-15');
127
+ it('should reset selection when clicking within range', () => {
128
+ const result = setStartOrEndDate({
129
+ date: tomorrow,
130
+ startDate: today,
131
+ endDate: nextWeek,
132
+ });
125
133
 
126
- const result = setStartOrEndDate({ date, startDate });
127
134
  expect(result).toEqual({
128
- startDate: new Date('2024-03-10'),
129
- endDate: new Date('2024-03-15'),
135
+ startDate: tomorrow,
136
+ endDate: undefined,
130
137
  });
131
138
  });
132
139
 
133
- // Test case 6: Clicking within existing range
134
- it('should start new selection when clicking within existing range', () => {
135
- const date = new Date('2024-03-17');
136
- const startDate = new Date('2024-03-15');
137
- const endDate = new Date('2024-03-20');
140
+ it('should reset selection when clicking outside range', () => {
141
+ const result = setStartOrEndDate({
142
+ date: nextWeek,
143
+ startDate: today,
144
+ endDate: tomorrow,
145
+ });
138
146
 
139
- const result = setStartOrEndDate({ date, startDate, endDate });
140
147
  expect(result).toEqual({
141
- startDate: new Date('2024-03-17'),
148
+ startDate: nextWeek,
142
149
  endDate: undefined,
143
150
  });
144
151
  });
145
152
 
146
- // Test case 7: Extending range before start date
147
- it('should extend range when clicking before start date', () => {
148
- const date = new Date('2024-03-10');
149
- const startDate = new Date('2024-03-15');
150
- const endDate = new Date('2024-03-20');
153
+ it('should set same date for both start and end when clicking start date', () => {
154
+ const result = setStartOrEndDate({
155
+ date: today,
156
+ startDate: today,
157
+ endDate: tomorrow,
158
+ });
151
159
 
152
- const result = setStartOrEndDate({ date, startDate, endDate });
153
160
  expect(result).toEqual({
154
- startDate: new Date('2024-03-10'),
155
- endDate: new Date('2024-03-20'),
161
+ startDate: today,
162
+ endDate: today,
156
163
  });
157
164
  });
158
165
 
159
- // Test case 8: Extending range after end date
160
- it('should extend range when clicking after end date', () => {
161
- const date = new Date('2024-03-25');
162
- const startDate = new Date('2024-03-15');
163
- const endDate = new Date('2024-03-20');
166
+ it('should set same date for both start and end when clicking end date', () => {
167
+ const result = setStartOrEndDate({
168
+ date: tomorrow,
169
+ startDate: today,
170
+ endDate: tomorrow,
171
+ });
164
172
 
165
- const result = setStartOrEndDate({ date, startDate, endDate });
166
173
  expect(result).toEqual({
167
- startDate: new Date('2024-03-15'),
168
- endDate: new Date('2024-03-25'),
174
+ startDate: tomorrow,
175
+ endDate: tomorrow,
169
176
  });
170
177
  });
171
178
  });
@@ -54,15 +54,15 @@ export const setStartOrEndDate = ({
54
54
  startDate?: Date;
55
55
  endDate?: Date;
56
56
  }) => {
57
- // Prevent selecting same date when both dates are set
57
+ // If both dates are set, selecting start or end date will set the same date
58
58
  if (
59
59
  startDate &&
60
60
  endDate &&
61
61
  (isEqDate(date, startDate) || isEqDate(date, endDate))
62
62
  ) {
63
63
  return {
64
- startDate,
65
- endDate,
64
+ startDate: date,
65
+ endDate: date,
66
66
  };
67
67
  }
68
68
 
@@ -95,14 +95,9 @@ export const setStartOrEndDate = ({
95
95
  };
96
96
  }
97
97
 
98
- // Clicking outside range - extend range
99
- return date < startDate
100
- ? {
101
- startDate: date,
102
- endDate,
103
- }
104
- : {
105
- startDate,
106
- endDate: date,
107
- };
98
+ // Clicking outside range - reset range
99
+ return {
100
+ startDate: date,
101
+ endDate: undefined,
102
+ };
108
103
  };