Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Commit

Permalink
fix: introduced forwardRef (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
priscilawebdev authored and juanpicado committed Oct 6, 2019
1 parent 909a8d9 commit 626bcce
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 71 deletions.
7 changes: 4 additions & 3 deletions src/components/Author/Author.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React, { FC, useContext } from 'react';

import Avatar from '@material-ui/core/Avatar';
import List from '@material-ui/core/List';

import { DetailContext } from '../../pages/Version';
import { Heading, AuthorListItem, AuthorListItemText } from './styles';
import { isEmail } from '../../utils/url';

const Authors: FC = () => {
import Avatar from '../../muiComponents/Avatar';

const Author: FC = () => {
const { packageMeta } = useContext(DetailContext);

if (!packageMeta) {
Expand Down Expand Up @@ -41,4 +42,4 @@ const Authors: FC = () => {
);
};

export default Authors;
export default Author;
2 changes: 1 addition & 1 deletion src/components/AvatarTooltip/AvatarTooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { FC } from 'react';

import Avatar from '@material-ui/core/Avatar';
import { isEmail } from '../../utils/url';

import Tooltip from '../../muiComponents/Tooltip';
import Avatar from '../../muiComponents/Avatar';

export interface AvatarDeveloper {
name: string;
Expand Down
128 changes: 72 additions & 56 deletions src/components/Developers/__snapshots__/Developers.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,29 @@ exports[`test Developers should render the component for contributors with items
target="_top"
title="dmethvin"
>
<WithStyles(ForwardRef(Avatar))
<ForwardRef(Avatar)
aria-label="dmethvin"
>
<ForwardRef(Avatar)
<WithStyles(ForwardRef(Avatar))
aria-label="dmethvin"
classes={
Object {
"colorDefault": "MuiAvatar-colorDefault",
"img": "MuiAvatar-img",
"root": "MuiAvatar-root",
}
}
>
<div
<ForwardRef(Avatar)
aria-label="dmethvin"
className="MuiAvatar-root MuiAvatar-colorDefault"
/>
</ForwardRef(Avatar)>
</WithStyles(ForwardRef(Avatar))>
classes={
Object {
"colorDefault": "MuiAvatar-colorDefault",
"img": "MuiAvatar-img",
"root": "MuiAvatar-root",
}
}
>
<div
aria-label="dmethvin"
className="MuiAvatar-root MuiAvatar-colorDefault"
/>
</ForwardRef(Avatar)>
</WithStyles(ForwardRef(Avatar))>
</ForwardRef(Avatar)>
</a>
<ForwardRef(Popper)
anchorEl={
Expand Down Expand Up @@ -199,25 +203,29 @@ exports[`test Developers should render the component for contributors with items
target="_top"
title="mgol"
>
<WithStyles(ForwardRef(Avatar))
<ForwardRef(Avatar)
aria-label="mgol"
>
<ForwardRef(Avatar)
<WithStyles(ForwardRef(Avatar))
aria-label="mgol"
classes={
Object {
"colorDefault": "MuiAvatar-colorDefault",
"img": "MuiAvatar-img",
"root": "MuiAvatar-root",
}
}
>
<div
<ForwardRef(Avatar)
aria-label="mgol"
className="MuiAvatar-root MuiAvatar-colorDefault"
/>
</ForwardRef(Avatar)>
</WithStyles(ForwardRef(Avatar))>
classes={
Object {
"colorDefault": "MuiAvatar-colorDefault",
"img": "MuiAvatar-img",
"root": "MuiAvatar-root",
}
}
>
<div
aria-label="mgol"
className="MuiAvatar-root MuiAvatar-colorDefault"
/>
</ForwardRef(Avatar)>
</WithStyles(ForwardRef(Avatar))>
</ForwardRef(Avatar)>
</a>
<ForwardRef(Popper)
anchorEl={
Expand Down Expand Up @@ -357,25 +365,29 @@ exports[`test Developers should render the component for maintainers with items
target="_top"
title="dmethvin"
>
<WithStyles(ForwardRef(Avatar))
<ForwardRef(Avatar)
aria-label="dmethvin"
>
<ForwardRef(Avatar)
<WithStyles(ForwardRef(Avatar))
aria-label="dmethvin"
classes={
Object {
"colorDefault": "MuiAvatar-colorDefault",
"img": "MuiAvatar-img",
"root": "MuiAvatar-root",
}
}
>
<div
<ForwardRef(Avatar)
aria-label="dmethvin"
className="MuiAvatar-root MuiAvatar-colorDefault"
/>
</ForwardRef(Avatar)>
</WithStyles(ForwardRef(Avatar))>
classes={
Object {
"colorDefault": "MuiAvatar-colorDefault",
"img": "MuiAvatar-img",
"root": "MuiAvatar-root",
}
}
>
<div
aria-label="dmethvin"
className="MuiAvatar-root MuiAvatar-colorDefault"
/>
</ForwardRef(Avatar)>
</WithStyles(ForwardRef(Avatar))>
</ForwardRef(Avatar)>
</a>
<ForwardRef(Popper)
anchorEl={
Expand Down Expand Up @@ -449,25 +461,29 @@ exports[`test Developers should render the component for maintainers with items
target="_top"
title="mgol"
>
<WithStyles(ForwardRef(Avatar))
<ForwardRef(Avatar)
aria-label="mgol"
>
<ForwardRef(Avatar)
<WithStyles(ForwardRef(Avatar))
aria-label="mgol"
classes={
Object {
"colorDefault": "MuiAvatar-colorDefault",
"img": "MuiAvatar-img",
"root": "MuiAvatar-root",
}
}
>
<div
<ForwardRef(Avatar)
aria-label="mgol"
className="MuiAvatar-root MuiAvatar-colorDefault"
/>
</ForwardRef(Avatar)>
</WithStyles(ForwardRef(Avatar))>
classes={
Object {
"colorDefault": "MuiAvatar-colorDefault",
"img": "MuiAvatar-img",
"root": "MuiAvatar-root",
}
}
>
<div
aria-label="mgol"
className="MuiAvatar-root MuiAvatar-colorDefault"
/>
</ForwardRef(Avatar)>
</WithStyles(ForwardRef(Avatar))>
</ForwardRef(Avatar)>
</a>
<ForwardRef(Popper)
anchorEl={
Expand Down
4 changes: 3 additions & 1 deletion src/components/Engines/Engines.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React, { Component, ReactElement } from 'react';

import Avatar from '@material-ui/core/Avatar';
import Grid from '@material-ui/core/Grid';
import List from '@material-ui/core/List';
import ListItemText from '@material-ui/core/ListItemText';

import { VersionPageConsumerProps, DetailContextConsumer } from '../../pages/Version';
import { Heading, EngineListItem } from './styles';

import Avatar from '../../muiComponents/Avatar';

// @ts-ignore
import node from './img/node.png';
import npm from '../Install/img/npm.svg';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Install/InstallListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import styled from 'react-emotion';
import Avatar from '@material-ui/core/Avatar';
import ListItem from '@material-ui/core/ListItem';
import ListItemText from '@material-ui/core/ListItemText';

import CopyToClipBoard from '../CopyToClipBoard';
import Avatar from '../../muiComponents/Avatar';

// logos of package managers
import npmLogo from './img/npm.svg';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Package/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Link } from 'react-router-dom';
import Grid from '@material-ui/core/Grid';
import List from '@material-ui/core/List';
import ListItemText from '@material-ui/core/ListItemText';
import Photo from '@material-ui/core/Avatar';
import Typography from '@material-ui/core/Typography';

import { breakpoints } from '../../utils/styles/media';
Expand All @@ -13,6 +12,7 @@ import Label from '../Label';
import colors from '../../utils/styles/colors';
import { fontWeight } from '../../utils/styles/sizes';
import { default as MuiIconButton } from '../../muiComponents/IconButton';
import { default as Photo } from '../../muiComponents/Avatar';

export const OverviewItem = styled('span')`
&& {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Repository/Repository.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint react/jsx-max-depth: 0 */

import React, { Component, Fragment, ReactElement } from 'react';
import Avatar from '@material-ui/core/Avatar';
import List from '@material-ui/core/List';

import { DetailContextConsumer } from '../../pages/Version';
Expand All @@ -12,6 +11,8 @@ import { Heading, GithubLink, RepositoryListItem, RepositoryListItemText } from
import git from './img/git.png';
import { isURL } from '../../utils/url';

import Avatar from '../../muiComponents/Avatar';

class Repository extends Component {
public render(): ReactElement<HTMLElement> {
return (
Expand Down
13 changes: 13 additions & 0 deletions src/muiComponents/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React, { forwardRef } from 'react';
import { default as MaterialUIAvatar, AvatarProps } from '@material-ui/core/Avatar';

// The default element type of MUI's Avatar is 'div' and we don't allow the change of this prop
type AvatarRef = HTMLElementTagNameMap['div'];

/* eslint-disable verdaccio/jsx-spread */
// eslint-disable-next-line react/display-name
const Avatar = forwardRef<AvatarRef, AvatarProps>(function Avatar(props, ref) {
return <MaterialUIAvatar {...props} ref={ref} />;
});

export default Avatar;
1 change: 1 addition & 0 deletions src/muiComponents/Avatar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './Avatar';
4 changes: 2 additions & 2 deletions src/muiComponents/IconButton/IconButton.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { forwardRef } from 'react';
import { default as MuiIconButton, IconButtonProps } from '@material-ui/core/IconButton';
import { default as MaterialUIIconButton, IconButtonProps } from '@material-ui/core/IconButton';

type IconButtonRef = HTMLElementTagNameMap['button'];

/* eslint-disable verdaccio/jsx-spread */
// eslint-disable-next-line react/display-name
const IconButton = forwardRef<IconButtonRef, IconButtonProps>(function IconButton(props, ref) {
return <MuiIconButton {...props} ref={ref} />;
return <MaterialUIIconButton {...props} ref={ref} />;
});

export default IconButton;
4 changes: 2 additions & 2 deletions src/muiComponents/TextField/TextField.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { forwardRef } from 'react';
import { default as TextFieldMaterialUI, TextFieldProps } from '@material-ui/core/TextField';
import { default as MaterialUITextField, TextFieldProps } from '@material-ui/core/TextField';

// The default element type of MUI's TextField is 'div'
type TextFieldRef = HTMLElementTagNameMap['div'];
Expand All @@ -8,7 +8,7 @@ type TextFieldRef = HTMLElementTagNameMap['div'];
// eslint-disable-next-line react/display-name
const TextField = forwardRef<TextFieldRef, TextFieldProps>(function ToolTip({ InputProps, classes, ...props }, ref) {
return (
<TextFieldMaterialUI
<MaterialUITextField
{...props}
InputProps={{
...InputProps,
Expand Down
4 changes: 2 additions & 2 deletions src/muiComponents/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { forwardRef } from 'react';
import { default as MuiTooltip, TooltipProps } from '@material-ui/core/Tooltip';
import { default as MaterialUITooltip, TooltipProps } from '@material-ui/core/Tooltip';

// The default element type of MUI's Tooltip is 'div' and the change of this prop is not allowed
type TooltipRef = HTMLElementTagNameMap['div'];

/* eslint-disable verdaccio/jsx-spread */
// eslint-disable-next-line react/display-name
const Tooltip = forwardRef<TooltipRef, TooltipProps>(function ToolTip(props, ref) {
return <MuiTooltip {...props} innerRef={ref} />;
return <MaterialUITooltip {...props} innerRef={ref} />;
});

export default Tooltip;
2 changes: 1 addition & 1 deletion src/pages/Version/Version.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { waitForElement } from '@testing-library/dom';
import ErrorBoundary from '../../App/AppError';

// :-) we mock this otherways fails on render, some weird issue on material-ui
jest.mock('@material-ui/core/Avatar');
jest.mock('../../muiComponents/Avatar');

// eslint-disable-next-line react/display-name
jest.mock('../../components/NotFound', () => () => <div>{'Not found'}</div>);
Expand Down

0 comments on commit 626bcce

Please sign in to comment.