Skip to content

Commit

Permalink
custom sidenav
Browse files Browse the repository at this point in the history
  • Loading branch information
pirupius committed Sep 25, 2023
1 parent 03fd3b2 commit aefc3e0
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 36 deletions.
4 changes: 2 additions & 2 deletions packages/esm-ohri-core-app/src/dashboard.meta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react';
import { Home, ListBulleted, Calendar, Medication, Events } from '@carbon/react/icons';

export const homeDashboardMeta = {
name: 'home',
slot: 'ohri-home-dashboard-slot',
name: 'Home',
slot: 'home-dashboard-slot',
config: { columns: 1, type: 'grid', icon: Home },
isLink: true,
title: 'Home',
Expand Down
34 changes: 34 additions & 0 deletions packages/esm-ohri-core-app/src/dashboard/_vars.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
$ui-01: #f4f4f4;
$ui-02: #ffffff;
$ui-03: #e0e0e0;
$ui-04: #8d8d8d;
$ui-05: #161616;
$text-02: #525252;
$text-03: #a8a8a8;
$ui-background: #ffffff;
$color-gray-30: #c6c6c6;
$color-gray-70: #525252;
$color-gray-100: #161616;
$color-blue-60-2: #0f62fe;
$color-blue-10: #edf5ff;
$color-yellow-50: #feecae;
$carbon--red-50: #fa4d56;
$inverse-link: #78a9ff;
$support-02: #24a148;
$inverse-support-03: #f1c21b;
$warning-background: #fff8e1;
$openmrs-background-grey: #f4f4f4;
$danger: #da1e28;
$interactive-01: #0f62fe;
$field-01: #f4f4f4;
$grey-2: #e0e0e0;
$labeldropdown: #c6c6c6;

$breakpoint-phone-min: 0px;
$breakpoint-phone-max: 600px;
$breakpoint-tablet-min: 601px;
$breakpoint-tablet-max: 1023px;
$breakpoint-small-desktop-min: 1024px;
$breakpoint-small-desktop-max: 1439px;
$breakpoint-large-desktop-min: 1440px;
$breakpoint-large-desktop-max: 99999999px;
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/** @module @category UI */
import React from 'react';
import { ExtensionSlot, useStore } from '@openmrs/esm-react-utils';
import { createGlobalStore } from '@openmrs/esm-state';
import { SideNav, SideNavProps } from '@carbon/react';
import styles from './left-nav.module.scss';

interface LeftNavStore {
slotName: string | null;
basePath: string;
}

const leftNavStore = createGlobalStore<LeftNavStore>('left-nav', {
slotName: null,
basePath: window.spaBase,
});

export function setLeftNav({ name, basePath }) {
leftNavStore.setState({ slotName: name, basePath });
}

export function unsetLeftNav(name) {
if (leftNavStore.getState().slotName == name) {
leftNavStore.setState({ slotName: null });
}
}

type LeftNavMenuProps = SideNavProps;

export const LeftNavMenu = React.forwardRef<HTMLElement, LeftNavMenuProps>((props, ref) => {
const { slotName, basePath } = useStore(leftNavStore);
const currentPath = window.location ?? { pathname: '' };

return (
<SideNav ref={ref} expanded aria-label="Left navigation" className={styles.leftNav} {...props}>
<ExtensionSlot name="global-nav-menu-slot" />
{slotName ? <ExtensionSlot name={slotName} state={{ basePath, currentPath }} /> : null}
</SideNav>
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@use "@carbon/styles/scss/type";
@import "../vars";

.leftNav {
border-right: 1px solid $ui-03;
padding-top: 1rem;

// Left nav menu item
:global(.cds--side-nav__link) {
color: $text-02;
@include type.type-style("heading-compact-01");

&:focus,
&:hover {
background-color: $ui-01;
}

// Active menu item
&:global(.active-left-nav-link) {
color: $ui-05;
border-left: 0.25rem solid var(--brand-01);
background-color: $ui-03;
outline: none;
padding: 0 0.75rem;
}
}
}

/* Desktop */
:global(.omrs-breakpoint-gt-tablet) {
:global(.cds--side-nav__link) {
height: 2rem;
}
}

/* Tablet */
:global(.omrs-breakpoint-lt-desktop) {
:global(.cds--side-nav__link) {
height: 3rem;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { LeftNavMenu } from '@openmrs/esm-framework';
import { LeftNavMenu } from './left-nav-menu';

const SideMenu = () => <LeftNavMenu />;

Expand Down
2 changes: 1 addition & 1 deletion packages/esm-ohri-core-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const options = {

export const root = getAsyncLifecycle(() => import('./root'), options);

export const dashboardNavMenu = getAsyncLifecycle(() => import('./dashboard/side-menu.component'), options);
export const dashboardNavMenu = getAsyncLifecycle(() => import('./dashboard/side-menu/side-menu.component'), options);

export const homeWidgetDbLink = getSyncLifecycle(createDashboardLink(homeDashboardMeta), options);

Expand Down
4 changes: 4 additions & 0 deletions packages/esm-ohri-core-app/src/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
{
"component": "root",
"route": "dashboard"
},
{
"component": "root",
"route": "home"
}
],
"extensions": [
Expand Down
70 changes: 38 additions & 32 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4066,13 +4066,8 @@ __metadata:
linkType: hard

"@openmrs/openmrs-form-engine-lib@npm:next":
<<<<<<< HEAD
version: 1.0.0-pre.365
resolution: "@openmrs/openmrs-form-engine-lib@npm:1.0.0-pre.365"
=======
version: 1.0.0-pre.330
resolution: "@openmrs/openmrs-form-engine-lib@npm:1.0.0-pre.330"
>>>>>>> 63da4759 (wip)
dependencies:
ace-builds: ^1.4.12
enzyme: ^3.11.0
Expand All @@ -4094,11 +4089,7 @@ __metadata:
react: ^18.2.0
react-i18next: 11.x
rxjs: 6.x
<<<<<<< HEAD
checksum: 69bff8401ff5b9f40fc0953438c44f381f7956335d2547e2532ff3b8cc9a229cb033056f9d153e38faa582e8739e3599fd4ec78cd39bc938dbcbb50d680b7457
=======
checksum: 86c413fe8b183e8328ddb2c874acf1580102c088745b397ad9ced3612e9f742e8c7f9279d95c9771936310a80f444756cc5a7226590cc4aeb5e50bf134ad1daf
>>>>>>> 63da4759 (wip)
languageName: node
linkType: hard

Expand Down Expand Up @@ -9602,22 +9593,6 @@ __metadata:
languageName: node
linkType: hard

<<<<<<< HEAD
"decompress-response@npm:^6.0.0":
version: 6.0.0
resolution: "decompress-response@npm:6.0.0"
dependencies:
mimic-response: ^3.1.0
checksum: d377cf47e02d805e283866c3f50d3d21578b779731e8c5072d6ce8c13cc31493db1c2f6784da9d1d5250822120cefa44f1deab112d5981015f2e17444b763812
=======
"decode-uri-component@npm:^0.2.0":
version: 0.2.0
resolution: "decode-uri-component@npm:0.2.0"
checksum: f3749344ab9305ffcfe4bfe300e2dbb61fc6359e2b736812100a3b1b6db0a5668cba31a05e4b45d4d63dbf1a18dfa354cd3ca5bb3ededddabb8cd293f4404f94
>>>>>>> 63da4759 (wip)
languageName: node
linkType: hard

"dedent@npm:^0.7.0":
version: 0.7.0
resolution: "dedent@npm:0.7.0"
Expand Down Expand Up @@ -17423,7 +17398,7 @@ __metadata:
languageName: node
linkType: hard

"qs@npm:6.11.0, qs@npm:^6.9.4":
"qs@npm:6.11.0":
version: 6.11.0
resolution: "qs@npm:6.11.0"
dependencies:
Expand Down Expand Up @@ -21110,11 +21085,6 @@ __metadata:
languageName: node
linkType: hard

<<<<<<< HEAD
"webpack@npm:^5.74.0, webpack@npm:^5.88.0, webpack@npm:^5.88.2":
version: 5.88.2
resolution: "webpack@npm:5.88.2"
=======
"webpack@npm:^5.74.0":
version: 5.75.0
resolution: "webpack@npm:5.75.0"
Expand Down Expand Up @@ -21155,7 +21125,6 @@ __metadata:
"webpack@npm:^5.88.0":
version: 5.88.1
resolution: "webpack@npm:5.88.1"
>>>>>>> 63da4759 (wip)
dependencies:
"@types/eslint-scope": ^3.7.3
"@types/estree": ^1.0.0
Expand Down Expand Up @@ -21190,6 +21159,43 @@ __metadata:
languageName: node
linkType: hard

"webpack@npm:^5.88.2":
version: 5.88.2
resolution: "webpack@npm:5.88.2"
dependencies:
"@types/eslint-scope": ^3.7.3
"@types/estree": ^1.0.0
"@webassemblyjs/ast": ^1.11.5
"@webassemblyjs/wasm-edit": ^1.11.5
"@webassemblyjs/wasm-parser": ^1.11.5
acorn: ^8.7.1
acorn-import-assertions: ^1.9.0
browserslist: ^4.14.5
chrome-trace-event: ^1.0.2
enhanced-resolve: ^5.15.0
es-module-lexer: ^1.2.1
eslint-scope: 5.1.1
events: ^3.2.0
glob-to-regexp: ^0.4.1
graceful-fs: ^4.2.9
json-parse-even-better-errors: ^2.3.1
loader-runner: ^4.2.0
mime-types: ^2.1.27
neo-async: ^2.6.2
schema-utils: ^3.2.0
tapable: ^2.1.1
terser-webpack-plugin: ^5.3.7
watchpack: ^2.4.0
webpack-sources: ^3.2.3
peerDependenciesMeta:
webpack-cli:
optional: true
bin:
webpack: bin/webpack.js
checksum: 79476a782da31a21f6dd38fbbd06b68da93baf6a62f0d08ca99222367f3b8668f5a1f2086b7bb78e23172e31fa6df6fa7ab09b25e827866c4fc4dc2b30443ce2
languageName: node
linkType: hard

"websocket-driver@npm:>=0.5.1, websocket-driver@npm:^0.7.4":
version: 0.7.4
resolution: "websocket-driver@npm:0.7.4"
Expand Down

0 comments on commit aefc3e0

Please sign in to comment.