0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-20 22:52:46 -05:00

chore: fix copy object issue

Update CopyToClipBoard, if has children render that, otherwise the raw text
This commit is contained in:
Juan Picado @jotadeveloper 2019-02-17 21:14:39 +01:00
parent f981024d5f
commit 6ebebcb023
No known key found for this signature in database
GPG key ID: 18AC54485952D158
6 changed files with 20 additions and 88 deletions

View file

@ -14,7 +14,7 @@ import { ClipBoardCopy, ClipBoardCopyText, CopyIcon } from './styles';
import { copyToClipBoardUtility } from '../../utils/cli-utils';
import { TEXT } from '../../utils/constants';
const CopyToClipBoard = ({ text }: IProps): Node => {
const CopyToClipBoard = ({ text, children }: IProps): Node => {
const renderToolTipFileCopy = () => (
<Tooltip disableFocusListener={true} title={TEXT.CLIPBOARD_COPY}>
<CopyIcon onClick={copyToClipBoardUtility(text)}>
@ -22,9 +22,17 @@ const CopyToClipBoard = ({ text }: IProps): Node => {
</CopyIcon>
</Tooltip>
);
const renderText = children => {
if (children) {
return <ClipBoardCopyText>{children}</ClipBoardCopyText>;
}
return <ClipBoardCopyText>{text}</ClipBoardCopyText>;
};
return (
<ClipBoardCopy>
<ClipBoardCopyText>{text}</ClipBoardCopyText>
{renderText(children)}
{renderToolTipFileCopy()}
</ClipBoardCopy>
);

View file

@ -5,4 +5,5 @@
export interface IProps {
text: string;
children: any;
}

View file

@ -11,7 +11,6 @@ import Developers from '../Developers';
import Dist from '../Dist';
import Engine from '../Engines';
import Install from '../Install';
import License from '../License';
import Repository from '../Repository';
@ -42,7 +41,6 @@ class DetailSidebar extends Component {
{this.renderAuthor()}
{this.renderMaintainers()}
{this.renderContributors()}
{/* {this.renderLicense()} */}
</CardContent>
</Card>
</div>
@ -74,10 +72,6 @@ class DetailSidebar extends Component {
return <Developers type={'contributors'} />;
}
renderLicense = () => {
return <License />;
}
renderRepository = () => {
return <Repository />;
}

View file

@ -1,48 +0,0 @@
import React, {Component} from 'react';
import List from '@material-ui/core/List';
import ListItemText from '@material-ui/core/ListItemText';
import BookIcon from '@material-ui/icons/Book';
import { DetailContextConsumer } from '../../pages/version/index';
import { Heading, LicenseListItem, LicenseAvatar } from './styles';
class License extends Component {
render() {
return (
<DetailContextConsumer>
{(context) => {
return this.renderLicense(context);
}}
</DetailContextConsumer>
);
};
renderLicense = ({packageMeta}) => {
const { license } = packageMeta.latest;
if (!license) {
return null;
}
return (
<List subheader={<Heading variant={"subheading"}>{'License'}</Heading>}>
{this.renderListItems(license)}
</List>
);
}
renderListItems = (license) => {
return (
<LicenseListItem>
<LicenseAvatar>
<BookIcon />
</LicenseAvatar>
<ListItemText primary={license} />
</LicenseListItem>
);
}
}
export default License;

View file

@ -1,31 +0,0 @@
/**
* @prettier
* @flow
*/
import styled from 'react-emotion';
import Avatar from '@material-ui/core/Avatar/index';
import ListItem from '@material-ui/core/ListItem/index';
import Typography from '@material-ui/core/Typography/index';
import colors from '../../utils/styles/colors';
export const Heading = styled(Typography)`
&& {
font-weight: 700;
text-transform: capitalize;
}
`;
export const LicenseListItem = styled(ListItem)`
&& {
padding-left: 0;
}
`;
export const LicenseAvatar = styled(Avatar)`
&& {
color: ${colors.greySuperLight};
background-color: ${colors.primary};
}
`;

View file

@ -39,12 +39,20 @@ class Repository extends Component<any, any> {
<List dense={true} subheader={<Heading variant={"subheading"}>{'Repository'}</Heading>}>
<RepositoryListItem>
<Avatar src={git} />
<ListItemText primary={(<CopyToClipBoard text={this.renderRepositoryText(url)} />)} />
<ListItemText primary={this.renderContent(url)} />
</RepositoryListItem>
</List>
</>
);
}
renderContent(url) {
return (
<CopyToClipBoard text={url}>
{this.renderRepositoryText(url)}
</CopyToClipBoard>
);
}
}