-
Notifications
You must be signed in to change notification settings - Fork 538
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
Set default theme #187
Conversation
@@ -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 |
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.
💯
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.
Can you explain why this needs to be set? I missed this addition!
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.
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.
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.
This looks good to me!
This simplifies our system-props helpers by removing all but
withSystemProps()
, updating that to use system-components'system()
, and adding awithDefaultTheme()
function that sets the component'sdefaultProps.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 getsystemComponent = true
, or detecting whetherdefaultProps.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 eithersystem()
orwithSystemProps()
because the former is what sets that flag.Fixes #186.