From c7fe08222a43b36afc9c4eb277f203292228d493 Mon Sep 17 00:00:00 2001 From: Jimmy Somsanith Date: Fri, 28 Jun 2019 00:24:58 +0200 Subject: [PATCH 1/5] feat: ButtonWrapper prop in Button to customise rendering --- src/components/Button.js | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/components/Button.js b/src/components/Button.js index edd093d8..4719096e 100644 --- a/src/components/Button.js +++ b/src/components/Button.js @@ -32,7 +32,7 @@ const SIZES = { MEDIUM: 'medium', }; -const ButtonWrapper = styled.button` +const StyledButton = styled.button` border: 0; border-radius: 3em; cursor: pointer; @@ -305,9 +305,17 @@ const ButtonWrapper = styled.button` `; -const ButtonLink = ButtonWrapper.withComponent('a'); - -export function Button({ isDisabled, isLoading, loadingText, isLink, children, ...props }) { +const ButtonLink = StyledButton.withComponent('a'); + +export function Button({ + isDisabled, + isLoading, + loadingText, + isLink, + children, + ButtonWrapper, + ...props +}) { const buttonInner = ( {children} @@ -315,17 +323,18 @@ export function Button({ isDisabled, isLoading, loadingText, isLink, children, . ); - if (isLink) { - return ( - - {buttonInner} - - ); + let SelectedButton = StyledButton; + if (ButtonWrapper) { + const StyledButtonWrapper = StyledButton.withComponent(ButtonWrapper); + SelectedButton = StyledButtonWrapper; + } else if (isLink) { + SelectedButton = ButtonLink; } + return ( - + {buttonInner} - + ); } @@ -351,6 +360,7 @@ Button.propTypes = { */ containsIcon: PropTypes.bool, size: PropTypes.oneOf(Object.values(SIZES)), + ButtonWrapper: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), }; Button.defaultProps = { @@ -362,4 +372,5 @@ Button.defaultProps = { isUnclickable: false, containsIcon: false, size: SIZES.MEDIUM, + ButtonWrapper: undefined, }; From a20100e32014274d3316bb208517ea992793cf1f Mon Sep 17 00:00:00 2001 From: Jimmy Somsanith Date: Fri, 28 Jun 2019 11:29:35 +0200 Subject: [PATCH 2/5] Add wrapper in Button stories --- src/components/Button.stories.js | 231 +++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) diff --git a/src/components/Button.stories.js b/src/components/Button.stories.js index e87220c9..1c3d4588 100644 --- a/src/components/Button.stories.js +++ b/src/components/Button.stories.js @@ -1,8 +1,30 @@ import React from 'react'; import { storiesOf } from '@storybook/react'; +import styled from 'styled-components'; +import { action } from '@storybook/addon-actions'; + import { Button } from './Button'; import { Icon } from './Icon'; +const CustomButton = styled.button` + border: 1px solid green; + background: lightgreen; + color: rebeccapurple; + padding: 1.5em; + font-size: 1.5em; +`; + +const CustomAnchor = styled.a` + border: 1px solid green; + background: lightgreen; + color: rebeccapurple; + font-size: 1.5em; +`; + +function ButtonWrapper(props) { + return ; +} + storiesOf('Design System|Button', module) .addParameters({ component: Button }) .add('all buttons', () => ( @@ -56,4 +78,213 @@ storiesOf('Design System|Button', module) Link + )) + .add('button wrapper', () => ( +
+ Original Button Wrapper +
+ + + + + + + +
+ + + + + +
+ + + + + + + +
+ )) + + .add('anchor wrapper', () => ( +
+ Original Anchor Wrapper +
+ + + + + + + +
+ + + + + +
+ + + + + + + +
)); From 4379c882d793b3013b293e69ddc46fbb4d7dbb7d Mon Sep 17 00:00:00 2001 From: Kyle Suss Date: Fri, 28 Jun 2019 09:20:22 -0600 Subject: [PATCH 3/5] refactor: use StoryLinkWrapper for ButtonWrapper link implementation --- src/components/Button.stories.js | 52 ++++++++++++++---------------- src/components/StoryLinkWrapper.js | 4 +-- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/components/Button.stories.js b/src/components/Button.stories.js index 1c3d4588..7625ae24 100644 --- a/src/components/Button.stories.js +++ b/src/components/Button.stories.js @@ -5,6 +5,7 @@ import { action } from '@storybook/addon-actions'; import { Button } from './Button'; import { Icon } from './Icon'; +import { StoryLinkWrapper } from './StoryLinkWrapper'; const CustomButton = styled.button` border: 1px solid green; @@ -14,13 +15,6 @@ const CustomButton = styled.button` font-size: 1.5em; `; -const CustomAnchor = styled.a` - border: 1px solid green; - background: lightgreen; - color: rebeccapurple; - font-size: 1.5em; -`; - function ButtonWrapper(props) { return ; } @@ -148,36 +142,38 @@ storiesOf('Design System|Button', module) .add('anchor wrapper', () => (
- Original Anchor Wrapper -
- - - - From 75a6d3d2ea0956bffef78ec7e9e7104bc8d88ac9 Mon Sep 17 00:00:00 2001 From: Jimmy Somsanith Date: Fri, 28 Jun 2019 22:58:43 +0200 Subject: [PATCH 5/5] Remove unnecessary if --- src/components/Button.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/components/Button.js b/src/components/Button.js index 859ac9d5..1c68d13c 100644 --- a/src/components/Button.js +++ b/src/components/Button.js @@ -308,10 +308,6 @@ const StyledButton = styled.button` const ButtonLink = StyledButton.withComponent('a'); const applyStyle = ButtonWrapper => { - if (!ButtonWrapper) { - return null; - } - return ( ButtonWrapper && StyledButton.withComponent(({ containsIcon, isLoading, isUnclickable, ...rest }) => (