mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
Grafana/ui: Add deprecation notice to the Form component (#81068)
* Grafana/ui: Add deprecation notice to the Form component * Fix notice * Deprecate types
This commit is contained in:
parent
d528d93b02
commit
41de0b4311
@ -7,6 +7,8 @@ import { FieldArray } from './FieldArray';
|
||||
|
||||
`FieldArray` provides a way to render a list of dynamic inputs. It exposes the functionality of `useFieldArray` in [react-hook-form](https://react-hook-form.com/advanced-usage/#FieldArrays). `FieldArray` must be wrapped at some level by a `<Form>` element.
|
||||
|
||||
**Note: This component is deprecated and will be removed in the future versions of grafana/ui. Use the `useFieldArray` hook from react-hook-form instead.**
|
||||
|
||||
### Usage
|
||||
|
||||
```jsx
|
||||
|
@ -7,6 +7,9 @@ export interface FieldArrayProps extends UseFieldArrayProps {
|
||||
children: (api: FieldArrayApi) => JSX.Element;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use the `useFieldArray` hook from react-hook-form instead
|
||||
*/
|
||||
export const FieldArray: FC<FieldArrayProps> = ({ name, control, children, ...rest }) => {
|
||||
const { fields, append, prepend, remove, swap, move, insert } = useFieldArray({
|
||||
control,
|
||||
|
@ -7,6 +7,8 @@ import { Form } from './Form';
|
||||
|
||||
Form component provides a way to build simple forms at Grafana. It is built on top of [react-hook-form](https://react-hook-form.com/) library and incorporates the same concepts while adjusting the API slightly.
|
||||
|
||||
**Note: This component is deprecated and will be removed in the future versions of grafana/ui. Use the `useForm` hook from react-hook-form instead.**
|
||||
|
||||
## Usage
|
||||
|
||||
```tsx
|
||||
|
@ -15,6 +15,9 @@ interface FormProps<T extends FieldValues> extends Omit<HTMLProps<HTMLFormElemen
|
||||
maxWidth?: number | 'none';
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use the `useForm` hook from react-hook-form instead
|
||||
*/
|
||||
export function Form<T extends FieldValues>({
|
||||
defaultValues,
|
||||
onSubmit,
|
||||
|
@ -2,4 +2,8 @@
|
||||
* Rollup does not support renamed exports so do not change this to export { Controller as InputControl } ...
|
||||
*/
|
||||
import { Controller } from 'react-hook-form';
|
||||
|
||||
/**
|
||||
* @deprecated use the `Controller` component from react-hook-form instead
|
||||
*/
|
||||
export const InputControl = Controller;
|
||||
|
@ -1,12 +1,18 @@
|
||||
import { UseFormReturn, FieldValues, FieldErrors, FieldArrayMethodProps } from 'react-hook-form';
|
||||
export type { SubmitHandler as FormsOnSubmit, FieldErrors as FormFieldErrors } from 'react-hook-form';
|
||||
|
||||
/**
|
||||
* @deprecated use the types from react-hook-form instead
|
||||
*/
|
||||
export type FormAPI<T extends FieldValues> = Omit<UseFormReturn<T>, 'handleSubmit'> & {
|
||||
errors: FieldErrors<T>;
|
||||
};
|
||||
|
||||
type FieldArrayValue = Partial<FieldValues> | Array<Partial<FieldValues>>;
|
||||
|
||||
/**
|
||||
* @deprecated use the types from react-hook-form instead
|
||||
*/
|
||||
export interface FieldArrayApi {
|
||||
fields: Array<Record<string, any>>;
|
||||
append: (value: FieldArrayValue, options?: FieldArrayMethodProps) => void;
|
||||
|
Loading…
Reference in New Issue
Block a user