Skip to content

Commit

Permalink
[FormControl] Add missing types in useFormControl (#35168)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeeshanTamboli authored Nov 25, 2022
1 parent 2861715 commit 1cb391c
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 44 deletions.
12 changes: 0 additions & 12 deletions packages/mui-material/src/FormControl/FormControlContext.js

This file was deleted.

36 changes: 36 additions & 0 deletions packages/mui-material/src/FormControl/FormControlContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as React from 'react';
import type { FormControlProps } from './FormControl';

type ContextFromPropsKey =
| 'color'
| 'disabled'
| 'error'
| 'fullWidth'
| 'hiddenLabel'
| 'margin'
| 'onBlur'
| 'onFocus'
| 'required'
| 'size'
| 'variant';

export interface FormControlState extends Pick<FormControlProps, ContextFromPropsKey> {
adornedStart: boolean;
filled: boolean;
focused: boolean;
onEmpty: () => void;
onFilled: () => void;
registerEffect: () => void;
setAdornedStart: React.Dispatch<React.SetStateAction<boolean>>;
}

/**
* @ignore - internal component.
*/
const FormControlContext = React.createContext<FormControlState | undefined>(undefined);

if (process.env.NODE_ENV !== 'production') {
FormControlContext.displayName = 'FormControlContext';
}

export default FormControlContext;
4 changes: 3 additions & 1 deletion packages/mui-material/src/FormControl/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export { default } from './FormControl';
export * from './FormControl';

export { default as useFormControl, FormControlState } from './useFormControl';
export { default as useFormControl } from './useFormControl';

export { FormControlState } from './FormControlContext';

export { default as formControlClasses } from './formControlClasses';
export * from './formControlClasses';
25 changes: 0 additions & 25 deletions packages/mui-material/src/FormControl/useFormControl.d.ts

This file was deleted.

6 changes: 0 additions & 6 deletions packages/mui-material/src/FormControl/useFormControl.js

This file was deleted.

6 changes: 6 additions & 0 deletions packages/mui-material/src/FormControl/useFormControl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as React from 'react';
import FormControlContext, { FormControlState } from './FormControlContext';

export default function useFormControl(): FormControlState | undefined {
return React.useContext(FormControlContext);
}

0 comments on commit 1cb391c

Please sign in to comment.