-
Notifications
You must be signed in to change notification settings - Fork 78
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
feat: wrap all components with withStyles HOC #749
Conversation
…to feat/withStyles
src/ActionBar/ActionBar.js
Outdated
|
||
const ActionBar = ({ children, className, ...props }) => { | ||
const ActionBar = React.forwardRef(({ children, className, customStyles, disableStyles, ...props }, ref) => { |
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.
I think we can get rid of the customStyles
in this prop pruning use case since this never gets passed here from withStyles
. It should stay in the PropTypes definition, however, because consumers are unaware that the component is wrapped in an HOC.
@@ -3,6 +3,7 @@ import Popover from '../Popover/Popover'; | |||
import PropTypes from 'prop-types'; | |||
import Time from '../Time/Time'; | |||
import TimePickerItem from './_TimePickerItem'; | |||
import withStyles from '../utils/WithStyles/WithStyles'; |
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.
Does TimePicker
need the ref forwarding?
import classnames from 'classnames'; | ||
import FormItem from '../Forms/FormItem'; | ||
import FormLabel from '../Forms/FormLabel'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import { TOGGLE_SIZES } from '../utils/constants'; | ||
|
||
import withStyles from '../utils/WithStyles/WithStyles'; | ||
class Toggle extends React.Component { |
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.
Does Toggle
need the ref forwarding?
import PropTypes from 'prop-types'; | ||
import Tree from './_Tree'; | ||
import TreeBranch from './_TreeBranch'; | ||
import TreeCol from './_TreeCol'; | ||
import TreeHead from './_TreeHead'; | ||
import TreeItem from './_TreeItem'; | ||
import TreeRow from './_TreeRow'; | ||
import withStyles from '../utils/WithStyles/WithStyles'; | ||
import React, { Component } from 'react'; | ||
|
||
class TreeView extends Component { |
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.
Does TreeView
need the ref forwarding?
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.
Disregard my last 3 comments about ref forwarding -- I didn't notice they weren't functional components. All aboard!!! 🚢
}; | ||
|
||
ActionBar.Actions = ActionBarActions; | ||
ActionBar.Back = ActionBarBack; | ||
ActionBar.Header = ActionBarHeader; | ||
|
||
export default ActionBar; | ||
export { ActionBar as __ActionBar }; |
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.
What is the purpose of these __
renamed exports?
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.
To have access to the "plain" component for the purposes of building the docs site (property tables and import statements).
<div {...props} className={actionBarClasses}>{children}</div> | ||
<div {...props} | ||
className={actionBarClasses} | ||
ref={ref}> |
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.
Why was this ref (and similar others) added? Usually they're for focus management, but this is just a containing div
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 reasoning was to go ahead and add them to every functional component being wrapped in withStyles
as it will be a breaking change to add them going forward. See: https://reactjs.org/docs/forwarding-refs.html#note-for-component-library-maintainers
@@ -64,12 +65,13 @@ class Alert extends Component { | |||
)} | |||
<div className='fd-alert__text'> | |||
{type && ( | |||
<Icon glyph={`mesage-${type}`} /> |
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.
Is this mesage
a typo?
@@ -23,7 +23,7 @@ describe('<DatePicker />', () => { | |||
}); | |||
|
|||
test('open/close by calendar icon button', () => { | |||
wrapper = mount(defaultDatePicker); | |||
wrapper = mount(defaultDatePicker).children().children(); |
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 are ~80 instances of this .children().children()
pattern—can we write a single mount function with a comment for why we need to dive down 2 levels?
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.
Definitely should be on the to do for the next iteration ✅
}; | ||
|
||
//HOCs do not automatically pass refs as they are not technically props | ||
function forwardRef(props, ref) { |
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 function name makes it sound like an imperative side-effecty thing, when really this is a component. Is there a better name?
Also, can this just return the "with ref" version so the hoisted thing below is a little clearer? Maybe something like:
const componentWithRef = (props, ref) => React.forwardRef(<WithStyles {...props} forwardedRef={ref} />);
const componentWithStaticMethods = hoistNonReactStatic(componentWithRef, WrappedComponent);
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.
We can definitely try that out in the next iteration - I took this from the react docs to rather be safe than sorry.
Description
The new
withStyles
higher order component wraps each component and dynamically requires the relevant styles, or disable the styles based on props.Pass custom styling via require statement in
customStyles
prop.Disable all styles using
disableStyles
propThis pr introduces storybook! 📖 🎉
Functional components now with wrapped with
forwardRefs
npm run start:playground
ornpm run storybook
to start itTo do:
withStyles
wrappercustomTestStyles
😆 - hot pink navigation anyone?