forked from sombochea/verdaccio-ui
fix: introduced forwardRef (#163)
This commit is contained in:
parent
909a8d9fb8
commit
626bcce5cb
@ -1,13 +1,14 @@
|
|||||||
import React, { FC, useContext } from 'react';
|
import React, { FC, useContext } from 'react';
|
||||||
|
|
||||||
import Avatar from '@material-ui/core/Avatar';
|
|
||||||
import List from '@material-ui/core/List';
|
import List from '@material-ui/core/List';
|
||||||
|
|
||||||
import { DetailContext } from '../../pages/Version';
|
import { DetailContext } from '../../pages/Version';
|
||||||
import { Heading, AuthorListItem, AuthorListItemText } from './styles';
|
import { Heading, AuthorListItem, AuthorListItemText } from './styles';
|
||||||
import { isEmail } from '../../utils/url';
|
import { isEmail } from '../../utils/url';
|
||||||
|
|
||||||
const Authors: FC = () => {
|
import Avatar from '../../muiComponents/Avatar';
|
||||||
|
|
||||||
|
const Author: FC = () => {
|
||||||
const { packageMeta } = useContext(DetailContext);
|
const { packageMeta } = useContext(DetailContext);
|
||||||
|
|
||||||
if (!packageMeta) {
|
if (!packageMeta) {
|
||||||
@ -41,4 +42,4 @@ const Authors: FC = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Authors;
|
export default Author;
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import React, { FC } from 'react';
|
import React, { FC } from 'react';
|
||||||
|
|
||||||
import Avatar from '@material-ui/core/Avatar';
|
|
||||||
import { isEmail } from '../../utils/url';
|
import { isEmail } from '../../utils/url';
|
||||||
|
|
||||||
import Tooltip from '../../muiComponents/Tooltip';
|
import Tooltip from '../../muiComponents/Tooltip';
|
||||||
|
import Avatar from '../../muiComponents/Avatar';
|
||||||
|
|
||||||
export interface AvatarDeveloper {
|
export interface AvatarDeveloper {
|
||||||
name: string;
|
name: string;
|
||||||
|
@ -107,25 +107,29 @@ exports[`test Developers should render the component for contributors with items
|
|||||||
target="_top"
|
target="_top"
|
||||||
title="dmethvin"
|
title="dmethvin"
|
||||||
>
|
>
|
||||||
<WithStyles(ForwardRef(Avatar))
|
<ForwardRef(Avatar)
|
||||||
aria-label="dmethvin"
|
aria-label="dmethvin"
|
||||||
>
|
>
|
||||||
<ForwardRef(Avatar)
|
<WithStyles(ForwardRef(Avatar))
|
||||||
aria-label="dmethvin"
|
aria-label="dmethvin"
|
||||||
classes={
|
|
||||||
Object {
|
|
||||||
"colorDefault": "MuiAvatar-colorDefault",
|
|
||||||
"img": "MuiAvatar-img",
|
|
||||||
"root": "MuiAvatar-root",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<div
|
<ForwardRef(Avatar)
|
||||||
aria-label="dmethvin"
|
aria-label="dmethvin"
|
||||||
className="MuiAvatar-root MuiAvatar-colorDefault"
|
classes={
|
||||||
/>
|
Object {
|
||||||
</ForwardRef(Avatar)>
|
"colorDefault": "MuiAvatar-colorDefault",
|
||||||
</WithStyles(ForwardRef(Avatar))>
|
"img": "MuiAvatar-img",
|
||||||
|
"root": "MuiAvatar-root",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
aria-label="dmethvin"
|
||||||
|
className="MuiAvatar-root MuiAvatar-colorDefault"
|
||||||
|
/>
|
||||||
|
</ForwardRef(Avatar)>
|
||||||
|
</WithStyles(ForwardRef(Avatar))>
|
||||||
|
</ForwardRef(Avatar)>
|
||||||
</a>
|
</a>
|
||||||
<ForwardRef(Popper)
|
<ForwardRef(Popper)
|
||||||
anchorEl={
|
anchorEl={
|
||||||
@ -199,25 +203,29 @@ exports[`test Developers should render the component for contributors with items
|
|||||||
target="_top"
|
target="_top"
|
||||||
title="mgol"
|
title="mgol"
|
||||||
>
|
>
|
||||||
<WithStyles(ForwardRef(Avatar))
|
<ForwardRef(Avatar)
|
||||||
aria-label="mgol"
|
aria-label="mgol"
|
||||||
>
|
>
|
||||||
<ForwardRef(Avatar)
|
<WithStyles(ForwardRef(Avatar))
|
||||||
aria-label="mgol"
|
aria-label="mgol"
|
||||||
classes={
|
|
||||||
Object {
|
|
||||||
"colorDefault": "MuiAvatar-colorDefault",
|
|
||||||
"img": "MuiAvatar-img",
|
|
||||||
"root": "MuiAvatar-root",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<div
|
<ForwardRef(Avatar)
|
||||||
aria-label="mgol"
|
aria-label="mgol"
|
||||||
className="MuiAvatar-root MuiAvatar-colorDefault"
|
classes={
|
||||||
/>
|
Object {
|
||||||
</ForwardRef(Avatar)>
|
"colorDefault": "MuiAvatar-colorDefault",
|
||||||
</WithStyles(ForwardRef(Avatar))>
|
"img": "MuiAvatar-img",
|
||||||
|
"root": "MuiAvatar-root",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
aria-label="mgol"
|
||||||
|
className="MuiAvatar-root MuiAvatar-colorDefault"
|
||||||
|
/>
|
||||||
|
</ForwardRef(Avatar)>
|
||||||
|
</WithStyles(ForwardRef(Avatar))>
|
||||||
|
</ForwardRef(Avatar)>
|
||||||
</a>
|
</a>
|
||||||
<ForwardRef(Popper)
|
<ForwardRef(Popper)
|
||||||
anchorEl={
|
anchorEl={
|
||||||
@ -357,25 +365,29 @@ exports[`test Developers should render the component for maintainers with items
|
|||||||
target="_top"
|
target="_top"
|
||||||
title="dmethvin"
|
title="dmethvin"
|
||||||
>
|
>
|
||||||
<WithStyles(ForwardRef(Avatar))
|
<ForwardRef(Avatar)
|
||||||
aria-label="dmethvin"
|
aria-label="dmethvin"
|
||||||
>
|
>
|
||||||
<ForwardRef(Avatar)
|
<WithStyles(ForwardRef(Avatar))
|
||||||
aria-label="dmethvin"
|
aria-label="dmethvin"
|
||||||
classes={
|
|
||||||
Object {
|
|
||||||
"colorDefault": "MuiAvatar-colorDefault",
|
|
||||||
"img": "MuiAvatar-img",
|
|
||||||
"root": "MuiAvatar-root",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<div
|
<ForwardRef(Avatar)
|
||||||
aria-label="dmethvin"
|
aria-label="dmethvin"
|
||||||
className="MuiAvatar-root MuiAvatar-colorDefault"
|
classes={
|
||||||
/>
|
Object {
|
||||||
</ForwardRef(Avatar)>
|
"colorDefault": "MuiAvatar-colorDefault",
|
||||||
</WithStyles(ForwardRef(Avatar))>
|
"img": "MuiAvatar-img",
|
||||||
|
"root": "MuiAvatar-root",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
aria-label="dmethvin"
|
||||||
|
className="MuiAvatar-root MuiAvatar-colorDefault"
|
||||||
|
/>
|
||||||
|
</ForwardRef(Avatar)>
|
||||||
|
</WithStyles(ForwardRef(Avatar))>
|
||||||
|
</ForwardRef(Avatar)>
|
||||||
</a>
|
</a>
|
||||||
<ForwardRef(Popper)
|
<ForwardRef(Popper)
|
||||||
anchorEl={
|
anchorEl={
|
||||||
@ -449,25 +461,29 @@ exports[`test Developers should render the component for maintainers with items
|
|||||||
target="_top"
|
target="_top"
|
||||||
title="mgol"
|
title="mgol"
|
||||||
>
|
>
|
||||||
<WithStyles(ForwardRef(Avatar))
|
<ForwardRef(Avatar)
|
||||||
aria-label="mgol"
|
aria-label="mgol"
|
||||||
>
|
>
|
||||||
<ForwardRef(Avatar)
|
<WithStyles(ForwardRef(Avatar))
|
||||||
aria-label="mgol"
|
aria-label="mgol"
|
||||||
classes={
|
|
||||||
Object {
|
|
||||||
"colorDefault": "MuiAvatar-colorDefault",
|
|
||||||
"img": "MuiAvatar-img",
|
|
||||||
"root": "MuiAvatar-root",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<div
|
<ForwardRef(Avatar)
|
||||||
aria-label="mgol"
|
aria-label="mgol"
|
||||||
className="MuiAvatar-root MuiAvatar-colorDefault"
|
classes={
|
||||||
/>
|
Object {
|
||||||
</ForwardRef(Avatar)>
|
"colorDefault": "MuiAvatar-colorDefault",
|
||||||
</WithStyles(ForwardRef(Avatar))>
|
"img": "MuiAvatar-img",
|
||||||
|
"root": "MuiAvatar-root",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
aria-label="mgol"
|
||||||
|
className="MuiAvatar-root MuiAvatar-colorDefault"
|
||||||
|
/>
|
||||||
|
</ForwardRef(Avatar)>
|
||||||
|
</WithStyles(ForwardRef(Avatar))>
|
||||||
|
</ForwardRef(Avatar)>
|
||||||
</a>
|
</a>
|
||||||
<ForwardRef(Popper)
|
<ForwardRef(Popper)
|
||||||
anchorEl={
|
anchorEl={
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
import React, { Component, ReactElement } from 'react';
|
import React, { Component, ReactElement } from 'react';
|
||||||
|
|
||||||
import Avatar from '@material-ui/core/Avatar';
|
|
||||||
import Grid from '@material-ui/core/Grid';
|
import Grid from '@material-ui/core/Grid';
|
||||||
import List from '@material-ui/core/List';
|
import List from '@material-ui/core/List';
|
||||||
import ListItemText from '@material-ui/core/ListItemText';
|
import ListItemText from '@material-ui/core/ListItemText';
|
||||||
|
|
||||||
import { VersionPageConsumerProps, DetailContextConsumer } from '../../pages/Version';
|
import { VersionPageConsumerProps, DetailContextConsumer } from '../../pages/Version';
|
||||||
import { Heading, EngineListItem } from './styles';
|
import { Heading, EngineListItem } from './styles';
|
||||||
|
|
||||||
|
import Avatar from '../../muiComponents/Avatar';
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import node from './img/node.png';
|
import node from './img/node.png';
|
||||||
import npm from '../Install/img/npm.svg';
|
import npm from '../Install/img/npm.svg';
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import styled from 'react-emotion';
|
import styled from 'react-emotion';
|
||||||
import Avatar from '@material-ui/core/Avatar';
|
|
||||||
import ListItem from '@material-ui/core/ListItem';
|
import ListItem from '@material-ui/core/ListItem';
|
||||||
import ListItemText from '@material-ui/core/ListItemText';
|
import ListItemText from '@material-ui/core/ListItemText';
|
||||||
|
|
||||||
import CopyToClipBoard from '../CopyToClipBoard';
|
import CopyToClipBoard from '../CopyToClipBoard';
|
||||||
|
import Avatar from '../../muiComponents/Avatar';
|
||||||
|
|
||||||
// logos of package managers
|
// logos of package managers
|
||||||
import npmLogo from './img/npm.svg';
|
import npmLogo from './img/npm.svg';
|
||||||
|
@ -4,7 +4,6 @@ import { Link } from 'react-router-dom';
|
|||||||
import Grid from '@material-ui/core/Grid';
|
import Grid from '@material-ui/core/Grid';
|
||||||
import List from '@material-ui/core/List';
|
import List from '@material-ui/core/List';
|
||||||
import ListItemText from '@material-ui/core/ListItemText';
|
import ListItemText from '@material-ui/core/ListItemText';
|
||||||
import Photo from '@material-ui/core/Avatar';
|
|
||||||
import Typography from '@material-ui/core/Typography';
|
import Typography from '@material-ui/core/Typography';
|
||||||
|
|
||||||
import { breakpoints } from '../../utils/styles/media';
|
import { breakpoints } from '../../utils/styles/media';
|
||||||
@ -13,6 +12,7 @@ import Label from '../Label';
|
|||||||
import colors from '../../utils/styles/colors';
|
import colors from '../../utils/styles/colors';
|
||||||
import { fontWeight } from '../../utils/styles/sizes';
|
import { fontWeight } from '../../utils/styles/sizes';
|
||||||
import { default as MuiIconButton } from '../../muiComponents/IconButton';
|
import { default as MuiIconButton } from '../../muiComponents/IconButton';
|
||||||
|
import { default as Photo } from '../../muiComponents/Avatar';
|
||||||
|
|
||||||
export const OverviewItem = styled('span')`
|
export const OverviewItem = styled('span')`
|
||||||
&& {
|
&& {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
/* eslint react/jsx-max-depth: 0 */
|
/* eslint react/jsx-max-depth: 0 */
|
||||||
|
|
||||||
import React, { Component, Fragment, ReactElement } from 'react';
|
import React, { Component, Fragment, ReactElement } from 'react';
|
||||||
import Avatar from '@material-ui/core/Avatar';
|
|
||||||
import List from '@material-ui/core/List';
|
import List from '@material-ui/core/List';
|
||||||
|
|
||||||
import { DetailContextConsumer } from '../../pages/Version';
|
import { DetailContextConsumer } from '../../pages/Version';
|
||||||
@ -12,6 +11,8 @@ import { Heading, GithubLink, RepositoryListItem, RepositoryListItemText } from
|
|||||||
import git from './img/git.png';
|
import git from './img/git.png';
|
||||||
import { isURL } from '../../utils/url';
|
import { isURL } from '../../utils/url';
|
||||||
|
|
||||||
|
import Avatar from '../../muiComponents/Avatar';
|
||||||
|
|
||||||
class Repository extends Component {
|
class Repository extends Component {
|
||||||
public render(): ReactElement<HTMLElement> {
|
public render(): ReactElement<HTMLElement> {
|
||||||
return (
|
return (
|
||||||
|
13
src/muiComponents/Avatar/Avatar.tsx
Normal file
13
src/muiComponents/Avatar/Avatar.tsx
Normal file
@ -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
src/muiComponents/Avatar/index.ts
Normal file
1
src/muiComponents/Avatar/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export { default } from './Avatar';
|
@ -1,12 +1,12 @@
|
|||||||
import React, { forwardRef } from 'react';
|
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'];
|
type IconButtonRef = HTMLElementTagNameMap['button'];
|
||||||
|
|
||||||
/* eslint-disable verdaccio/jsx-spread */
|
/* eslint-disable verdaccio/jsx-spread */
|
||||||
// eslint-disable-next-line react/display-name
|
// eslint-disable-next-line react/display-name
|
||||||
const IconButton = forwardRef<IconButtonRef, IconButtonProps>(function IconButton(props, ref) {
|
const IconButton = forwardRef<IconButtonRef, IconButtonProps>(function IconButton(props, ref) {
|
||||||
return <MuiIconButton {...props} ref={ref} />;
|
return <MaterialUIIconButton {...props} ref={ref} />;
|
||||||
});
|
});
|
||||||
|
|
||||||
export default IconButton;
|
export default IconButton;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React, { forwardRef } from 'react';
|
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'
|
// The default element type of MUI's TextField is 'div'
|
||||||
type TextFieldRef = HTMLElementTagNameMap['div'];
|
type TextFieldRef = HTMLElementTagNameMap['div'];
|
||||||
@ -8,7 +8,7 @@ type TextFieldRef = HTMLElementTagNameMap['div'];
|
|||||||
// eslint-disable-next-line react/display-name
|
// eslint-disable-next-line react/display-name
|
||||||
const TextField = forwardRef<TextFieldRef, TextFieldProps>(function ToolTip({ InputProps, classes, ...props }, ref) {
|
const TextField = forwardRef<TextFieldRef, TextFieldProps>(function ToolTip({ InputProps, classes, ...props }, ref) {
|
||||||
return (
|
return (
|
||||||
<TextFieldMaterialUI
|
<MaterialUITextField
|
||||||
{...props}
|
{...props}
|
||||||
InputProps={{
|
InputProps={{
|
||||||
...InputProps,
|
...InputProps,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React, { forwardRef } from 'react';
|
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
|
// The default element type of MUI's Tooltip is 'div' and the change of this prop is not allowed
|
||||||
type TooltipRef = HTMLElementTagNameMap['div'];
|
type TooltipRef = HTMLElementTagNameMap['div'];
|
||||||
@ -7,7 +7,7 @@ type TooltipRef = HTMLElementTagNameMap['div'];
|
|||||||
/* eslint-disable verdaccio/jsx-spread */
|
/* eslint-disable verdaccio/jsx-spread */
|
||||||
// eslint-disable-next-line react/display-name
|
// eslint-disable-next-line react/display-name
|
||||||
const Tooltip = forwardRef<TooltipRef, TooltipProps>(function ToolTip(props, ref) {
|
const Tooltip = forwardRef<TooltipRef, TooltipProps>(function ToolTip(props, ref) {
|
||||||
return <MuiTooltip {...props} innerRef={ref} />;
|
return <MaterialUITooltip {...props} innerRef={ref} />;
|
||||||
});
|
});
|
||||||
|
|
||||||
export default Tooltip;
|
export default Tooltip;
|
||||||
|
@ -10,7 +10,7 @@ import { waitForElement } from '@testing-library/dom';
|
|||||||
import ErrorBoundary from '../../App/AppError';
|
import ErrorBoundary from '../../App/AppError';
|
||||||
|
|
||||||
// :-) we mock this otherways fails on render, some weird issue on material-ui
|
// :-) 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
|
// eslint-disable-next-line react/display-name
|
||||||
jest.mock('../../components/NotFound', () => () => <div>{'Not found'}</div>);
|
jest.mock('../../components/NotFound', () => () => <div>{'Not found'}</div>);
|
||||||
|
Loading…
Reference in New Issue
Block a user