Skip to content

Instantly share code, notes, and snippets.

@michaelneu
Last active January 9, 2019 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelneu/ac42a7b405ab7f78087fd21fb71fd329 to your computer and use it in GitHub Desktop.
Save michaelneu/ac42a7b405ab7f78087fd21fb71fd329 to your computer and use it in GitHub Desktop.
Color context sensitive styled-components HoC
import styled from "styled-components";
export const withButtonStyle = (component) => styled(component)`
position: relative;
display: block;
width: 100%;
padding: 0.5rem 2rem;
color: currentColor;
background-color: transparent;
border: none;
border-radius: 5px;
overflow: hidden;
text-transform: uppercase;
font-weight: bold;
cursor: pointer;
transition-property: background-color, color;
transition-duration: 0.2s;
z-index: 1;
&::before,
&::after {
content: " ";
display: block;
position: absolute;
top: 0rem;
left: 0rem;
right: 0rem;
bottom: 0rem;
}
&::before {
background-color: white;
z-index: -1;
transition-property: background-color;
transition-duration: 0.2s;
}
&::after {
border: 2px solid currentColor;
border-radius: 5px;
}
&:hover {
&::before {
background-color: currentColor;
}
-webkit-text-fill-color: white;
-webkit-background-clip: text;
background-clip: text;
color: currentColor;
border-color: currentColor;
}
`;
import React from "react";
import { withButtonStyle } from "button.js"
const Button = (text) => (
<button style={{ color: black; }}>{text}</button>
);
export default withButtonStyle(Button);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment