@linzjs/windows 1.0.0 → 1.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.
Files changed (38) hide show
  1. package/.storybook/main.ts +26 -6
  2. package/README.md +129 -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,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
  };