mui / material-ui

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
https://mui.com/material-ui/
MIT License
94.02k stars 32.3k forks source link

[docs][TypeScript] Add examples of how to extend types from MUI components #44493

Open CzarOfScripts opened 1 day ago

CzarOfScripts commented 1 day ago

Related page

https://mui.com/material-ui/

Kind of issue

Other

Issue description

Let me start by saying that I am using a translator and I hope my message will be understood. I have always had problems with creating custom components based on MUI components. The problem is the typing of such components. List of examples I would like to see:

  1. Typing of components that have component props.
    • I don't understand how to take all the props of let's say Box component, add some of my own (mandatory and non-mandatory) props to them. And to add props from component when specifying component.
  2. Typing of components that have variant in their generics (for example, if we take TextFieldProps).
  3. Typing of more complex components such as Button.
  4. How to type it all if we need to wrap everything in forwardRef.
    • How to define the element type for ref (HTMLDivElement, HTMLButtonElement, etc.).
    • It's also worth considering this type if a component is passed in component.
  5. Also for all this I would like to see an example where we remove some props from the component and/or replace them with our own. For example in a Chip component I would like to be able to pass children and they would be placed in the props label, with the props label itself removed from the typing props (I don't know how to explain it).

(Important: The point is not to change the theme of some component, but to add your logic to it.)

If you could add a new page and/or to the component page examples of how to create a component based on that component - that would be awesome.

I realize it would take a lot of time to add this to the documentation, so I would like to see these examples under my Issue.

Thank you for your work and efforts!

Context

No response

Search keywords: no