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

fix: default variant not being applied when setting variant property name #152

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

wwdrew
Copy link

@wwdrew wwdrew commented Apr 14, 2022

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 the property value, the defaults are no longer applied.

I've taken a look at the code and from what I can see, on this line:

const props = omitPropertiesMap.variant

It's hardcoded to check for variant, but when changing this using property 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!

@ghost ghost added the cla-needed label Apr 14, 2022
@wwdrew wwdrew changed the title fix: default variant not being applied when setting variant property name WIP fix: default variant not being applied when setting variant property name Apr 14, 2022
@ghost ghost removed the cla-needed label Apr 14, 2022
@wwdrew
Copy link
Author

wwdrew commented Apr 20, 2022

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.

@wwdrew wwdrew changed the title WIP fix: default variant not being applied when setting variant property name fix: default variant not being applied when setting variant property name Apr 29, 2022
@wwdrew
Copy link
Author

wwdrew commented Apr 29, 2022

I think I've cracked the types now, if someone can take a look at this PR that'd be great.

Copy link
Contributor

@fortmarek fortmarek left a 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',
Copy link
Contributor

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.

Suggested change
variantProp: variantProp ? variantProp.property : 'variant',
variantProp: variantProp ? variantProp.property : undefined,

Or possibly even variantProp: variantProp?.property, if that works.

@PR7JW7L
Copy link

PR7JW7L commented Mar 8, 2024

Is this getting merged anytime soon?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants