@eml-payments/ui-kit 1.8.16 → 1.8.17
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.
|
@@ -82,6 +82,19 @@ const applyDeletionKey = (displayChars, slotPositions, template, isBackspace, st
|
|
|
82
82
|
const formatDate = (date, format) => {
|
|
83
83
|
return date ? dayjs(date).format(format) : '';
|
|
84
84
|
};
|
|
85
|
+
const isSameSingleDate = (a, b) => a === b || (a instanceof Date && b instanceof Date && a.getTime() === b.getTime());
|
|
86
|
+
const isSameDateValue = (a, b) => {
|
|
87
|
+
if (a === b) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
if (a instanceof Date || b instanceof Date) {
|
|
91
|
+
return isSameSingleDate(a, b);
|
|
92
|
+
}
|
|
93
|
+
if (a && b) {
|
|
94
|
+
return isSameSingleDate(a.from, b.from) && isSameSingleDate(a.to, b.to);
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
};
|
|
85
98
|
const formatRangeDisplay = (dateRange, format) => {
|
|
86
99
|
if (!(dateRange === null || dateRange === void 0 ? void 0 : dateRange.from)) {
|
|
87
100
|
return '';
|
|
@@ -126,17 +139,20 @@ export const DatePicker = ({ mode = 'single', placeholder, dateFormat = 'DD/MM/Y
|
|
|
126
139
|
const [prevDateFormat, setPrevDateFormat] = useState(dateFormat);
|
|
127
140
|
const [prevRangeDateFormat, setPrevRangeDateFormat] = useState(effectiveRangeDateFormat);
|
|
128
141
|
const [prevMode, setPrevMode] = useState(mode);
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
effectiveRangeDateFormat !== prevRangeDateFormat ||
|
|
132
|
-
mode !== prevMode) {
|
|
142
|
+
const formatOrModeChanged = dateFormat !== prevDateFormat || effectiveRangeDateFormat !== prevRangeDateFormat || mode !== prevMode;
|
|
143
|
+
if (!isSameDateValue(currentDate, prevCurrentDate) || formatOrModeChanged) {
|
|
133
144
|
setPrevCurrentDate(currentDate);
|
|
134
145
|
setPrevDateFormat(dateFormat);
|
|
135
146
|
setPrevRangeDateFormat(effectiveRangeDateFormat);
|
|
136
147
|
setPrevMode(mode);
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
148
|
+
// Only rewrite the display for a genuine external change. If the prop merely
|
|
149
|
+
// caught up with what the user just did (controlled round-trip), or never
|
|
150
|
+
// updates at all (uncontrolled parent), preserve the in-progress display.
|
|
151
|
+
if (formatOrModeChanged || !isSameDateValue(currentDate, date)) {
|
|
152
|
+
setDate(currentDate);
|
|
153
|
+
setValue(computeDisplayValue(currentDate));
|
|
154
|
+
setDefaultError('');
|
|
155
|
+
}
|
|
140
156
|
}
|
|
141
157
|
const onUpdateDate = (selected) => {
|
|
142
158
|
setDate(selected);
|
|
@@ -161,7 +177,6 @@ export const DatePicker = ({ mode = 'single', placeholder, dateFormat = 'DD/MM/Y
|
|
|
161
177
|
if (!isComplete) {
|
|
162
178
|
setDate(undefined);
|
|
163
179
|
setDefaultError('');
|
|
164
|
-
setPrevCurrentDate(undefined); // absorbs change → sync block won't fire
|
|
165
180
|
onChangeDate === null || onChangeDate === void 0 ? void 0 : onChangeDate(undefined); // notify parent the value is gone
|
|
166
181
|
return;
|
|
167
182
|
}
|
|
@@ -170,7 +185,6 @@ export const DatePicker = ({ mode = 'single', placeholder, dateFormat = 'DD/MM/Y
|
|
|
170
185
|
setDate(undefined);
|
|
171
186
|
setDefaultError(showErrorWhenComplete ? 'Invalid date format' : '');
|
|
172
187
|
if (showErrorWhenComplete) {
|
|
173
|
-
setPrevCurrentDate(undefined);
|
|
174
188
|
onChangeDate === null || onChangeDate === void 0 ? void 0 : onChangeDate(undefined);
|
|
175
189
|
}
|
|
176
190
|
return;
|
|
@@ -182,7 +196,6 @@ export const DatePicker = ({ mode = 'single', placeholder, dateFormat = 'DD/MM/Y
|
|
|
182
196
|
}
|
|
183
197
|
else {
|
|
184
198
|
setDate(undefined);
|
|
185
|
-
setPrevCurrentDate(undefined);
|
|
186
199
|
onChangeDate === null || onChangeDate === void 0 ? void 0 : onChangeDate(undefined);
|
|
187
200
|
setDefaultError('Date is out of range');
|
|
188
201
|
}
|
|
@@ -4,6 +4,7 @@ declare const meta: Meta<typeof DatePicker>;
|
|
|
4
4
|
export default meta;
|
|
5
5
|
type Story = StoryObj<typeof DatePicker>;
|
|
6
6
|
export declare const Default: Story;
|
|
7
|
+
export declare const WithDefaultValue: Story;
|
|
7
8
|
export declare const WithLabel: Story;
|
|
8
9
|
export declare const WithError: Story;
|
|
9
10
|
export declare const WithDateRange: Story;
|
|
@@ -87,6 +87,19 @@ export const Default = {
|
|
|
87
87
|
},
|
|
88
88
|
},
|
|
89
89
|
};
|
|
90
|
+
export const WithDefaultValue = {
|
|
91
|
+
args: {
|
|
92
|
+
label: 'Date of Birth',
|
|
93
|
+
currentDate: new Date(1990, 5, 15),
|
|
94
|
+
},
|
|
95
|
+
parameters: {
|
|
96
|
+
docs: {
|
|
97
|
+
description: {
|
|
98
|
+
story: 'Date picker pre-populated with a default date value.',
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
};
|
|
90
103
|
export const WithLabel = {
|
|
91
104
|
args: {
|
|
92
105
|
label: 'Select Date',
|