Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FeaturedBadge: Move styled outside of the render function #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions src/FeaturedBadge.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,42 @@ import PropTypes from "prop-types";
import styled from "styled-components";
import featuredLogos from "./assets/featuredLogos";

const StyledLogo = styled(({ tagName, isHoverable, ...props }) => {
const Component = tagName || "svg";
// Do not forward `isHoverable` to DOM
// This method can be replaced with `styled.svg.withConfig({ shouldForwardProp: ... })`
// with [email protected]
return <Component {...props} />;
})`
${(props) =>
props.isHoverable &&
`
.inner-ring,
.outer-ring {
transition: 0.3s;
}

&:hover .inner-ring {
opacity: 0.3;
}

&:hover .outer-ring {
opacity: 0.6;
}
`}
`;

const FeaturedBadge = ({ name, className, isHoverable }) => {
const Logo = featuredLogos[name.toLowerCase()];
if (!Logo) return null;
const StyledLogo = styled(({ isHoverable, ...rest }) => <Logo {...rest} />)`
${({ isHoverable }) =>
isHoverable &&
`
.inner-ring,
.outer-ring {
transition: 0.3s;
}

&:hover .inner-ring {
opacity: 0.3;
}

&:hover .outer-ring {
opacity: 0.6;
}`}
`;
return <StyledLogo className={className} isHoverable={isHoverable} />;
return (
<StyledLogo
tagName={Logo}
className={className}
isHoverable={isHoverable}
/>
);
};

FeaturedBadge.propTypes = {
Expand Down