Skip to content

Instantly share code, notes, and snippets.

@Archakov06
Last active January 18, 2018 12:39
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 Archakov06/4d242e12c49e3d61ba78b5687dcf3de7 to your computer and use it in GitHub Desktop.
Save Archakov06/4d242e12c49e3d61ba78b5687dcf3de7 to your computer and use it in GitHub Desktop.
Button.js
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import PlusIcon from 'react-icons/lib/fa/plus';
import CheckIcon from 'react-icons/lib/fa/check';
import { COLORS } from '../constants/styles';
const StyledButton = styled.button`
display: flex;
align-items: center;
padding: 10px 20px;
border: 1px solid transparent;
background-color: transparent;
text-align: center;
border-radius: 30px;
cursor: pointer;
${({ fluid }) =>
fluid &&
`
width: 100%;
`};
${({ color }) => `
color: ${COLORS[color.toUpperCase()]};
border-color: ${COLORS[color.toUpperCase()]};
`};
&:hover {
${({ color }) => `
background-color: ${COLORS[color.toUpperCase()]};
color: #fff !important;
border-color: ${COLORS[color.toUpperCase()]};
`};
svg path {
${({ color }) => `
fill: #fff;
`};
}
}
svg {
margin-right: 7px;
path {
${({ color }) => `
fill: ${COLORS[color.toUpperCase()]};
`};
}
}
`;
const Button = ({ label, color, icon }) => (
<StyledButton color={color}>
{icon === 'plus' && <PlusIcon size="17" name="plus" />}
{icon === 'check' && <CheckIcon size="17" name="check" />}
{label}
</StyledButton>
);
Button.propTypes = {
label: PropTypes.string.isRequired,
icon: PropTypes.string,
color: PropTypes.string,
};
Button.defaultProps = {
icon: '',
color: 'blue',
};
export default Button;
// App.js
<Button fluid color="red" {...props}>Hello, World!</Button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment