@workday/canvas-kit-docs 11.0.18 → 11.0.19

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.
@@ -4692,7 +4692,27 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
4692
4692
  "required": false,
4693
4693
  "type": {
4694
4694
  "kind": "function",
4695
- "parameters": [],
4695
+ "parameters": [
4696
+ {
4697
+ "kind": "parameter",
4698
+ "name": "element",
4699
+ "type": {
4700
+ "kind": "symbol",
4701
+ "name": "HTMLElement",
4702
+ "value": "HTMLElement"
4703
+ },
4704
+ "required": false,
4705
+ "rest": false,
4706
+ "description": "",
4707
+ "declarations": [
4708
+ {
4709
+ "name": "element",
4710
+ "filePath": "/home/runner/work/canvas-kit/canvas-kit/modules/popup-stack/lib/PopupStack.ts"
4711
+ }
4712
+ ],
4713
+ "tags": {}
4714
+ }
4715
+ ],
4696
4716
  "members": [],
4697
4717
  "returnType": {
4698
4718
  "kind": "symbol",
@@ -4700,7 +4720,7 @@ export const docs = (typeof window !== 'undefined' && window.__docs) ||
4700
4720
  "value": "HTMLElement"
4701
4721
  }
4702
4722
  },
4703
- "description": "",
4723
+ "description": "Returns the container of a stack given an optional element.",
4704
4724
  "declarations": [
4705
4725
  {
4706
4726
  "name": "container",
@@ -10,6 +10,7 @@ import FocusRedirect from './examples/FocusRedirect';
10
10
  import FocusTrap from './examples/FocusTrap';
11
11
  import RTL from './examples/RTL';
12
12
  import CustomTarget from './examples/CustomTarget';
13
+ import ExternalWindow from './examples/ExternalWindow';
13
14
  import FullScreen from './examples/FullScreen';
14
15
 
15
16
 
@@ -159,6 +160,16 @@ the popup's stack context when entering/exiting fullscreen.
159
160
 
160
161
  <ExampleCodeBlock code={FullScreen} />
161
162
 
163
+ ### Opening an external window
164
+
165
+ A popup can open an external window. This isn't supported directly. The `Popup.Popper` subcomponent
166
+ is replaced with a custom subcomponent that connects to the Popup model and controls the lifecycle
167
+ of the extenal window. Be sure to connect the `unload` event of both the parent `window` and the
168
+ external child `window` to the lifecycle of the Popup model to prevent memory leaks or zombie
169
+ windows.
170
+
171
+ <ExampleCodeBlock code={ExternalWindow} />
172
+
162
173
  ### RTL
163
174
 
164
175
  The Popup component automatically handles right-to-left rendering.
@@ -170,8 +181,8 @@ The Popup component automatically handles right-to-left rendering.
170
181
  ## Component API
171
182
 
172
183
  <>
173
- <SymbolDoc name="Popper" fileName="/react/" />
174
- <SymbolDoc name="Popup" fileName="/react/" />
184
+ <SymbolDoc name="Popper" fileName="/react/" />
185
+ <SymbolDoc name="Popup" fileName="/react/" />
175
186
  </>
176
187
 
177
188
  ## Hooks
@@ -0,0 +1,177 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom';
3
+
4
+ import {system} from '@workday/canvas-tokens-web';
5
+ import {createStyles} from '@workday/canvas-kit-styling';
6
+ import {infoIcon} from '@workday/canvas-system-icons-web';
7
+
8
+ import {
9
+ CanvasProvider,
10
+ ContentDirection,
11
+ createSubcomponent,
12
+ PartialEmotionCanvasTheme,
13
+ useMount,
14
+ useTheme,
15
+ } from '@workday/canvas-kit-react/common';
16
+ import {Tooltip} from '@workday/canvas-kit-react/tooltip';
17
+ import {Popup, usePopupModel} from '@workday/canvas-kit-react/popup';
18
+ import {SecondaryButton} from '@workday/canvas-kit-react/button';
19
+ import {Flex} from '../../../layout';
20
+
21
+ const mainContentStyles = createStyles({
22
+ padding: system.space.x4,
23
+ });
24
+
25
+ export interface ExternalWindowPortalProps {
26
+ /**
27
+ * Child components of WindowPortal
28
+ */
29
+ children: React.ReactNode;
30
+ /**
31
+ * Callback to close the popup
32
+ */
33
+ onWindowClose?: () => void;
34
+ /**
35
+ * Width of the popup window
36
+ */
37
+ width?: number;
38
+ /**
39
+ * Height of the popup window
40
+ */
41
+ height?: number;
42
+ /**
43
+ * The name of the popup window. If another popup opens with the same name, that instance will
44
+ * be reused. Use caution with setting this value
45
+ */
46
+ target?: string;
47
+ }
48
+
49
+ async function copyAssets(sourceDoc: Document, targetDoc: Document) {
50
+ for (const font of (sourceDoc as any).fonts.values()) {
51
+ (targetDoc as any).fonts.add(font);
52
+
53
+ font.load();
54
+ }
55
+
56
+ await (targetDoc as any).fonts.ready;
57
+
58
+ // The current ES lib version doesn't include iterable interfaces, so we cast as an iterable
59
+ for (const styleSheet of sourceDoc.styleSheets as StyleSheetList & Iterable<CSSStyleSheet>) {
60
+ if (styleSheet.cssRules) {
61
+ // text based styles
62
+ const styleEl = targetDoc.createElement('style');
63
+ for (const cssRule of styleSheet.cssRules as CSSRuleList & Iterable<CSSRule>) {
64
+ styleEl.appendChild(targetDoc.createTextNode(cssRule.cssText));
65
+ }
66
+ targetDoc.head.appendChild(styleEl);
67
+ } else if (styleSheet.href) {
68
+ // link based styles
69
+ const linkEl = targetDoc.createElement('link');
70
+
71
+ linkEl.rel = 'stylesheet';
72
+ linkEl.href = styleSheet.href;
73
+ targetDoc.head.appendChild(linkEl);
74
+ }
75
+ }
76
+ }
77
+
78
+ const ExternalWindowPortal = ({
79
+ children,
80
+ width = 300,
81
+ height = 500,
82
+ target = '',
83
+ onWindowClose,
84
+ }: ExternalWindowPortalProps) => {
85
+ const [portalElement, setPortalElement] = React.useState<HTMLDivElement | null>(null);
86
+
87
+ useMount(() => {
88
+ const newWindow = window.open(
89
+ '', // url
90
+ target,
91
+ `width=${width},height=${height},left=100,top=100,popup=true`
92
+ );
93
+
94
+ if (newWindow) {
95
+ // copy fonts and styles
96
+ copyAssets(document, newWindow.document);
97
+
98
+ const element = newWindow.document.createElement('div');
99
+ newWindow.document.body.appendChild(element);
100
+ setPortalElement(element);
101
+ } else {
102
+ onWindowClose();
103
+ }
104
+
105
+ const closeWindow = event => {
106
+ onWindowClose();
107
+ };
108
+
109
+
110
+ window.addEventListener('unload', closeWindow);
111
+ newWindow?.addEventListener('unload', closeWindow);
112
+
113
+ return () => {
114
+ window.removeEventListener('unload', closeWindow);
115
+ newWindow?.removeEventListener('unload', closeWindow);
116
+ newWindow?.close();
117
+ };
118
+ });
119
+
120
+ if (!portalElement) {
121
+ return null;
122
+ }
123
+
124
+ return ReactDOM.createPortal(<CanvasProvider>{children}</CanvasProvider>, portalElement);
125
+ };
126
+
127
+ const PopupExternalWindow = createSubcomponent()({
128
+ displayName: 'Popup.ExternalWindow',
129
+ modelHook: usePopupModel,
130
+ })<ExternalWindowPortalProps>(({children, ...elemProps}, Element, model) => {
131
+ if (model.state.visibility === 'visible') {
132
+ return (
133
+ <ExternalWindowPortal onWindowClose={model.events.hide} {...elemProps}>
134
+ {children}
135
+ </ExternalWindowPortal>
136
+ );
137
+ }
138
+
139
+ return null;
140
+ });
141
+
142
+ export default () => {
143
+ // useTheme is filling in the Canvas theme object if any keys are missing
144
+ const canvasTheme: PartialEmotionCanvasTheme = useTheme({
145
+ canvas: {
146
+ // Switch to `ContentDirection.RTL` to change direction
147
+ direction: ContentDirection.LTR,
148
+ },
149
+ });
150
+
151
+ const model = usePopupModel();
152
+
153
+ return (
154
+ <CanvasProvider theme={canvasTheme}>
155
+ <>
156
+ <main className={mainContentStyles}>
157
+ <p>Popup that opens a new Operating System Window</p>
158
+ <Popup model={model}>
159
+ <Tooltip title="Open External Window Tooltip">
160
+ <Popup.Target>Open External Window</Popup.Target>
161
+ </Tooltip>
162
+ <PopupExternalWindow>
163
+ <p>External Window Contents! Mouse over the info icon to get a tooltip</p>
164
+ <Flex gap="s">
165
+ <Tooltip title="More information">
166
+ <SecondaryButton icon={infoIcon} />
167
+ </Tooltip>
168
+ <Popup.CloseButton>Close Window</Popup.CloseButton>
169
+ </Flex>
170
+ </PopupExternalWindow>
171
+ </Popup>
172
+ <p>Popup visibility: {model.state.visibility}</p>
173
+ </main>
174
+ </>
175
+ </CanvasProvider>
176
+ );
177
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workday/canvas-kit-docs",
3
- "version": "11.0.18",
3
+ "version": "11.0.19",
4
4
  "description": "Documentation components of Canvas Kit components",
5
5
  "author": "Workday, Inc. (https://www.workday.com)",
6
6
  "license": "Apache-2.0",
@@ -44,10 +44,10 @@
44
44
  "dependencies": {
45
45
  "@emotion/styled": "^11.6.0",
46
46
  "@storybook/csf": "0.0.1",
47
- "@workday/canvas-kit-labs-react": "^11.0.18",
48
- "@workday/canvas-kit-preview-react": "^11.0.18",
49
- "@workday/canvas-kit-react": "^11.0.18",
50
- "@workday/canvas-kit-styling": "^11.0.18",
47
+ "@workday/canvas-kit-labs-react": "^11.0.19",
48
+ "@workday/canvas-kit-preview-react": "^11.0.19",
49
+ "@workday/canvas-kit-react": "^11.0.19",
50
+ "@workday/canvas-kit-styling": "^11.0.19",
51
51
  "@workday/canvas-system-icons-web": "^3.0.0",
52
52
  "@workday/canvas-tokens-web": "^2.0.0",
53
53
  "markdown-to-jsx": "^7.2.0",
@@ -59,5 +59,5 @@
59
59
  "mkdirp": "^1.0.3",
60
60
  "typescript": "4.2"
61
61
  },
62
- "gitHead": "b8919f552eadd3b280dffd8e6c4d445a275d2ee5"
62
+ "gitHead": "c2d95558a8716248923ecb281c94406c0071792c"
63
63
  }