@star-insure/sdk 1.1.43 → 1.2.0
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/dist/components/forms/DateOfBirthField.d.ts +6 -2
- package/dist/sdk.cjs.development.js +45 -51
- package/dist/sdk.cjs.development.js.map +1 -1
- package/dist/sdk.cjs.production.min.js +1 -1
- package/dist/sdk.cjs.production.min.js.map +1 -1
- package/dist/sdk.esm.js +42 -48
- package/dist/sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/forms/DateOfBirthField.tsx +112 -72
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
interface Props {
|
|
3
|
+
name?: string;
|
|
4
|
+
id?: string;
|
|
5
|
+
onChange: (dateString: string) => void;
|
|
3
6
|
value?: string;
|
|
4
|
-
|
|
7
|
+
maxYear?: number;
|
|
8
|
+
showAge?: boolean;
|
|
5
9
|
}
|
|
6
|
-
export default function DateOfBirthField({
|
|
10
|
+
export default function DateOfBirthField({ name, id, onChange, value, maxYear, showAge, }: Props): JSX.Element;
|
|
7
11
|
export {};
|
|
@@ -10,7 +10,7 @@ var React = require('react');
|
|
|
10
10
|
var React__default = _interopDefault(React);
|
|
11
11
|
var uuid = require('uuid');
|
|
12
12
|
var react = require('@headlessui/react');
|
|
13
|
-
var
|
|
13
|
+
var lodash = require('lodash');
|
|
14
14
|
var cn = _interopDefault(require('classnames'));
|
|
15
15
|
|
|
16
16
|
function parseDate(dateString) {
|
|
@@ -1474,67 +1474,57 @@ function TableRow(_ref) {
|
|
|
1474
1474
|
}
|
|
1475
1475
|
|
|
1476
1476
|
function DateOfBirthField(_ref) {
|
|
1477
|
-
var
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1477
|
+
var _ref$name = _ref.name,
|
|
1478
|
+
name = _ref$name === void 0 ? 'dob' : _ref$name,
|
|
1479
|
+
_ref$id = _ref.id,
|
|
1480
|
+
id = _ref$id === void 0 ? 'dob' : _ref$id,
|
|
1481
|
+
onChange = _ref.onChange,
|
|
1482
|
+
value = _ref.value,
|
|
1483
|
+
_ref$maxYear = _ref.maxYear,
|
|
1484
|
+
maxYear = _ref$maxYear === void 0 ? 0 : _ref$maxYear,
|
|
1485
|
+
_ref$showAge = _ref.showAge,
|
|
1486
|
+
showAge = _ref$showAge === void 0 ? false : _ref$showAge;
|
|
1488
1487
|
var dayOptions = [].concat(Array.from(Array(31).keys())).map(function (value) {
|
|
1489
|
-
return
|
|
1488
|
+
return lodash.padStart("" + (value + 1), 2, '0');
|
|
1490
1489
|
});
|
|
1491
1490
|
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
|
1492
1491
|
var monthOptions = [].concat(Array.from(Array(12).keys())).map(function (value) {
|
|
1493
1492
|
return {
|
|
1494
1493
|
title: months[value],
|
|
1495
|
-
value:
|
|
1494
|
+
value: lodash.padStart("" + (value + 1), 2, '0')
|
|
1496
1495
|
};
|
|
1497
|
-
});
|
|
1498
|
-
|
|
1496
|
+
}); // Create 100 years of options, subtracting the maximum year if provided
|
|
1497
|
+
|
|
1499
1498
|
var yearOptions = [].concat(Array.from(Array(100).keys())).map(function (value) {
|
|
1500
|
-
return
|
|
1499
|
+
return maxYear ? maxYear - value : new Date().getFullYear() - value;
|
|
1501
1500
|
});
|
|
1502
1501
|
|
|
1503
|
-
function
|
|
1504
|
-
var _extends2;
|
|
1505
|
-
|
|
1502
|
+
function handleChange(e) {
|
|
1506
1503
|
var _e$currentTarget = e.currentTarget,
|
|
1507
1504
|
name = _e$currentTarget.name,
|
|
1508
1505
|
value = _e$currentTarget.value;
|
|
1509
|
-
|
|
1510
|
-
var
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
setDateOfBirth(newDob); // Format the date for the API
|
|
1514
|
-
|
|
1515
|
-
var formattedDate = newDob.year + "-" + newDob.month + "-" + newDob.day; // Call the upstream prop if we have all of the date parts
|
|
1516
|
-
|
|
1517
|
-
if (Object.values(newDob).every(function (value) {
|
|
1518
|
-
return value !== '';
|
|
1519
|
-
})) {
|
|
1520
|
-
onChange(formattedDate);
|
|
1521
|
-
} else {
|
|
1522
|
-
// Otherwise, clear the value
|
|
1523
|
-
onChange('');
|
|
1524
|
-
}
|
|
1506
|
+
var y = name.includes('year') ? value : year;
|
|
1507
|
+
var m = name.includes('month') ? value : month;
|
|
1508
|
+
var d = name.includes('day') ? value : day;
|
|
1509
|
+
onChange(y + "-" + m + "-" + d);
|
|
1525
1510
|
}
|
|
1526
1511
|
|
|
1527
|
-
|
|
1528
|
-
|
|
1512
|
+
var _ref2 = value ? value.split('-') : ['', '', ''],
|
|
1513
|
+
year = _ref2[0],
|
|
1514
|
+
month = _ref2[1],
|
|
1515
|
+
day = _ref2[2];
|
|
1516
|
+
|
|
1517
|
+
var isValidDate = year && month && day && !isNaN(Date.parse(year + "-" + month + "-" + day));
|
|
1518
|
+
return React__default.createElement("span", {
|
|
1519
|
+
className: "flex flex-col gap-2"
|
|
1529
1520
|
}, React__default.createElement("span", {
|
|
1530
|
-
className: "
|
|
1531
|
-
}, React__default.createElement("span", null, "Date of birth")), React__default.createElement("span", {
|
|
1532
|
-
className: "flex space-x-4 border border-gray-300 rounded-lg mt-1 bg-white"
|
|
1521
|
+
className: "flex space-x-4 border border-gray-300 rounded-lg bg-white"
|
|
1533
1522
|
}, React__default.createElement("select", {
|
|
1534
|
-
name: "
|
|
1535
|
-
|
|
1523
|
+
name: name + "_day",
|
|
1524
|
+
id: id + "_day",
|
|
1525
|
+
value: day,
|
|
1536
1526
|
className: "flex-grow focus:outline-none border-0",
|
|
1537
|
-
onChange:
|
|
1527
|
+
onChange: handleChange,
|
|
1538
1528
|
required: true
|
|
1539
1529
|
}, React__default.createElement("option", {
|
|
1540
1530
|
value: ""
|
|
@@ -1544,10 +1534,11 @@ function DateOfBirthField(_ref) {
|
|
|
1544
1534
|
value: option
|
|
1545
1535
|
}, option);
|
|
1546
1536
|
})), React__default.createElement("select", {
|
|
1547
|
-
name: "
|
|
1548
|
-
|
|
1537
|
+
name: name + "_month",
|
|
1538
|
+
id: id + "_month",
|
|
1539
|
+
value: month,
|
|
1549
1540
|
className: "flex-grow focus:outline-none border-0",
|
|
1550
|
-
onChange:
|
|
1541
|
+
onChange: handleChange,
|
|
1551
1542
|
required: true
|
|
1552
1543
|
}, React__default.createElement("option", {
|
|
1553
1544
|
value: ""
|
|
@@ -1557,10 +1548,11 @@ function DateOfBirthField(_ref) {
|
|
|
1557
1548
|
value: option.value
|
|
1558
1549
|
}, option.title);
|
|
1559
1550
|
})), React__default.createElement("select", {
|
|
1560
|
-
name: "
|
|
1561
|
-
|
|
1551
|
+
name: name + "_year",
|
|
1552
|
+
id: id + "_year",
|
|
1553
|
+
value: year,
|
|
1562
1554
|
className: "flex-grow focus:outline-none border-0",
|
|
1563
|
-
onChange:
|
|
1555
|
+
onChange: handleChange,
|
|
1564
1556
|
required: true
|
|
1565
1557
|
}, React__default.createElement("option", {
|
|
1566
1558
|
value: ""
|
|
@@ -1569,7 +1561,9 @@ function DateOfBirthField(_ref) {
|
|
|
1569
1561
|
key: option,
|
|
1570
1562
|
value: option
|
|
1571
1563
|
}, option);
|
|
1572
|
-
})))
|
|
1564
|
+
}))), showAge && value && isValidDate && React__default.createElement("span", {
|
|
1565
|
+
className: "font-bold"
|
|
1566
|
+
}, "Age: ", calculateAge(value), " years"));
|
|
1573
1567
|
}
|
|
1574
1568
|
|
|
1575
1569
|
function MoneyField(_ref) {
|