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

Set default theme #187

Merged
merged 19 commits into from
Aug 6, 2018
Merged

Set default theme #187

merged 19 commits into from
Aug 6, 2018

Conversation

shawnbot
Copy link
Contributor

@shawnbot shawnbot commented Aug 6, 2018

This simplifies our system-props helpers by removing all but withSystemProps(), updating that to use system-components' system(), and adding a withDefaultTheme() function that sets the component's defaultProps.theme to our internal theme object so that there's no need for a ThemeProvider to get primer styles.

One problem that I ran into here was that a couple of our components were "extending" system components (CircleOcticon → FlexContainer, CaretBox → Box), which (because of how system-components does things) was actually calling the underlying render function twice with different props. I've attempted to catch cases of this by looking for instances of either components that were directly created with system(), which get systemComponent = true, or detecting whether defaultProps.blacklist is an array, which happens when we spread another system component's defaultProps into ours.

I've also added (and marked as pending for un-migrated components) a test to each component's suite that asserts Component.systemComponent === true. This will need to be set manually for components that aren't explicitly created with either system() or withSystemProps() because the former is what sets that flag.

Fixes #186.

@shawnbot shawnbot mentioned this pull request Aug 6, 2018
@@ -31,4 +25,7 @@ CaretBox.defaultProps = {
position: 'relative'
}

export default withSystemProps(CaretBox, ['color'])
// we can set this because it "inherits" all of Box's system props
CaretBox.systemComponent = true
Copy link

Choose a reason for hiding this comment

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

💯

Copy link

Choose a reason for hiding this comment

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

Can you explain why this needs to be set? I missed this addition!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because CaretBox renders a Box and forwards most of its props, it can safely be considered a system component even though we don't call withSystemProps() on it explicitly. In fact, if we do, it causes that weird double-render bug that I mentioned above. ☹️

Copy link

@emplums emplums left a comment

Choose a reason for hiding this comment

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

This looks good to me!

@shawnbot shawnbot merged commit 9eb5174 into release-1.0.0-beta Aug 6, 2018
@shawnbot shawnbot deleted the default-theme branch August 6, 2018 20:57
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.

2 participants