-
Notifications
You must be signed in to change notification settings - Fork 25
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
Add prop types of custom components #121
Comments
I've been thinking a lot about a good solution for that. The In the example, I simply omitted the size prop :P But I think we need to have a better way. The only solution I thought of so far is to add a generic to @diogob @gustavoguichard, what do you think? |
The render function of the
The That being said, I personally think it would be a better to expose a
Something similar could be done for indicators on input fields. |
I love the idea of the hooks, @bvangraafeiland! Can you create separate issues for each hook you'd like to exist? Thank you! |
I'm not sure if this might be helpful, but i'm using a sort of "polymorphic" component in my projects (similar to mantine). With that you can use a component like <MenuItem as='input' />
// Gives you types for the input like value, autocomplete or whatever + the props of MenuItem. type AsProp<C extends React.ElementType> = {
as?: C;
asElement?: C;
};
type PropsToOmit<C extends React.ElementType, P> = keyof (AsProp<C> & P);
export type PolymorphicComponentProp<C extends React.ElementType, Props = {}> = React.PropsWithChildren<Props & AsProp<C>> &
Omit<React.ComponentPropsWithoutRef<C>, PropsToOmit<C, Props>>;
export type PolymorphicRef<C extends React.ElementType> = React.ComponentPropsWithRef<C>['ref'];
export type PolymorphicComponentPropWithRef<C extends React.ElementType, Props = {}> = PolymorphicComponentProp<C, Props> & {
ref?: PolymorphicRef<C>;
}; Big thanks to this article: |
When using the field children, you can pass some props to the Label/Input etc. However, the prop types of the components are
JSX.IntrinsicElements['input']
for example, so if you have a custom input component that takes asize
prop, you end up with a typescript error.In reality the props are being passed through, so it will work if you ignore the type error, but it would be nice if the prop types could be merged somehow.
The text was updated successfully, but these errors were encountered: