Skip to content

Commit 9747089

Browse files
[core] Standardize the component injection pattern (#11204)
1 parent 8101150 commit 9747089

29 files changed

+79
-81
lines changed

ROADMAP.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ that **are needed for the stable version**:
115115
+import Button from '@material-ui/core/Button';
116116
```
117117

118-
- [ ] Look into the Render Props API over the Component Injection API. This one is an area of investigation. For instance, there is potential for simplifying the customization of the transitions.
119-
120118
These breaking changes will be spread into different releases over the next few months to make the upgrade path as smooth as possible.
121119
Not only does the Material-UI project have to be upgraded for each breaking change,
122120
but we also have to upgrade our own projects.

docs/src/pages/demos/dialogs/AlertDialogSlide.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AlertDialogSlide extends React.Component {
3131
<Button onClick={this.handleClickOpen}>Slide in alert dialog</Button>
3232
<Dialog
3333
open={this.state.open}
34-
transition={Transition}
34+
TransitionComponent={Transition}
3535
keepMounted
3636
onClose={this.handleClose}
3737
aria-labelledby="alert-dialog-slide-title"

docs/src/pages/demos/dialogs/FullScreenDialog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class FullScreenDialog extends React.Component {
4747
fullScreen
4848
open={this.state.open}
4949
onClose={this.handleClose}
50-
transition={Transition}
50+
TransitionComponent={Transition}
5151
>
5252
<AppBar className={classes.appBar}>
5353
<Toolbar>

docs/src/pages/demos/menus/FadeMenu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class FadeMenu extends React.Component {
3333
anchorEl={anchorEl}
3434
open={Boolean(anchorEl)}
3535
onClose={this.handleClose}
36-
transition={Fade}
36+
TransitionComponent={Fade}
3737
>
3838
<MenuItem onClick={this.handleClose}>Profile</MenuItem>
3939
<MenuItem onClick={this.handleClose}>My account</MenuItem>

docs/src/pages/demos/snackbars/DirectionSnackbar.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ function TransitionDown(props) {
2222
class DirectionSnackbar extends React.Component {
2323
state = {
2424
open: false,
25-
transition: null,
25+
Transition: null,
2626
};
2727

28-
handleClick = transition => () => {
29-
this.setState({ open: true, transition });
28+
handleClick = Transition => () => {
29+
this.setState({ open: true, Transition });
3030
};
3131

3232
handleClose = () => {
@@ -43,7 +43,7 @@ class DirectionSnackbar extends React.Component {
4343
<Snackbar
4444
open={this.state.open}
4545
onClose={this.handleClose}
46-
transition={this.state.transition}
46+
TransitionComponent={this.state.Transition}
4747
ContentProps={{
4848
'aria-describedby': 'message-id',
4949
}}

docs/src/pages/demos/snackbars/FadeSnackbar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class FadeSnackbar extends React.Component {
2323
<Snackbar
2424
open={this.state.open}
2525
onClose={this.handleClose}
26-
transition={Fade}
26+
TransitionComponent={Fade}
2727
ContentProps={{
2828
'aria-describedby': 'message-id',
2929
}}

docs/src/pages/demos/tables/CustomPaginationActionsTable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class CustomPaginationActionsTable extends React.Component {
180180
page={page}
181181
onChangePage={this.handleChangePage}
182182
onChangeRowsPerPage={this.handleChangeRowsPerPage}
183-
Actions={TablePaginationActionsWrapped}
183+
ActionsComponent={TablePaginationActionsWrapped}
184184
/>
185185
</TableRow>
186186
</TableFooter>

docs/src/pages/guides/api/api.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@ const styles = {
7070
};
7171
```
7272

73-
### Internal components
74-
75-
Internal components have:
76-
- their own flattened properties when these are key to the abstraction.
77-
- their own `xxxProps` property when users might need to tweak the internal render method's sub-components,
78-
for instance, exposing the `inputProps` and `InputProps` properties on components that use `Input` internally.
79-
For instance, exposing a `value` property.
73+
### Nested components
74+
75+
Nested components inside a component have:
76+
- their own flattened properties when these are key to the top level component abstraction.
77+
For instance and `id` property for the `Input` component.
78+
- their own `xxxProps` property when users might need to tweak the internal render method's sub-components.
79+
For instance, exposing the `inputProps` and `InputProps` properties on components that use `Input` internally.
80+
- their own `xxxComponent` property for performing component injection.
8081
- their own `xxxRef` property when user might need to perform imperative actions.
8182
For instance, exposing a `inputRef` property to access the native `input` on the `Input` component.
8283
It help answering the following question. [How can I access the DOM element?](/getting-started/faq#how-can-i-access-the-dom-element-)

packages/material-ui-lab/src/SpeedDial/SpeedDial.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class SpeedDial extends React.Component {
9898
onKeyDown,
9999
open,
100100
openIcon,
101-
transition: Transition,
101+
TransitionComponent,
102102
transitionDuration,
103103
TransitionProps,
104104
...other
@@ -137,7 +137,12 @@ class SpeedDial extends React.Component {
137137

138138
return (
139139
<div className={classNames(classes.root, classNameProp)} {...other}>
140-
<Transition in={!hidden} timeout={transitionDuration} unmountOnExit {...TransitionProps}>
140+
<TransitionComponent
141+
in={!hidden}
142+
timeout={transitionDuration}
143+
unmountOnExit
144+
{...TransitionProps}
145+
>
141146
<Button
142147
variant="fab"
143148
color="primary"
@@ -155,7 +160,7 @@ class SpeedDial extends React.Component {
155160
>
156161
{icon()}
157162
</Button>
158-
</Transition>
163+
</TransitionComponent>
159164
<div
160165
id={`${id}-actions`}
161166
className={classNames(classes.actions, { [classes.actionsClosed]: !open })}
@@ -227,7 +232,7 @@ SpeedDial.propTypes = {
227232
/**
228233
* Transition component.
229234
*/
230-
transition: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
235+
TransitionComponent: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
231236
/**
232237
* The duration for the transition, in milliseconds.
233238
* You may specify a single timeout for all transitions, or individually with an object.
@@ -244,7 +249,7 @@ SpeedDial.propTypes = {
244249

245250
SpeedDial.defaultProps = {
246251
hidden: false,
247-
transition: Zoom,
252+
TransitionComponent: Zoom,
248253
transitionDuration: {
249254
enter: duration.enteringScreen,
250255
exit: duration.leavingScreen,

packages/material-ui/src/Dialog/Dialog.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface DialogProps
1111
fullWidth?: boolean;
1212
maxWidth?: 'xs' | 'sm' | 'md' | false;
1313
PaperProps?: Partial<PaperProps>;
14-
transition?: React.ReactType;
14+
TransitionComponent?: React.ReactType;
1515
transitionDuration?: TransitionProps['timeout'];
1616
TransitionProps?: TransitionProps;
1717
}

packages/material-ui/src/Dialog/Dialog.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function Dialog(props) {
7373
onExiting,
7474
open,
7575
PaperProps,
76-
transition: TransitionProp,
76+
TransitionComponent,
7777
transitionDuration,
7878
TransitionProps,
7979
...other
@@ -95,7 +95,7 @@ function Dialog(props) {
9595
role="dialog"
9696
{...other}
9797
>
98-
<TransitionProp
98+
<TransitionComponent
9999
appear
100100
in={open}
101101
timeout={transitionDuration}
@@ -119,7 +119,7 @@ function Dialog(props) {
119119
>
120120
{children}
121121
</Paper>
122-
</TransitionProp>
122+
</TransitionComponent>
123123
</Modal>
124124
);
125125
}
@@ -214,7 +214,7 @@ Dialog.propTypes = {
214214
/**
215215
* Transition component.
216216
*/
217-
transition: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
217+
TransitionComponent: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
218218
/**
219219
* The duration for the transition, in milliseconds.
220220
* You may specify a single timeout for all transitions, or individually with an object.
@@ -235,7 +235,7 @@ Dialog.defaultProps = {
235235
fullScreen: false,
236236
fullWidth: false,
237237
maxWidth: 'sm',
238-
transition: Fade,
238+
TransitionComponent: Fade,
239239
transitionDuration: { enter: duration.enteringScreen, exit: duration.leavingScreen },
240240
};
241241

packages/material-ui/src/Dialog/Dialog.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ describe('<Dialog />', () => {
2525
assert.strictEqual(wrapper.type(), Modal);
2626
});
2727

28-
it('should render a Modal with transition', () => {
28+
it('should render a Modal with TransitionComponent', () => {
2929
const Transition = props => <div className="cloned-element-class" {...props} />;
3030
const wrapper = shallow(
31-
<Dialog {...defaultProps} transition={Transition}>
31+
<Dialog {...defaultProps} TransitionComponent={Transition}>
3232
foo
3333
</Dialog>,
3434
);
3535
assert.strictEqual(
3636
wrapper.find(Transition).length,
3737
1,
38-
'should include element given in transition',
38+
'should include element given in TransitionComponent',
3939
);
4040
});
4141

packages/material-ui/src/Popover/Popover.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export interface PopoverProps
3131
PaperProps?: Partial<PaperProps>;
3232
role?: string;
3333
transformOrigin?: PopoverOrigin;
34-
transition?: React.ReactType;
34+
TransitionComponent?: React.ReactType;
3535
transitionDuration?: TransitionProps['timeout'] | 'auto';
3636
TransitionProps?: TransitionProps;
3737
}

packages/material-ui/src/Popover/Popover.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class Popover extends React.Component {
290290
PaperProps,
291291
role,
292292
transformOrigin,
293-
transition: TransitionProp,
293+
TransitionComponent,
294294
transitionDuration,
295295
TransitionProps,
296296
...other
@@ -304,7 +304,7 @@ class Popover extends React.Component {
304304

305305
return (
306306
<Modal container={container} open={open} BackdropProps={{ invisible: true }} {...other}>
307-
<TransitionProp
307+
<TransitionComponent
308308
appear
309309
in={open}
310310
onEnter={this.handleEnter}
@@ -328,7 +328,7 @@ class Popover extends React.Component {
328328
<EventListener target="window" onResize={this.handleResize} />
329329
{children}
330330
</Paper>
331-
</TransitionProp>
331+
</TransitionComponent>
332332
</Modal>
333333
);
334334
}
@@ -472,7 +472,7 @@ Popover.propTypes = {
472472
/**
473473
* Transition component.
474474
*/
475-
transition: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
475+
TransitionComponent: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
476476
/**
477477
* Set to 'auto' to automatically calculate transition time based on height.
478478
*/
@@ -499,7 +499,7 @@ Popover.defaultProps = {
499499
vertical: 'top',
500500
horizontal: 'left',
501501
},
502-
transition: Grow,
502+
TransitionComponent: Grow,
503503
transitionDuration: 'auto',
504504
};
505505

packages/material-ui/src/Snackbar/Snackbar.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class Snackbar extends React.Component {
208208
onMouseLeave,
209209
open,
210210
resumeHideDuration,
211-
transition: TransitionProp,
211+
TransitionComponent,
212212
transitionDuration,
213213
TransitionProps,
214214
...other
@@ -236,7 +236,7 @@ class Snackbar extends React.Component {
236236
onFocus={disableWindowBlurListener ? undefined : this.handleResume}
237237
onBlur={disableWindowBlurListener ? undefined : this.handlePause}
238238
/>
239-
<TransitionProp
239+
<TransitionComponent
240240
appear
241241
in={open}
242242
onEnter={onEnter}
@@ -250,7 +250,7 @@ class Snackbar extends React.Component {
250250
{...TransitionProps}
251251
>
252252
{children || <SnackbarContent message={message} action={action} {...ContentProps} />}
253-
</TransitionProp>
253+
</TransitionComponent>
254254
</div>
255255
</ClickAwayListener>
256256
);
@@ -368,7 +368,7 @@ Snackbar.propTypes = {
368368
/**
369369
* Transition component.
370370
*/
371-
transition: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
371+
TransitionComponent: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
372372
/**
373373
* The duration for the transition, in milliseconds.
374374
* You may specify a single timeout for all transitions, or individually with an object.
@@ -389,7 +389,7 @@ Snackbar.defaultProps = {
389389
horizontal: 'center',
390390
},
391391
disableWindowBlurListener: false,
392-
transition: Slide,
392+
TransitionComponent: Slide,
393393
transitionDuration: {
394394
enter: duration.enteringScreen,
395395
exit: duration.leavingScreen,

packages/material-ui/src/Snackbar/Snackbar.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,14 @@ describe('<Snackbar />', () => {
362362
});
363363
});
364364

365-
describe('prop: transition', () => {
366-
it('should render a Snackbar with transition', () => {
365+
describe('prop: TransitionComponent', () => {
366+
it('should render a Snackbar with TransitionComponent', () => {
367367
const Transition = props => <div className="cloned-element-class" {...props} />;
368-
const wrapper = shallow(<Snackbar open transition={Transition} />);
368+
const wrapper = shallow(<Snackbar open TransitionComponent={Transition} />);
369369
assert.strictEqual(
370370
wrapper.find(Transition).length,
371371
1,
372-
'should include element given in transition',
372+
'should include element given in TransitionComponent',
373373
);
374374
});
375375
});

packages/material-ui/src/Stepper/StepContent.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface StepContentProps
1212
last?: boolean;
1313
optional?: boolean;
1414
orientation?: Orientation;
15-
transition?: React.ComponentType<TransitionProps>;
15+
TransitionComponent?: React.ComponentType<TransitionProps>;
1616
transitionDuration?: TransitionProps['timeout'] | 'auto';
1717
TransitionProps?: TransitionProps;
1818
}

packages/material-ui/src/Stepper/StepContent.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function StepContent(props) {
3232
last,
3333
optional,
3434
orientation,
35-
transition: Transition,
35+
TransitionComponent,
3636
transitionDuration,
3737
TransitionProps,
3838
...other
@@ -45,15 +45,15 @@ function StepContent(props) {
4545

4646
return (
4747
<div className={classNames(classes.root, { [classes.last]: last }, className)} {...other}>
48-
<Transition
48+
<TransitionComponent
4949
in={active}
5050
className={classes.transition}
5151
timeout={transitionDuration}
5252
unmountOnExit
5353
{...TransitionProps}
5454
>
5555
{children}
56-
</Transition>
56+
</TransitionComponent>
5757
</div>
5858
);
5959
}
@@ -101,7 +101,7 @@ StepContent.propTypes = {
101101
/**
102102
* Collapse component.
103103
*/
104-
transition: PropTypes.func,
104+
TransitionComponent: PropTypes.func,
105105
/**
106106
* Adjust the duration of the content expand transition.
107107
* Passed as a property to the transition component.
@@ -120,7 +120,7 @@ StepContent.propTypes = {
120120
};
121121

122122
StepContent.defaultProps = {
123-
transition: Collapse,
123+
TransitionComponent: Collapse,
124124
transitionDuration: 'auto',
125125
};
126126

0 commit comments

Comments
 (0)