Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

fix(Pill): fix ConditionalFlexWrapper margin, noissue #156

Merged
merged 4 commits into from
Sep 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions src/Pill/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,18 @@ const SideButton = styled(Button).withConfig({
: getBackgroundShade(p.theme)};
`;

function ConditionalFlexWrapper({wrap, children}) {
function ConditionalFlexWrapper({wrap, children, ...otherProps}) {
if (!wrap) {
return children;
}

return (
<Box display="inline-flex" alignItems="center" maxWidth="100%">
<Box
{...otherProps}
display="inline-flex"
alignItems="center"
maxWidth="100%"
>
{children}
</Box>
);
Expand All @@ -237,6 +242,21 @@ function defaultIconRenderer({iconName, iconColor}) {
);
}

function splitMarginProps(props) {
const marginProps = {};
const filteredProps = {};

for (const propName in props) {
if (marginPropNames.includes(propName)) {
marginProps[propName] = props[propName];
} else {
filteredProps[propName] = props[propName];
}
}

return {marginProps, filteredProps};
}

const Pill = forwardRef((props, ref) => {
const {
as,
Expand Down Expand Up @@ -270,10 +290,12 @@ const Pill = forwardRef((props, ref) => {
);
}

const {marginProps, filteredProps} = splitMarginProps(otherProps);

return (
<ConditionalFlexWrapper wrap={hasSideButton}>
<ConditionalFlexWrapper wrap={hasSideButton} {...marginProps}>
<Wrapper
{...otherProps}
{...(hasSideButton ? filteredProps : otherProps)}
ref={ref}
as={isClickable ? ButtonCore : as}
forwardedAs={isClickable ? as : forwardedAs}
Expand Down