-
Notifications
You must be signed in to change notification settings - Fork 136
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
fix: default variant not being applied when setting variant property name #152
base: master
Are you sure you want to change the base?
Conversation
I've managed to get this working now, but one of the types isn't playing nicely and I'm not sure how to fix it. I hope this solution makes sense, I tried to make it as simple as possible. |
I think I've cracked the types now, if someone can take a look at this PR that'd be great. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the tests!
The changes look good, can you also add an entry into CHANGELOG
? And sorry for the longer response here 🙇
@@ -62,6 +64,7 @@ const composeRestyleFunctions = < | |||
buildStyle, | |||
properties, | |||
propertiesMap, | |||
variantProp: variantProp ? variantProp.property : 'variant', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default should be coming from here, so I don't think defaulting here to variant
, too, is necessary.
variantProp: variantProp ? variantProp.property : 'variant', | |
variantProp: variantProp ? variantProp.property : undefined, |
Or possibly even variantProp: variantProp?.property,
if that works.
Is this getting merged anytime soon? |
The recent PR (#148) that fixed the problem where defaults weren't being applied only works when the variant prop is the default value (
variant
).If you're creating a component and using
createVariant
to change the name of the variant prop, using theproperty
value, the defaults are no longer applied.I've taken a look at the code and from what I can see, on this line:
restyle/src/hooks/useRestyle.ts
Line 17 in e4a51db
It's hardcoded to check for
variant
, but when changing this usingproperty
it's no longer this value, so it falls through.I've had a go at trying to fix this issue but I've not been able to come up with a solution yet. I've added some more exhaustive test cases to make sure all possibilities are being covered, but if someone could point me in the right direction to how to fix this issue I'd be happy to finish up the PR.
Hope you don't mind me submitting a WIP PR!