Skip to content

Commit

Permalink
fix(Button): Fix button align-prop not working
Browse files Browse the repository at this point in the history
The align prop of Button did not work, because it gave the margin to
the buttonwrapper, which was itself wrapped with withRipple HOC. This
was fixed by handling the align prop in the rippleprovider. This has the
positive side effect of allowing alignment of any withRipple components.
  • Loading branch information
Ilari Sinkkonen committed Jun 8, 2017
1 parent 7424913 commit 17f9cc7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
8 changes: 0 additions & 8 deletions src/components/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,12 @@ function getColor(props) {
return colorGetter(props, 'primaryColor'); // default
}

function getAlignement(props) {
if (props.align === 'center') return '0px auto';
if (props.align === 'right') return '0px 0px 0px auto';
if (props.align === 'left') return '0px auto 0px 0px';
return '0px';
}

const ButtonWrapper = styled.button`
outline: none;
font-size: 1rem;
padding: 8px 16px;
font-weight: normal;
width: ${props => props.w || 'auto'};
margin: ${props => getAlignement(props)};
text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
border-style: solid;
border-width: ${props => props.outline && !props.clear ? '1px' : '0px'};
Expand Down
11 changes: 10 additions & 1 deletion src/components/withRipple.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import React, { Component } from 'react';
import styled from 'styled-components';

function getAlignement(props) {
if (props.align === 'center') return '0px auto';
if (props.align === 'right') return '0px 0px 0px auto';
if (props.align === 'left') return '0px auto 0px 0px';
return '0px';
}

const RippleWrapper = styled.div`
position: relative;
overflow: hidden;
transform: translate3d(0, 0, 0);
display: inline-block;
align-self: flex-start;
margin: ${props => getAlignement(props)};
&:after {
content: "";
Expand All @@ -32,12 +40,13 @@ const RippleWrapper = styled.div`
}
`;


/* eslint-disable react/prefer-stateless-function */
const withRipple = (Comp) => {
return class RippleProvider extends Component {
render() {
return (
<RippleWrapper>
<RippleWrapper align={this.props.align}>
<Comp {...this.props} />
</RippleWrapper>
);
Expand Down

0 comments on commit 17f9cc7

Please sign in to comment.