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

chore: replace deprecated retrieveComponentStyles with componentStyles utility #1989

Merged
merged 3 commits into from
Dec 13, 2024

Conversation

jzempel
Copy link
Member

@jzempel jzempel commented Dec 12, 2024

Description

Big find/replace follow-on from #1986

@coveralls
Copy link

coveralls commented Dec 12, 2024

Coverage Status

coverage: 95.584% (-0.06%) from 95.647%
when pulling ceb05f9 on x-retrievecomponentstyles
into a868259 on main.

@@ -18,5 +18,5 @@ export const StyledInput = styled(Input as any).attrs({
})`
text-align: center;

${props => retrieveComponentStyles(COMPONENT_ID, props)};
${componentStyles};
Copy link
Contributor

@ze-flo ze-flo Dec 12, 2024

Choose a reason for hiding this comment

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

Food for thought...

At first glance, one could assume that the componentId received by componentStyles is colorpickers.colorpicker_input.

Sadly, that's incorrect as this story's DOM shows. 😞

Screenshot 2024-12-12 at 10 51 27 AM

The data-garden-id is in fact coming from the component returned by Input: StyledTextInput.

const COMPONENT_ID = 'forms.input';

This PR explains why and what pattern works with great detail.

For the intended behavior, we should explicitly define componentId.

Suggested change
${componentStyles};
${(props) => componentStyles({ ...props, componentId: COMPONENT_ID })};

However, unless our users found the colorpickers.colorpicker_input component id by exploring the source code, it's unlikely they knew the ColorPicker's input could be modified independently from the other Inputs by viewing the DOM only. Therefore I think it's acceptable keeping ${componentStyles};. However, I would remove

'data-garden-id': COMPONENT_ID,
'data-garden-version': PACKAGE_VERSION,

from attrs. It has no impact on the output and creates confusion.

Finally, we agree that how .attrs inherits values is confusing. This is why some cases call for ugly logic to get the intended result.

This can be all simplified by explicitly setting data-garden-id in the element component rather than .attrs. I hope we can get to that point in the future. 🤞

Copy link
Member Author

Choose a reason for hiding this comment

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

My instinct is to leave these (false) COMPONENT_ID "overrides" in place. Following Garden's original implementation and expectation, these IDs were meant to provide highly targeted component styling overrides without unanticipated component side effects. When we rectify the current implementation with element-specified data-garden-ids (most likely in a future major) the existing COMPONENT_ID will serve as a breadcrumb for the original intention.

Copy link
Contributor

Choose a reason for hiding this comment

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

To be clear, the clean up work would only apply to styled components extending another styled component.

Sounds good to me. We can follow-up on this in the future. 👍

@jzempel jzempel merged commit b2bc411 into main Dec 13, 2024
8 checks passed
@jzempel jzempel deleted the x-retrievecomponentstyles branch December 13, 2024 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants