-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added descriptions for AutoComponents
- Loading branch information
1 parent
fce894e
commit 70fdb0f
Showing
46 changed files
with
1,409 additions
and
642 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@gadgetinc/react": patch | ||
--- | ||
|
||
Added descriptions for AutoComponents |
22 changes: 18 additions & 4 deletions
22
packages/react/src/auto/interfaces/AutoRelationshipInputProps.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,28 @@ | ||
import type { ReactNode } from "react"; | ||
import type { Control } from "../../useActionForm.js"; | ||
import { ControllableWithReactHookForm, InputLabel } from "../shared/AutoInputTypes.js"; | ||
|
||
export interface AutoRelationshipInputProps { | ||
export interface AutoRelationshipInputProps extends ControllableWithReactHookForm { | ||
/** | ||
* The API identifier of the field | ||
*/ | ||
field: string; | ||
control?: Control<any>; | ||
|
||
/** | ||
* Controls how records on the related model are displayed as options in the relationship field input component | ||
* When using a string, the string will indicate the field on the related model record to be displayed as the option label | ||
* When using a function, the function will be called with the record to return a ReactNode to be displayed as the option label | ||
*/ | ||
optionLabel?: OptionLabel; | ||
label?: string; | ||
|
||
/** | ||
* The label of the field input component | ||
*/ | ||
label?: InputLabel; | ||
} | ||
|
||
/** | ||
* Type for the option label when displaying a list of records from a related model | ||
* When using a string, the string will indicate the field on the related model record to be displayed as the option label | ||
* When using a function, the function will be called with the record to return a ReactNode to be displayed as the option label | ||
*/ | ||
export type OptionLabel = string | ((record: Record<string, any>) => ReactNode); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 36 additions & 17 deletions
53
packages/react/src/auto/mui/inputs/MUIAutoBooleanInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,47 @@ | ||
import type { CheckboxProps } from "@mui/material"; | ||
import { Checkbox } from "@mui/material"; | ||
import React from "react"; | ||
import { useController, type Control } from "../../../useActionForm.js"; | ||
import { useController } from "../../../useActionForm.js"; | ||
import { autoInput } from "../../AutoInput.js"; | ||
import { useFieldMetadata } from "../../hooks/useFieldMetadata.js"; | ||
import { AutoBooleanInputProps, InputLabel } from "../../shared/AutoInputTypes.js"; | ||
import { MUIAutoFormControl } from "./MUIAutoFormControl.js"; | ||
|
||
export const MUIAutoBooleanInput = autoInput( | ||
(props: { field: string; control?: Control<any>; label?: string } & Partial<CheckboxProps>) => { | ||
const { field: fieldApiIdentifier, label, control, ...rest } = props; | ||
export interface MUIAutoBooleanInputProps extends AutoBooleanInputProps, Partial<CheckboxProps> { | ||
/** | ||
* The label of the checkbox | ||
*/ | ||
label?: InputLabel; | ||
} | ||
|
||
const { path } = useFieldMetadata(fieldApiIdentifier); | ||
/** | ||
* A checkbox input for boolean inputs for use within <AutoForm></AutoForm> components | ||
* @example | ||
* ```tsx | ||
* <AutoForm action={api.modelA.create}> | ||
* <AutoBooleanInput field="isActive" /> | ||
* </AutoForm> | ||
* ``` | ||
* @param props.field - The API identifier of the Boolean field | ||
* @param props.label - The label of the checkbox | ||
* | ||
* @returns The checkbox input component | ||
*/ | ||
export const MUIAutoBooleanInput = autoInput((props: MUIAutoBooleanInputProps) => { | ||
const { field: fieldApiIdentifier, label, control, ...rest } = props; | ||
|
||
const { field: fieldProps } = useController({ | ||
control, | ||
name: path, | ||
}); | ||
const { path } = useFieldMetadata(fieldApiIdentifier); | ||
|
||
const { value: _value, ...restFieldProps } = fieldProps; | ||
const { field: fieldProps } = useController({ | ||
control, | ||
name: path, | ||
}); | ||
|
||
return ( | ||
<MUIAutoFormControl field={props.field} label={label}> | ||
<Checkbox {...restFieldProps} checked={fieldProps.value} {...rest} /> | ||
</MUIAutoFormControl> | ||
); | ||
} | ||
); | ||
const { value: _value, ...restFieldProps } = fieldProps; | ||
|
||
return ( | ||
<MUIAutoFormControl field={props.field} label={label as string}> | ||
<Checkbox {...restFieldProps} checked={fieldProps.value} {...rest} /> | ||
</MUIAutoFormControl> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 20 additions & 15 deletions
35
packages/react/src/auto/mui/inputs/MUIAutoEncryptedStringInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
import type { TextFieldProps } from "@mui/material"; | ||
import { IconButton } from "@mui/material"; | ||
import { IconButton, type TextFieldProps } from "@mui/material"; | ||
import React, { useState } from "react"; | ||
import type { Control } from "../../../useActionForm.js"; | ||
import { autoInput } from "../../AutoInput.js"; | ||
import type { AutoEncryptedStringInputProps } from "../../shared/AutoInputTypes.js"; | ||
import { MUIAutoTextInput } from "./MUIAutoTextInput.js"; | ||
|
||
export const MUIAutoEncryptedStringInput = autoInput( | ||
( | ||
props: { | ||
field: string; // The field API identifier | ||
control?: Control<any>; | ||
} & Partial<TextFieldProps> | ||
) => { | ||
const [isShown, setIsShown] = useState(false); | ||
const showHideToggleButton = <IconButton onClick={() => setIsShown(!isShown)}>{isShown ? `🔒` : `👁️`}</IconButton>; | ||
type MUIAutoEncryptedStringInputProps = AutoEncryptedStringInputProps & Partial<TextFieldProps>; | ||
/** | ||
* An encrypted string input for use within <AutoForm></AutoForm> components. | ||
* @example | ||
* ```tsx | ||
* <AutoForm action={api.modelA.create}> | ||
* <AutoEncryptedStringInput field="encryptedStringField" /> | ||
* </AutoForm> | ||
* ``` | ||
* @param props.field - The API identifier for the EncryptedString field. | ||
* @param props.label - The label of the EncryptedString field. | ||
* @returns The AutoEncryptedStringInput component. | ||
*/ | ||
export const MUIAutoEncryptedStringInput = autoInput((props: MUIAutoEncryptedStringInputProps) => { | ||
const [isShown, setIsShown] = useState(false); | ||
const showHideToggleButton = <IconButton onClick={() => setIsShown(!isShown)}>{isShown ? `🔒` : `👁️`}</IconButton>; | ||
|
||
return <MUIAutoTextInput InputProps={{ endAdornment: showHideToggleButton }} type={isShown ? "text" : "password"} {...props} />; | ||
} | ||
); | ||
return <MUIAutoTextInput InputProps={{ endAdornment: showHideToggleButton }} type={isShown ? "text" : "password"} {...props} />; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
import React from "react"; | ||
import { autoInput } from "../../AutoInput.js"; | ||
import { useHiddenInput } from "../../hooks/useHiddenInput.js"; | ||
import { AutoHiddenInputProps } from "../../shared/AutoInputTypes.js"; | ||
|
||
export const MUIAutoHiddenInput = autoInput( | ||
(props: { | ||
field: string; // The field API identifier | ||
value: any; | ||
}) => { | ||
const fieldProps = useHiddenInput(props); | ||
/** | ||
* A hidden input for use within <AutoForm></AutoForm> components. The value is included in form submission without rendering a visible input. | ||
* @example | ||
* ```tsx | ||
* <AutoForm action={api.modelA.create}> | ||
* <AutoHiddenInput field="fieldA" value="Value included in submission for fieldA" /> | ||
* </AutoForm> | ||
* ``` | ||
* @param props.field - The field API identifier | ||
* @param props.value - The value to be included in form submission | ||
* @returns The hidden input component | ||
*/ | ||
export const MUIAutoHiddenInput = autoInput((props: AutoHiddenInputProps) => { | ||
const fieldProps = useHiddenInput(props); | ||
|
||
return <input type="hidden" {...fieldProps} />; | ||
} | ||
); | ||
return <input type="hidden" {...fieldProps} />; | ||
}); |
Oops, something went wrong.