@openmrs/esm-styleguide 8.0.1-pre.3735 → 8.0.1-pre.3744
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +2 -2
- package/dist/custom-overflow-menu/custom-overflow-menu.component.d.ts +8 -1
- package/dist/custom-overflow-menu/custom-overflow-menu.component.d.ts.map +1 -1
- package/dist/openmrs-esm-styleguide.js +1 -1
- package/dist/openmrs-esm-styleguide.js.map +1 -1
- package/dist/patient-banner/actions-menu/patient-banner-actions-menu.component.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/custom-overflow-menu/custom-overflow-menu.component.tsx +26 -2
- package/src/custom-overflow-menu/custom-overflow-menu.test.tsx +48 -1
- package/src/patient-banner/actions-menu/patient-banner-actions-menu.component.tsx +59 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patient-banner-actions-menu.component.d.ts","sourceRoot":"","sources":["../../../src/patient-banner/actions-menu/patient-banner-actions-menu.component.tsx"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,OAAO,
|
|
1
|
+
{"version":3,"file":"patient-banner-actions-menu.component.d.ts","sourceRoot":"","sources":["../../../src/patient-banner/actions-menu/patient-banner-actions-menu.component.tsx"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,OAAO,KAAyC,MAAM,OAAO,CAAC;AAQ9D,MAAM,WAAW,6BAA6B;IAC5C,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,0BAA0B,CAAC,EAAE,MAAM,CAAC;CACrC;AAED,wBAAgB,wBAAwB,CAAC,EACvC,OAAO,EACP,WAAW,EACX,eAAe,EACf,0BAA0B,GAC3B,EAAE,6BAA6B,qBAqE/B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmrs/esm-styleguide",
|
|
3
|
-
"version": "8.0.1-pre.
|
|
3
|
+
"version": "8.0.1-pre.3744",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "The styleguide for OpenMRS SPA",
|
|
6
6
|
"main": "dist/openmrs-esm-styleguide.js",
|
|
@@ -98,17 +98,17 @@
|
|
|
98
98
|
"swr": "2.x"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
|
-
"@openmrs/esm-api": "8.0.1-pre.
|
|
102
|
-
"@openmrs/esm-config": "8.0.1-pre.
|
|
103
|
-
"@openmrs/esm-emr-api": "8.0.1-pre.
|
|
104
|
-
"@openmrs/esm-error-handling": "8.0.1-pre.
|
|
105
|
-
"@openmrs/esm-extensions": "8.0.1-pre.
|
|
106
|
-
"@openmrs/esm-globals": "8.0.1-pre.
|
|
107
|
-
"@openmrs/esm-navigation": "8.0.1-pre.
|
|
108
|
-
"@openmrs/esm-react-utils": "8.0.1-pre.
|
|
109
|
-
"@openmrs/esm-state": "8.0.1-pre.
|
|
110
|
-
"@openmrs/esm-translations": "8.0.1-pre.
|
|
111
|
-
"@openmrs/esm-utils": "8.0.1-pre.
|
|
101
|
+
"@openmrs/esm-api": "8.0.1-pre.3744",
|
|
102
|
+
"@openmrs/esm-config": "8.0.1-pre.3744",
|
|
103
|
+
"@openmrs/esm-emr-api": "8.0.1-pre.3744",
|
|
104
|
+
"@openmrs/esm-error-handling": "8.0.1-pre.3744",
|
|
105
|
+
"@openmrs/esm-extensions": "8.0.1-pre.3744",
|
|
106
|
+
"@openmrs/esm-globals": "8.0.1-pre.3744",
|
|
107
|
+
"@openmrs/esm-navigation": "8.0.1-pre.3744",
|
|
108
|
+
"@openmrs/esm-react-utils": "8.0.1-pre.3744",
|
|
109
|
+
"@openmrs/esm-state": "8.0.1-pre.3744",
|
|
110
|
+
"@openmrs/esm-translations": "8.0.1-pre.3744",
|
|
111
|
+
"@openmrs/esm-utils": "8.0.1-pre.3744",
|
|
112
112
|
"@rspack/cli": "^1.3.11",
|
|
113
113
|
"@rspack/core": "^1.3.11",
|
|
114
114
|
"@types/geopattern": "^1.2.9",
|
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
/** @module @category UI */
|
|
2
|
-
import React, { useCallback } from 'react';
|
|
2
|
+
import React, { createContext, useCallback, useContext, useMemo, type ComponentProps } from 'react';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
|
+
import { OverflowMenuItem } from '@carbon/react';
|
|
4
5
|
import { useLayoutType, useOnClickOutside } from '@openmrs/esm-react-utils';
|
|
5
6
|
import styles from './custom-overflow-menu.module.scss';
|
|
6
7
|
|
|
8
|
+
interface CustomOverflowMenuContextValue {
|
|
9
|
+
closeMenu: () => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const CustomOverflowMenuContext = createContext<CustomOverflowMenuContextValue | null>(null);
|
|
13
|
+
|
|
14
|
+
export function useCustomOverflowMenu() {
|
|
15
|
+
const context = useContext(CustomOverflowMenuContext);
|
|
16
|
+
if (!context) {
|
|
17
|
+
throw new Error('useCustomOverflowMenu must be used within a CustomOverflowMenu');
|
|
18
|
+
}
|
|
19
|
+
return context;
|
|
20
|
+
}
|
|
21
|
+
|
|
7
22
|
interface CustomOverflowMenuProps {
|
|
8
23
|
menuTitle: React.ReactNode;
|
|
9
24
|
children: React.ReactNode;
|
|
@@ -14,6 +29,8 @@ export function CustomOverflowMenu({ menuTitle, children }: CustomOverflowMenuPr
|
|
|
14
29
|
const ref = useOnClickOutside<HTMLDivElement>(() => setMenuIsOpen(false), menuIsOpen);
|
|
15
30
|
const isTablet = useLayoutType() === 'tablet';
|
|
16
31
|
const toggleShowMenu = useCallback(() => setMenuIsOpen((state) => !state), []);
|
|
32
|
+
const closeMenu = useCallback(() => setMenuIsOpen(false), []);
|
|
33
|
+
const contextValue = useMemo(() => ({ closeMenu }), [closeMenu]);
|
|
17
34
|
|
|
18
35
|
return (
|
|
19
36
|
<div data-overflow-menu className={classNames('cds--overflow-menu', styles.container)} ref={ref}>
|
|
@@ -46,10 +63,17 @@ export function CustomOverflowMenu({ menuTitle, children }: CustomOverflowMenuPr
|
|
|
46
63
|
<ul
|
|
47
64
|
className={classNames('cds--overflow-menu-options__content', { 'cds--overflow-menu-options--lg': isTablet })}
|
|
48
65
|
>
|
|
49
|
-
{children}
|
|
66
|
+
<CustomOverflowMenuContext.Provider value={contextValue}>{children}</CustomOverflowMenuContext.Provider>
|
|
50
67
|
</ul>
|
|
51
68
|
<span />
|
|
52
69
|
</div>
|
|
53
70
|
</div>
|
|
54
71
|
);
|
|
55
72
|
}
|
|
73
|
+
|
|
74
|
+
type OverflowMenuItemProps = ComponentProps<typeof OverflowMenuItem>;
|
|
75
|
+
|
|
76
|
+
export function CustomOverflowMenuItem(props: Omit<OverflowMenuItemProps, 'closeMenu'>) {
|
|
77
|
+
const context = useContext(CustomOverflowMenuContext);
|
|
78
|
+
return <OverflowMenuItem {...props} closeMenu={context?.closeMenu} />;
|
|
79
|
+
}
|
|
@@ -4,7 +4,7 @@ import '@testing-library/jest-dom/vitest';
|
|
|
4
4
|
import userEvent from '@testing-library/user-event';
|
|
5
5
|
import { render, screen } from '@testing-library/react';
|
|
6
6
|
import { useLayoutType } from '@openmrs/esm-react-utils';
|
|
7
|
-
import { CustomOverflowMenu } from './custom-overflow-menu.component';
|
|
7
|
+
import { CustomOverflowMenu, CustomOverflowMenuItem, useCustomOverflowMenu } from './custom-overflow-menu.component';
|
|
8
8
|
|
|
9
9
|
const mockUseLayoutType = vi.mocked(useLayoutType);
|
|
10
10
|
|
|
@@ -94,3 +94,50 @@ describe('CustomOverflowMenu', () => {
|
|
|
94
94
|
expect(menu).toHaveAttribute('data-floating-menu-direction', 'bottom');
|
|
95
95
|
});
|
|
96
96
|
});
|
|
97
|
+
|
|
98
|
+
describe('CustomOverflowMenuItem', () => {
|
|
99
|
+
beforeEach(() => {
|
|
100
|
+
mockUseLayoutType.mockReturnValue('small-desktop');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('should render within CustomOverflowMenu', async () => {
|
|
104
|
+
render(
|
|
105
|
+
<CustomOverflowMenu menuTitle="Menu">
|
|
106
|
+
<CustomOverflowMenuItem itemText="Test Item" />
|
|
107
|
+
</CustomOverflowMenu>,
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
expect(screen.getByText('Test Item')).toBeInTheDocument();
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('should close menu when clicked', async () => {
|
|
114
|
+
const user = userEvent.setup();
|
|
115
|
+
|
|
116
|
+
render(
|
|
117
|
+
<CustomOverflowMenu menuTitle="Menu">
|
|
118
|
+
<CustomOverflowMenuItem itemText="Click Me" />
|
|
119
|
+
</CustomOverflowMenu>,
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const triggerButton = screen.getByRole('button', { name: /menu/i });
|
|
123
|
+
|
|
124
|
+
// Open the menu
|
|
125
|
+
await user.click(triggerButton);
|
|
126
|
+
expect(triggerButton).toHaveAttribute('aria-expanded', 'true');
|
|
127
|
+
|
|
128
|
+
// Click the menu item
|
|
129
|
+
await user.click(screen.getByText('Click Me'));
|
|
130
|
+
expect(triggerButton).toHaveAttribute('aria-expanded', 'false');
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe('useCustomOverflowMenu', () => {
|
|
135
|
+
it('should throw error when used outside CustomOverflowMenu', () => {
|
|
136
|
+
const TestComponent = () => {
|
|
137
|
+
useCustomOverflowMenu();
|
|
138
|
+
return null;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
expect(() => render(<TestComponent />)).toThrow('useCustomOverflowMenu must be used within a CustomOverflowMenu');
|
|
142
|
+
});
|
|
143
|
+
});
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/** @module @category UI */
|
|
2
|
-
import React, { useMemo } from 'react';
|
|
2
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
3
|
+
import classNames from 'classnames';
|
|
3
4
|
import { OverflowMenuVertical } from '@carbon/react/icons';
|
|
4
|
-
import { ExtensionSlot, useExtensionSlot } from '@openmrs/esm-react-utils';
|
|
5
|
+
import { ExtensionSlot, useExtensionSlot, useLayoutType, useOnClickOutside } from '@openmrs/esm-react-utils';
|
|
5
6
|
import { getCoreTranslation } from '@openmrs/esm-translations';
|
|
6
|
-
import
|
|
7
|
+
import customOverflowMenuStyles from '../../custom-overflow-menu/custom-overflow-menu.module.scss';
|
|
7
8
|
import styles from './patient-banner-actions-menu.module.scss';
|
|
8
9
|
|
|
9
10
|
export interface PatientBannerActionsMenuProps {
|
|
@@ -23,26 +24,70 @@ export function PatientBannerActionsMenu({
|
|
|
23
24
|
actionsSlotName,
|
|
24
25
|
additionalActionsSlotState,
|
|
25
26
|
}: PatientBannerActionsMenuProps) {
|
|
27
|
+
const [menuIsOpen, setMenuIsOpen] = useState(false);
|
|
26
28
|
const { extensions: patientActions } = useExtensionSlot(actionsSlotName);
|
|
29
|
+
const isTablet = useLayoutType() === 'tablet';
|
|
30
|
+
const ref = useOnClickOutside<HTMLDivElement>(() => setMenuIsOpen(false), menuIsOpen);
|
|
31
|
+
|
|
32
|
+
const toggleShowMenu = useCallback(() => setMenuIsOpen((state) => !state), []);
|
|
33
|
+
const closeMenu = useCallback(() => setMenuIsOpen(false), []);
|
|
34
|
+
|
|
27
35
|
const patientActionsSlotState = useMemo(
|
|
28
|
-
() => ({ patientUuid, patient, ...additionalActionsSlotState }),
|
|
29
|
-
[patientUuid, additionalActionsSlotState],
|
|
36
|
+
() => ({ patientUuid, patient, closeMenu, ...additionalActionsSlotState }),
|
|
37
|
+
[patientUuid, patient, closeMenu, additionalActionsSlotState],
|
|
30
38
|
);
|
|
31
39
|
|
|
32
40
|
return (
|
|
33
41
|
<>
|
|
34
42
|
{patientActions.length > 0 ? (
|
|
35
43
|
<div className={styles.overflowMenuContainer}>
|
|
36
|
-
<
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
<OverflowMenuVertical size={16} style={{ marginLeft: '0.5rem', fill: '#78A9FF' }} />
|
|
41
|
-
</>
|
|
42
|
-
}
|
|
44
|
+
<div
|
|
45
|
+
data-overflow-menu
|
|
46
|
+
className={classNames('cds--overflow-menu', customOverflowMenuStyles.container)}
|
|
47
|
+
ref={ref}
|
|
43
48
|
>
|
|
44
|
-
<
|
|
45
|
-
|
|
49
|
+
<button
|
|
50
|
+
className={classNames(
|
|
51
|
+
'cds--btn',
|
|
52
|
+
'cds--btn--ghost',
|
|
53
|
+
'cds--overflow-menu__trigger',
|
|
54
|
+
{ 'cds--overflow-menu--open': menuIsOpen },
|
|
55
|
+
customOverflowMenuStyles.overflowMenuButton,
|
|
56
|
+
)}
|
|
57
|
+
aria-haspopup="true"
|
|
58
|
+
aria-expanded={menuIsOpen}
|
|
59
|
+
id="custom-actions-overflow-menu-trigger"
|
|
60
|
+
aria-controls="custom-actions-overflow-menu"
|
|
61
|
+
onClick={toggleShowMenu}
|
|
62
|
+
>
|
|
63
|
+
<span className={styles.actionsButtonText}>{getCoreTranslation('actions', 'Actions')}</span>{' '}
|
|
64
|
+
<OverflowMenuVertical size={16} style={{ marginLeft: '0.5rem', fill: '#78A9FF' }} />
|
|
65
|
+
</button>
|
|
66
|
+
<div
|
|
67
|
+
className={classNames(
|
|
68
|
+
'cds--overflow-menu-options',
|
|
69
|
+
'cds--overflow-menu--flip',
|
|
70
|
+
customOverflowMenuStyles.menu,
|
|
71
|
+
{
|
|
72
|
+
[customOverflowMenuStyles.show]: menuIsOpen,
|
|
73
|
+
},
|
|
74
|
+
)}
|
|
75
|
+
tabIndex={0}
|
|
76
|
+
data-floating-menu-direction="bottom"
|
|
77
|
+
role="menu"
|
|
78
|
+
aria-labelledby="custom-actions-overflow-menu-trigger"
|
|
79
|
+
id="custom-actions-overflow-menu"
|
|
80
|
+
>
|
|
81
|
+
<ul
|
|
82
|
+
className={classNames('cds--overflow-menu-options__content', {
|
|
83
|
+
'cds--overflow-menu-options--lg': isTablet,
|
|
84
|
+
})}
|
|
85
|
+
>
|
|
86
|
+
<ExtensionSlot name={actionsSlotName} key={actionsSlotName} state={patientActionsSlotState} />
|
|
87
|
+
</ul>
|
|
88
|
+
<span />
|
|
89
|
+
</div>
|
|
90
|
+
</div>
|
|
46
91
|
</div>
|
|
47
92
|
) : null}
|
|
48
93
|
</>
|