Skip to content

Commit

Permalink
feat(button): add prop support for Button icons
Browse files Browse the repository at this point in the history
Add left icon props and right icon props props to allow easy override of their values

ref Headstorm#330
  • Loading branch information
PatrickDeVries committed Oct 27, 2021
1 parent 30191c5 commit 490705a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ BasicButton.args = {
iconSuffix: 'none',
children: 'Default text',
StyledRightIconContainer: StyledIconContainer,
leftIconProps: { size: '1rem' },
rightIconProps: { size: '1rem' },
};

const iconOptions = {
Expand Down
9 changes: 6 additions & 3 deletions src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export type ButtonProps = {

containerProps?: SubcomponentPropsType;
interactionFeedbackProps?: Omit<InteractionFeedbackProps, 'children'>;
leftIconProps?: SubcomponentPropsType;
rightIconProps?: SubcomponentPropsType;

children?: ReactNode;

Expand Down Expand Up @@ -135,7 +137,6 @@ export const ButtonContainer: string & StyledComponentBase<any, {}, ButtonContai
`;

const IconContainer = styled(Div)`
height: 1rem;
vertical-align: middle;
`;

Expand Down Expand Up @@ -176,6 +177,8 @@ const Button = ({

containerProps = {},
interactionFeedbackProps,
leftIconProps = {},
rightIconProps = {},

containerRef,
leftIconContainerRef,
Expand Down Expand Up @@ -230,7 +233,7 @@ const Button = ({
iconPrefix &&
(typeof iconPrefix === 'string' && iconPrefix !== '' ? (
<StyledLeftIconContainer hasContent={hasContent} ref={leftIconContainerRef}>
<UnstyledIcon path={iconPrefix} size="1rem" />
<UnstyledIcon path={iconPrefix} size="1rem" {...leftIconProps} />
</StyledLeftIconContainer>
) : (
<StyledLeftIconContainer ref={leftIconContainerRef}>{iconPrefix}</StyledLeftIconContainer>
Expand All @@ -244,7 +247,7 @@ const Button = ({
{iconSuffix &&
(typeof iconSuffix === 'string' ? (
<StyledRightIconContainer hasContent={hasContent} ref={rightIconContainerRef}>
<UnstyledIcon path={iconSuffix} size="1rem" />
<UnstyledIcon path={iconSuffix} size="1rem" {...rightIconProps} />
</StyledRightIconContainer>
) : (
<StyledRightIconContainer hasContent={hasContent} ref={rightIconContainerRef}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,6 @@ exports[`Button shows LeftIconContainer when isProcessing 1`] = `
}
.c2 {
height: 1rem;
vertical-align: middle;
}
Expand Down Expand Up @@ -915,7 +914,6 @@ exports[`Button shows icons 1`] = `
}
.c2 {
height: 1rem;
vertical-align: middle;
}
Expand Down Expand Up @@ -1063,7 +1061,6 @@ exports[`Button shows icons with type string 1`] = `
}
.c2 {
height: 1rem;
vertical-align: middle;
}
Expand Down

0 comments on commit 490705a

Please sign in to comment.