diff --git a/client/common/Button.jsx b/client/common/Button.jsx index f789b660..20bd9c25 100644 --- a/client/common/Button.jsx +++ b/client/common/Button.jsx @@ -150,8 +150,10 @@ const StyledIconButton = styled.button` * A Button performs an primary action */ const Button = ({ - children, href, kind, 'aria-label': ariaLabel, to, type, ...props + children, href, kind, iconBefore, iconAfter, 'aria-label': ariaLabel, to, type, ...props }) => { + const hasChildren = React.Children.count(children) > 0; + const content = <>{iconBefore}{hasChildren && {children}}{iconAfter}; let StyledComponent = StyledButton; if (kind === kinds.inline) { @@ -161,19 +163,31 @@ const Button = ({ } if (href) { - return {children}; + return ( + + {content} + + ); } if (to) { - return {children}; + return {content}; } - return {children}; + return {content}; }; Button.defaultProps = { 'children': null, 'disabled': false, + 'iconAfter': null, + 'iconBefore': null, 'kind': kinds.block, 'href': null, 'aria-label': null, @@ -193,6 +207,14 @@ Button.propTypes = { If the button can be activated or not */ 'disabled': PropTypes.bool, + /** + * SVG icon to place after child content + */ + 'iconAfter': PropTypes.element, + /** + * SVG icon to place before child content + */ + 'iconBefore': PropTypes.element, /** * The kind of button - determines how it appears visually */ diff --git a/client/common/Button.stories.jsx b/client/common/Button.stories.jsx index 9b6ab3b3..745ccdcf 100644 --- a/client/common/Button.stories.jsx +++ b/client/common/Button.stories.jsx @@ -3,9 +3,7 @@ import { action } from '@storybook/addon-actions'; import { boolean, text } from '@storybook/addon-knobs'; import Button from './Button'; -import Icons from './Icons'; - -const { Github, DropdownArrow, Plus } = Icons; +import { GithubIcon, DropdownArrowIcon, PlusIcon } from './Icons'; export default { title: 'Common/Button', @@ -39,28 +37,34 @@ export const ReactRouterLink = () => ( ); export const ButtonWithIconBefore = () => ( - ); export const ButtonWithIconAfter = () => ( - ); export const InlineButtonWithIconAfter = () => ( - ); export const InlineIconOnlyButton = () => ( - + diff --git a/client/modules/User/components/Collection.jsx b/client/modules/User/components/Collection.jsx index 60e54e0b..3f3949d7 100644 --- a/client/modules/User/components/Collection.jsx +++ b/client/modules/User/components/Collection.jsx @@ -8,7 +8,7 @@ import { bindActionCreators } from 'redux'; import classNames from 'classnames'; import Button from '../../../common/Button'; -import Icons from '../../../common/Icons'; +import { DropdownArrowIcon } from '../../../common/Icons'; import * as ProjectActions from '../../IDE/actions/project'; import * as ProjectsActions from '../../IDE/actions/projects'; import * as CollectionsActions from '../../IDE/actions/collections'; @@ -54,9 +54,9 @@ const ShareURL = ({ value }) => {
{ showURL &&
diff --git a/client/modules/User/components/SocialAuthButton.jsx b/client/modules/User/components/SocialAuthButton.jsx index 95f8e2b2..59c545a6 100644 --- a/client/modules/User/components/SocialAuthButton.jsx +++ b/client/modules/User/components/SocialAuthButton.jsx @@ -4,7 +4,7 @@ import styled from 'styled-components'; import { remSize } from '../../../theme'; -import Icons from '../../../common/Icons'; +import { GithubIcon, GoogleIcon } from '../../../common/Icons'; import Button from '../../../common/Button'; const authUrls = { @@ -18,8 +18,8 @@ const labels = { }; const icons = { - github: Icons.Github, - google: Icons.Google + github: GithubIcon, + google: GoogleIcon }; const services = { @@ -35,10 +35,10 @@ function SocialAuthButton({ service }) { const ServiceIcon = icons[service]; return ( } href={authUrls[service]} > - - {labels[service]} + {labels[service]} ); }