Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct types of component labels #2736

Merged
merged 5 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/toolpad-components/src/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ interface AutocompleteProps
Pick<FormInputComponentProps, 'name' | 'isRequired' | 'minLength' | 'maxLength' | 'isInvalid'> {
value: AutocompleteValue;
onChange: (newValue: AutocompleteValue) => void;
label?: string;
options: AutocompleteOption[];
label: string;
}

function Autocomplete({
Expand Down
20 changes: 10 additions & 10 deletions packages/toolpad-components/src/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
FormHelperText,
FormControl,
} from '@mui/material';
import type { CheckboxProps } from '@mui/material/Checkbox';
import type { CheckboxProps as MuiCheckBoxProps } from '@mui/material/Checkbox';
import type { FormControlLabelProps } from '@mui/material/FormControlLabel';
import { SX_PROP_HELPER_TEXT } from './constants';
import {
Expand All @@ -17,19 +17,19 @@ import {
FORM_INPUT_ARG_TYPES,
} from './Form';

export type FormControlLabelOptions = {
onChange: (newValue: boolean) => void;
defaultValue: string;
fullWidth: boolean;
} & Omit<FormControlLabelProps, 'control' | 'onChange'> &
Omit<CheckboxProps, 'onChange'> &
Pick<FormInputComponentProps, 'name' | 'isRequired' | 'isInvalid'>;
export type CheckboxProps = Omit<FormControlLabelProps, 'control' | 'onChange'> &
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aligning coding style with the rest of the components

Omit<MuiCheckBoxProps, 'onChange'> & {
onChange: (newValue: boolean) => void;
label?: string;
defaultValue: string;
fullWidth: boolean;
} & Pick<FormInputComponentProps, 'name' | 'isRequired' | 'isInvalid'>;

function Checkbox({ ...rest }: FormControlLabelOptions) {
function Checkbox({ ...rest }: CheckboxProps) {
rest.checked = rest.checked ?? false;
const { onFormInputChange, renderFormInput, formInputError } = useFormInput<boolean>({
name: rest.name,
label: rest.label as string,
label: rest.label,
onChange: rest.onChange,
validationProps: { isRequired: rest.isRequired, isInvalid: rest.isInvalid },
});
Expand Down
3 changes: 2 additions & 1 deletion packages/toolpad-components/src/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export interface DatePickerProps
Pick<FormInputComponentProps, 'name' | 'isRequired' | 'isInvalid'> {
value?: string;
onChange: (newValue: string | null) => void;
label?: string;
format: string;
fullWidth: boolean;
variant: 'outlined' | 'filled' | 'standard';
Expand All @@ -91,7 +92,7 @@ function DatePicker({
}: DatePickerProps) {
const { onFormInputChange, formInputError, renderFormInput } = useFormInput<string | null>({
name: rest.name,
label: rest.label as string,
label: rest.label,
value: valueProp,
onChange,
defaultValue: defaultValueProp,
Expand Down
3 changes: 2 additions & 1 deletion packages/toolpad-components/src/FilePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type FilePickerProps = MuiTextFieldProps & {
multiple: boolean;
value: FullFile[];
onChange: (files: FullFile[]) => void;
label?: string;
} & Pick<FormInputComponentProps, 'name' | 'isRequired' | 'isInvalid'>;

const readFile = async (file: Blob): Promise<string> => {
Expand Down Expand Up @@ -49,7 +50,7 @@ function FilePicker({
}: FilePickerProps) {
const { onFormInputChange, formInputError, renderFormInput } = useFormInput<FullFile[]>({
name: rest.name,
label: rest.label as string,
label: rest.label,
value,
onChange,
validationProps: { isRequired, isInvalid },
Expand Down
3 changes: 2 additions & 1 deletion packages/toolpad-components/src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface SelectOption {
export type SelectProps = Omit<TextFieldProps, 'value' | 'onChange'> & {
value: string;
onChange: (newValue: string) => void;
label?: string;
defaultValue: string;
options: (string | SelectOption)[];
} & Pick<FormInputComponentProps, 'name' | 'isRequired' | 'isInvalid'>;
Expand All @@ -34,7 +35,7 @@ function Select({
}: SelectProps) {
const { onFormInputChange, formInputError, renderFormInput } = useFormInput<string>({
name: rest.name,
label: rest.label as string,
label: rest.label,
value,
onChange,
defaultValue,
Expand Down
3 changes: 2 additions & 1 deletion packages/toolpad-components/src/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { SX_PROP_HELPER_TEXT } from './constants';
export type TextFieldProps = Omit<MuiTextFieldProps, 'value' | 'onChange'> & {
value: string;
onChange: (newValue: string) => void;
label?: string;
defaultValue: string;
alignItems?: BoxProps['alignItems'];
justifyContent?: BoxProps['justifyContent'];
Expand All @@ -34,7 +35,7 @@ function TextField({
}: TextFieldProps) {
const { onFormInputChange, formInputError, renderFormInput } = useFormInput<string>({
name: rest.name,
label: rest.label as string,
label: rest.label,
value,
onChange,
emptyValue: '',
Expand Down
Loading