@@ -50,28 +50,15 @@ export interface GeneratorProps
50
50
extends React . BaseHTMLAttributes < HTMLElement > ,
51
51
VariantProps < typeof generatorVariants >
52
52
{
53
+ devicePSKBitCount ?: number ;
53
54
passwordValue ?: string ;
54
55
textValue ?: string ;
55
56
}
56
57
57
58
const Generator = React . forwardRef < HTMLButtonElement , GeneratorProps > (
58
- ( { passwordValue, textValue, className, variant, size, ...props } , ref ) => {
59
- const [ pass , setPass ] = useState < string > ( "" ) ;
60
- const [ bitCount , setBits ] = useState < string > ( "bit256" ) ;
61
-
62
- const generate = ( ) => {
63
- let generated = "thisisapass" ;
64
- if ( bitCount == "bit8" ) {
65
- generated = btoa ( cryptoRandomString ( { length : 1 , type : 'alphanumeric' } ) ) ;
66
- }
67
- if ( bitCount == "bit128" ) {
68
- generated = btoa ( cryptoRandomString ( { length : 16 , type : 'alphanumeric' } ) ) ;
69
- }
70
- if ( bitCount == "bit256" ) {
71
- generated = btoa ( cryptoRandomString ( { length : 32 , type : 'alphanumeric' } ) ) ;
72
- }
73
- return generated ;
74
- } ;
59
+ ( { devicePSKBitCount, passwordValue, textValue, className, variant, size, ...props } , ref ) => {
60
+ const [ pass , setPass ] = useState < string > ( passwordValue ?? "" ) ;
61
+ const [ bitCount , setBits ] = useState < string > ( devicePSKBitCount ?. toString ( ) ?? "" ) ;
75
62
76
63
return (
77
64
< >
@@ -87,9 +74,9 @@ const Generator = React.forwardRef<HTMLButtonElement, GeneratorProps>(
87
74
< SelectValue />
88
75
</ SelectTrigger >
89
76
< SelectContent >
90
- < SelectItem key = "bit256" value = "bit256 " > 256 bit</ SelectItem >
91
- < SelectItem key = "bit128" value = "bit128 " > 128 bit</ SelectItem >
92
- < SelectItem key = "bit8" value = "bit8 " > 8 bit</ SelectItem >
77
+ < SelectItem key = "bit256" value = "32 " > 256 bit</ SelectItem >
78
+ < SelectItem key = "bit128" value = "16 " > 128 bit</ SelectItem >
79
+ < SelectItem key = "bit8" value = "1 " > 8 bit</ SelectItem >
93
80
</ SelectContent >
94
81
</ Select >
95
82
< Button
@@ -98,7 +85,7 @@ const Generator = React.forwardRef<HTMLButtonElement, GeneratorProps>(
98
85
ref = { ref }
99
86
{ ...props }
100
87
onClick = { ( ) => {
101
- setPass ( generate ( ) ) ;
88
+ setPass ( btoa ( cryptoRandomString ( { length : Number . parseInt ( bitCount ) , type : 'alphanumeric' } ) ) ) ;
102
89
} }
103
90
>
104
91
{ textValue }
0 commit comments