Skip to content

Commit

Permalink
refactor(*): apply remainingProps to components
Browse files Browse the repository at this point in the history
  • Loading branch information
topheman committed Apr 24, 2018
1 parent 0fd99c7 commit 9a602d7
Show file tree
Hide file tree
Showing 28 changed files with 164 additions and 118 deletions.
16 changes: 6 additions & 10 deletions src/components/CodeBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ class CodeBlock extends PureComponent {
highlightBlock(this.codeEl);
}
render() {
const { className, style } = this.props;
const { value, language } = this.props;
return (
<pre className={className} style={style}>
<pre {...this.props}>
<code
ref={ref => {
this.codeEl = ref;
}}
className={`language-${this.props.language}`}
className={`language-${language}`}
>
{this.props.value}
{value}
</code>
</pre>
);
Expand All @@ -33,14 +33,10 @@ class CodeBlock extends PureComponent {

CodeBlock.propTypes = {
value: PropTypes.string.isRequired,
language: PropTypes.string,
className: PropTypes.string,
style: PropTypes.object
language: PropTypes.string
};
CodeBlock.defaultProps = {
language: "",
className: undefined,
style: undefined
language: ""
};

export default CodeBlock;
16 changes: 10 additions & 6 deletions src/components/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ const styles = {
}
};

const Footer = ({ classes, fromFullYear, toFullYear, className, style }) => (
<footer className={classNames(classes.root, className)} style={style}>
const Footer = ({
classes,
fromFullYear,
toFullYear,
className,
...remainingProps
}) => (
<footer className={classNames(classes.root, className)} {...remainingProps}>
<p>
©{fromFullYear === toFullYear
? toFullYear
Expand Down Expand Up @@ -45,13 +51,11 @@ Footer.propTypes = {
toFullYear: PropTypes.number,
fromFullYear: PropTypes.number.isRequired,
classes: PropTypes.object.isRequired,
className: PropTypes.string,
style: PropTypes.object
className: PropTypes.string
};
Footer.defaultProps = {
toFullYear: new Date().getFullYear(),
className: undefined,
style: undefined
className: undefined
};

export default withStyles(styles)(Footer);
4 changes: 2 additions & 2 deletions src/components/Gravatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import Avatar from "material-ui/Avatar";

import md5 from "js-md5";

const Gravatar = ({ email, size, ...props }) => (
const Gravatar = ({ email, size, ...remainingProps }) => (
<Avatar
src={`https://s.gravatar.com/avatar/${md5(email)}${
size ? `?s=${size}` : ""
}`}
alt="avatar"
{...props}
{...remainingProps}
/>
);

Expand Down
13 changes: 11 additions & 2 deletions src/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,19 @@ const styles = theme => ({
});

const Header = props => {
const { classes, drawerOpen, toggleDrawer, className, style } = props;
const {
classes,
drawerOpen,
toggleDrawer,
className,
...remainingProps
} = props;
return (
<Fragment>
<header className={classNames(classes.root, className)} style={style}>
<header
className={classNames(classes.root, className)}
{...remainingProps}
>
<AppBar position="absolute">
<Toolbar>
<IconButton
Expand Down
10 changes: 4 additions & 6 deletions src/components/KeywordsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ const styles = {
}
};

const KeywordsList = ({ keywords, classes, className, style }) => {
const KeywordsList = ({ keywords, classes, className, ...remainingProps }) => {
if (keywords && keywords.length > 0) {
return (
<div className={classNames(classes.root, className)} style={style}>
<div className={classNames(classes.root, className)} {...remainingProps}>
<LocalOfferIcon />
{keywords.map((keyword, index) => (
<Link
Expand All @@ -60,14 +60,12 @@ const KeywordsList = ({ keywords, classes, className, style }) => {
KeywordsList.propTypes = {
classes: PropTypes.object.isRequired,
keywords: PropTypes.array,
className: PropTypes.string,
style: PropTypes.object
className: PropTypes.string
};

KeywordsList.defaultProps = {
keywords: [],
className: undefined,
style: undefined
className: undefined
};

export default withStyles(styles)(KeywordsList);
4 changes: 2 additions & 2 deletions src/components/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ CustomLoader.defaultProps = {
message: "Loading"
};

const Loader = ({ message, classes, overrideClasses, ...props }) => {
const Loader = ({ message, classes, overrideClasses, ...remainingProps }) => {
const loaderClasses = {
...classes,
...overrideClasses
};
return (
<Waiting
loader={<CustomLoader message={message} classes={loaderClasses} />}
{...props}
{...remainingProps}
/>
);
};
Expand Down
9 changes: 7 additions & 2 deletions src/components/MainDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const styles = {
}
};

const MainDrawer = ({ classes, anchor, open, onClose }) => {
const MainDrawer = ({ classes, anchor, open, onClose, ...remainingProps }) => {
const sideList = (
<div
className={
Expand Down Expand Up @@ -85,7 +85,12 @@ const MainDrawer = ({ classes, anchor, open, onClose }) => {
);

return (
<MuiDrawer anchor={anchor} open={open} onClose={onClose}>
<MuiDrawer
anchor={anchor}
open={open}
onClose={onClose}
{...remainingProps}
>
<div
tabIndex={0}
role="button"
Expand Down
5 changes: 3 additions & 2 deletions src/components/Markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ LinkRenderer.defaultProps = {

/** Markdown component */

const Markdown = ({ repository, ...props }) => (
const Markdown = ({ repository, source, ...remainingProps }) => (
<ReactMarkdown
{...props}
source={source}
renderers={{
code: CodeBlock,
heading: HeadingRenderer,
Expand All @@ -127,6 +127,7 @@ const Markdown = ({ repository, ...props }) => (
escapeHtml={false}
transformLinkUri={makeTransformLinkUri({ repository })}
transformImageUri={makeTransformImageUri({ repository })}
{...remainingProps}
/>
);
Markdown.propTypes = {
Expand Down
13 changes: 3 additions & 10 deletions src/components/Package/DependenciesTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ const DependenciesTab = ({
version,
packageInfos,
classes,
className,
style
...remainingProps
}) => {
const dependencies =
(packageInfos &&
Expand Down Expand Up @@ -77,7 +76,7 @@ const DependenciesTab = ({
[`Peer Dependencies`]: peerDependencies
};
return (
<div className={className} style={style}>
<div {...remainingProps}>
<ExpansionPanel>
<ExpansionPanelSummary expandIcon={<ExpandMoreIcon />}>
<Typography>Dependencies ({dependencies.length})</Typography>
Expand Down Expand Up @@ -111,13 +110,7 @@ const DependenciesTab = ({
DependenciesTab.propTypes = {
version: PropTypes.string.isRequired,
packageInfos: PropTypes.object.isRequired,
classes: PropTypes.object.isRequired,
className: PropTypes.string,
style: PropTypes.object
};
DependenciesTab.defaultProps = {
className: undefined,
style: undefined
classes: PropTypes.object.isRequired
};

export default withStyles(styles)(DependenciesTab);
17 changes: 8 additions & 9 deletions src/components/Package/InfosContents.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ const styles = {
maintainers: {}
};

const InfosContent = ({ packageInfos, version, classes, className, style }) => {
const InfosContent = ({
packageInfos,
version,
classes,
...remainingProps
}) => {
const licenseInfos = extractLicenseInfos(packageInfos, version);
const homepage = extractUrl(
safeExtractVersion(packageInfos, version).homepage
Expand All @@ -47,7 +52,7 @@ const InfosContent = ({ packageInfos, version, classes, className, style }) => {
relativeDate(new Date(packageInfos.time[version]))) ||
undefined;
return (
<div className={className} style={style}>
<div {...remainingProps}>
{datePublishedRelative && (
<div>
<strong>v{version}</strong> published <i>{datePublishedRelative}</i>
Expand Down Expand Up @@ -106,13 +111,7 @@ const InfosContent = ({ packageInfos, version, classes, className, style }) => {
InfosContent.propTypes = {
packageInfos: PropTypes.object.isRequired,
version: PropTypes.string.isRequired,
classes: PropTypes.object.isRequired,
className: PropTypes.string,
style: PropTypes.object
};
InfosContent.defaultProps = {
className: undefined,
style: undefined
classes: PropTypes.object.isRequired
};

export default withStyles(styles)(InfosContent);
10 changes: 4 additions & 6 deletions src/components/Package/NotFound.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const styles = {
}
};

const NotFound = ({ classes, packageName, className, style }) => (
<div className={classNames(classes.root, className)} style={style}>
const NotFound = ({ classes, packageName, className, ...remainingProps }) => (
<div className={classNames(classes.root, className)} {...remainingProps}>
<h2>Not Found</h2>
<p>Package &quot;{packageName}&quot; not found</p>
<p>
Expand All @@ -30,12 +30,10 @@ const NotFound = ({ classes, packageName, className, style }) => (
NotFound.propTypes = {
packageName: PropTypes.string.isRequired,
classes: PropTypes.object.isRequired,
className: PropTypes.string,
style: PropTypes.object
className: PropTypes.string
};
NotFound.defaultProps = {
className: undefined,
style: undefined
className: undefined
};

export default withStyles(styles)(NotFound);
10 changes: 4 additions & 6 deletions src/components/Package/Package.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ const Package = ({
loadRegistryInfos,
classes,
className,
style
...remainingProps
}) => (
<section className={classNames(classes.root, className)} style={style}>
<section className={classNames(classes.root, className)} {...remainingProps}>
<header className={`${classes.blocks} ${classes.areaHeader}`}>
<Title
scope={scope}
Expand Down Expand Up @@ -242,16 +242,14 @@ Package.propTypes = {
loadApiInfos: PropTypes.func.isRequired,
loadRegistryInfos: PropTypes.func.isRequired,
classes: PropTypes.object.isRequired,
className: PropTypes.string,
style: PropTypes.object
className: PropTypes.string
};
Package.defaultProps = {
scope: undefined,
version: undefined,
packageInfos: undefined,
downloads: undefined,
className: undefined,
style: undefined
className: undefined
};

export default withStyles(styles)(Package);
10 changes: 4 additions & 6 deletions src/components/Package/PackageJsonTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const styles = theme => ({
}
});

const PackageJson = ({ value, classes, className, style }) => {
const PackageJson = ({ value, classes, className, ...remainingProps }) => {
const { version } = value;
const formattedValue = JSON.stringify(
value,
Expand All @@ -42,7 +42,7 @@ const PackageJson = ({ value, classes, className, style }) => {
" "
);
return (
<div className={classNames(classes.root, className)} style={style}>
<div className={classNames(classes.root, className)} {...remainingProps}>
<ExpansionPanel>
<ExpansionPanelSummary expandIcon={<ExpandMoreIcon />}>
<Typography className={classes.heading}>
Expand All @@ -63,12 +63,10 @@ const PackageJson = ({ value, classes, className, style }) => {
PackageJson.propTypes = {
value: PropTypes.object.isRequired,
classes: PropTypes.object.isRequired,
className: PropTypes.string,
style: PropTypes.object
className: PropTypes.string
};
PackageJson.defaultProps = {
className: undefined,
style: undefined
className: undefined
};

export default withStyles(styles)(PackageJson);
Loading

0 comments on commit 9a602d7

Please sign in to comment.