committed by
GitHub
10 changed files with 241 additions and 11 deletions
@ -80,6 +80,9 @@ importers: |
|||||
cmdk: |
cmdk: |
||||
specifier: ^1.0.0 |
specifier: ^1.0.0 |
||||
version: 1.0.0(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected]) |
version: 1.0.0(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected]) |
||||
|
crypto-random-string: |
||||
|
specifier: ^5.0.0 |
||||
|
version: 5.0.0 |
||||
immer: |
immer: |
||||
specifier: ^10.1.1 |
specifier: ^10.1.1 |
||||
version: 10.1.1 |
version: 10.1.1 |
||||
@ -1901,6 +1904,10 @@ packages: |
|||||
resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} |
resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} |
||||
engines: {node: '>= 8'} |
engines: {node: '>= 8'} |
||||
|
|
||||
|
[email protected]: |
||||
|
resolution: {integrity: sha512-KWjTXWwxFd6a94m5CdRGW/t82Tr8DoBc9dNnPCAbFI1EBweN6v1tv8y4Y1m7ndkp/nkIBRxUxAzpaBnR2k3bcQ==} |
||||
|
engines: {node: '>=14.16'} |
||||
|
|
||||
[email protected]: |
[email protected]: |
||||
resolution: {integrity: sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==} |
resolution: {integrity: sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==} |
||||
engines: {node: '>=4'} |
engines: {node: '>=4'} |
||||
@ -2929,6 +2936,10 @@ packages: |
|||||
[email protected]: |
[email protected]: |
||||
resolution: {integrity: sha512-Ja03QIJlPuHt4IQ2FfGex4F4JAr8m3jpaHbFbQrgwr7s7L6U8ocrHiF3J1+wf9jzhGKxvDeaCAnGDot8OjGFyA==} |
resolution: {integrity: sha512-Ja03QIJlPuHt4IQ2FfGex4F4JAr8m3jpaHbFbQrgwr7s7L6U8ocrHiF3J1+wf9jzhGKxvDeaCAnGDot8OjGFyA==} |
||||
|
|
||||
|
[email protected]: |
||||
|
resolution: {integrity: sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==} |
||||
|
engines: {node: '>=12.20'} |
||||
|
|
||||
[email protected]: |
[email protected]: |
||||
resolution: {integrity: sha512-NcRtPEOsPFFWjobJEtfihkLCZCXZt/os3zf8nTxjVH3RvTSxjrCamJpbExGvYOF+tFHc3pA65qpdwPbzjohhew==} |
resolution: {integrity: sha512-NcRtPEOsPFFWjobJEtfihkLCZCXZt/os3zf8nTxjVH3RvTSxjrCamJpbExGvYOF+tFHc3pA65qpdwPbzjohhew==} |
||||
engines: {node: '>=14.17'} |
engines: {node: '>=14.17'} |
||||
@ -5293,6 +5304,10 @@ snapshots: |
|||||
shebang-command: 2.0.0 |
shebang-command: 2.0.0 |
||||
which: 2.0.2 |
which: 2.0.2 |
||||
|
|
||||
|
[email protected]: |
||||
|
dependencies: |
||||
|
type-fest: 2.19.0 |
||||
|
|
||||
[email protected]: {} |
[email protected]: {} |
||||
|
|
||||
[email protected]: {} |
[email protected]: {} |
||||
@ -6365,6 +6380,8 @@ snapshots: |
|||||
|
|
||||
[email protected]: {} |
[email protected]: {} |
||||
|
|
||||
|
[email protected]: {} |
||||
|
|
||||
[email protected]: {} |
[email protected]: {} |
||||
|
|
||||
[email protected]: {} |
[email protected]: {} |
||||
|
|||||
@ -0,0 +1,40 @@ |
|||||
|
import type { |
||||
|
BaseFormBuilderProps, |
||||
|
GenericFormElementProps, |
||||
|
} from "@components/Form/DynamicForm.js"; |
||||
|
import { Generator } from "@components/UI/Generator.js"; |
||||
|
import type { ChangeEventHandler, MouseEventHandler } from "react"; |
||||
|
import { Controller, type FieldValues } from "react-hook-form"; |
||||
|
|
||||
|
export interface PasswordGeneratorProps<T> extends BaseFormBuilderProps<T> { |
||||
|
type: "passwordGenerator"; |
||||
|
devicePSKBitCount: number; |
||||
|
inputChange: ChangeEventHandler; |
||||
|
selectChange: (event: string) => void; |
||||
|
buttonClick: MouseEventHandler; |
||||
|
} |
||||
|
|
||||
|
export function PasswordGenerator<T extends FieldValues>({ |
||||
|
control, |
||||
|
field, |
||||
|
}: GenericFormElementProps<T, PasswordGeneratorProps<T>>) { |
||||
|
return ( |
||||
|
<Controller |
||||
|
name={field.name} |
||||
|
control={control} |
||||
|
render={({ field: { value, ...rest } }) => ( |
||||
|
<Generator |
||||
|
devicePSKBitCount={field.devicePSKBitCount} |
||||
|
inputChange={field.inputChange} |
||||
|
selectChange={field.selectChange} |
||||
|
buttonClick={field.buttonClick} |
||||
|
value={value} |
||||
|
variant={field.validationText ? "invalid" : "default"} |
||||
|
buttonText="Generate" |
||||
|
{...field.properties} |
||||
|
{...rest} |
||||
|
/> |
||||
|
)} |
||||
|
/> |
||||
|
); |
||||
|
} |
||||
@ -0,0 +1,79 @@ |
|||||
|
import * as React from "react"; |
||||
|
|
||||
|
import { Button } from "@components/UI/Button.js"; |
||||
|
import { Input } from "@components/UI/Input.js"; |
||||
|
import { |
||||
|
Select, |
||||
|
SelectContent, |
||||
|
SelectItem, |
||||
|
SelectTrigger, |
||||
|
SelectValue, |
||||
|
} from "@components/UI/Select.js"; |
||||
|
|
||||
|
export interface GeneratorProps extends React.BaseHTMLAttributes<HTMLElement> { |
||||
|
devicePSKBitCount?: number; |
||||
|
value: string; |
||||
|
variant: "default" | "invalid"; |
||||
|
buttonText?: string; |
||||
|
selectChange: (event: string) => void; |
||||
|
inputChange: (event: React.ChangeEvent<HTMLInputElement>) => void; |
||||
|
buttonClick: React.MouseEventHandler<HTMLButtonElement>; |
||||
|
} |
||||
|
|
||||
|
const Generator = React.forwardRef<HTMLInputElement, GeneratorProps>( |
||||
|
( |
||||
|
{ |
||||
|
devicePSKBitCount, |
||||
|
variant, |
||||
|
value, |
||||
|
buttonText, |
||||
|
selectChange, |
||||
|
inputChange, |
||||
|
buttonClick, |
||||
|
...props |
||||
|
}, |
||||
|
ref, |
||||
|
) => { |
||||
|
return ( |
||||
|
<> |
||||
|
<Input |
||||
|
type="text" |
||||
|
id="pskInput" |
||||
|
variant={variant} |
||||
|
value={value} |
||||
|
onChange={inputChange} |
||||
|
/> |
||||
|
<Select |
||||
|
value={devicePSKBitCount?.toString()} |
||||
|
onValueChange={(e) => selectChange(e)} |
||||
|
> |
||||
|
<SelectTrigger> |
||||
|
<SelectValue /> |
||||
|
</SelectTrigger> |
||||
|
<SelectContent> |
||||
|
<SelectItem key="bit256" value="32"> |
||||
|
256 bit |
||||
|
</SelectItem> |
||||
|
<SelectItem key="bit128" value="16"> |
||||
|
128 bit |
||||
|
</SelectItem> |
||||
|
<SelectItem key="bit8" value="1"> |
||||
|
8 bit |
||||
|
</SelectItem> |
||||
|
</SelectContent> |
||||
|
</Select> |
||||
|
<Button |
||||
|
type="button" |
||||
|
variant="success" |
||||
|
onClick={buttonClick} |
||||
|
{...props} |
||||
|
> |
||||
|
{buttonText} |
||||
|
</Button> |
||||
|
</> |
||||
|
); |
||||
|
}, |
||||
|
); |
||||
|
Generator.displayName = "Button"; |
||||
|
|
||||
|
export { Generator }; |
||||
Loading…
Reference in new issue