-
Notifications
You must be signed in to change notification settings - Fork 234
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
(Feat) O3-2801 Icons across O3 Navigation MVP #2121
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,7 +3,22 @@ import classNames from 'classnames'; | |||||
import last from 'lodash-es/last'; | ||||||
import { useTranslation } from 'react-i18next'; | ||||||
import { useLocation } from 'react-router-dom'; | ||||||
import { ConfigurableLink } from '@openmrs/esm-framework'; | ||||||
import { | ||||||
ConfigurableLink, | ||||||
ActivityIcon, | ||||||
ShoppingCartIcon, | ||||||
MedicationIcon, | ||||||
ChartAverageIcon, | ||||||
CalendarHeatMapIcon, | ||||||
WarningIcon, | ||||||
ListCheckedIcon, | ||||||
DocumentAttachmentIcon, | ||||||
EventScheduleIcon, | ||||||
ReportIcon, | ||||||
SyringeIcon, | ||||||
ProgramsIcon, | ||||||
} from '@openmrs/esm-framework'; | ||||||
import styles from './dashboard-extension.scss'; | ||||||
|
||||||
export interface DashboardExtensionProps { | ||||||
path: string; | ||||||
|
@@ -22,13 +37,40 @@ export const DashboardExtension = ({ | |||||
const location = useLocation(); | ||||||
const navLink = useMemo(() => decodeURIComponent(last(location.pathname.split('/'))), [location.pathname]); | ||||||
|
||||||
type MenuTitle = keyof typeof MenuIcons; | ||||||
|
||||||
const MenuIcons = { | ||||||
'Patient Summary': ReportIcon, | ||||||
'Vitals & Biometrics': ActivityIcon, | ||||||
Medications: MedicationIcon, | ||||||
Orders: ShoppingCartIcon, | ||||||
Results: ChartAverageIcon, | ||||||
Visits: CalendarHeatMapIcon, | ||||||
Allergies: WarningIcon, | ||||||
Conditions: ListCheckedIcon, | ||||||
Immunizations: SyringeIcon, | ||||||
Attachments: DocumentAttachmentIcon, | ||||||
Programs: ProgramsIcon, | ||||||
Appointments: EventScheduleIcon, | ||||||
} as const; | ||||||
|
||||||
const menuIcon = (title: MenuTitle) => { | ||||||
const Icon = MenuIcons[title]; | ||||||
return Icon ? <Icon className={styles.icon} /> : null; | ||||||
}; | ||||||
|
||||||
const renderIcon = menuIcon(title as MenuTitle); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No weird edge-cases and we don't have to lie to TypeScript:
Suggested change
|
||||||
|
||||||
return ( | ||||||
<div key={path}> | ||||||
<ConfigurableLink | ||||||
className={classNames('cds--side-nav__link', { 'active-left-nav-link': path === navLink })} | ||||||
to={`${basePath}/${encodeURIComponent(path)}`} | ||||||
> | ||||||
{t(title)} | ||||||
<span className={styles.menu}> | ||||||
{renderIcon} | ||||||
<span>{t(title)}</span> | ||||||
</span> | ||||||
</ConfigurableLink> | ||||||
</div> | ||||||
); | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,8 @@ | ||||||
.menu { | ||||||
display: flex; | ||||||
align-items: center; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think centering is the right option here. The items should flex from the start regardless of the width of the container.
Suggested change
|
||||||
} | ||||||
|
||||||
.icon { | ||||||
margin-right: 0.5rem; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use the Carbon spacing tokens for things like this ( |
||||||
} |
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.
There's no good reason for these to be located inside this component. They would be better located outside of it.
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.
Honestly, though, I think this might not be the right way to design things. This works, but only for providing icons for known menu titles, which is bad for extensibility. Better would be to update the
DashboardExtensionProps
to take a string of the name icon and just render it like: