mirror of
https://github.com/grafana/grafana.git
synced 2025-09-24 07:04:18 +08: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:
@ -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.
|
`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
|
### Usage
|
||||||
|
|
||||||
```jsx
|
```jsx
|
||||||
|
@ -7,6 +7,9 @@ export interface FieldArrayProps extends UseFieldArrayProps {
|
|||||||
children: (api: FieldArrayApi) => JSX.Element;
|
children: (api: FieldArrayApi) => JSX.Element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated use the `useFieldArray` hook from react-hook-form instead
|
||||||
|
*/
|
||||||
export const FieldArray: FC<FieldArrayProps> = ({ name, control, children, ...rest }) => {
|
export const FieldArray: FC<FieldArrayProps> = ({ name, control, children, ...rest }) => {
|
||||||
const { fields, append, prepend, remove, swap, move, insert } = useFieldArray({
|
const { fields, append, prepend, remove, swap, move, insert } = useFieldArray({
|
||||||
control,
|
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.
|
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
|
## Usage
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
|
@ -15,6 +15,9 @@ interface FormProps<T extends FieldValues> extends Omit<HTMLProps<HTMLFormElemen
|
|||||||
maxWidth?: number | 'none';
|
maxWidth?: number | 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated use the `useForm` hook from react-hook-form instead
|
||||||
|
*/
|
||||||
export function Form<T extends FieldValues>({
|
export function Form<T extends FieldValues>({
|
||||||
defaultValues,
|
defaultValues,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
|
@ -2,4 +2,8 @@
|
|||||||
* Rollup does not support renamed exports so do not change this to export { Controller as InputControl } ...
|
* Rollup does not support renamed exports so do not change this to export { Controller as InputControl } ...
|
||||||
*/
|
*/
|
||||||
import { Controller } from 'react-hook-form';
|
import { Controller } from 'react-hook-form';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated use the `Controller` component from react-hook-form instead
|
||||||
|
*/
|
||||||
export const InputControl = Controller;
|
export const InputControl = Controller;
|
||||||
|
@ -1,12 +1,18 @@
|
|||||||
import { UseFormReturn, FieldValues, FieldErrors, FieldArrayMethodProps } from 'react-hook-form';
|
import { UseFormReturn, FieldValues, FieldErrors, FieldArrayMethodProps } from 'react-hook-form';
|
||||||
export type { SubmitHandler as FormsOnSubmit, FieldErrors as FormFieldErrors } 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'> & {
|
export type FormAPI<T extends FieldValues> = Omit<UseFormReturn<T>, 'handleSubmit'> & {
|
||||||
errors: FieldErrors<T>;
|
errors: FieldErrors<T>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type FieldArrayValue = Partial<FieldValues> | Array<Partial<FieldValues>>;
|
type FieldArrayValue = Partial<FieldValues> | Array<Partial<FieldValues>>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated use the types from react-hook-form instead
|
||||||
|
*/
|
||||||
export interface FieldArrayApi {
|
export interface FieldArrayApi {
|
||||||
fields: Array<Record<string, any>>;
|
fields: Array<Record<string, any>>;
|
||||||
append: (value: FieldArrayValue, options?: FieldArrayMethodProps) => void;
|
append: (value: FieldArrayValue, options?: FieldArrayMethodProps) => void;
|
||||||
|
Reference in New Issue
Block a user