@linzjs/windows 8.0.0 → 8.1.0

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.
@@ -9,11 +9,11 @@ interface OpenPanelButtonProps extends OpenPanelOptions {
9
9
  }
10
10
 
11
11
  export const OpenPanelButton = ({ buttonText, uniqueId = buttonText, ...openPanelOptions }: OpenPanelButtonProps) => {
12
- const { openPanel, openPanels } = useContext(PanelsContext);
12
+ const { openPanel, hasOpenPanel } = useContext(PanelsContext);
13
13
 
14
14
  return (
15
15
  <button onClick={() => openPanel({ uniqueId, ...openPanelOptions })}>
16
- Show {buttonText} {openPanels.has(buttonText) ? '(Open)' : ''}
16
+ Show {buttonText} {hasOpenPanel(buttonText) ? '(Open)' : ''}
17
17
  </button>
18
18
  );
19
19
  };
@@ -21,6 +21,7 @@ export interface OpenPanelOptions {
21
21
 
22
22
  export interface PanelsContextType {
23
23
  openPanels: Set<string>;
24
+ hasOpenPanel: (panelId: string) => boolean;
24
25
  // returns unique id of panel that was created/or arleady found, otherwise null on error.
25
26
  openPanel: (args: OpenPanelOptions) => string | null;
26
27
  closePanel: (uniqueId: string) => void;
@@ -38,6 +39,7 @@ const NoContext = <T,>(): T => {
38
39
 
39
40
  export const PanelsContext = createContext<PanelsContextType>({
40
41
  openPanels: new Set(),
42
+ hasOpenPanel: () => false,
41
43
  openPanel: NoContext,
42
44
  closePanel: NoContext,
43
45
  bringPanelToFront: NoContext,
@@ -105,9 +105,9 @@ export const PanelsContextProvider = ({
105
105
  [baseZIndex, bringPanelToFront, panelInstances],
106
106
  );
107
107
 
108
- const closePanel = useCallback(
109
- (closePanelUniqueIds: string | string[]) => {
110
- const panelNames = castArray(closePanelUniqueIds);
108
+ const closePanel = useCallback((closePanelUniqueIds: string | string[]) => {
109
+ const panelNames = castArray(closePanelUniqueIds);
110
+ setPanelInstances((panelInstances) => {
111
111
  const [closedPanelInstances, stillOpenPanelInstances] = partition(panelInstances, (pi) =>
112
112
  panelNames.includes(pi.uniqueId),
113
113
  );
@@ -115,11 +115,11 @@ export const PanelsContextProvider = ({
115
115
  closedPanelInstances.forEach(({ onClose }) => {
116
116
  onClose?.();
117
117
  });
118
- setPanelInstances(stillOpenPanelInstances);
118
+ return stillOpenPanelInstances;
119
119
  }
120
- },
121
- [panelInstances],
122
- );
120
+ return panelInstances;
121
+ });
122
+ }, []);
123
123
 
124
124
  /**
125
125
  * It's not easy to tell the difference between a window closing and a window popping in via events,
@@ -144,10 +144,13 @@ export const PanelsContextProvider = ({
144
144
 
145
145
  const openPanels = useMemo(() => new Set(panelInstances.map((pi) => pi.uniqueId)), [panelInstances]);
146
146
 
147
+ const hasOpenPanel = useCallback((panelId: string): boolean => openPanels.has(panelId), [openPanels]);
148
+
147
149
  return (
148
150
  <PanelsContext.Provider
149
151
  value={{
150
152
  openPanels,
153
+ hasOpenPanel,
151
154
  openPanel,
152
155
  closePanel,
153
156
  bringPanelToFront,
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "popout"
14
14
  ],
15
15
  "main": "./dist/index.ts",
16
- "version": "8.0.0",
16
+ "version": "8.1.0",
17
17
  "peerDependencies": {
18
18
  "@linzjs/lui": ">=21",
19
19
  "lodash-es": ">=4",