Skip to content

Commit beda1b4

Browse files
committed
More stuff
1 parent fee6edc commit beda1b4

4 files changed

Lines changed: 89 additions & 20 deletions

File tree

homedocs/src/examples/layout/WindowExample.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ export default () => (
3030
title="Contact"
3131
visible={m.contact.visible}
3232
center
33-
style={{ width: "500px" }}
3433
modal
3534
draggable
3635
closeOnEscape
3736
>
38-
<div style={{ padding: "20px" }}>
37+
<div>
3938
<LabelsLeftLayout>
4039
<TextField value={m.contact.name} label="Name" />
4140
<TextField value={m.contact.email} label="Email" />
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Store } from "cx/data";
2+
import { Button, Widget, Window } from "cx/widgets";
3+
4+
// @index
5+
export default () => (
6+
<Button
7+
onClick={() => {
8+
let window = Widget.create(
9+
<Window title="Programmatic Window" center modal>
10+
<div>
11+
<p>This window was opened programmatically.</p>
12+
</div>
13+
<div
14+
putInto="footer"
15+
style={{ display: "flex", justifyContent: "flex-end" }}
16+
>
17+
<Button dismiss>Close</Button>
18+
</div>
19+
</Window>,
20+
);
21+
window.open(new Store());
22+
}}
23+
>
24+
Open Programmatic Window
25+
</Button>
26+
);
27+
// @index-end

homedocs/src/pages/docs/layout/window.mdx

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import CodeExample from "../../../components/CodeExample.astro";
99
import WindowExample from "../../../examples/layout/WindowExample.tsx";
1010
import WindowExampleCode from "../../../examples/layout/WindowExample.tsx?raw";
1111

12+
import WindowProgrammaticExample from "../../../examples/layout/WindowProgrammaticExample.tsx";
13+
import WindowProgrammaticExampleCode from "../../../examples/layout/WindowProgrammaticExample.tsx?raw";
14+
1215
# Window
1316

1417
<ImportPath path="import { Window } from 'cx/widgets';" />
@@ -19,7 +22,47 @@ Windows are overlays with headers, footers, and special appearance. They provide
1922
<WindowExample client:load />
2023
</CodeExample>
2124

22-
Use `putInto="footer"` to place content in the window footer. Add the `dismiss` prop to buttons that should close the window.
25+
Use `putInto="footer"` or `putInto="header"` to place content in the window footer or header. Add the `dismiss` prop to buttons that should close the window.
26+
27+
## Programmatic Windows
28+
29+
Windows can also be opened programmatically using `Widget.create` and the `open` method. This approach creates an independent window with its own store:
30+
31+
<CodeExample code={WindowProgrammaticExampleCode}>
32+
<WindowProgrammaticExample client:load />
33+
</CodeExample>
34+
35+
### Hot Module Replacement (HMR)
36+
37+
Programmatic windows have issues with HMR during development - changes to the window content won't reflect until you close and reopen the window. Use `createHotPromiseWindowFactory` or `createHotPromiseWindowFactoryWithProps` to solve this:
38+
39+
```tsx
40+
import { createHotPromiseWindowFactoryWithProps, Window, Button } from "cx/widgets";
41+
42+
const openUserDialog = createHotPromiseWindowFactoryWithProps(
43+
module,
44+
(userId: string) => (resolve, reject) => {
45+
let result = null;
46+
return Window.create({
47+
title: `User ${userId}`,
48+
onDestroy: () => resolve(result),
49+
children: (
50+
<div>
51+
<p>Edit user details here...</p>
52+
<Button onClick={() => { result = "saved"; }} dismiss>
53+
Save
54+
</Button>
55+
</div>
56+
),
57+
});
58+
}
59+
);
60+
61+
// Usage
62+
const result = await openUserDialog("123");
63+
```
64+
65+
The factory returns a Promise that resolves when the window is closed, making it easy to get results back from dialog windows.
2366

2467
## Configuration
2568

litmus/tsconfig.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
2-
"compilerOptions": {
3-
"target": "es6",
4-
"jsx": "preserve",
5-
"allowJs": true,
6-
"moduleResolution": "node",
7-
"module": "es2015",
8-
"sourceMap": false,
9-
"jsxFactory": "cx",
10-
"baseUrl": ".",
11-
"paths": {
12-
"cx": ["../packages/cx"],
13-
"cx-react": ["../packages/cx-react"],
14-
"cx-immer": ["../packages/cx-immer"]
15-
},
16-
"outDir": "./build/"
17-
},
18-
"exclude": ["node_modules", "./babel-config.js", "./webpack.config.js"]
2+
"compilerOptions": {
3+
"target": "es6",
4+
"jsx": "preserve",
5+
"allowJs": true,
6+
"moduleResolution": "bundler",
7+
"module": "es2015",
8+
"sourceMap": false,
9+
"jsxFactory": "cx",
10+
"baseUrl": ".",
11+
"paths": {
12+
"cx": ["../packages/cx"],
13+
"cx-react": ["../packages/cx-react"],
14+
"cx-immer": ["../packages/cx-immer"]
15+
},
16+
"outDir": "./build/"
17+
},
18+
"exclude": ["node_modules", "./babel-config.js", "./webpack.config.js"]
1919
}

0 commit comments

Comments
 (0)