Skip to content

Commit

Permalink
Merge pull request #73 from quid/fix/button-icon-spacing
Browse files Browse the repository at this point in the history
fix: properly space Icon when inside Button
  • Loading branch information
FezVrasta authored Apr 11, 2019
2 parents 6b02ae8 + b2bb849 commit c3ebc9b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 41 deletions.
15 changes: 15 additions & 0 deletions packages/react-core/src/Button/Button.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ import Icon from '../Icon';
</Button>
</td>
</tr>
<tr>
<td>Primary with both (alt)</td>
<td>
<Button importance="primary">
Button
<Icon name="download" />
</Button>
</td>
<td>
<Button importance="primary" disabled>
Button
<Icon name="download" />
</Button>
</td>
</tr>
<tr>
<td>Primary Small with both</td>
<td>
Expand Down
34 changes: 18 additions & 16 deletions packages/react-core/src/Button/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,8 @@ exports[`renders a Button with small size 1`] = `
.emotion-0 .e1t5eso00 {
display: block;
line-height: 1;
font-size: 1.42em;
margin-left: -6px;
margin-right: -6px;
margin-top: 5px;
margin-bottom: 5px;
font-size: 1em;
margin: 5px -6px;
}
<Button
Expand All @@ -80,7 +76,11 @@ exports[`renders a Button with small size 1`] = `
className="emotion-0 emotion-1"
type="button"
>
Hello, World!
<span
key=".0"
>
Hello, World!
</span>
</button>
</Button>
`;
Expand Down Expand Up @@ -158,10 +158,7 @@ exports[`renders a disabled and transparent Button 1`] = `
display: block;
line-height: 1;
font-size: 1.42em;
margin-left: -6px;
margin-right: -6px;
margin-top: 5px;
margin-bottom: 5px;
margin: 5px -6px;
}
<Button
Expand All @@ -176,7 +173,11 @@ exports[`renders a disabled and transparent Button 1`] = `
disabled={true}
type="button"
>
Hello, World!
<span
key=".0"
>
Hello, World!
</span>
</button>
</Button>
`;
Expand Down Expand Up @@ -245,10 +246,7 @@ exports[`renders the expected markup 1`] = `
display: block;
line-height: 1;
font-size: 1.42em;
margin-left: -6px;
margin-right: -6px;
margin-top: 5px;
margin-bottom: 5px;
margin: 5px -6px;
}
<Button
Expand All @@ -262,7 +260,11 @@ exports[`renders the expected markup 1`] = `
data-action="foo"
type="button"
>
Hello, World!
<span
key=".0"
>
Hello, World!
</span>
</button>
</Button>
`;
63 changes: 38 additions & 25 deletions packages/react-core/src/Button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const Button = styled(
importance,
disabled,
type,
children,
...props
}: Props) => {
let Tag, specificProps;
Expand All @@ -94,7 +95,17 @@ const Button = styled(
specificProps = { disabled, type };
}

return <Tag {...specificProps} {...props} />;
return (
<Tag {...specificProps} {...props}>
{React.Children.map(children, node =>
['string', 'number'].includes(typeof node) ? (
<span>{node}</span>
) : (
node
)
)}
</Tag>
);
}
)`
${reset};
Expand Down Expand Up @@ -162,31 +173,33 @@ const Button = styled(
`}
${Icon} {
display: block;
line-height: 1;
font-size: 1.42em;
margin-left: -6px;
margin-right: -6px;
margin-top: 5px;
margin-bottom: 5px;
${props =>
props.size === 'small' &&
css`
font-size: 1em;
`}
${props =>
React.Children.count(props.children) > 1 &&
css`
display: inline-block;
position: relative;
font-size: 1em;
margin-left: 0;
bottom: -1px;
margin-right: 0.35em;
`}
display: block;
line-height: 1;
font-size: ${props => (props.size === 'small' ? 1 : 1.42)}em;
margin: 5px -6px;
}
${props =>
React.Children.count(props.children) > 1 &&
css`
${Icon} {
display: inline-block;
position: relative;
font-size: 1em;
margin-left: 0;
bottom: -1px;
margin-left: 0.35em;
margin-right: 0;
&:first-child {
margin-right: 0.35em;
margin-left: 0;
}
&:last-child {
margin-left: 0.35em;
margin-right: 0;
}
}
`}
`;

Button.defaultProps = {
Expand Down

0 comments on commit c3ebc9b

Please sign in to comment.