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

Fix/chip right icon margin #2772

merged 12 commits into from
Oct 26, 2023

Conversation

nitzanyiz
Copy link
Collaborator

Description

Added horizontal margins to the right icon in the chip component. The icon was really close to the label when rendering the icon without setting margins manually.

Changelog

Chip - Added default horizontal margins to right icon.

Additional info

WOAUILIB-3772

@nitzanyiz
Copy link
Collaborator Author

Created this pull request so we can review if the margins are good enough.
@ethanshar

Comment on lines 296 to 300
if (label || leftElement || rightElement) {
return {
marginLeft: Spacings.s1,
marginRight: Spacings.s2
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

overall It looks much better.
But I think it mostly solve the right icon
notice that the use can either pass rightIconSource or iconSource (rendered on the left)
I think those margins works good for right icons and maybe should be opposite for left icon

@nitzanyiz nitzanyiz requested a review from ethanshar October 19, 2023 08:05
Comment on lines 258 to 277
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.

@nitzanyiz nitzanyiz requested a review from ethanshar October 25, 2023 12:01
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you revert this file changes, it's not relevant to the PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Weird. Idk where it came from. Done

@ethanshar ethanshar merged commit a6435c8 into master Oct 26, 2023
@nitzanyiz nitzanyiz deleted the fix/Chip-RightIconMargin branch October 26, 2023 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants