Skip to content

Fix/chip right icon margin #2772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Oct 26, 2023
Merged
Changes from 7 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
35 changes: 19 additions & 16 deletions src/components/chip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,22 +255,25 @@ const Chip = ({
marginRight: Spacings.s1
};
}
if (rightElement && leftElement) {
return {
marginHorizontal: 2
};
}
if (iconSource || leftElement) {
return {
marginLeft: 2,
marginRight: Spacings.s3
};
}
if (rightIconSource || rightElement) {
return {
marginLeft: Spacings.s3,
marginRight: 2
};
if (iconSource || leftElement || rightIconSource || rightElement) {
const marginFromElement = Spacings.s1;
if ((iconSource || leftElement) && (rightIconSource || rightElement)) {
return {
marginHorizontal: marginFromElement
};
}
if (iconSource || leftElement) {
return {
marginLeft: marginFromElement,
marginRight: Spacings.s3
};
}
if (rightIconSource || rightElement) {
return {
marginLeft: Spacings.s3,
marginRight: marginFromElement
};
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A small suggestion for making this a little more readable
you can define two consts

const addLeftMargin = !!(iconSource || leftElement)
const addRightMargin = !!(rightIconSource || rightElement)

Then the conditions will much more readable. Also if there will new elements in either left or right we can simply add them to the const definition and that's it

Last, consider using ternary to make things a little shorter, for example

const marginStyle = {
  marginHorizontal: addLeftMargin && addLeftMargin ? Spacings.1 : 0,
 marginLeft: ...
 marginRight: ... 
}
``

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean
marginHorizontal: addLeftMargin && addRightMargin ? Spacings.s1 : 0?
About the last part. I don't really understand what you mean, If I use marginHorizontal and margin left or right in the same object marginHorizontal will always be overridden by the left and right margins. So I don't really know how to use them together in the same object.

if (onDismiss) {
return {
Expand Down