@linzjs/windows 1.1.1 → 1.2.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.
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "panel",
13
13
  "popout"
14
14
  ],
15
- "version": "1.1.1",
15
+ "version": "1.2.0",
16
16
  "peerDependencies": {
17
17
  "@linzjs/lui": "^17",
18
18
  "lodash-es": ">=4",
@@ -0,0 +1,103 @@
1
+ import { Modal } from "./Modal";
2
+ import { ModalCallback } from "./ModalContext";
3
+ import { useShowModal } from "./useShowModal";
4
+ import { isEmpty } from "lodash-es";
5
+ import { ReactElement } from "react";
6
+
7
+ import { LuiAlertModalButtons, LuiButton, LuiIcon } from "@linzjs/lui";
8
+ import { LuiButtonProps } from "@linzjs/lui/dist/components/LuiButton/LuiButton";
9
+ import { IconName } from "@linzjs/lui/dist/components/LuiIcon/LuiIcon";
10
+
11
+ export type WarningLevel = "success" | "info" | "warning" | "error";
12
+
13
+ export interface PrefabButton<RT> {
14
+ default?: boolean;
15
+ level?: LuiButtonProps["level"];
16
+ title: string;
17
+ value: RT;
18
+ }
19
+
20
+ export interface PrefabModalProps extends ModalCallback<string | null> {
21
+ level?: WarningLevel;
22
+ children: ReactElement;
23
+ buttons?: PrefabButton<any>[];
24
+ }
25
+ export const getIconForLevel = (level: "success" | "info" | "warning" | "error"): IconName => {
26
+ switch (level) {
27
+ case "success":
28
+ return "ic_check_circle";
29
+ case "info":
30
+ return "ic_info";
31
+ case "warning":
32
+ return "ic_warning";
33
+ case "error":
34
+ return "ic_error";
35
+ }
36
+ };
37
+
38
+ export const PrefabModal = ({ level = "warning", children, resolve, ...props }: PrefabModalProps) => {
39
+ const icon = getIconForLevel(level);
40
+ const buttons: PrefabButton<any>[] = props.buttons ?? [];
41
+ if (isEmpty(buttons)) {
42
+ if (level === "warning") {
43
+ buttons.push({
44
+ title: "Cancel",
45
+ value: null,
46
+ });
47
+ }
48
+ buttons.push({
49
+ title: "Continue",
50
+ value: true,
51
+ });
52
+ }
53
+
54
+ buttons.forEach((b, i) => {
55
+ if (!b.level) {
56
+ b.level = i === buttons.length - 1 ? "primary" : "secondary";
57
+ }
58
+ });
59
+
60
+ return (
61
+ <Modal>
62
+ <div className={`lui-modal lui-box-shadow lui-modal-${level}`} style={{ minWidth: 400 }}>
63
+ <LuiIcon name={icon} alt={"warning"} size={"lg"} className={"lui-msg-status-icon"} />
64
+ {children}
65
+ <LuiAlertModalButtons>
66
+ {buttons.map((pf, i) => (
67
+ <LuiButton
68
+ key={i}
69
+ level={pf.level}
70
+ onClick={() => resolve(pf.value === undefined ? pf.title : pf.value)}
71
+ buttonProps={pf.default ? { "data-autofocus": true } : undefined}
72
+ >
73
+ {pf.title}
74
+ </LuiButton>
75
+ ))}
76
+ </LuiAlertModalButtons>
77
+ </div>
78
+ </Modal>
79
+ );
80
+ };
81
+
82
+ export const usePrefabModal = () => {
83
+ const { showModal, modalOwnerRef } = useShowModal();
84
+ return {
85
+ modalOwnerRef,
86
+ showPrefabModal: <RT extends any = boolean>(
87
+ level: WarningLevel,
88
+ title: ReactElement | string,
89
+ content: ReactElement | string,
90
+ buttons?: PrefabButton<RT>[],
91
+ ) =>
92
+ showModal(PrefabModal, {
93
+ level,
94
+ children: (
95
+ <>
96
+ {typeof title === "string" ? <h2>{title}</h2> : title}
97
+ {typeof content === "string" ? <p>{content}</p> : content}
98
+ </>
99
+ ),
100
+ buttons,
101
+ }) as Promise<RT>,
102
+ };
103
+ };
@@ -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,65 @@
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
+ {/* Warning */}
24
+ <button
25
+ onClick={async () =>
26
+ alert(
27
+ "Warning result: " +
28
+ (await showPrefabModal(
29
+ "warning",
30
+ "You are about to make changes",
31
+ "Are you sure that you want to make these changes?",
32
+ )),
33
+ )
34
+ }
35
+ >
36
+ Warning Prefab-Modal
37
+ </button>
38
+ {/* Info */}
39
+ <button onClick={() => showPrefabModal("info", "You are a fantastic person", "Keep it up!")}>
40
+ Info Prefab-Modal
41
+ </button>
42
+ {/* Error */}
43
+ <button onClick={() => showPrefabModal("error", "Something is not right", "Maybe stop doing that")}>
44
+ Error Prefab-Modal
45
+ </button>
46
+ {/* Success */}
47
+ <button onClick={() => showPrefabModal("success", "You are a success", "Keep succeeding!")}>
48
+ Success Prefab-Modal
49
+ </button>
50
+ {/* Custom */}
51
+ <button
52
+ onClick={async () => {
53
+ const result = await showPrefabModal("success", "Custom buttons", <b>Custom buttons are customary!</b>, [
54
+ { value: null, title: "Nope" },
55
+ { value: "barple", title: "Barple" },
56
+ { value: "floople", title: "Floople", default: true },
57
+ ]);
58
+ alert(result);
59
+ }}
60
+ >
61
+ Custom buttons
62
+ </button>
63
+ </div>
64
+ );
65
+ };
@@ -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,45 +0,0 @@
1
- import { Modal } from "./Modal";
2
- import { ModalCallback } from "./ModalContext";
3
- import { ReactElement } from "react";
4
-
5
- import { LuiAlertModalButtons, LuiButton, LuiIcon } from "@linzjs/lui";
6
- import { IconName } from "@linzjs/lui/dist/components/LuiIcon/LuiIcon";
7
-
8
- export type WarningLevel = "success" | "info" | "warning" | "error";
9
-
10
- export interface PreModalProps extends ModalCallback<boolean> {
11
- level?: WarningLevel;
12
- children: ReactElement;
13
- }
14
- export const getIconForLevel = (level: "success" | "info" | "warning" | "error"): IconName => {
15
- switch (level) {
16
- case "success":
17
- return "ic_check_circle";
18
- case "info":
19
- return "ic_info";
20
- case "warning":
21
- return "ic_warning";
22
- case "error":
23
- return "ic_error";
24
- }
25
- };
26
-
27
- export const PreModal = ({ level = "warning", children, resolve }: PreModalProps) => {
28
- const icon = getIconForLevel(level);
29
- return (
30
- <Modal>
31
- <div className={`lui-modal lui-box-shadow lui-modal-${level}`} style={{ minWidth: 400 }}>
32
- <LuiIcon name={icon} alt={"warning"} size={"lg"} className={"lui-msg-status-icon"} />
33
- {children}
34
- <LuiAlertModalButtons>
35
- {level === "warning" && (
36
- <LuiButton level="secondary" onClick={() => resolve(false)} buttonProps={{ "data-autofocus": true }}>
37
- Cancel
38
- </LuiButton>
39
- )}
40
- <LuiButton onClick={() => resolve(true)}>Continue</LuiButton>
41
- </LuiAlertModalButtons>
42
- </div>
43
- </Modal>
44
- );
45
- };
@@ -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
- };