@workday/canvas-kit-docs 12.0.0-alpha.841-next.0 → 12.0.0-alpha.852-next.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.
@@ -1,3 +1,10 @@
1
+ import {Table} from '@workday/canvas-kit-react/table';
2
+ import {base, brand, system} from '@workday/canvas-tokens-web';
3
+ import {StatusIndicator} from '@workday/canvas-kit-preview-react/status-indicator';
4
+ import {cssVar} from '@workday/canvas-kit-styling';
5
+ import {Box} from '@workday/canvas-kit-react/layout';
6
+
7
+
1
8
  # Canvas Kit 12.0 Upgrade Guide
2
9
 
3
10
  This guide contains an overview of the changes in Canvas Kit v12. Please
@@ -6,10 +13,59 @@ any questions.
6
13
 
7
14
  ## Why You Should Upgrade
8
15
 
16
+ Canvas Kit v12 is transitioning into a
17
+ [new way of styling](https://github.com/Workday/canvas-kit/discussions/2265). Theming and building
18
+ an in sync Canvas Kit CSS has been at the top of our minds. We've started using our new
19
+ [Canvas Tokens Web](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs)
20
+ package to take advantage of
21
+ [CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties) and
22
+ provide semantic tokens that can translate to theming components.
23
+
24
+ A note to the reader:
25
+
26
+ - While we still support our old tokens from `@workday/canvas-kit-react/tokens` in v12, you must
27
+ install our new tokens from `@workday/canvas-tokens-web`. You can find more info in our
28
+ [docs](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs).
29
+ - In this release, we've introduced a
30
+ [new styling API](https://workday.github.io/canvas-kit/?path=/docs/styling-basics--create-stencil).
31
+ This shouldn't effect the way you currently style your components. Because we're moving away from
32
+ Emotion, support for style props will eventually be removed, however, this API provide backwards
33
+ compatability. If you want to slowly move off of Emotion as well, you can start styling components
34
+ via the `cs` prop or our new styling utilities.
35
+
9
36
  ## Table of contents
10
37
 
38
+ - [Canvas Tokens](#canvas-tokens)
39
+ - [Codemod](#codemod)
40
+ - [Deprecations](#deprecations)
11
41
  - [Removals](#removals)
42
+ - [InputIconContainer](#inputiconcontainer)
12
43
  - [Select (Preview)](#select-preview)
44
+ - [Component Updates](#component-updates)
45
+ - [Popup, Dialog and Modal](#popup-dialog-and-modal)
46
+ - [Toast](#toast)
47
+ - [Style Utility Updates](#style-utility-updates)
48
+ - [createStencil](#createstencil)
49
+ - [Troubleshooting](#troubleshooting)
50
+ - [Glossary](#glossary)
51
+ - [Main](#main)
52
+ - [Preview](#preview)
53
+ - [Labs](#labs)
54
+
55
+ ## Canvas Tokens
56
+
57
+ In v12, all the components listed in this guide have started using our new
58
+ [Canvas Tokens Web](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs).
59
+
60
+ In v12 you must add `@workday/canvas-tokens-web` to ensure our components are properly styled and the
61
+ variables are defined. For more information on installing and using, please reference our tokens
62
+ [docs](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs).
63
+
64
+ ## Deprecations
65
+
66
+ We add the [@deprecated](https://jsdoc.app/tags-deprecated.html) JSDoc tag to code we plan to remove
67
+ in a future major release. This signals consumers to migrate to a more stable alternative before the
68
+ deprecated code is removed.
13
69
 
14
70
  ## Removals
15
71
  Removals are deletions from our codebase and you can no longer consume this component. We've either promoted or replaced a component or utility.
@@ -18,4 +74,106 @@ Removals are deletions from our codebase and you can no longer consume this comp
18
74
 
19
75
  **PR:** [#2796](https://github.com/Workday/canvas-kit/pull/2796)
20
76
 
21
- We've removed the `Select` component that was in Preview. Please use the compound [`Select` component from Main](https://workday.github.io/canvas-kit/?path=/docs/components-inputs-select--basic).
77
+ We've removed the `Select` component that was in Preview. Please use the compound [Select component from Main](https://workday.github.io/canvas-kit/?path=/docs/components-inputs-select--basic).
78
+
79
+ ### InputIconContainer
80
+
81
+ **PR:** [#2838](https://github.com/Workday/canvas-kit/pull/2838)
82
+
83
+ We've removed `InputIconContainer` from Main. Please use [InputGroup](https://workday.github.io/canvas-kit/?path=/docs/components-inputs-text-input--icons) from Main instead.
84
+
85
+ ---
86
+
87
+ ## Component Updates
88
+
89
+ ### Styling API and CSS Tokens
90
+
91
+ Several components have been refactored to use our new
92
+ [Canvas Tokens](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs) and
93
+ [styling API](https://workday.github.io/canvas-kit/?path=/docs/styling-basics--create-modifiers#createstyles-api).
94
+ The React interface **has not changed**, but CSS variables are now used for dynamic properties.
95
+
96
+ The following components are affected:
97
+
98
+ - `Popup`
99
+ - `Dialog`
100
+ - `Modal`
101
+ - `Toast`
102
+
103
+ > **Note:** These components also support our new `cs` prop for styling. Learn more about styling
104
+ > with `cs` in our
105
+ > [documentation](https://workday.github.io/canvas-kit/?path=/docs/styling-basics--cs-prop).
106
+
107
+ ### Popup, Dialog and Modal
108
+
109
+ **PR:** [#2795](https://github.com/Workday/canvas-kit/pull/2795)
110
+
111
+ ### Toast
112
+
113
+ **PR:** [#2795](https://github.com/Workday/canvas-kit/pull/2795)
114
+
115
+ ## Style Utility Updates
116
+
117
+ ## Troubleshooting
118
+
119
+ ### My Styles Seem Broken?
120
+
121
+ Our components are reliant on our new Canvas Tokens Web package. Be sure you install
122
+ `@workday/canvas-tokens-web`. For more information, reference our
123
+ [Getting Started docs](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs)
124
+ for this package.
125
+
126
+ ### Did You Upgrade All Canvas Kit Related Packages?
127
+
128
+ In order for all the packages to work in harmony, you must upgrade all Canvas Kit packages to the
129
+ same version that you're using, including:
130
+
131
+ - `@workday/canvas-kit-react`
132
+ - `@workday/canvas-kit-preview-react`
133
+ - `@workday/canvas-kit-labs-react`
134
+ - `@workday/canvas-kit-styling`
135
+ - `@workday/canvas-kit-react-fonts`
136
+ - `@workday/canvas-kit-docs`
137
+
138
+ ## Glossary
139
+
140
+ ### Main
141
+
142
+ Our Main package of Canvas Kit tokens, components, and utilities at `@workday/canvas-kit-react` has
143
+ undergone a full design and a11y review and is approved for use in product.
144
+
145
+ Breaking changes to code in Main will only occur during major version updates and will always be
146
+ communicated in advance and accompanied by migration strategies.
147
+
148
+ ---
149
+
150
+ ### Preview
151
+
152
+ Our Preview package of Canvas Kit tokens, components, and utilities at
153
+ `@workday/canvas-kit-preview-react` has undergone a full design and a11y review and is approved for
154
+ use in product, but may not be up to the high code standards upheld in the [Main](#main) package.
155
+ Preview is analagous to code in beta.
156
+
157
+ Breaking changes are unlikely, but possible, and can be deployed to Preview at any time without
158
+ triggering a major version update, though such changes will be communicated in advance and
159
+ accompanied by migration strategies.
160
+
161
+ Generally speaking, our goal is to eventually promote code from Preview to [Main](#main).
162
+ Occasionally, a component with the same name will exist in both [Main](#main) and Preview (for
163
+ example, see Segmented Control in [Preview](/components/buttons/segmented-control/) and
164
+ [Main](https://d2krrudi3mmzzw.cloudfront.net/v8/?path=/docs/components-buttons-segmented-control--basic)).
165
+ In these cases, Preview serves as a staging ground for an improved version of the component with a
166
+ different API. The component in [Main](#main) will eventually be replaced with the one in Preview.
167
+
168
+ ---
169
+
170
+ ### Labs
171
+
172
+ Our Labs package of Canvas Kit tokens, components, and utilities at `@workday/canvas-kit-labs-react`
173
+ has **not** undergone a full design and a11y review. Labs serves as an incubator space for new and
174
+ experimental code and is analagous to code in alpha.
175
+
176
+ Breaking changes can be deployed to Labs at any time without triggering a major version update and
177
+ may not be subject to the same rigor in communcation and migration strategies reserved for breaking
178
+ changes in [Preview](#preview) and [Main](#main). import { opacity } from
179
+ "@workday/canvas-tokens-web/dist/es6/system"
@@ -1,9 +1,8 @@
1
1
  import {AriaLiveRegion} from '@workday/canvas-kit-react/common';
2
- import FilterListWithLiveStatus from './examples/common/FilterListWithLiveStatus';
3
- import VisibleLiveRegion from './examples/common/VisibleLiveRegion';
4
- import HiddenLiveRegion from './examples/common/HiddenLiveRegion';
5
- import TextInputWithLiveError from './examples/common/TextInputWithLiveError';
6
- import IconButtonsWithLiveBadges from './examples/common/IconButtonsWithLiveBadges';
2
+ import FilterListWithLiveStatus from './examples/AriaLiveRegions/FilterListWithLiveStatus';
3
+ import VisibleLiveRegion from './examples/AriaLiveRegions/VisibleLiveRegion';
4
+ import HiddenLiveRegion from './examples/AriaLiveRegions/HiddenLiveRegion';
5
+ import TextInputWithLiveError from './examples/AriaLiveRegions/TextInputWithLiveError';
7
6
 
8
7
 
9
8
  # ARIA Live Regions
@@ -56,7 +55,7 @@ experience when moving the keyboard focus to a new element on screen isn't feasi
56
55
 
57
56
  In this example, a live region is applied to a short UI text describing the number of items shown in
58
57
  the list. As you type characters into the input, listen for the screen reader to automatically
59
- describe how many items in the list or shown.
58
+ describe how many items in the list are shown.
60
59
 
61
60
  <ExampleCodeBlock code={FilterListWithLiveStatus} />
62
61
 
@@ -72,4 +71,9 @@ of error conditions. As forms increase in complexity, live regions on each error
72
71
  increasingly distracting and disruptive to the experience, especially if users are trying to first
73
72
  understand the information that is required of them to complete the task.
74
73
 
74
+ **Note:** The `<AriaLiveRegion>` component is used inside of the `Hint` to ensure the live
75
+ region remains in the browser DOM at all times. The `Hint` is only rendered in the DOM when it
76
+ contains content, so it will not work reliably as a live region for screen readers using the
77
+ `as={AriaLiveRegion}` prop.
78
+
75
79
  <ExampleCodeBlock code={TextInputWithLiveError} />
@@ -1,10 +1,12 @@
1
1
  import React, {useState} from 'react';
2
- import {TextInput} from '@workday/canvas-kit-preview-react/text-input';
3
- import {BodyText, Heading} from '@workday/canvas-kit-react/text';
2
+
4
3
  import {AriaLiveRegion} from '@workday/canvas-kit-react/common';
4
+ import {BodyText, Heading} from '@workday/canvas-kit-react/text';
5
5
  import {Flex} from '@workday/canvas-kit-react/layout';
6
+ import {FormField} from '@workday/canvas-kit-preview-react/form-field';
7
+ import {TextInput} from '@workday/canvas-kit-react/text-input';
6
8
  import {system, base} from '@workday/canvas-tokens-web';
7
- import {createStyles, px2rem} from '@workday/canvas-kit-styling';
9
+ import {createStyles, cssVar, px2rem} from '@workday/canvas-kit-styling';
8
10
 
9
11
  const fruits = [
10
12
  'Apples',
@@ -23,13 +25,19 @@ const liveRegionStyle = createStyles({
23
25
  padding: system.space.x2,
24
26
  });
25
27
 
26
- const listStyles = {paddingLeft: '0px'};
28
+ const listStyles = createStyles({
29
+ paddingLeft: system.space.zero,
30
+ });
27
31
 
28
32
  const listItemStyles = createStyles({
29
33
  listStyle: 'none',
30
34
  paddingLeft: system.space.zero,
31
35
  });
32
36
 
37
+ const flexStyles = createStyles({
38
+ gap: system.space.x4,
39
+ });
40
+
33
41
  let filteredFruits = fruits;
34
42
 
35
43
  export default () => {
@@ -41,7 +49,7 @@ export default () => {
41
49
 
42
50
  return (
43
51
  <>
44
- <Flex gap="1rem">
52
+ <Flex cs={flexStyles}>
45
53
  <Heading size="small">Fruits</Heading>
46
54
  <AriaLiveRegion>
47
55
  <BodyText size="small" cs={liveRegionStyle}>
@@ -49,11 +57,11 @@ export default () => {
49
57
  </BodyText>
50
58
  </AriaLiveRegion>
51
59
  </Flex>
52
- <TextInput orientation="vertical">
53
- <TextInput.Label>Filter Items:</TextInput.Label>
54
- <TextInput.Field value={filter} onChange={handleFilter} />
55
- </TextInput>
56
- <ul style={listStyles}>
60
+ <FormField>
61
+ <FormField.Label>Filter Items:</FormField.Label>
62
+ <FormField.Input as={TextInput} value={filter} onChange={handleFilter} />
63
+ </FormField>
64
+ <ul className={listStyles}>
57
65
  {filteredFruits.map(i => (
58
66
  <BodyText size="small" as="li" cs={listItemStyles} key={i}>
59
67
  {i}
@@ -0,0 +1,46 @@
1
+ import React from 'react';
2
+
3
+ import {AccessibleHide, AriaLiveRegion} from '@workday/canvas-kit-react/common';
4
+ import {PrimaryButton} from '@workday/canvas-kit-react/button';
5
+ import {FormField} from '@workday/canvas-kit-preview-react/form-field';
6
+ import {Flex} from '@workday/canvas-kit-react/layout';
7
+ import {Text} from '@workday/canvas-kit-react/text';
8
+ import {TextInput} from '@workday/canvas-kit-react/text-input';
9
+ import {createStyles} from '@workday/canvas-kit-styling';
10
+ import {system} from '@workday/canvas-tokens-web';
11
+
12
+ let liveRegionStr = '';
13
+
14
+ const flexStyles = createStyles({
15
+ gap: system.space.x4,
16
+ alignItems: 'center',
17
+ });
18
+
19
+ export default () => {
20
+ const [message, setMessage] = React.useState('');
21
+
22
+ function handleChange(e) {
23
+ setMessage(e.target.value);
24
+ }
25
+
26
+ function handleSendMessage(e) {
27
+ e.preventDefault();
28
+ liveRegionStr = message;
29
+ setMessage('');
30
+ }
31
+
32
+ return (
33
+ <>
34
+ <Flex as="form" aria-label="Hidden Live Region" onSubmit={handleSendMessage} cs={flexStyles}>
35
+ <FormField>
36
+ <FormField.Label>Type your message:</FormField.Label>
37
+ <FormField.Input as={TextInput} onChange={handleChange} value={message} />
38
+ </FormField>
39
+ <PrimaryButton type="submit">Send Message</PrimaryButton>
40
+ </Flex>
41
+ <AriaLiveRegion>
42
+ <Text as={AccessibleHide}>{liveRegionStr}</Text>
43
+ </AriaLiveRegion>
44
+ </>
45
+ );
46
+ };
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ import {AriaLiveRegion, changeFocus} from '@workday/canvas-kit-react/common';
3
+ import {FormField} from '@workday/canvas-kit-preview-react/form-field';
4
+ import {PrimaryButton} from '@workday/canvas-kit-react/button';
5
+ import {TextInput} from '@workday/canvas-kit-react/text-input';
6
+ import {system} from '@workday/canvas-tokens-web';
7
+ import {createStyles} from '@workday/canvas-kit-styling';
8
+
9
+ const hintStyles = createStyles({
10
+ height: system.space.x6,
11
+ });
12
+ export default () => {
13
+ const errMsg = 'Error: First name is required.';
14
+ const [hasError, setHasError] = React.useState('no');
15
+ const inputRef = React.useRef(null);
16
+ const handleBlur = e => setHasError(e.target.value.trim().length === 0 ? 'error' : 'no');
17
+ const handleSubmit = () => hasError && changeFocus(inputRef.current);
18
+
19
+ return (
20
+ <>
21
+ <FormField error={hasError === 'error' ? 'error' : undefined} isRequired={true}>
22
+ <FormField.Label>First Name:</FormField.Label>
23
+ <FormField.Input as={TextInput} onBlur={handleBlur} ref={inputRef} />
24
+ <FormField.Hint cs={hintStyles}>
25
+ <AriaLiveRegion>{hasError === 'error' && errMsg}</AriaLiveRegion>
26
+ </FormField.Hint>
27
+ </FormField>
28
+ <PrimaryButton onClick={handleSubmit}>Continue</PrimaryButton>
29
+ </>
30
+ );
31
+ };
@@ -0,0 +1,61 @@
1
+ import React from 'react';
2
+
3
+ import {AriaLiveRegion} from '@workday/canvas-kit-react/common';
4
+ import {PrimaryButton} from '@workday/canvas-kit-react/button';
5
+ import {FormField} from '@workday/canvas-kit-preview-react/form-field';
6
+ import {Flex} from '@workday/canvas-kit-react/layout';
7
+ import {Text} from '@workday/canvas-kit-react/text';
8
+ import {TextInput} from '@workday/canvas-kit-react/text-input';
9
+ import {system, base} from '@workday/canvas-tokens-web';
10
+ import {createStyles, px2rem, calc} from '@workday/canvas-kit-styling';
11
+
12
+ const liveRegionStyle = createStyles({
13
+ border: `${px2rem(1)} solid ${system.color.border.caution.default}`,
14
+ backgroundColor: system.color.bg.caution.default,
15
+ padding: system.space.x4,
16
+ display: 'block',
17
+ marginBlockStart: system.space.x4,
18
+ marginBlockEnd: system.space.x4,
19
+ width: calc.multiply(system.space.x16, 7),
20
+ });
21
+
22
+ const flexGapStyles = createStyles({
23
+ gap: system.space.x4,
24
+ alignItems: 'center',
25
+ });
26
+
27
+ let liveRegionStr = 'This is an ARIA Live Region!';
28
+
29
+ export default () => {
30
+ const [message, setMessage] = React.useState('');
31
+
32
+ function handleChange(e) {
33
+ setMessage(e.target.value);
34
+ }
35
+
36
+ function handleSendMessage(e) {
37
+ e.preventDefault();
38
+ liveRegionStr = message;
39
+ setMessage('');
40
+ }
41
+
42
+ return (
43
+ <>
44
+ <AriaLiveRegion>
45
+ <Text cs={liveRegionStyle}>{liveRegionStr}</Text>
46
+ </AriaLiveRegion>
47
+ <Flex
48
+ as="form"
49
+ aria-label="Visible Live Region"
50
+ onSubmit={handleSendMessage}
51
+ cs={flexGapStyles}
52
+ >
53
+ <FormField>
54
+ <FormField.Label>Type your message:</FormField.Label>
55
+ <FormField.Input as={TextInput} onChange={handleChange} value={message} />
56
+ </FormField>
57
+ <PrimaryButton type="submit">Send Message</PrimaryButton>
58
+ </Flex>
59
+ </>
60
+ );
61
+ };
@@ -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
@@ -26,7 +26,7 @@ export default () => {
26
26
  return (
27
27
  <Popup model={model}>
28
28
  <Popup.Target as={DeleteButton}>Delete Item</Popup.Target>
29
- <Popup.Popper placement="bottom">
29
+ <Popup.Popper placement="top">
30
30
  <Popup.Card width={400}>
31
31
  <Popup.CloseIcon aria-label="Close" />
32
32
  <Popup.Heading>Delete Item</Popup.Heading>
@@ -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": "12.0.0-alpha.841-next.0",
3
+ "version": "12.0.0-alpha.852-next.0",
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,13 +44,13 @@
44
44
  "dependencies": {
45
45
  "@emotion/styled": "^11.6.0",
46
46
  "@storybook/csf": "0.0.1",
47
- "@workday/canvas-kit-labs-react": "^12.0.0-alpha.841-next.0",
48
- "@workday/canvas-kit-preview-react": "^12.0.0-alpha.841-next.0",
49
- "@workday/canvas-kit-react": "^12.0.0-alpha.841-next.0",
50
- "@workday/canvas-kit-styling": "^12.0.0-alpha.841-next.0",
47
+ "@workday/canvas-kit-labs-react": "^12.0.0-alpha.852-next.0",
48
+ "@workday/canvas-kit-preview-react": "^12.0.0-alpha.852-next.0",
49
+ "@workday/canvas-kit-react": "^12.0.0-alpha.852-next.0",
50
+ "@workday/canvas-kit-styling": "^12.0.0-alpha.852-next.0",
51
51
  "@workday/canvas-system-icons-web": "^3.0.0",
52
52
  "@workday/canvas-tokens-web": "^2.0.0",
53
- "markdown-to-jsx": "^6.10.3",
53
+ "markdown-to-jsx": "^7.2.0",
54
54
  "ts-node": "^10.9.1"
55
55
  },
56
56
  "devDependencies": {
@@ -59,5 +59,5 @@
59
59
  "mkdirp": "^1.0.3",
60
60
  "typescript": "4.2"
61
61
  },
62
- "gitHead": "066c4b170850949586bf9f89370f5302a6c8f9a4"
62
+ "gitHead": "bbd7343aec2a6657b8eff4981a7aa4a6e47af161"
63
63
  }