[Popover] Refactor popover transition - separation of concerns#7720
Conversation
|
NOTE: I have seen cross-contamination of tests when run sequentially. I could use some help with that. Individually, tests are passing and the Grow.spec.js in fact never uses the value I have changed all references to |
…ross contamination
|
This appears to be stubbed and perhaps never unstubbed:
|
|
@oliviertassinari this recently changed from a styleManagerMock = wrapper.context('styleManager');
styleManagerMock.theme.transitions.getAutoHeightDuration = stub().returns('woof');
wrapper.setContext({ styleManager: styleManagerMock });
wrapper.setProps({ transitionDuration: 'auto' });
instance = wrapper.instance();Now: theme = instance.props.theme;
theme.transitions.getAutoHeightDuration = stub().returns('woofCollapseStub');
wrapper.setProps({ transitionDuration: 'auto' });
instance = wrapper.instance();Either we need to regenerate theme so it is pristine on each |
|
I added an explicit restore of the stubbed method. |
oliviertassinari
left a comment
There was a problem hiding this comment.
I like the idea of this PR. It's a quick review, I need to have a deeper look this evening :).
| * @ignore - internal component. | ||
| */ | ||
| class Popover extends Component<DefaultProps, AllProps, void> { | ||
| class Popover extends PureComponent<DefaultProps, AllProps, void> { |
There was a problem hiding this comment.
The component takes a children, let's keep Component.
| /** | ||
| * @ignore - internal component. | ||
| */ | ||
| class Grow extends PureComponent<DefaultProps, AllProps, void> { |
There was a problem hiding this comment.
The component takes a children, PureComponent is harming the performance, let's use to Component.
|
I've confirmed the |
|
Feel free to ping me if you need help or more info about |
|
Thanks @FezVrasta - hope you are well. |
oliviertassinari
left a comment
There was a problem hiding this comment.
I had a deep look into it. That looks great 😄 .
| </Grow> | ||
| </Modal> | ||
| ); | ||
| } |
There was a problem hiding this comment.
You can remove all the occurrences of withTheme and theme in this file.
There was a problem hiding this comment.
still need it in #handleEnter for theme.transitions
There was a problem hiding this comment.
Sorry, I was looking at the wrong file, you are right.
| ...other | ||
| } = this.props; | ||
|
|
||
| // FIXME: props API consistency problem? - `...other` not spread over the root |
There was a problem hiding this comment.
I agree, let's move the ...other to the root. What's preventing us from doing it?
There was a problem hiding this comment.
Nothing yet, just want to save that for the next wave of the refactor.
| } | ||
|
|
||
| type DefaultProps = { | ||
| theme: Object, |
There was a problem hiding this comment.
This property is injected by withTheme(), I don't think that we need it.
There was a problem hiding this comment.
necessary for flow resolution. We could add it to AllProps instead, but that would differ from the pattern in other files.
There was a problem hiding this comment.
Won't making the property required allow us to remove it here? It's the same for the classes.
There was a problem hiding this comment.
It has to be required somewhere, and it is not required outside this component. If it is not required outside the component, we cannot require it in export type Props, as it would prohibit using the type externally to compose components.
| /** | ||
| * @ignore | ||
| */ | ||
| theme?: Object, |
There was a problem hiding this comment.
I think that it should be required.
There was a problem hiding this comment.
It's not required externally (maybe type), but it is internally, that's why it's optional in Props and required in DefaultProps. The intersection of these mean internally the component can expect it to be non-null.
There was a problem hiding this comment.
Isn't the same thing with the classes? I have put them required in the code, but in the documentation I have change them to be optional. Anyway here it's not documented.
There was a problem hiding this comment.
Same as classes, see above for explanation. It's all about externalizing Props for reuse. If theme isn't allowed to be passed in (by the user), we should remove it from Props.
| import Transition from '../internal/Transition'; | ||
| import type { TransitionCallback } from '../internal/Transition'; | ||
|
|
||
| export function getScale(value: number) { |
There was a problem hiding this comment.
Maybe we should add // Only exported for the tests.
I'm not that sure about it. The |
This can be done with popper, even the custom positioning with a modifier. I'm not too keen to take that on yet. I've got a lot on my plate, but it is certainly viable and I think it would cut code and rely on a good external project. |
|
@rosskevin Great, it's much better with the concerns separated :). |
* upstream/v1-beta: (24 commits) v1.0.0-beta.5 Update CHANGELOG.md [CHANGELOG] Prepare v1.0.0-beta.5 chore(package): update size-limit to version 0.9.0 (mui#7757) [docs] Fix yarn docs:build script (mui#7745) [docs] Update the readme [Radio] Fix accessibility issue (mui#7742) [Tabs][BottomNavigation] Use value over index property (mui#7741) [core] Remove createStyleSheet (mui#7740) [core] Start simplifying styling API (mui#7730) [LinearProgress] Use transform instead width (mui#7732) Fix Typo (mui#7736) Documentation Fix - Fixing up the README documentation (mui#7733) [ButtonBase] Expose internal component (mui#7727) [Popover] Refactor popover transition - separation of concerns (mui#7720) Button documentation fix (mui#7726) Update supported-components.md (mui#7722) chore(package): update webpack to version 3.5.3 (mui#7723) [flow] flow type transitions Slide, Fade, Collapse (fixes) Create CODE_OF_CONDUCT.md ...

squash+mergeFor simplification and external reuse of the
Popovertransition (now calledGrow) withreact-autosuggest, I have refactoredPopover.Popoveris currently used exclusively byMenu.As it stands, here are the purposes:
internal/Popover= positioning +Modal+Grow+Paper(used byMenu)transitions/Grow= only the effect exhibited by popovers - grow with a bit of fade in.There are also various small fixes I encountered as I refactored.
I should also mention that this is possibly the lead-in to deleting the positioning code in
Popoverin lieu of usingreact-popper, but I'll wait to take that on after I've used it a bit withreact-autosuggest.