@linzjs/windows 1.1.0 → 1.1.2

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/README.md CHANGED
@@ -33,101 +33,4 @@ yarn add @linzjs/windows
33
33
  npm run storybook
34
34
  ```
35
35
 
36
- See [Chromatic storybook](https://64a2356b80885af35510b627-gsvwsgdsde.chromatic.com/) for the best documentation.
37
-
38
- ## Examples
39
-
40
- ### Modal
41
- #### Example: Modal Context Provider
42
- Don't forget to add a ModalContextProvider at the root of your project.
43
- ```
44
- export const App = () => (
45
- <ModalContextProvider>
46
- <div>...the rest of your app...</div>
47
- </ModalContextProvider>
48
- );
49
- ```
50
-
51
- #### Example: Modal Component
52
- ```
53
- // Extend your props with ModalCallback<RESULT_TYPE> to add a return type, and enable close/resolve
54
- export interface TestModalProps extends ModalCallback<number> {
55
- text: string; // A user property
56
- }
57
-
58
- // Close and resolve will be passed to your props magically!
59
- export const TestModal = ({ text, close, resolve }: TestModalProps) => (
60
- <Modal>
61
- <div>
62
- <div>This is the modal text: '{text}'</div>
63
- <div>
64
- <button onClick={close}>Close</button>
65
- <button onClick={() => resolve(1)}>Return 1</button>
66
- </div>
67
- </div>
68
- </Modal>
69
- );
70
- ```
71
-
72
- #### Example: Modal Invocation
73
- ```
74
- export const TestModalUsage = () => {
75
- // showModal to show modal, modalOwnerRef is only required if you have popout windows
76
- const { showModal, modalOwnerRef } = useShowModal();
77
-
78
- const showModalHandler = async () => {
79
- // Show modal and await result
80
- const result = await showModal(TestModal, { text: "Text text" });
81
-
82
- // If result is undefined the modal was closed
83
- if (!result) return alert("Modal closed");
84
-
85
- // Otherwise we have a result
86
- alert(`Modal result is: ${result}`);
87
- };
88
-
89
- // Remember to add the modalOwnerRef!
90
- return (
91
- <div ref={modalOwnerRef}>
92
- <button onClick={showModalHandler}>Show modal</button>
93
- </div>
94
- );
95
- };
96
- ```
97
-
98
- ### Windows
99
- **Note:** *Windows are called Panels so as not to conflict with browser window types*
100
-
101
- ##### Example: Panel Context Provider
102
- Don't forget to add a PanelContextProvider at the root of your project.
103
- ```
104
- export const App = () => (
105
- <PanelsContextProvider baseZIndex={500}>
106
- ...the rest of your app...
107
- </PanelsContextProvider>
108
- );
109
- ```
110
-
111
- ##### Example: Panel Component
112
- ```
113
- export const TestPanel = () => {
114
- return (
115
- <Panel name={"Panel demo"} size={{ width: 640, height: 400 }}>
116
- <PanelHeader title={"Panel demo"} />
117
- <PanelContent>
118
- ...PanelContent...
119
- </PanelContent>
120
- </Panel>
121
- );
122
- };
123
- ```
124
-
125
- ##### Example: Panel Invocation
126
- ```
127
- export const TestPanelUsage = () => {
128
- const { openPanel } = useContext(PanelsContext);
129
-
130
- return <button onClick={() => openPanel(TestPanel)}>Show panel</button>;
131
- };
132
- ```
133
-
36
+ See [Chromatic storybook](https://master--64a2356b80885af35510b627.chromatic.com/) for documentation.
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "panel",
13
13
  "popout"
14
14
  ],
15
- "version": "1.1.0",
15
+ "version": "1.1.2",
16
16
  "peerDependencies": {
17
17
  "@linzjs/lui": "^17",
18
18
  "lodash-es": ">=4",
@@ -1,5 +1,6 @@
1
1
  import { Modal } from "./Modal";
2
2
  import { ModalCallback } from "./ModalContext";
3
+ import { useShowModal } from "./useShowModal";
3
4
  import { ReactElement } from "react";
4
5
 
5
6
  import { LuiAlertModalButtons, LuiButton, LuiIcon } from "@linzjs/lui";
@@ -7,7 +8,7 @@ import { IconName } from "@linzjs/lui/dist/components/LuiIcon/LuiIcon";
7
8
 
8
9
  export type WarningLevel = "success" | "info" | "warning" | "error";
9
10
 
10
- export interface PreModalProps extends ModalCallback<boolean> {
11
+ export interface PrefabModalProps extends ModalCallback<boolean> {
11
12
  level?: WarningLevel;
12
13
  children: ReactElement;
13
14
  }
@@ -24,7 +25,7 @@ export const getIconForLevel = (level: "success" | "info" | "warning" | "error")
24
25
  }
25
26
  };
26
27
 
27
- export const PreModal = ({ level = "warning", children, resolve }: PreModalProps) => {
28
+ export const PrefabModal = ({ level = "warning", children, resolve }: PrefabModalProps) => {
28
29
  const icon = getIconForLevel(level);
29
30
  return (
30
31
  <Modal>
@@ -43,3 +44,22 @@ export const PreModal = ({ level = "warning", children, resolve }: PreModalProps
43
44
  </Modal>
44
45
  );
45
46
  };
47
+
48
+ export const usePrefabModal = () => {
49
+ const { showModal, modalOwnerRef } = useShowModal();
50
+ return {
51
+ modalOwnerRef,
52
+ showPrefabModal: (level: WarningLevel, title: ReactElement | string, content: ReactElement | string) => {
53
+ const children = (
54
+ <>
55
+ {typeof title === "string" ? <h2>{title}</h2> : title}
56
+ {typeof content === "string" ? <p>{content}</p> : content}
57
+ </>
58
+ );
59
+ return showModal(PrefabModal, {
60
+ level,
61
+ children,
62
+ });
63
+ },
64
+ };
65
+ };
@@ -9,11 +9,15 @@ import { LuiIcon } from "@linzjs/lui";
9
9
  import { IconName } from "@linzjs/lui/dist/components/LuiIcon/LuiIcon";
10
10
 
11
11
  export const ButtonIconHorizontalGroup = ({ children }: { children: ReactNode }) => (
12
- <div className={"OpenPanelIcon-horizontalGroup"}>{children}</div>
12
+ <div>
13
+ <div className={"OpenPanelIcon-horizontalGroup"}>{children}</div>
14
+ </div>
13
15
  );
14
16
 
15
17
  export const ButtonIconVerticalGroup = ({ children }: { children: ReactNode }) => (
16
- <div className={"OpenPanelIcon-verticalGroup"}>{children}</div>
18
+ <div>
19
+ <div className={"OpenPanelIcon-verticalGroup"}>{children}</div>
20
+ </div>
17
21
  );
18
22
 
19
23
  export const ButtonIconSeparator = () => <div className="OpenPanelIcon-separator">&#160;</div>;
@@ -37,7 +41,7 @@ export const OpenPanelIcon = ({ iconTitle, uniqueId, icon, component, className,
37
41
  className={clsx(
38
42
  className,
39
43
  "lui-button lui-button-secondary lui-button-toolbar panel-button",
40
- openPanels.has(iconTitle) && "OpenPanelIcon-selected",
44
+ openPanels.has(id.current) && "OpenPanelIcon-selected",
41
45
  disabled && "OpenPanelIcon-disabled",
42
46
  )}
43
47
  title={iconTitle}
@@ -1,14 +1,14 @@
1
1
  import {getBlocks, blockToString} from "../support";
2
2
  import {Meta, Source, Story} from "@storybook/blocks";
3
- import * as PreModalStories from "./PreModal.stories"
3
+ import * as PrefabModalStories from "./PrefabModal.stories"
4
4
 
5
- import myModule from './PreModal?raw';
5
+ import myModule from './PrefabModal?raw';
6
6
 
7
- <Meta name="Show Preset Modal" of={PreModalStories}/>
7
+ <Meta name="Show Prefab" of={PrefabModalStories}/>
8
8
  # Show Preset Modal
9
9
  ## Example
10
10
  Click to show the modal:
11
- <Story of={PreModalStories.ShowPreModal}/>
11
+ <Story of={PrefabModalStories.ShowPrefabModal}/>
12
12
 
13
13
  ## Code
14
14
  <br/>
@@ -1,10 +1,10 @@
1
1
  import { ModalContextProvider } from "../../modal/ModalContextProvider";
2
- import { PreModalUsage } from "./PreModal";
2
+ import { PrefabModalUsage } from "./PrefabModal";
3
3
  import type { Meta, StoryObj } from "@storybook/react";
4
4
 
5
- const meta: Meta<typeof PreModalUsage> = {
5
+ const meta: Meta<typeof PrefabModalUsage> = {
6
6
  title: "Components/Modal",
7
- component: PreModalUsage,
7
+ component: PrefabModalUsage,
8
8
  argTypes: {
9
9
  backgroundColor: { control: "color" },
10
10
  },
@@ -22,6 +22,6 @@ const meta: Meta<typeof PreModalUsage> = {
22
22
  export default meta;
23
23
  type Story = StoryObj<typeof meta>;
24
24
 
25
- export const ShowPreModal: Story = {
25
+ export const ShowPrefabModal: Story = {
26
26
  args: {},
27
27
  };
@@ -0,0 +1,48 @@
1
+ import "./TestModal.scss";
2
+ import "@linzjs/lui/dist/scss/base.scss";
3
+
4
+ import { ModalContextProvider } from "../../modal/ModalContextProvider";
5
+ import { usePrefabModal } from "../../modal/PrefabModal";
6
+
7
+ // #Example: Modal Context Provider
8
+ // Don't forget to add a ModalContextProvider at the root of your project
9
+ export const App = () => (
10
+ <ModalContextProvider>
11
+ <div>...the rest of your app...</div>
12
+ </ModalContextProvider>
13
+ );
14
+
15
+ // #Example: PrefabModal Invocation
16
+ export const PrefabModalUsage = () => {
17
+ // showModal to show modal, modalOwnerRef is only required if you have popout windows
18
+ const { modalOwnerRef, showPrefabModal } = usePrefabModal();
19
+
20
+ // Remember to add the modalOwnerRef!
21
+ return (
22
+ <div ref={modalOwnerRef} style={{ display: "flex", gap: 10 }}>
23
+ <button
24
+ onClick={async () =>
25
+ alert(
26
+ "Warning result: " +
27
+ (await showPrefabModal(
28
+ "warning",
29
+ "You are about to make changes",
30
+ "Are you sure that you want to make these changes?",
31
+ )),
32
+ )
33
+ }
34
+ >
35
+ Warning Prefab-Modal
36
+ </button>
37
+ <button onClick={() => showPrefabModal("info", "You are a fantastic person", "Keep it up!")}>
38
+ Info Prefab-Modal
39
+ </button>
40
+ <button onClick={() => showPrefabModal("error", "Something is not right", "Maybe stop doing that")}>
41
+ Error Prefab-Modal
42
+ </button>
43
+ <button onClick={() => showPrefabModal("success", "You are a success", "Keep succeeding!")}>
44
+ Success Prefab-Modal
45
+ </button>
46
+ </div>
47
+ );
48
+ };
@@ -59,19 +59,18 @@ export const PanelContents = () => {
59
59
 
60
60
  // #Example: Show Panel Buttons
61
61
  export const TestShowPanelButtons = () => (
62
- <>
62
+ <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
63
63
  <div>
64
64
  <OpenPanelButton buttonText={"Panel name 1"} component={() => <ShowPanel data={1} />} />{" "}
65
65
  <OpenPanelButton buttonText={"Panel name 2"} component={() => <ShowPanel data={2} />} />
66
66
  </div>
67
- <br />
67
+
68
68
  <ButtonIconHorizontalGroup>
69
69
  <OpenPanelIcon iconTitle={"Marks"} icon={"ic_marks"} component={() => <ShowPanel data={1} />} />
70
70
  <ButtonIconSeparator />
71
71
  <OpenPanelIcon iconTitle={"Vectors"} icon={"ic_line_irregular"} component={() => <ShowPanel data={2} />} />
72
72
  </ButtonIconHorizontalGroup>
73
- <br />
74
- <br />
73
+
75
74
  <ButtonIconVerticalGroup>
76
75
  <OpenPanelIcon iconTitle={"Marks"} icon={"ic_marks"} component={() => <ShowPanel data={1} />} />
77
76
  <ButtonIconSeparator />
@@ -82,5 +81,5 @@ export const TestShowPanelButtons = () => (
82
81
  component={() => <ShowPanel data={3} />}
83
82
  />
84
83
  </ButtonIconVerticalGroup>
85
- </>
84
+ </div>
86
85
  );
@@ -1,79 +0,0 @@
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
- };