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

Navbar: Add Badge icon to Notification Button #2424

Merged
merged 7 commits into from
Apr 12, 2024

Conversation

ElishaSamPeterPrabhu
Copy link
Collaborator

@ElishaSamPeterPrabhu ElishaSamPeterPrabhu commented Apr 9, 2024

Description

  • Added prop counter as a badge to the notification icon button

References #
Fixes: #1011

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)
  • Documentation update

How Has This Been Tested?

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • 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
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Copy link

netlify bot commented Apr 9, 2024

Deploy Preview for moduswebcomponents ready!

Name Link
🔨 Latest commit a4b303a
🔍 Latest deploy log https://app.netlify.com/sites/moduswebcomponents/deploys/6618890362b1e800083caa52
😎 Deploy Preview https://deploy-preview-2424--moduswebcomponents.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 27 (no change from production)
Accessibility: 98 (no change from production)
Best Practices: 92 (no change from production)
SEO: 92 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@ElishaSamPeterPrabhu ElishaSamPeterPrabhu changed the title Update badge icon in notification button Navbar: Add Badge icon to Notification Button Apr 9, 2024
@@ -70,6 +70,9 @@ export class ModusNavbar {
/** (optional) Whether to show notifications. */
@Prop() showNotifications: boolean;

/** (optional) Whether to show badge on top of notification */
@Prop() counter: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make this notificationCount as a number?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Isn't string preferable so in the future we can allow up to 3 character string

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Made it to be a number for now

this.counter = null;
}
}
console.log('countervalue', counterValue);
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove console logs

Also this above logic can probably be simplified if the prop is a number

Also break this into a separate function, render is getting a little heavy with all this logic. something like

const notificationCount = getNotificationCount()`

That can return a string value

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Modified

@@ -109,14 +115,16 @@ const defaultApps = [{
url: 'https://modus.trimble.com/',
}];

const Template = ({ buttons, enableSearchOverlay, helpTooltip, profileMenuOptions, searchTooltip, showHelp, showProfile, showSearch }) => html`
const Template = ({ buttons,counter, enableSearchOverlay, helpTooltip, profileMenuOptions, searchTooltip, showHelp, showProfile, showSearch }) => html`
Copy link
Contributor

Choose a reason for hiding this comment

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

missing a space after the , and before counter

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Formatted

};

const FailedToLoadAvatarTemplate = ({ buttons, enableSearchOverlay, helpTooltip, profileMenuOptions, searchTooltip, showHelp, showProfile, showSearch }) => html`
const FailedToLoadAvatarTemplate = ({ buttons,counter, enableSearchOverlay, helpTooltip, profileMenuOptions, searchTooltip, showHelp, showProfile, showSearch }) => html`
Copy link
Contributor

Choose a reason for hiding this comment

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

missing a space after the , and before counter

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Formatted

@cjwinsor
Copy link
Contributor

cjwinsor commented Apr 9, 2024

@coliff @egunther39 Can you take a look and let me know if the size of this notification badge is too small in the deploy preveiw?...

image

@@ -58,3 +58,6 @@ $modus-navbar-blue-profile-icon-active-border-color: var(
--modus-navbar-blue-profile-icon-active-border-color,
#019aeb
) !default;

// Badge
$modus-navbar-badge-bg: var(--modus-navbar-badge-bg, #da212c) !default;
Copy link
Contributor

Choose a reason for hiding this comment

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

Badge is showing as blue in deploy preview

@egunther39
Copy link

@cjwinsor - It's a bit small. Here is an example of the red badge we use in our application. The badge is 20x20 inside/overlaid above the 48x48 navbar button/icon. I'd suggest, doing the same.
image

@cjwinsor
Copy link
Contributor

cjwinsor commented Apr 9, 2024

Here is a shot with a medium badge
image

@@ -349,6 +352,21 @@ export class ModusNavbar {
}
}

getNotificationCount(): string {
let counterValue;
if (this.notificationCount) {
Copy link
Contributor

Choose a reason for hiding this comment

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

To avoid nesting, we can treat this as a guard statement

if (!this.notificationCount) {
    return;
}

Also I don't do one liners for this because I feel they are slightly less readable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated code without one liners and avoiding nesting

@@ -223,6 +223,7 @@ interface ModusNavbarButton {
| ---------------------- | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------- | ----------- |
| `apps` | -- | (optional) The apps to render in the apps menu. | `ModusNavbarApp[]` | `undefined` |
| `buttons` | -- | (optional) The buttons to render in the Navbar. | `ModusNavbarButton[]` | `undefined` |
| `notificationCount` | `notification-count` | (optional) To add the counter value to the notification icon. | `string` | `undefined` |
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be a number now, not a string

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated

name: 'notification-count',
description: 'To add the counter value to the notification icon',
table: {
type: { summary: 'string' },
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be handled as a number.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated

@@ -174,16 +184,18 @@ Default.args = {
showHelp: false,
showProfile: true,
showSearch: false,
notificationCount:""
Copy link
Contributor

Choose a reason for hiding this comment

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

All these can be 0. I'm not sure how storybook handles undefined or null when it comes to showing the control. This applies to all 3 stories.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated

@cjwinsor
Copy link
Contributor

@ElishaSamPeterPrabhu Notifications are still blue in the deploy preview as well.

@ElishaSamPeterPrabhu
Copy link
Collaborator Author

ElishaSamPeterPrabhu commented Apr 11, 2024

@ElishaSamPeterPrabhu Notifications are still blue in the deploy preview as well.

Updated to red

@cjwinsor cjwinsor merged commit bd30463 into main Apr 12, 2024
9 checks passed
@cjwinsor cjwinsor deleted the issue-1011/notification-button-badge branch April 12, 2024 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Modus Button - Add a Badge for Notification Icon button
3 participants