@star-insure/sdk 4.1.1 → 4.1.3
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/lib/calculateAge.d.ts +1 -2
- package/dist/sdk.cjs.development.js +29 -19
- 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 +29 -19
- package/dist/sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/filter/FilterItem.tsx +10 -8
- package/src/lib/calculateAge.ts +17 -10
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@star-insure/sdk",
|
|
3
3
|
"description": "The SDK for Star Insure client apps with shared helper functions and TypeScript definitions.",
|
|
4
4
|
"author": "alexclark_nz",
|
|
5
|
-
"version": "4.1.
|
|
5
|
+
"version": "4.1.3",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -198,10 +198,10 @@ export function FilterItem({ filter }: { filter: FilterOption, path?: string })
|
|
|
198
198
|
</div>
|
|
199
199
|
}>
|
|
200
200
|
<form
|
|
201
|
-
className={`mt-2 flex max-h-[350px] min-w-[200px] max-w-[260px] flex-col gap-2 rounded-md border border-gray-300 bg-white
|
|
201
|
+
className={`mt-2 flex max-h-[350px] min-w-[200px] max-w-[260px] flex-col gap-2 rounded-md border border-gray-300 bg-white shadow-lg ${ filter.type && filter.type === 'select' ? '' : 'overflow-y-scroll'}`}
|
|
202
202
|
onSubmit={handleApply}
|
|
203
203
|
>
|
|
204
|
-
<div className="flex flex-col items-start gap-1">
|
|
204
|
+
<div className="flex flex-col items-start gap-1 p-4">
|
|
205
205
|
{(!filter.type || filter.type === 'options') &&
|
|
206
206
|
filter.options?.map((option, i) => (
|
|
207
207
|
<div className="checkbox text-sm " key={`${option.label}-${i}`}>
|
|
@@ -226,7 +226,7 @@ export function FilterItem({ filter }: { filter: FilterOption, path?: string })
|
|
|
226
226
|
id={filter.label}
|
|
227
227
|
value={selected[0]}
|
|
228
228
|
onChange={handleSelect}
|
|
229
|
-
className="w-full"
|
|
229
|
+
className="!p-2 text-sm w-full"
|
|
230
230
|
>
|
|
231
231
|
<option value="">Select option</option>
|
|
232
232
|
{filter.options?.map((option) => (
|
|
@@ -244,7 +244,7 @@ export function FilterItem({ filter }: { filter: FilterOption, path?: string })
|
|
|
244
244
|
id={filter.label}
|
|
245
245
|
value={selected[0]}
|
|
246
246
|
onChange={handleSelect}
|
|
247
|
-
className="w-full"
|
|
247
|
+
className="!p-2 text-sm w-full"
|
|
248
248
|
>
|
|
249
249
|
<option value="">Select option</option>
|
|
250
250
|
{filter.options?.map((option) => (
|
|
@@ -256,8 +256,8 @@ export function FilterItem({ filter }: { filter: FilterOption, path?: string })
|
|
|
256
256
|
</label>
|
|
257
257
|
)}
|
|
258
258
|
{filter.type === 'date' && (
|
|
259
|
-
<div className="mb-2 flex flex-col gap-4">
|
|
260
|
-
<label className="text-xs">
|
|
259
|
+
<div className="mb-2 flex flex-col gap-4 w-full">
|
|
260
|
+
<label className="text-xs w-full">
|
|
261
261
|
From
|
|
262
262
|
<input
|
|
263
263
|
type="date"
|
|
@@ -265,9 +265,10 @@ export function FilterItem({ filter }: { filter: FilterOption, path?: string })
|
|
|
265
265
|
id={`${filter.name}[from]`}
|
|
266
266
|
onChange={handleDateSelect}
|
|
267
267
|
value={selected[0] ?? ''}
|
|
268
|
+
className="!p-2 text-sm w-full"
|
|
268
269
|
/>
|
|
269
270
|
</label>
|
|
270
|
-
<label className="text-xs">
|
|
271
|
+
<label className="text-xs w-full">
|
|
271
272
|
To
|
|
272
273
|
<input
|
|
273
274
|
type="date"
|
|
@@ -275,6 +276,7 @@ export function FilterItem({ filter }: { filter: FilterOption, path?: string })
|
|
|
275
276
|
id={`${filter.name}[to]`}
|
|
276
277
|
onChange={handleDateSelect}
|
|
277
278
|
value={selected[1] ?? ''}
|
|
279
|
+
className="!p-2 text-sm w-full"
|
|
278
280
|
/>
|
|
279
281
|
</label>
|
|
280
282
|
</div>
|
|
@@ -303,7 +305,7 @@ export function FilterItem({ filter }: { filter: FilterOption, path?: string })
|
|
|
303
305
|
</div>
|
|
304
306
|
)}
|
|
305
307
|
</div>
|
|
306
|
-
<div className="flex items-center gap-2
|
|
308
|
+
<div className="bg-gray-100 border-t border-gray-200 flex items-center gap-2 p-4 bottom-0 sticky">
|
|
307
309
|
<Button type="button" className="!min-w-[0px] flex-grow !px-2 text-sm !transition-none" onClick={handleClear} small>
|
|
308
310
|
Clear
|
|
309
311
|
</Button>
|
package/src/lib/calculateAge.ts
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Calculate someone's age from a date of birth.
|
|
3
|
-
* @param date YYYY-MM-DD
|
|
4
3
|
*/
|
|
5
|
-
export function calculateAge(date: string): number {
|
|
6
|
-
|
|
4
|
+
export function calculateAge(date: string|Date|null|undefined): number {
|
|
5
|
+
if (!date) {
|
|
6
|
+
return 0;
|
|
7
|
+
}
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
try {
|
|
10
|
+
const today = new Date();
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
const birthDate = new Date(date);
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
const age = today.getFullYear() - birthDate.getFullYear();
|
|
15
|
+
const m = today.getMonth() - birthDate.getMonth();
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
|
|
18
|
+
return age - 1;
|
|
19
|
+
}
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
return age;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.error(error);
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
19
26
|
}
|