@openmrs/esm-styleguide 8.0.1-pre.3615 → 8.0.1-pre.3634

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.
@@ -94,7 +94,7 @@ type PromptReason = {
94
94
  export declare function promptForClosingWorkspaces(promptReason: PromptReason): Promise<boolean>;
95
95
  export declare function useWorkspace2Store(): WorkspaceStoreState2 & {
96
96
  setWindowMaximized: (windowName: string, maximized: boolean) => void;
97
- hideWindow: (windowName: string) => void;
97
+ hideWindow: () => void;
98
98
  restoreWindow: (windowName: string) => void;
99
99
  closeWorkspace: (workspaceName: string) => void;
100
100
  openChildWorkspace: (parentWorkspaceName: string, childWorkspaceName: string, childWorkspaceProps: Record<string, any>) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-styleguide",
3
- "version": "8.0.1-pre.3615",
3
+ "version": "8.0.1-pre.3634",
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.3615",
102
- "@openmrs/esm-config": "8.0.1-pre.3615",
103
- "@openmrs/esm-emr-api": "8.0.1-pre.3615",
104
- "@openmrs/esm-error-handling": "8.0.1-pre.3615",
105
- "@openmrs/esm-extensions": "8.0.1-pre.3615",
106
- "@openmrs/esm-globals": "8.0.1-pre.3615",
107
- "@openmrs/esm-navigation": "8.0.1-pre.3615",
108
- "@openmrs/esm-react-utils": "8.0.1-pre.3615",
109
- "@openmrs/esm-state": "8.0.1-pre.3615",
110
- "@openmrs/esm-translations": "8.0.1-pre.3615",
111
- "@openmrs/esm-utils": "8.0.1-pre.3615",
101
+ "@openmrs/esm-api": "8.0.1-pre.3634",
102
+ "@openmrs/esm-config": "8.0.1-pre.3634",
103
+ "@openmrs/esm-emr-api": "8.0.1-pre.3634",
104
+ "@openmrs/esm-error-handling": "8.0.1-pre.3634",
105
+ "@openmrs/esm-extensions": "8.0.1-pre.3634",
106
+ "@openmrs/esm-globals": "8.0.1-pre.3634",
107
+ "@openmrs/esm-navigation": "8.0.1-pre.3634",
108
+ "@openmrs/esm-react-utils": "8.0.1-pre.3634",
109
+ "@openmrs/esm-state": "8.0.1-pre.3634",
110
+ "@openmrs/esm-translations": "8.0.1-pre.3634",
111
+ "@openmrs/esm-utils": "8.0.1-pre.3634",
112
112
  "@rspack/cli": "^1.3.11",
113
113
  "@rspack/core": "^1.3.11",
114
114
  "@types/geopattern": "^1.2.9",
@@ -70,21 +70,21 @@ export const ActionMenuButton2: React.FC<ActionMenuButtonProps2> = ({
70
70
  onBeforeWorkspaceLaunch,
71
71
  }) => {
72
72
  const layout = useLayoutType();
73
- const { openedWindows, restoreWindow } = useWorkspace2Store();
73
+ const { openedWindows, restoreWindow, isMostRecentlyOpenedWindowHidden } = useWorkspace2Store();
74
74
 
75
75
  // name of the window that the button is associated with
76
76
  const { windowName } = useContext(SingleSpaContext);
77
77
 
78
+ const openedWindowIndex = openedWindows.findIndex((w) => w.windowName === windowName);
78
79
  // can be undefined if the window is not opened
79
- const window = openedWindows.find((w) => w.windowName === windowName);
80
-
80
+ const window: OpenedWindow | undefined = openedWindows[openedWindowIndex];
81
81
  const isWindowOpened = window != null;
82
- const isWindowHidden = window?.hidden ?? false;
83
- const isFocused = isCurrentWindowFocused(openedWindows, window);
82
+ const isWindowHidden =
83
+ isWindowOpened && (openedWindowIndex < openedWindows.length - 1 || isMostRecentlyOpenedWindowHidden);
84
84
 
85
85
  const onClick = async () => {
86
86
  if (isWindowOpened) {
87
- if (!isFocused) {
87
+ if (isWindowHidden) {
88
88
  restoreWindow(window.windowName);
89
89
  }
90
90
  } else {
@@ -121,7 +121,6 @@ export const ActionMenuButton2: React.FC<ActionMenuButtonProps2> = ({
121
121
  aria-label={label}
122
122
  className={classNames(styles.container, {
123
123
  [styles.active]: isWindowOpened,
124
- [styles.focused]: isFocused,
125
124
  })}
126
125
  enterDelayMs={300}
127
126
  kind="ghost"
@@ -135,15 +134,3 @@ export const ActionMenuButton2: React.FC<ActionMenuButtonProps2> = ({
135
134
  </IconButton>
136
135
  );
137
136
  };
138
-
139
- function isCurrentWindowFocused(openedWindows: Array<OpenedWindow>, currentWindow: OpenedWindow | undefined): boolean {
140
- // openedWindows array is sorted with most recently opened window appearing last.
141
- // We check if the current window is the last one in the array that is not hidden.
142
- for (let i = openedWindows.length - 1; i >= 0; i--) {
143
- const win = openedWindows[i];
144
- if (!win.hidden) {
145
- return win.windowName === currentWindow?.windowName;
146
- }
147
- }
148
- return false;
149
- }
@@ -14,10 +14,6 @@
14
14
  color: $text-02;
15
15
  }
16
16
 
17
- &:focus {
18
- border-color: $interactive-01;
19
- }
20
-
21
17
  & > span {
22
18
  margin-top: layout.$spacing-02;
23
19
  @include type.type-style('body-compact-01');
@@ -63,11 +59,6 @@
63
59
  @include brand-03(border-color);
64
60
  border-radius: 50%;
65
61
  background-color: $ui-02;
66
-
67
- &.focused {
68
- border-color: var(--brand-03) !important;
69
- box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--brand-03) 80%, black 20%) !important;
70
- }
71
62
  }
72
63
 
73
64
  .container {
@@ -77,6 +77,7 @@ export const Workspace2: React.FC<Workspace2Props> = ({ title, children, hasUnsa
77
77
  registeredWorkspacesByName,
78
78
  workspaceTitleByWorkspaceName,
79
79
  setWorkspaceTitle,
80
+ isMostRecentlyOpenedWindowHidden,
80
81
  } = useWorkspace2Store();
81
82
  const { workspaceName, isRootWorkspace, closeWorkspace } = useWorkspace2Context();
82
83
 
@@ -122,6 +123,8 @@ export const Workspace2: React.FC<Workspace2Props> = ({ title, children, hasUnsa
122
123
  (window) => window.group === openedGroup.groupName && window.icon !== undefined,
123
124
  );
124
125
 
126
+ const isWindowHidden = openedWindowIndex < openedWindows.length - 1 || isMostRecentlyOpenedWindowHidden;
127
+
125
128
  return (
126
129
  <div
127
130
  className={classNames(styles.workspaceOuterContainer, {
@@ -133,20 +136,20 @@ export const Workspace2: React.FC<Workspace2Props> = ({ title, children, hasUnsa
133
136
  >
134
137
  <div
135
138
  className={classNames(styles.workspaceSpacer, {
136
- [styles.hidden]: openedWindow.hidden,
139
+ [styles.hidden]: isWindowHidden,
137
140
  })}
138
141
  />
139
142
  <div
140
143
  className={classNames(styles.workspaceMiddleContainer, {
141
144
  [styles.maximized]: maximized,
142
- [styles.hidden]: openedWindow.hidden,
145
+ [styles.hidden]: isWindowHidden,
143
146
  [styles.isRootWorkspace]: isRootWorkspace,
144
147
  })}
145
148
  >
146
149
  <div
147
150
  className={classNames(styles.workspaceInnerContainer, {
148
151
  [styles.maximized]: maximized,
149
- [styles.hidden]: openedWindow.hidden,
152
+ [styles.hidden]: isWindowHidden,
150
153
  [styles.isRootWorkspace]: isRootWorkspace,
151
154
  })}
152
155
  >
@@ -166,10 +169,7 @@ export const Workspace2: React.FC<Workspace2Props> = ({ title, children, hasUnsa
166
169
  </HeaderGlobalAction>
167
170
  )}
168
171
  {canHide ? (
169
- <HeaderGlobalAction
170
- aria-label={getCoreTranslation('hide')}
171
- onClick={() => hideWindow(windowName)}
172
- >
172
+ <HeaderGlobalAction aria-label={getCoreTranslation('hide')} onClick={() => hideWindow()}>
173
173
  <ArrowRightIcon />
174
174
  </HeaderGlobalAction>
175
175
  ) : (
@@ -184,10 +184,7 @@ export const Workspace2: React.FC<Workspace2Props> = ({ title, children, hasUnsa
184
184
  ) : (
185
185
  <>
186
186
  {canHide && (
187
- <HeaderGlobalAction
188
- aria-label={getCoreTranslation('hide')}
189
- onClick={() => hideWindow(windowName)}
190
- >
187
+ <HeaderGlobalAction aria-label={getCoreTranslation('hide')} onClick={() => hideWindow()}>
191
188
  <DownToBottom />
192
189
  </HeaderGlobalAction>
193
190
  )}
@@ -35,11 +35,6 @@ $extraWideWorkspaceWidth: 48.25rem;
35
35
  bottom: 0;
36
36
  inset-inline-end: var(--actionPanelOffset);
37
37
  z-index: 100;
38
- will-change: transform;
39
-
40
- &.isRootWorkspace {
41
- animation: slideFromRight 0.5s ease-in-out;
42
- }
43
38
 
44
39
  &.maximized {
45
40
  position: fixed !important;
@@ -55,20 +50,10 @@ $extraWideWorkspaceWidth: 48.25rem;
55
50
  &.hidden {
56
51
  width: 0;
57
52
  }
58
-
59
- @keyframes slideFromRight {
60
- from {
61
- transform: translateX(100%);
62
- }
63
- to {
64
- transform: translateX(0);
65
- }
66
- }
67
53
  }
68
54
 
69
55
  // This container contains the actual workspace content
70
- // it has sliding transitions when hidden / restored, and
71
- // changes size (width) when maximized
56
+ // and changes size (width) when maximized
72
57
  .workspaceInnerContainer {
73
58
  display: flex;
74
59
  flex-direction: column;
@@ -93,29 +78,9 @@ $extraWideWorkspaceWidth: 48.25rem;
93
78
  .workspaceSpacer {
94
79
  width: inherit;
95
80
  height: 100%;
96
- will-change: width;
97
- animation: growToWidth 0.5s ease-in-out;
98
81
 
99
82
  &.hidden {
100
- animation: shrinkWidth 0.5s ease-in-out forwards;
101
- }
102
-
103
- @keyframes growToWidth {
104
- from {
105
- width: 0;
106
- }
107
- to {
108
- width: inherit;
109
- }
110
- }
111
-
112
- @keyframes shrinkWidth {
113
- from {
114
- width: inherit;
115
- }
116
- to {
117
- width: 0;
118
- }
83
+ width: 0;
119
84
  }
120
85
  }
121
86
  }
@@ -214,35 +179,11 @@ $extraWideWorkspaceWidth: 48.25rem;
214
179
 
215
180
  .workspaceInnerContainer {
216
181
  width: 100vw !important;
217
-
218
- &.isRootWorkspace {
219
- animation: slideFromBottom 0.5s ease-in-out;
220
- }
221
182
  }
222
183
 
223
184
  .marginWorkspaceContent {
224
185
  margin-bottom: var(--bottom-nav-height);
225
186
  }
226
-
227
- @keyframes slideFromBottom {
228
- from {
229
- transform: translateY(100%);
230
- }
231
- to {
232
- transform: translateY(0%);
233
- }
234
- }
235
-
236
- @keyframes slideToBottom {
237
- from {
238
- transform: translateX(0%);
239
- width: $narrowWorkspaceWidth;
240
- }
241
- to {
242
- transform: translateX($narrowWorkspaceWidth);
243
- width: 0;
244
- }
245
- }
246
187
  }
247
188
 
248
189
  // Overriding styles for RTL support
@@ -182,9 +182,9 @@ export async function launchWorkspace2<
182
182
  openedWorkspaces: [newOpenedWorkspace(workspaceName, workspaceProps)], // root workspace at index 0
183
183
  props: windowProps,
184
184
  maximized: false,
185
- hidden: false,
186
185
  },
187
186
  ],
187
+ isMostRecentlyOpenedWindowHidden: false,
188
188
  });
189
189
  return true;
190
190
  } else {
@@ -193,6 +193,7 @@ export async function launchWorkspace2<
193
193
  } else if (isWindowAlreadyOpened) {
194
194
  const openedWindow = storeState.openedWindows[openedWindowIndex];
195
195
  const groupProps = storeState.openedGroup?.props ?? {};
196
+ const isMostRecentlyOpenedWindowHidden = storeState.isMostRecentlyOpenedWindowHidden;
196
197
  const { openedWorkspaces } = openedWindow;
197
198
 
198
199
  if (arePropsCompatible(openedWindow.props, windowProps)) {
@@ -204,7 +205,7 @@ export async function launchWorkspace2<
204
205
  const openedWorkspace = openedWorkspaces.find((w) => w.workspaceName === workspaceName);
205
206
  if (openedWorkspace && arePropsCompatible(openedWorkspace.props, workspaceProps)) {
206
207
  // restore the window if it is hidden or not the most recently opened one
207
- if (openedWindow.hidden || openedWindowIndex !== storeState.openedWindows.length - 1) {
208
+ if (isMostRecentlyOpenedWindowHidden || openedWindowIndex !== storeState.openedWindows.length - 1) {
208
209
  workspace2Store.setState(workspace2StoreActions.restoreWindow(storeState, windowName));
209
210
  }
210
211
  return true;
@@ -230,9 +231,9 @@ export async function launchWorkspace2<
230
231
  openedWorkspaces: [newOpenedWorkspace(workspaceName, workspaceProps)],
231
232
  props: openedWindow?.props ?? windowProps,
232
233
  maximized: false,
233
- hidden: false,
234
234
  },
235
235
  ],
236
+ isMostRecentlyOpenedWindowHidden: false,
236
237
  });
237
238
  return true;
238
239
  } else {
@@ -262,9 +263,9 @@ export async function launchWorkspace2<
262
263
  openedWorkspaces: [newOpenedWorkspace(workspaceName, workspaceProps)],
263
264
  props: windowProps,
264
265
  maximized: false,
265
- hidden: false,
266
266
  },
267
267
  ],
268
+ isMostRecentlyOpenedWindowHidden: false,
268
269
  });
269
270
  return true;
270
271
  } else {
@@ -286,9 +287,9 @@ export async function launchWorkspace2<
286
287
  openedWorkspaces: [newOpenedWorkspace(workspaceName, workspaceProps)], // root workspace at index 0
287
288
  props: windowProps,
288
289
  maximized: false,
289
- hidden: false,
290
290
  },
291
291
  ],
292
+ isMostRecentlyOpenedWindowHidden: false,
292
293
  });
293
294
  return true;
294
295
  }
@@ -407,25 +408,21 @@ const workspace2StoreActions = {
407
408
  openedWindows,
408
409
  };
409
410
  },
410
- hideWindow(state: WorkspaceStoreState2, windowName: string) {
411
- const openedWindowIndex = state.openedWindows.findIndex((a) => a.windowName === windowName);
412
- const openedWindows = [...state.openedWindows];
413
- const currentWindow = { ...openedWindows[openedWindowIndex], hidden: true };
414
-
415
- openedWindows[openedWindowIndex] = currentWindow;
416
-
411
+ // hides the most recently opened window (all other opened windows are implicitly hidden)
412
+ hideWindow(state: WorkspaceStoreState2) {
417
413
  return {
418
414
  ...state,
419
- openedWindows,
415
+ isMostRecentlyOpenedWindowHidden: true,
420
416
  };
421
417
  },
422
418
  restoreWindow(state: WorkspaceStoreState2, windowName: string) {
423
419
  const openedWindowIndex = state.openedWindows.findIndex((a) => a.windowName === windowName);
424
- const currentWindow = { ...state.openedWindows[openedWindowIndex], hidden: false };
420
+ const currentWindow = state.openedWindows[openedWindowIndex];
425
421
  const openedWindows = [...state.openedWindows.filter((_, i) => i !== openedWindowIndex), currentWindow];
426
422
  return {
427
423
  ...state,
428
424
  openedWindows,
425
+ isMostRecentlyOpenedWindowHidden: false,
429
426
  };
430
427
  },
431
428
  closeWorkspace(state, workspaceName: string) {
@@ -440,9 +437,16 @@ const workspace2StoreActions = {
440
437
  // close all children of the input workspace as well
441
438
  window.openedWorkspaces = window.openedWorkspaces.slice(0, workspaceIndex);
442
439
 
440
+ let hidden = state.isMostRecentlyOpenedWindowHidden;
443
441
  if (window.openedWorkspaces.length === 0) {
442
+ const wasMostRecentWindow = openedWindowIndex === state.openedWindows.length - 1;
444
443
  // if no workspaces left, remove the window
445
444
  openedWindows.splice(openedWindowIndex, 1);
445
+ // If we removed the most recent window and there are still windows left,
446
+ // the new most recent window should be shown
447
+ if (wasMostRecentWindow && openedWindows.length > 0) {
448
+ hidden = false;
449
+ }
446
450
  } else {
447
451
  // if there are still workspaces left, just update the window
448
452
  openedWindows[openedWindowIndex] = window;
@@ -451,6 +455,7 @@ const workspace2StoreActions = {
451
455
  return {
452
456
  ...state,
453
457
  openedWindows,
458
+ isMostRecentlyOpenedWindowHidden: hidden,
454
459
  };
455
460
  },
456
461
  openChildWorkspace(