-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**Examples** ```tsx <AutocompleteField name="autocomplete" label="Autocomplete" options={[ { value: "chocolate", label: "Chocolate" }, { value: "strawberry", label: "Strawberry" }, { value: "vanilla", label: "Vanilla" }, ]} getOptionLabel={(option: Option) => option.label} isOptionEqualToValue={(option: Option, value: Option) => option.value === value.value} fullWidth /> ``` ```tsx <AsyncAutocompleteField name="asyncAutocomplete" label="Async Autocomplete" loadOptions={async () => { // Load options here }} getOptionLabel={(option: Option) => option.label} isOptionEqualToValue={(option: Option, value: Option) => option.value === value.value} fullWidth /> ```
- Loading branch information
1 parent
c51b250
commit 796e832
Showing
5 changed files
with
113 additions
and
1 deletion.
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,35 @@ | ||
--- | ||
"@comet/admin": minor | ||
--- | ||
|
||
Add `AutocompleteField` and `AsyncAutocompleteField` components | ||
|
||
**Examples** | ||
|
||
```tsx | ||
<AutocompleteField | ||
name="autocomplete" | ||
label="Autocomplete" | ||
options={[ | ||
{ value: "chocolate", label: "Chocolate" }, | ||
{ value: "strawberry", label: "Strawberry" }, | ||
{ value: "vanilla", label: "Vanilla" }, | ||
]} | ||
getOptionLabel={(option: Option) => option.label} | ||
isOptionEqualToValue={(option: Option, value: Option) => option.value === value.value} | ||
fullWidth | ||
/> | ||
``` | ||
|
||
```tsx | ||
<AsyncAutocompleteField | ||
name="asyncAutocomplete" | ||
label="Async Autocomplete" | ||
loadOptions={async () => { | ||
// Load options here | ||
}} | ||
getOptionLabel={(option: Option) => option.label} | ||
isOptionEqualToValue={(option: Option, value: Option) => option.value === value.value} | ||
fullWidth | ||
/> | ||
``` |
25 changes: 25 additions & 0 deletions
25
packages/admin/admin/src/form/fields/AsyncAutocompleteField.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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { AutocompleteProps } from "@mui/material"; | ||
import React from "react"; | ||
|
||
import { Field, FieldProps } from "../Field"; | ||
import { FinalFormAsyncAutocomplete } from "../FinalFormAsyncAutocomplete"; | ||
|
||
export type AsyncAutocompleteFieldProps< | ||
T extends Record<string, any>, | ||
Multiple extends boolean | undefined, | ||
DisableClearable extends boolean | undefined, | ||
FreeSolo extends boolean | undefined, | ||
> = FieldProps<T, HTMLInputElement | HTMLTextAreaElement> & { | ||
loadOptions: () => Promise<T[]>; | ||
} & Omit<AutocompleteProps<T, Multiple, DisableClearable, FreeSolo>, "options" | "renderInput"> & { | ||
clearable?: boolean; | ||
}; | ||
|
||
export function AsyncAutocompleteField< | ||
T extends Record<string, any>, | ||
Multiple extends boolean | undefined, | ||
DisableClearable extends boolean | undefined, | ||
FreeSolo extends boolean | undefined, | ||
>(props: AsyncAutocompleteFieldProps<T, Multiple, DisableClearable, FreeSolo>) { | ||
return <Field component={FinalFormAsyncAutocomplete} {...props} />; | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/admin/admin/src/form/fields/AutocompleteField.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { AutocompleteProps } from "@mui/material"; | ||
import React from "react"; | ||
|
||
import { AsyncOptionsProps } from "../../hooks/useAsyncOptionsProps"; | ||
import FinalFormAutocomplete from "../Autocomplete"; | ||
import { Field, FieldProps } from "../Field"; | ||
|
||
export type AutocompleteFieldProps< | ||
T extends Record<string, any>, | ||
Multiple extends boolean | undefined, | ||
DisableClearable extends boolean | undefined, | ||
FreeSolo extends boolean | undefined, | ||
> = FieldProps<T, HTMLInputElement | HTMLTextAreaElement> & | ||
Partial<AsyncOptionsProps<T>> & | ||
Omit<AutocompleteProps<T, Multiple, DisableClearable, FreeSolo>, "renderInput"> & { | ||
clearable?: boolean; | ||
}; | ||
|
||
export function AutocompleteField< | ||
T extends Record<string, any>, | ||
Multiple extends boolean | undefined, | ||
DisableClearable extends boolean | undefined, | ||
FreeSolo extends boolean | undefined, | ||
>(props: AutocompleteFieldProps<T, Multiple, DisableClearable, FreeSolo>) { | ||
return <Field component={FinalFormAutocomplete} {...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