Skip to content
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

LF-4374 Badge component #3486

Open
wants to merge 6 commits into
base: integration
Choose a base branch
from

Conversation

gursimran-singh
Copy link
Collaborator

Description

A reusable badge component that shows the content when onHover - desktop, onClick - mobile, desktop. Usage:
<Badge title='Beta' content='This is the content which will be displayed onHover - desktop, onClick - mobile, desktop' />

Jira link: https://lite-farm.atlassian.net/browse/LF-4374

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Passes test case
  • UI components visually reviewed on desktop view
  • UI components visually reviewed on mobile view
  • Other (please explain)

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • The precommit and linting ran successfully
  • I have added or updated language tags for text that's part of the UI
  • I have added "MISSING" for all new language tags to languages I don't speak
  • I have added the GNU General Public License to all new files

@gursimran-singh gursimran-singh requested review from a team as code owners October 2, 2024 19:47
@gursimran-singh gursimran-singh requested review from antsgar and kathyavini and removed request for a team October 2, 2024 19:47
Copy link
Collaborator

@antsgar antsgar left a comment

Choose a reason for hiding this comment

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

@gursimran-singh thank you so much for working on this, we really appreciate it. It looks great! 🙌

I left a couple of comments throughout, and additionally:

  • In the designs, when the popover is open, the badge's bottom border has a smaller border radius (half of the normal radius) to sort of align with the popover.
  • The ticket description includes adding the Beta badge to different Animals components, were you planning on tackling that in a separate PR? If you can't get to it it's no problem, we can split it up to a separate ticket.

packages/webapp/src/components/Badge/index.tsx Outdated Show resolved Hide resolved
packages/webapp/src/components/Badge/styles.module.scss Outdated Show resolved Hide resolved
packages/webapp/src/components/Badge/index.tsx Outdated Show resolved Hide resolved
packages/webapp/src/components/Badge/styles.module.scss Outdated Show resolved Hide resolved
@gursimran-singh
Copy link
Collaborator Author

@antsgar

I will do the mentioned changes. And regarding adding Beta badge to different Animals components, to what i remember when having discussion with team is that these can be added later(i might have got it wrong). I will add the Badge component to required places and will get in touch if i have any questions/issues doing that. Thanks.

Copy link
Collaborator

@antsgar antsgar left a comment

Choose a reason for hiding this comment

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

Looks great! Not a blocker for merging (we can fix later), but on second thought I think on desktop the tooltip content should appear/disappear on click instead of on hover. It seems strange to me that the badge changes appearance on click and when clicking outside of it, but the tooltip interaction happens on hover. I'll double check with design tomorrow though.

On the other hand, I think there's a different design for the tooltip on mobile, which is full screen. I'll double check this tomorrow as well and let you know!

>
{content}
</div>
dangerouslySetInnerHTML={{ __html: content }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you explain the reason behind this change? Instead of setting the link as HTML within the content string, I think we should keep this as is and set the content up as a React Node including the tag

Copy link
Collaborator Author

@gursimran-singh gursimran-singh Oct 22, 2024

Choose a reason for hiding this comment

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

My intentions when developing the component was to make it reusable with different title and content in any other section. So, do not want to hard code anything in the component itself. I will change it to use <Trans> component from 'react-i18next' package(which i found later), is safer way to handle these situations and set the link when passing the content to the component.

Also, it would be nice if you can tell the link address, then i will update that as well.

@gursimran-singh
Copy link
Collaborator Author

I had discussion with team and showed them the functionality and they were ok with it. Only change was that the badge in the menu items should no show the content popup in any case.

I think there's a different design for the tooltip on mobile, which is full screen
We had a discussion on this as well, showing on full screen is a part of spotlight feature and in mobile content should only be shown on click as we do not have hover there.

Do let me know if there are changes and i will do it accordingly.

@Duncan-Brain Duncan-Brain requested review from Duncan-Brain and removed request for kathyavini October 25, 2024 16:02
Copy link
Collaborator

@Duncan-Brain Duncan-Brain left a comment

Choose a reason for hiding this comment

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

Hey @gursimran-singh ! Thanks for working on this, so sorry it took a while for us to get a review.

I think overall it is looking great I just found a few small things:

  1. The onClick behaviour does not quite work as expected on mobile (click does not work as click out) and desktop (click changes styles but does not keep tooltip open) for please see video
Screen.Recording.2024-10-25.at.12.09.29.PM.mov
Screen.Recording.2024-10-25.at.12.10.09.PM.mov
  1. Couple inline comments
  2. Would you be willing to make storybook stories for this new component?

setOpen(true);
}
};
const handleTooltipClose = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could handleTooltipOpen + handleTooltipClose be combined by letting the state setter to use previous/pending value. React reference if useful

setOpen(prevState => !prevState)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That can be done if we want the button to behave like toggle(one click open tooltip and another closes it). Honestly speaking, i am little unclear about the behaviour of this component and that is why i came to the meeting to show you guys what i build. Got some feedback and changed accordingly. Even Antonella is not sure about the hover/click functionality for both mobile and desktop and told me that she would let me know after discussing with the team.

So, do let me know what should be the behaviour of this component for onHover and click, for both mobile and desktop and i will make changes accordingly

Copy link
Collaborator

Choose a reason for hiding this comment

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

Honestly its mostly fine the way you have it as an only onHover on desktop and onClick on mobile.

But specifically the style of the button on desktop should not change onClick on desktop though as shown in the first video... unless the full click behaviour opens the tooltip. So either we need to disable click styles on desktop, or add the full onClick open behaviour. I would personally approve either of those two options.

I will tag Loic on the Jira ticket to hopefully get you clarification on this though so you feel confident. Sorry about that lack of clarity -- please always feel free to tag Loic with your UI/UX questions on the Jira ticket too!

Comment on lines +49 to +73
:global(.hasBadge) .badge {
height: 12px;
font-size: 11px;
padding: 6px;
position: absolute;
left: 50px;
top: 8px;
border-radius: 16px;
&:focus,
&:hover {
color: var(--Colors-Accent-Accent-yellow-600);
background: #fffbf2;
border-radius: 16px !important;
}

@include xs-breakpoint {
height: 16px;
position: relative;
font-size: 14px;
top: initial;
left: initial;
padding: 6px;
margin-right: 6px;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be a bad idea to pass a className with these styles to the Badge component instead?
I've never seen a raw CSS className used here before, so it would be nice if we could keep things consistent!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is one of the way by which we can access the parent class in the child component. But, i will see these styles can be attained by passing class to the component and also avoiding the inline css.

style?: React.CSSProperties;
}

const Badge: React.FC<BadgeProps> = ({ content = '', title, showIcon = true, style }) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We're aiming to avoid inline CSS, so could you please change the style prop to className instead? 🙏

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Its good we are avoiding the inline css, i have seen a lot here. And sure, i will update accordingly.

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.

4 participants