@linzjs/windows 1.0.0 → 1.1.1

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.
Files changed (38) hide show
  1. package/.storybook/main.ts +26 -6
  2. package/README.md +32 -6
  3. package/package.json +34 -12
  4. package/src/modal/Modal.tsx +9 -5
  5. package/src/modal/ModalContextProvider.tsx +35 -36
  6. package/src/modal/PreModal.tsx +45 -0
  7. package/src/panel/OpenPanelButton.tsx +18 -0
  8. package/src/panel/OpenPanelIcon.scss +73 -0
  9. package/src/panel/OpenPanelIcon.tsx +50 -0
  10. package/src/panel/Panel.scss +34 -0
  11. package/src/panel/Panel.tsx +150 -0
  12. package/src/panel/PanelContext.ts +17 -0
  13. package/src/panel/PanelInstanceContext.ts +41 -0
  14. package/src/panel/PanelInstanceContextProvider.tsx +47 -0
  15. package/src/panel/PanelsContext.tsx +36 -0
  16. package/src/panel/PanelsContextProvider.tsx +140 -0
  17. package/src/panel/PopoutWindow.tsx +183 -0
  18. package/src/panel/generateId.ts +23 -0
  19. package/src/panel/handleStyleSheetsChanges.ts +71 -0
  20. package/src/stories/Introduction.mdx +18 -0
  21. package/src/stories/Introduction.stories.tsx +8 -0
  22. package/src/stories/modal/Modal.mdx +9 -3
  23. package/src/stories/modal/Modal.stories.tsx +1 -1
  24. package/src/stories/modal/PreModal.mdx +26 -0
  25. package/src/stories/modal/PreModal.stories.tsx +27 -0
  26. package/src/stories/modal/PreModal.tsx +79 -0
  27. package/src/stories/modal/TestModal.scss +21 -0
  28. package/src/stories/panel/PanelButtons/ShowPanel.mdx +21 -0
  29. package/src/stories/panel/PanelButtons/ShowPanel.stories.tsx +27 -0
  30. package/src/stories/panel/PanelButtons/ShowPanel.tsx +86 -0
  31. package/src/stories/panel/ShowPanel/ShowPanel.mdx +20 -0
  32. package/src/stories/panel/ShowPanel/ShowPanel.stories.tsx +27 -0
  33. package/src/stories/panel/ShowPanel/ShowPanel.tsx +70 -0
  34. package/src/stories/panel/ShowPanelResizingAgGrid/ShowPanelResizingAgGrid.mdx +21 -0
  35. package/src/stories/panel/ShowPanelResizingAgGrid/ShowPanelResizingAgGrid.stories.tsx +27 -0
  36. package/src/stories/panel/ShowPanelResizingAgGrid/ShowPanelResizingStepAgGrid.tsx +164 -0
  37. package/src/stories/support.js +16 -0
  38. package/src/util/useInterval.ts +11 -19
@@ -0,0 +1,79 @@
1
+ import "./TestModal.scss";
2
+ import "@linzjs/lui/dist/scss/base.scss";
3
+
4
+ import { ModalContextProvider } from "../../modal/ModalContextProvider";
5
+ import { PreModal } from "../../modal/PreModal";
6
+ import { useShowModal } from "../../modal/useShowModal";
7
+
8
+ // #Example: Modal Context Provider
9
+ // Don't forget to add a ModalContextProvider at the root of your project
10
+ export const App = () => (
11
+ <ModalContextProvider>
12
+ <div>...the rest of your app...</div>
13
+ </ModalContextProvider>
14
+ );
15
+
16
+ // #Example: PreModal Invocation
17
+ export const PreModalUsage = () => {
18
+ // showModal to show modal, modalOwnerRef is only required if you have popout windows
19
+ const { showModal, modalOwnerRef } = useShowModal();
20
+
21
+ const showWarningModal = async () => {
22
+ const result = await showModal(PreModal, {
23
+ level: "warning",
24
+ children: (
25
+ <>
26
+ <h2>You are about to make changes</h2>
27
+ <p>Are you sure that you want to make these changes?</p>
28
+ </>
29
+ ),
30
+ });
31
+ alert(`Modal result is: ${result}`);
32
+ };
33
+
34
+ const showInfoModal = async () => {
35
+ await showModal(PreModal, {
36
+ level: "info",
37
+ children: (
38
+ <>
39
+ <h2>You are a fantastic person</h2>
40
+ <p>Keep it up!</p>
41
+ </>
42
+ ),
43
+ });
44
+ };
45
+
46
+ const showErrorModal = async () => {
47
+ await showModal(PreModal, {
48
+ level: "error",
49
+ children: (
50
+ <>
51
+ <h2>Something is not right</h2>
52
+ <p>Maybe stop doing that</p>
53
+ </>
54
+ ),
55
+ });
56
+ };
57
+
58
+ const showSuccessModal = async () => {
59
+ await showModal(PreModal, {
60
+ level: "success",
61
+ children: (
62
+ <>
63
+ <h2>You are a success</h2>
64
+ <p>Keep succeeding!</p>
65
+ </>
66
+ ),
67
+ });
68
+ };
69
+
70
+ // Remember to add the modalOwnerRef!
71
+ return (
72
+ <div ref={modalOwnerRef}>
73
+ <button onClick={showWarningModal}>Show Warning Bi-Modal</button>{" "}
74
+ <button onClick={showInfoModal}>Show Info Bi-Modal</button>{" "}
75
+ <button onClick={showErrorModal}>Show Error Bi-Modal</button>{" "}
76
+ <button onClick={showSuccessModal}>Show Success Bi-Modal</button>
77
+ </div>
78
+ );
79
+ };
@@ -1,3 +1,6 @@
1
+ @use "node_modules/@linzjs/lui/dist/scss/Core" as lui;
2
+ @use "node_modules/@linzjs/lui/dist/scss/Foundation/Variables/ColorVars.scss" as colours;
3
+
1
4
  dialog > div {
2
5
  padding: 20px;
3
6
  display: flex;
@@ -12,4 +15,22 @@ dialog > div {
12
15
  button {
13
16
  flex: 1;
14
17
  }
18
+ }
19
+
20
+ .lui-modal {
21
+ margin: 0 !important;
22
+ }
23
+
24
+ button:focus {
25
+ outline: 2px solid colours.$brand-primary;
26
+ // make sure the button sits above the others so the outline is not cut off on focus
27
+ position: relative;
28
+ }
29
+
30
+ dialog::backdrop {
31
+ background: rgba(0,0,0,0.6);
32
+ }
33
+
34
+ dialog {
35
+ border: none;
15
36
  }
@@ -0,0 +1,21 @@
1
+ import {getBlocks, blockToString} from "../../support.js";
2
+ import {Meta, Source, Story} from "@storybook/blocks";
3
+ import * as ShowPanelStories from "./ShowPanel.stories"
4
+
5
+ import myModule from './ShowPanel.tsx?raw';
6
+
7
+ <Meta name="Buttons" of={ShowPanelStories}/>
8
+ # Show Panel
9
+ ## Example
10
+ Click to show the panel:
11
+ <Story of={ShowPanelStories.ShowPanel}/>
12
+
13
+ ## Code
14
+ <br/>
15
+ {getBlocks(myModule).map(block => (
16
+ <>
17
+ <h3>{block.split("\n")[0]}</h3>
18
+ <Source code={blockToString(block)} language='typescript'/>
19
+ </>
20
+ ))}
21
+
@@ -0,0 +1,27 @@
1
+ import { PanelsContextProvider } from "../../../panel/PanelsContextProvider";
2
+ import { TestShowPanelButtons } from "./ShowPanel";
3
+ import type { Meta, StoryObj } from "@storybook/react";
4
+
5
+ const meta: Meta<typeof TestShowPanelButtons> = {
6
+ title: "Components/PanelButtons",
7
+ component: TestShowPanelButtons,
8
+ argTypes: {
9
+ backgroundColor: { control: "color" },
10
+ },
11
+ decorators: [
12
+ (Story: any) => (
13
+ <div>
14
+ <PanelsContextProvider baseZIndex={500}>
15
+ <Story />
16
+ </PanelsContextProvider>
17
+ </div>
18
+ ),
19
+ ],
20
+ };
21
+
22
+ export default meta;
23
+ type Story = StoryObj<typeof meta>;
24
+
25
+ export const ShowPanel: Story = {
26
+ args: {},
27
+ };
@@ -0,0 +1,86 @@
1
+ import "@linzjs/lui/dist/scss/base.scss";
2
+
3
+ import { OpenPanelButton } from "../../../panel/OpenPanelButton";
4
+ import {
5
+ ButtonIconHorizontalGroup,
6
+ ButtonIconSeparator,
7
+ ButtonIconVerticalGroup,
8
+ OpenPanelIcon,
9
+ } from "../../../panel/OpenPanelIcon";
10
+ import { Panel, PanelContent, PanelHeader } from "../../../panel/Panel";
11
+
12
+ /* exclude */
13
+ export interface ShowPanelProps {
14
+ data: number;
15
+ }
16
+
17
+ export const ShowPanel = ({ data }: ShowPanelProps) => {
18
+ return (
19
+ <Panel title={`Panel demo ${data}`} size={{ width: 640, height: 400 }}>
20
+ <PanelHeader />
21
+ <PanelContent>
22
+ <PanelContents />
23
+ </PanelContent>
24
+ </Panel>
25
+ );
26
+ };
27
+
28
+ export const PanelContents = () => {
29
+ return (
30
+ <table>
31
+ <thead>
32
+ <tr>
33
+ <th>Owner</th>
34
+ <th>Title</th>
35
+ <th>Address</th>
36
+ </tr>
37
+ </thead>
38
+ <tbody>
39
+ <tr>
40
+ <td>Roy</td>
41
+ <td>OT10A/1011</td>
42
+ <td>5 Grange St, Auckland</td>
43
+ </tr>
44
+ <tr>
45
+ <td>Ryan</td>
46
+ <td>OT10A/154</td>
47
+ <td>145 Garry St, Wellington</td>
48
+ </tr>
49
+ <tr>
50
+ <td>Suzy</td>
51
+ <td>OT10A/155</td>
52
+ <td>15 Aix St, Auckland</td>
53
+ </tr>
54
+ </tbody>
55
+ </table>
56
+ );
57
+ };
58
+ /* exclude */
59
+
60
+ // #Example: Show Panel Buttons
61
+ export const TestShowPanelButtons = () => (
62
+ <>
63
+ <div>
64
+ <OpenPanelButton buttonText={"Panel name 1"} component={() => <ShowPanel data={1} />} />{" "}
65
+ <OpenPanelButton buttonText={"Panel name 2"} component={() => <ShowPanel data={2} />} />
66
+ </div>
67
+ <br />
68
+ <ButtonIconHorizontalGroup>
69
+ <OpenPanelIcon iconTitle={"Marks"} icon={"ic_marks"} component={() => <ShowPanel data={1} />} />
70
+ <ButtonIconSeparator />
71
+ <OpenPanelIcon iconTitle={"Vectors"} icon={"ic_line_irregular"} component={() => <ShowPanel data={2} />} />
72
+ </ButtonIconHorizontalGroup>
73
+ <br />
74
+ <br />
75
+ <ButtonIconVerticalGroup>
76
+ <OpenPanelIcon iconTitle={"Marks"} icon={"ic_marks"} component={() => <ShowPanel data={1} />} />
77
+ <ButtonIconSeparator />
78
+ <OpenPanelIcon iconTitle={"Vectors"} icon={"ic_timeline"} component={() => <ShowPanel data={2} />} />
79
+ <OpenPanelIcon
80
+ iconTitle={"Irregular lines"}
81
+ icon={"ic_line_irregular"}
82
+ component={() => <ShowPanel data={3} />}
83
+ />
84
+ </ButtonIconVerticalGroup>
85
+ </>
86
+ );
@@ -0,0 +1,20 @@
1
+ import {getBlocks, blockToString} from "../../support.js";
2
+ import {Meta, Source, Story} from "@storybook/blocks";
3
+ import * as ShowPanelStories from "./ShowPanel.stories.tsx"
4
+
5
+ import myModule from './ShowPanel.tsx?raw';
6
+
7
+ <Meta name="Show" of={ShowPanelStories}/>
8
+ # Show Panel
9
+ ## Example
10
+ Click to show the panel:
11
+ <Story of={ShowPanelStories.ShowPanel}/>
12
+
13
+ ## Code
14
+ <br/>
15
+ {getBlocks(myModule).map(block => (
16
+ <>
17
+ <h3>{block.split("\n")[0]}</h3>
18
+ <Source code={blockToString(block)} language='typescript'/>
19
+ </>
20
+ ))}
@@ -0,0 +1,27 @@
1
+ import { PanelsContextProvider } from "../../../panel/PanelsContextProvider";
2
+ import { TestShowPanel } from "./ShowPanel";
3
+ import type { Meta, StoryObj } from "@storybook/react";
4
+
5
+ const meta: Meta<typeof TestShowPanel> = {
6
+ title: "Components/Panel",
7
+ component: TestShowPanel,
8
+ argTypes: {
9
+ backgroundColor: { control: "color" },
10
+ },
11
+ decorators: [
12
+ (Story: any) => (
13
+ <div>
14
+ <PanelsContextProvider baseZIndex={500}>
15
+ <Story />
16
+ </PanelsContextProvider>
17
+ </div>
18
+ ),
19
+ ],
20
+ };
21
+
22
+ export default meta;
23
+ type Story = StoryObj<typeof meta>;
24
+
25
+ export const ShowPanel: Story = {
26
+ args: {},
27
+ };
@@ -0,0 +1,70 @@
1
+ import "@linzjs/lui/dist/scss/base.scss";
2
+
3
+ import { OpenPanelButton } from "../../../panel/OpenPanelButton";
4
+ import { Panel, PanelContent, PanelHeader } from "../../../panel/Panel";
5
+ import { PanelsContextProvider } from "../../../panel/PanelsContextProvider";
6
+
7
+ // #Example: Panel Context Provider
8
+ // Don't forget to add a PanelContextProvider at the root of your project
9
+ export const App = () => (
10
+ <PanelsContextProvider baseZIndex={500}>
11
+ <div>...the rest of your app...</div>
12
+ </PanelsContextProvider>
13
+ );
14
+
15
+ // #Example: Panel Component
16
+ export interface ShowPanelComponentProps {
17
+ data: number;
18
+ }
19
+
20
+ export const ShowPanelComponent = ({ data }: ShowPanelComponentProps) => (
21
+ <Panel title={`Panel demo ${data}`} size={{ width: 640, height: 400 }}>
22
+ <PanelHeader />
23
+ <PanelContent>
24
+ <PanelContents />
25
+ </PanelContent>
26
+ </Panel>
27
+ );
28
+
29
+ /* exclude */
30
+ export const PanelContents = () => {
31
+ return (
32
+ <table>
33
+ <thead>
34
+ <tr>
35
+ <th>Owner</th>
36
+ <th>Title</th>
37
+ <th>Address</th>
38
+ </tr>
39
+ </thead>
40
+ <tbody>
41
+ <tr>
42
+ <td>Roy</td>
43
+ <td>OT10A/1011</td>
44
+ <td>5 Grange St, Auckland</td>
45
+ </tr>
46
+ <tr>
47
+ <td>Ryan</td>
48
+ <td>OT10A/154</td>
49
+ <td>145 Garry St, Wellington</td>
50
+ </tr>
51
+ <tr>
52
+ <td>Suzy</td>
53
+ <td>OT10A/155</td>
54
+ <td>15 Aix St, Auckland</td>
55
+ </tr>
56
+ </tbody>
57
+ </table>
58
+ );
59
+ };
60
+ /* exclude */
61
+
62
+ // #Example: Panel Invocation
63
+ export const TestShowPanel = () => {
64
+ return (
65
+ <>
66
+ <OpenPanelButton buttonText={"TestPanel 1"} component={() => <ShowPanelComponent data={1} />} />{" "}
67
+ <OpenPanelButton buttonText={"TestPanel 2"} component={() => <ShowPanelComponent data={2} />} />
68
+ </>
69
+ );
70
+ };
@@ -0,0 +1,21 @@
1
+ import {getBlocks, blockToString} from "../../support.js";
2
+ import {Meta, Source, Story} from "@storybook/blocks";
3
+ import * as PanelStories from "./ShowPanelResizingAgGrid.stories.tsx"
4
+
5
+ import myModule from './ShowPanelResizingStepAgGrid.tsx?raw';
6
+
7
+ <Meta name="Show Resizing step-ag-grid" of={PanelStories}/>
8
+ # Show Panel
9
+ ## Example
10
+ Click to show the panel:
11
+ <Story of={PanelStories.PanelResizing}/>
12
+
13
+ ## Code
14
+ <br/>
15
+ {getBlocks(myModule).map(block => (
16
+ <>
17
+ <h3>{block.split("\n")[0]}</h3>
18
+ <Source code={blockToString(block)} language='typescript'/>
19
+ </>
20
+ ))}
21
+
@@ -0,0 +1,27 @@
1
+ import { PanelsContextProvider } from "../../../panel/PanelsContextProvider";
2
+ import { TestShowPanelResizingAgGrid } from "./ShowPanelResizingStepAgGrid";
3
+ import type { Meta, StoryObj } from "@storybook/react";
4
+
5
+ const meta: Meta<typeof TestShowPanelResizingAgGrid> = {
6
+ title: "Components/Panel",
7
+ component: TestShowPanelResizingAgGrid,
8
+ argTypes: {
9
+ backgroundColor: { control: "color" },
10
+ },
11
+ decorators: [
12
+ (Story: any) => (
13
+ <div>
14
+ <PanelsContextProvider baseZIndex={500}>
15
+ <Story />
16
+ </PanelsContextProvider>
17
+ </div>
18
+ ),
19
+ ],
20
+ };
21
+
22
+ export default meta;
23
+ type Story = StoryObj<typeof meta>;
24
+
25
+ export const PanelResizing: Story = {
26
+ args: {},
27
+ };
@@ -0,0 +1,164 @@
1
+ import "@linzjs/lui/dist/scss/base.scss";
2
+ import "@linzjs/step-ag-grid/dist/GridTheme.scss";
3
+ import "@linzjs/step-ag-grid/dist/index.css";
4
+
5
+ import { OpenPanelButton } from "../../../panel/OpenPanelButton";
6
+ import { Panel, PanelContent, PanelHeader } from "../../../panel/Panel";
7
+ import { PanelContext } from "../../../panel/PanelContext";
8
+ import { PanelsContextProvider } from "../../../panel/PanelsContextProvider";
9
+ import { useContext, useMemo, useState } from "react";
10
+
11
+ import {
12
+ ColDefT,
13
+ Grid,
14
+ GridCell,
15
+ GridContextProvider,
16
+ GridIcon,
17
+ GridPopoverMenu,
18
+ GridPopoverMessage,
19
+ GridUpdatingContextProvider,
20
+ GridWrapper,
21
+ } from "@linzjs/step-ag-grid";
22
+
23
+ // #Example: Panel Context Provider
24
+ // Don't forget to add a PanelContextProvider at the root of your project
25
+ export const App = () => (
26
+ <PanelsContextProvider baseZIndex={500}>
27
+ <div>...the rest of your app...</div>
28
+ </PanelsContextProvider>
29
+ );
30
+
31
+ // #Example: Panel Component
32
+ export interface TestPanelProps {
33
+ data: number;
34
+ }
35
+
36
+ export const TestPanelResizing = ({ data }: TestPanelProps) => {
37
+ return (
38
+ <Panel title={`Panel resizing demo ${data}`} size={{ width: 320, height: 400 }}>
39
+ <PanelHeader />
40
+ <PanelContent>
41
+ <PanelContentsWithResize />
42
+ </PanelContent>
43
+ </Panel>
44
+ );
45
+ };
46
+
47
+ // #Example: Panel Invocation
48
+ export const TestShowPanelResizingAgGrid = () => (
49
+ <>
50
+ <OpenPanelButton buttonText={"TestPanel resizing 1"} component={() => <TestPanelResizing data={1} />} />{" "}
51
+ <OpenPanelButton buttonText={"TestPanel resizing 2"} component={() => <TestPanelResizing data={2} />} />
52
+ </>
53
+ );
54
+
55
+ /* exclude */
56
+ interface ITestRow {
57
+ id: number;
58
+ position: string;
59
+ age: number;
60
+ desc: string;
61
+ dd: string;
62
+ }
63
+
64
+ /* exclude */
65
+
66
+ // #Example: Resizing panel to content after load
67
+ // Note: Resize can only be used from within the panel content.
68
+ export const PanelContentsWithResize = () => {
69
+ // This is the first important bit
70
+ const { resizePanel } = useContext(PanelContext);
71
+
72
+ const columnDefs: ColDefT<ITestRow>[] = useMemo(
73
+ () => [
74
+ /* Your grid ColDefs */
75
+ /* exclude */
76
+ GridCell({
77
+ field: "id",
78
+ headerName: "Id",
79
+ lockVisible: true,
80
+ }),
81
+ GridCell({
82
+ field: "position",
83
+ headerName: "Position",
84
+ cellRendererParams: {
85
+ warning: (props) => props.value === "Tester" && "Testers are testing",
86
+ info: (props) => props.value === "Developer" && "Developers are awesome",
87
+ },
88
+ }),
89
+ GridCell({
90
+ field: "age",
91
+ headerName: "Age",
92
+ }),
93
+ GridCell({
94
+ field: "desc",
95
+ headerName: "Description",
96
+ flex: 1,
97
+ }),
98
+ GridPopoverMessage(
99
+ {
100
+ headerName: "Popout message",
101
+ cellRenderer: () => <>Single Click me!</>,
102
+ exportable: false,
103
+ },
104
+ {
105
+ multiEdit: true,
106
+ editorParams: {
107
+ message: async (selectedRows): Promise<string> => {
108
+ return `There are ${selectedRows.length} row(s) selected`;
109
+ },
110
+ },
111
+ },
112
+ ),
113
+ GridCell({
114
+ headerName: "Custom edit",
115
+ editable: true,
116
+ valueFormatter: () => "Press E",
117
+ cellRendererParams: {
118
+ rightHoverElement: (
119
+ <GridIcon icon={"ic_launch_modal"} title={"Title text"} className={"GridCell-editableIcon"} />
120
+ ),
121
+ editAction: (selectedRows) => {
122
+ alert(`Custom edit ${selectedRows.map((r) => r.id)} rowId(s) selected`);
123
+ },
124
+ shortcutKeys: {
125
+ e: () => {
126
+ alert("Hi");
127
+ },
128
+ },
129
+ },
130
+ }),
131
+ GridPopoverMenu(
132
+ {},
133
+ {
134
+ multiEdit: true,
135
+ editorParams: {
136
+ options: async () => [],
137
+ },
138
+ },
139
+ ),
140
+ /* exclude */
141
+ ],
142
+ [],
143
+ );
144
+
145
+ const [rowData] = useState([
146
+ /* Your grid row data */
147
+ /* exclude */
148
+ { id: 1000, position: "Tester", age: 30, desc: "Tests application", dd: "1" },
149
+ { id: 1001, position: "Developer", age: 12, desc: "Develops application", dd: "2" },
150
+ { id: 1002, position: "Manager", age: 65, desc: "Manages", dd: "3" },
151
+ /* exclude */
152
+ ]);
153
+
154
+ return (
155
+ <GridUpdatingContextProvider>
156
+ <GridContextProvider>
157
+ <GridWrapper>
158
+ {/* onContentSize={resizePanel} does the resize on a callback */}
159
+ <Grid columnDefs={columnDefs} rowData={rowData} onContentSize={resizePanel} />
160
+ </GridWrapper>
161
+ </GridContextProvider>
162
+ </GridUpdatingContextProvider>
163
+ );
164
+ };
@@ -0,0 +1,16 @@
1
+ export const getBlocks = (obj) => obj.toString().split("// #").splice(1);
2
+
3
+ export const blockToString = (block) => {
4
+ const result = block.split("\n").splice(1);
5
+ let inComment = false;
6
+ return result
7
+ .map((line) => {
8
+ if (line.includes("// exclude") || line.includes("/* exclude */") || line.includes("/*exclude*/")) {
9
+ inComment = !inComment;
10
+ return undefined;
11
+ }
12
+ return inComment ? undefined : line;
13
+ })
14
+ .filter((l) => l)
15
+ .join("\n");
16
+ };
@@ -2,25 +2,17 @@ import { useEffect, useRef } from "react";
2
2
 
3
3
  type Callback = () => void | Promise<void>;
4
4
 
5
- export const useInterval = (callback: Callback, delay: number | null) => {
6
- const savedCallback = useRef(callback);
7
- const callbackInProgress = useRef(false);
8
- savedCallback.current = callback;
5
+ export const useInterval = (callback: Callback, timeoutMs: number | null) => {
6
+ const callbackRef = useRef(callback);
7
+ callbackRef.current = callback;
9
8
 
10
9
  useEffect(() => {
11
- if (delay == null) return;
12
-
13
- const id = setInterval(async () => {
14
- // Since this is an interval, then next tick could occur before the previous has finished
15
- if (!callbackInProgress.current && savedCallback.current) {
16
- callbackInProgress.current = true;
17
- try {
18
- await savedCallback.current();
19
- } finally {
20
- callbackInProgress.current = false;
21
- }
22
- }
23
- }, delay);
24
- return () => clearInterval(id);
25
- }, [delay]);
10
+ if (!timeoutMs) return;
11
+ const interval = setInterval(() => {
12
+ callbackRef.current && callbackRef.current();
13
+ }, timeoutMs);
14
+ return () => {
15
+ clearInterval(interval);
16
+ };
17
+ }, [timeoutMs]);
26
18
  };