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

[Doc] Convert Inputs Tutorial Examples to TS #9183

Merged
merged 4 commits into from Aug 14, 2023

Conversation

djhi
Copy link
Contributor

@djhi djhi commented Aug 14, 2023

No description provided.

ret = children({ formData, ...rest });
ret = children({
formData,
getSource: (scopedSource: string) => scopedSource,
Copy link
Contributor Author

@djhi djhi Aug 14, 2023

Choose a reason for hiding this comment

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

This ensures TS users don't have to check that getSource is defined before calling it

docs/Inputs.md Outdated
Comment on lines 866 to 884
const { source, ...rest } = props;

return (
<span>
<BoundedTextField
source="lat"
label="Latitude"
validate={required()}
{...rest}
/>
&nbsp;
<BoundedTextField
source="lng"
label="Longitude"
validate={required()}
{...rest}
/>
</span>
);
Copy link
Member

Choose a reason for hiding this comment

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

weird (too large?) indentation

docs/Inputs.md Outdated
Comment on lines 833 to 863
extends Omit<
TextFieldProps,
"label" | "helperText" | "onChange" | "onBlur" | "type" | "defaultValue"
>,
InputProps {}

const BoundedTextField = (props: BoundedTextFieldProps) => {
const { onChange, onBlur, label, ...rest } = props;
const {
field,
fieldState: { isTouched, invalid, error },
formState: { isSubmitted },
isRequired,
} = useInput({
// Pass the event handlers to the hook but not the component as the field property already has them.
// useInput will call the provided onChange and onBlur in addition to the default needed by react-hook-form.
onChange,
onBlur,
...rest,
});

return (
<TextField
{...field}
label={label}
error={(isTouched || isSubmitted) && invalid}
helperText={(isTouched || isSubmitted) && invalid ? error?.message : ""}
required={isRequired}
{...rest}
/>
);
Copy link
Member

Choose a reason for hiding this comment

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

weird indentation

docs/Inputs.md Show resolved Hide resolved
docs/Inputs.md Outdated
Comment on lines 510 to 525
<Edit>
<SimpleForm>
<SelectInput source="country" choices={toChoices(countries)} />
<FormDataConsumer<{ country: string }>>
{({ formData, ...rest }) => (
<SelectInput
source="cities"
choices={
formData.country ? toChoices(cities[formData.country]) : []
}
{...rest}
/>
)}
</FormDataConsumer>
</SimpleForm>
</Edit>
Copy link
Member

Choose a reason for hiding this comment

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

indentation too large

docs/Inputs.md Outdated
Comment on lines 464 to 468
const cities: Record<string, string[]> = {
USA: ["New York", "Los Angeles", "Chicago", "Houston", "Phoenix"],
UK: ["London", "Birmingham", "Glasgow", "Liverpool", "Bristol"],
France: ["Paris", "Marseille", "Lyon", "Toulouse", "Nice"],
};
Copy link
Member

Choose a reason for hiding this comment

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

indentation too large

docs/Inputs.md Outdated
Comment on lines 471 to 480
const CityInput = (props: SelectInputProps) => {
const country = useWatch<{ country: string }>({ name: "country" });

return (
<SelectInput
choices={country ? toChoices(cities[country]) : []}
{...props}
/>
);
};
Copy link
Member

Choose a reason for hiding this comment

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

indentation too large

@fzaninotto fzaninotto merged commit ad639dc into master Aug 14, 2023
10 checks passed
@fzaninotto fzaninotto deleted the ts-documentation-inputs-tutorial branch August 14, 2023 16:25
@fzaninotto fzaninotto changed the title Rewrite Inputs Tutorial Examples in TS [Doc] Convert Inputs Tutorial Examples to TS Aug 14, 2023
@fzaninotto fzaninotto added this to the 4.13.1 milestone Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants