@transferwise/components 0.0.0-experimental-3ede9cc → 0.0.0-experimental-e477c03
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/build/index.js +48 -60
- package/build/index.js.map +1 -1
- package/build/index.mjs +48 -60
- package/build/index.mjs.map +1 -1
- package/build/types/dateInput/DateInput.d.ts.map +1 -1
- package/build/types/field/Field.d.ts +2 -2
- package/build/types/field/Field.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/dateInput/DateInput.spec.tsx +220 -0
- package/src/dateInput/DateInput.story.tsx +3 -76
- package/src/dateInput/DateInput.tests.story.tsx +238 -0
- package/src/dateInput/DateInput.tsx +50 -53
- package/src/field/Field.story.tsx +3 -3
- package/src/field/Field.tests.story.tsx +2 -2
- package/src/field/Field.tsx +8 -8
- package/src/dateInput/DateInput.rtl.spec.tsx +0 -17
- package/src/dateInput/DateInput.spec.js +0 -477
package/build/index.mjs
CHANGED
|
@@ -3159,8 +3159,10 @@ const DateInput = ({
|
|
|
3159
3159
|
return null;
|
|
3160
3160
|
};
|
|
3161
3161
|
const [day, setDay] = useState(() => getInitialDate('day'));
|
|
3162
|
+
const [displayDay, setDisplayDay] = useState(day?.toString());
|
|
3162
3163
|
const [month, setMonth] = useState(() => getInitialDate('month'));
|
|
3163
3164
|
const [year, setYear] = useState(() => getInitialDate('year'));
|
|
3165
|
+
const [displayYear, setDisplayYear] = useState(year?.toString());
|
|
3164
3166
|
const [lastBroadcastedValue, setLastBroadcastedValue] = useState(getDateObject);
|
|
3165
3167
|
const monthNames = getMonthNames(locale, monthFormat);
|
|
3166
3168
|
dayLabel ||= formatMessage(messages$9.dayLabel);
|
|
@@ -3186,8 +3188,8 @@ const DateInput = ({
|
|
|
3186
3188
|
const getSelectElement = () => {
|
|
3187
3189
|
return /*#__PURE__*/jsxs("label", {
|
|
3188
3190
|
className: "d-flex flex-column",
|
|
3189
|
-
children: [/*#__PURE__*/jsx(
|
|
3190
|
-
|
|
3191
|
+
children: [/*#__PURE__*/jsx(Body, {
|
|
3192
|
+
type: Typography.BODY_DEFAULT,
|
|
3191
3193
|
children: monthLabel
|
|
3192
3194
|
}), /*#__PURE__*/jsx(SelectInput, {
|
|
3193
3195
|
name: "month",
|
|
@@ -3209,12 +3211,23 @@ const DateInput = ({
|
|
|
3209
3211
|
})]
|
|
3210
3212
|
});
|
|
3211
3213
|
};
|
|
3214
|
+
const isDayValid = (newDay, newMonth, newYear) => {
|
|
3215
|
+
const maxDay = new Date(newYear, newMonth + 1, 0).getDate();
|
|
3216
|
+
return newDay <= maxDay;
|
|
3217
|
+
};
|
|
3212
3218
|
const handleInternalValue = (newDay = day, newMonth = month, newYear = year) => {
|
|
3213
|
-
if (newDay == null || newMonth == null || newYear == null) {
|
|
3219
|
+
if (newDay == null || newDay === 0 || newMonth == null || newYear == null || newYear === 0) {
|
|
3220
|
+
broadcastNewValue(null);
|
|
3221
|
+
return;
|
|
3222
|
+
}
|
|
3223
|
+
if (!isDayValid(newDay, newMonth, newYear)) {
|
|
3214
3224
|
broadcastNewValue(null);
|
|
3215
3225
|
return;
|
|
3216
3226
|
}
|
|
3217
3227
|
const dateValue = new Date(newYear, newMonth, newDay);
|
|
3228
|
+
if (newYear < 100) {
|
|
3229
|
+
dateValue.setFullYear(newYear);
|
|
3230
|
+
}
|
|
3218
3231
|
if (!isDateValid(dateValue)) {
|
|
3219
3232
|
broadcastNewValue(null);
|
|
3220
3233
|
return;
|
|
@@ -3228,11 +3241,11 @@ const DateInput = ({
|
|
|
3228
3241
|
}
|
|
3229
3242
|
};
|
|
3230
3243
|
const handleDayChange = event => {
|
|
3231
|
-
const
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
handleInternalValue(
|
|
3244
|
+
const newDayString = event.target.value.replace(/\D/g, '');
|
|
3245
|
+
const newDayNumber = Number.parseInt(newDayString, 10);
|
|
3246
|
+
setDay(newDayNumber);
|
|
3247
|
+
setDisplayDay(newDayString);
|
|
3248
|
+
handleInternalValue(newDayNumber, month, year);
|
|
3236
3249
|
};
|
|
3237
3250
|
const handleMonthChange = selectedMonth => {
|
|
3238
3251
|
if (selectedMonth === null) {
|
|
@@ -3240,30 +3253,19 @@ const DateInput = ({
|
|
|
3240
3253
|
handleInternalValue(day, null, year);
|
|
3241
3254
|
return;
|
|
3242
3255
|
}
|
|
3243
|
-
const {
|
|
3244
|
-
checkedDay
|
|
3245
|
-
} = checkDate(day, selectedMonth, year);
|
|
3246
3256
|
setMonth(selectedMonth);
|
|
3247
|
-
|
|
3248
|
-
setDay(checkedDay);
|
|
3249
|
-
}
|
|
3250
|
-
handleInternalValue(checkedDay, selectedMonth, year);
|
|
3257
|
+
handleInternalValue(day, selectedMonth, year);
|
|
3251
3258
|
};
|
|
3252
3259
|
const handleYearChange = event => {
|
|
3253
|
-
const
|
|
3254
|
-
const
|
|
3255
|
-
if (
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
} = checkDate(day, month, Number.parseInt(newValue, 10));
|
|
3260
|
-
if (day && checkedDay !== day) {
|
|
3261
|
-
setDay(checkedDay);
|
|
3262
|
-
}
|
|
3263
|
-
setYear(Number.parseInt(slicedYear, 10));
|
|
3264
|
-
handleInternalValue(checkedDay, month, Number.parseInt(slicedYear, 10));
|
|
3260
|
+
const newYearString = event.target.value.replace(/\D/g, '');
|
|
3261
|
+
const newYearNumber = Number.parseInt(newYearString, 10);
|
|
3262
|
+
if (newYearString.length >= 4 && newYearString.length <= 6) {
|
|
3263
|
+
setYear(newYearNumber);
|
|
3264
|
+
setDisplayYear(newYearString);
|
|
3265
|
+
handleInternalValue(day, month, newYearNumber);
|
|
3265
3266
|
} else {
|
|
3266
|
-
setYear(
|
|
3267
|
+
setYear(null);
|
|
3268
|
+
setDisplayYear(newYearString);
|
|
3267
3269
|
handleInternalValue(day, month, null);
|
|
3268
3270
|
}
|
|
3269
3271
|
};
|
|
@@ -3273,24 +3275,6 @@ const DateInput = ({
|
|
|
3273
3275
|
onChange(newValue != null ? getDateAsString(newValue) : null);
|
|
3274
3276
|
}
|
|
3275
3277
|
};
|
|
3276
|
-
const checkDate = (newDay = null, newMonth = 0, newYear = null) => {
|
|
3277
|
-
let checkedDay = newDay;
|
|
3278
|
-
const maxDay = new Date(newYear || 2000, newMonth != null ? newMonth + 1 : 1, 0).getDate();
|
|
3279
|
-
if (!newDay) {
|
|
3280
|
-
checkedDay = null;
|
|
3281
|
-
}
|
|
3282
|
-
if (newDay && newDay < 0) {
|
|
3283
|
-
checkedDay = 1;
|
|
3284
|
-
}
|
|
3285
|
-
if (newDay && newMonth || newDay && newDay > 31) {
|
|
3286
|
-
checkedDay = newDay > maxDay ? maxDay : newDay;
|
|
3287
|
-
}
|
|
3288
|
-
return {
|
|
3289
|
-
checkedDay,
|
|
3290
|
-
checkedMonth: newMonth,
|
|
3291
|
-
checkedYear: newYear
|
|
3292
|
-
};
|
|
3293
|
-
};
|
|
3294
3278
|
const monthYearOnly = mode === DateMode.MONTH_YEAR;
|
|
3295
3279
|
const monthWidth = classNames({
|
|
3296
3280
|
'col-sm-8': monthYearOnly,
|
|
@@ -3306,8 +3290,8 @@ const DateInput = ({
|
|
|
3306
3290
|
return /*#__PURE__*/jsx("div", {
|
|
3307
3291
|
className: "col-sm-3",
|
|
3308
3292
|
children: /*#__PURE__*/jsxs("label", {
|
|
3309
|
-
children: [/*#__PURE__*/jsx(
|
|
3310
|
-
|
|
3293
|
+
children: [/*#__PURE__*/jsx(Body, {
|
|
3294
|
+
type: Typography.BODY_DEFAULT,
|
|
3311
3295
|
children: dayLabel
|
|
3312
3296
|
}), /*#__PURE__*/jsx("div", {
|
|
3313
3297
|
className: `input-group input-group-${size}`,
|
|
@@ -3317,10 +3301,12 @@ const DateInput = ({
|
|
|
3317
3301
|
pattern: "[0-9]*",
|
|
3318
3302
|
name: "day",
|
|
3319
3303
|
autoComplete: dayAutoComplete,
|
|
3320
|
-
value:
|
|
3304
|
+
value: displayDay || '',
|
|
3321
3305
|
placeholder: placeholders?.day,
|
|
3322
3306
|
disabled: disabled,
|
|
3323
3307
|
min: 1,
|
|
3308
|
+
max: 31,
|
|
3309
|
+
maxLength: 2,
|
|
3324
3310
|
onChange: event => handleDayChange(event)
|
|
3325
3311
|
})
|
|
3326
3312
|
})]
|
|
@@ -3331,8 +3317,8 @@ const DateInput = ({
|
|
|
3331
3317
|
return /*#__PURE__*/jsx("div", {
|
|
3332
3318
|
className: "col-sm-4",
|
|
3333
3319
|
children: /*#__PURE__*/jsxs("label", {
|
|
3334
|
-
children: [/*#__PURE__*/jsx(
|
|
3335
|
-
|
|
3320
|
+
children: [/*#__PURE__*/jsx(Body, {
|
|
3321
|
+
type: Typography.BODY_DEFAULT,
|
|
3336
3322
|
children: yearLabel
|
|
3337
3323
|
}), /*#__PURE__*/jsx("div", {
|
|
3338
3324
|
className: `input-group input-group-${size}`,
|
|
@@ -3343,9 +3329,11 @@ const DateInput = ({
|
|
|
3343
3329
|
name: "year",
|
|
3344
3330
|
autoComplete: yearAutoComplete,
|
|
3345
3331
|
placeholder: placeholders?.year,
|
|
3346
|
-
value:
|
|
3332
|
+
value: displayYear || '',
|
|
3347
3333
|
disabled: disabled,
|
|
3348
|
-
min:
|
|
3334
|
+
min: 0,
|
|
3335
|
+
max: 9999,
|
|
3336
|
+
maxLength: 6,
|
|
3349
3337
|
onChange: event => handleYearChange(event)
|
|
3350
3338
|
})
|
|
3351
3339
|
})]
|
|
@@ -4908,14 +4896,14 @@ const Field = ({
|
|
|
4908
4896
|
id,
|
|
4909
4897
|
label,
|
|
4910
4898
|
message: propMessage,
|
|
4911
|
-
|
|
4899
|
+
sentiment: propType,
|
|
4912
4900
|
className,
|
|
4913
4901
|
children,
|
|
4914
4902
|
...props
|
|
4915
4903
|
}) => {
|
|
4916
|
-
const
|
|
4904
|
+
const sentiment = props.error ? Sentiment.NEGATIVE : propType;
|
|
4917
4905
|
const message = props.error || props.hint || propMessage;
|
|
4918
|
-
const hasError =
|
|
4906
|
+
const hasError = sentiment === Sentiment.NEGATIVE;
|
|
4919
4907
|
const labelId = useId();
|
|
4920
4908
|
const fallbackInputId = useId();
|
|
4921
4909
|
const inputId = id !== null ? id ?? fallbackInputId : undefined;
|
|
@@ -4930,17 +4918,17 @@ const Field = ({
|
|
|
4930
4918
|
value: hasError,
|
|
4931
4919
|
children: /*#__PURE__*/jsxs("div", {
|
|
4932
4920
|
className: classNames('form-group d-block', {
|
|
4933
|
-
'has-success':
|
|
4934
|
-
'has-warning':
|
|
4921
|
+
'has-success': sentiment === Sentiment.POSITIVE,
|
|
4922
|
+
'has-warning': sentiment === Sentiment.WARNING,
|
|
4935
4923
|
'has-error': hasError,
|
|
4936
|
-
'has-info':
|
|
4924
|
+
'has-info': sentiment === Sentiment.NEUTRAL
|
|
4937
4925
|
}, className),
|
|
4938
4926
|
children: [/*#__PURE__*/jsxs(Label, {
|
|
4939
4927
|
id: labelId,
|
|
4940
4928
|
htmlFor: inputId,
|
|
4941
4929
|
children: [label, children]
|
|
4942
4930
|
}), message && /*#__PURE__*/jsx(InlineAlert, {
|
|
4943
|
-
type:
|
|
4931
|
+
type: sentiment,
|
|
4944
4932
|
id: descriptionId,
|
|
4945
4933
|
children: message
|
|
4946
4934
|
})]
|