@@ -4,8 +4,12 @@ import gen from '@personnummer/generate';
44import QRCode from 'react-qr-code' ;
55import Block , { BlockProps } from '../Block' ;
66
7- const computePersonnummer = ( y : number , m : number , d : number ) =>
8- gen ( new Date ( y , m , d ) ) ;
7+ const computePersonnummer = ( y : number , m : number , d : number ) => {
8+ const date = new Date ( y , m , d ) ;
9+
10+ // Reject dates that rolled over, such as February 31.
11+ return date . getMonth ( ) === m ? gen ( date ) : '' ;
12+ } ;
913
1014const Generate = ( props : BlockProps ) => {
1115 const today = useMemo ( ( ) => new Date ( ) , [ ] ) ;
@@ -42,7 +46,7 @@ const Generate = (props: BlockProps) => {
4246 min = { 1 }
4347 value = { year }
4448 onChange = { ( e ) => setYear ( Number ( e . target . value ) ) }
45- className = "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline "
49+ className = "shadow-sm appearance-none border rounded-sm w-full py-2 px-3 text-gray-700 leading-tight focus:outline-hidden focus:ring-2 focus:ring-blue-300 "
4650 />
4751 </ div >
4852
@@ -58,7 +62,7 @@ const Generate = (props: BlockProps) => {
5862 max = { 12 }
5963 value = { month }
6064 onChange = { ( e ) => setMonth ( Number ( e . target . value ) ) }
61- className = "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline "
65+ className = "shadow-sm appearance-none border rounded-sm w-full py-2 px-3 text-gray-700 leading-tight focus:outline-hidden focus:ring-2 focus:ring-blue-300 "
6266 />
6367 </ div >
6468
@@ -74,7 +78,7 @@ const Generate = (props: BlockProps) => {
7478 max = { 31 }
7579 value = { day }
7680 onChange = { ( e ) => setDay ( Number ( e . target . value ) ) }
77- className = "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline "
81+ className = "shadow-sm appearance-none border rounded-sm w-full py-2 px-3 text-gray-700 leading-tight focus:outline-hidden focus:ring-2 focus:ring-blue-300 "
7882 />
7983 </ div >
8084 </ div >
@@ -85,7 +89,7 @@ const Generate = (props: BlockProps) => {
8589 type = "tel"
8690 readOnly
8791 value = { displayValue }
88- className = "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline "
92+ className = "shadow-sm appearance-none border rounded-sm w-full py-2 px-3 text-gray-700 leading-tight focus:outline-hidden focus:ring-2 focus:ring-blue-300 "
8993 />
9094 </ div >
9195 </ div >
0 commit comments