-
Notifications
You must be signed in to change notification settings - Fork 71
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
Conversation
✅ Deploy Preview for moduswebcomponents ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@@ -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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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` |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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` |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatted
@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?... |
@@ -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; |
There was a problem hiding this comment.
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
@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. |
@@ -349,6 +352,21 @@ export class ModusNavbar { | |||
} | |||
} | |||
|
|||
getNotificationCount(): string { | |||
let counterValue; | |||
if (this.notificationCount) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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` | |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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' }, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:"" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
@ElishaSamPeterPrabhu Notifications are still blue in the deploy preview as well. |
Updated to red |
Description
References #
Fixes: #1011
Type of change
How Has This Been Tested?
Checklist