@workday/canvas-kit-docs 5.3.0-next.6 → 5.3.0-next.9
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/dist/commonjs/lib/specs.js +135 -1
- package/dist/es6/lib/specs.js +135 -1
- package/dist/mdx/6.0-MIGRATION-GUIDE.mdx +296 -0
- package/dist/mdx/labs-react/search-form/SearchForm.mdx +64 -0
- package/dist/mdx/labs-react/search-form/examples/Basic.tsx +61 -0
- package/dist/mdx/labs-react/search-form/examples/CustomTheme.tsx +72 -0
- package/dist/mdx/labs-react/search-form/examples/Grow.tsx +62 -0
- package/dist/mdx/labs-react/search-form/examples/PropTables.splitProps.tsx +4 -0
- package/dist/mdx/labs-react/search-form/examples/RTL.tsx +70 -0
- package/dist/mdx/labs-react/search-form/examples/Theming.tsx +64 -0
- package/dist/mdx/labs-react/text-input/TextInput.mdx +123 -0
- package/dist/mdx/labs-react/text-input/examples/Alert.tsx +46 -0
- package/dist/mdx/labs-react/text-input/examples/Basic.tsx +20 -0
- package/dist/mdx/labs-react/text-input/examples/Disabled.tsx +20 -0
- package/dist/mdx/labs-react/text-input/examples/Error.tsx +43 -0
- package/dist/mdx/labs-react/text-input/examples/Grow.tsx +20 -0
- package/dist/mdx/labs-react/text-input/examples/HiddenLabel.tsx +17 -0
- package/dist/mdx/labs-react/text-input/examples/LabelPosition.tsx +20 -0
- package/dist/mdx/labs-react/text-input/examples/LoginForm.tsx +100 -0
- package/dist/mdx/labs-react/text-input/examples/Password.tsx +20 -0
- package/dist/mdx/labs-react/text-input/examples/Placeholder.tsx +20 -0
- package/dist/mdx/labs-react/text-input/examples/RefForwarding.tsx +27 -0
- package/dist/mdx/labs-react/text-input/examples/Required.tsx +20 -0
- package/dist/mdx/labs-react/text-input/examples/ThemedAlert.tsx +51 -0
- package/dist/mdx/labs-react/text-input/examples/ThemedError.tsx +40 -0
- package/dist/mdx/preview-react/menu/Menu.mdx +17 -9
- package/dist/mdx/preview-react/menu/examples/Basic.tsx +65 -10
- package/dist/mdx/preview-react/menu/examples/ContextMenu.tsx +45 -29
- package/dist/mdx/preview-react/menu/examples/CustomMenuItem.tsx +2 -2
- package/dist/mdx/preview-react/menu/examples/ManyItems.tsx +1 -1
- package/dist/mdx/react/text-area/TextArea.mdx +1 -1
- package/package.json +3 -3
- package/dist/mdx/preview-react/menu/examples/ContextMenuTarget.tsx +0 -33
- package/dist/mdx/preview-react/menu/examples/ControlButton.tsx +0 -84
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import {useFormik} from 'formik';
|
|
4
|
+
import * as yup from 'yup';
|
|
5
|
+
|
|
6
|
+
import {TextInput} from '@workday/canvas-kit-labs-react/text-input';
|
|
7
|
+
import {HStack, VStack} from '@workday/canvas-kit-labs-react/layout';
|
|
8
|
+
import {IconButton, PrimaryButton} from '@workday/canvas-kit-react/button';
|
|
9
|
+
import {visibleIcon, invisibleIcon} from '@workday/canvas-system-icons-web';
|
|
10
|
+
import {useUniqueId} from '@workday/canvas-kit-react/common';
|
|
11
|
+
|
|
12
|
+
export default () => {
|
|
13
|
+
const passwordMinimum = 8;
|
|
14
|
+
const passwordHint = `Password should be of minimum ${passwordMinimum} characters length`;
|
|
15
|
+
const emailRequired = 'Email is required';
|
|
16
|
+
const passwordRequired = 'Password is required';
|
|
17
|
+
|
|
18
|
+
const validationSchema = yup.object({
|
|
19
|
+
email: yup
|
|
20
|
+
.string()
|
|
21
|
+
.email('Enter a valid email')
|
|
22
|
+
.required(emailRequired),
|
|
23
|
+
password: yup
|
|
24
|
+
.string()
|
|
25
|
+
.min(passwordMinimum, passwordHint)
|
|
26
|
+
.required(passwordRequired),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const passwordRef = React.useRef<HTMLInputElement>(null);
|
|
30
|
+
const [showPassword, setShowPassword] = React.useState(false);
|
|
31
|
+
const passwordId = useUniqueId();
|
|
32
|
+
|
|
33
|
+
const formik = useFormik({
|
|
34
|
+
initialValues: {
|
|
35
|
+
email: 'example@baz.com',
|
|
36
|
+
password: 'foobarbaz',
|
|
37
|
+
},
|
|
38
|
+
validationSchema: validationSchema,
|
|
39
|
+
onSubmit: values => {
|
|
40
|
+
passwordRef.current.type = 'password';
|
|
41
|
+
|
|
42
|
+
// Send data to server
|
|
43
|
+
setTimeout(() => {
|
|
44
|
+
alert(JSON.stringify(values, null, 2));
|
|
45
|
+
}, 0);
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<form onSubmit={formik.handleSubmit} action=".">
|
|
51
|
+
<VStack spacing="xs" alignItems="flex-start">
|
|
52
|
+
<TextInput isRequired={true} hasError={formik.touched.email && !!formik.errors.email}>
|
|
53
|
+
<TextInput.Label>Email</TextInput.Label>
|
|
54
|
+
<TextInput.Field
|
|
55
|
+
name="email"
|
|
56
|
+
autoComplete="username"
|
|
57
|
+
placeholder="yourName@example.com"
|
|
58
|
+
onChange={formik.handleChange}
|
|
59
|
+
onBlur={formik.handleBlur}
|
|
60
|
+
value={formik.values.email}
|
|
61
|
+
/>
|
|
62
|
+
<TextInput.Hint>{formik.touched.email && formik.errors.email}</TextInput.Hint>
|
|
63
|
+
</TextInput>
|
|
64
|
+
<TextInput
|
|
65
|
+
inputId={passwordId}
|
|
66
|
+
hasError={formik.touched.password && !!formik.errors.password}
|
|
67
|
+
isRequired={true}
|
|
68
|
+
>
|
|
69
|
+
<TextInput.Label>Password</TextInput.Label>
|
|
70
|
+
<HStack spacing="xxs">
|
|
71
|
+
<TextInput.Field
|
|
72
|
+
type={showPassword ? 'text' : 'password'}
|
|
73
|
+
name="password"
|
|
74
|
+
autoComplete="current-password"
|
|
75
|
+
ref={passwordRef}
|
|
76
|
+
onChange={formik.handleChange}
|
|
77
|
+
onBlur={formik.handleBlur}
|
|
78
|
+
value={formik.values.password}
|
|
79
|
+
/>
|
|
80
|
+
<IconButton
|
|
81
|
+
type="button"
|
|
82
|
+
icon={showPassword ? invisibleIcon : visibleIcon}
|
|
83
|
+
aria-label={showPassword ? 'Hide Password' : 'Show Password'}
|
|
84
|
+
aria-controls={passwordId}
|
|
85
|
+
onClick={() => {
|
|
86
|
+
setShowPassword(state => !state);
|
|
87
|
+
passwordRef.current.focus();
|
|
88
|
+
}}
|
|
89
|
+
/>
|
|
90
|
+
</HStack>
|
|
91
|
+
<TextInput.Hint>
|
|
92
|
+
{(formik.touched.password && formik.errors.password) || passwordHint}
|
|
93
|
+
</TextInput.Hint>
|
|
94
|
+
</TextInput>
|
|
95
|
+
|
|
96
|
+
<PrimaryButton type="submit">Submit</PrimaryButton>
|
|
97
|
+
</VStack>
|
|
98
|
+
</form>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {TextInput} from '@workday/canvas-kit-labs-react/text-input';
|
|
3
|
+
import {VStack} from '@workday/canvas-kit-labs-react/layout';
|
|
4
|
+
|
|
5
|
+
export default () => {
|
|
6
|
+
const [value, setValue] = React.useState('SuperSecret1');
|
|
7
|
+
|
|
8
|
+
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
9
|
+
setValue(event.target.value);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<VStack spacing="xxxs" alignItems="flex-start">
|
|
14
|
+
<TextInput>
|
|
15
|
+
<TextInput.Label>Password</TextInput.Label>
|
|
16
|
+
<TextInput.Field onChange={handleChange} value={value} type="password" />
|
|
17
|
+
</TextInput>
|
|
18
|
+
</VStack>
|
|
19
|
+
);
|
|
20
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {TextInput} from '@workday/canvas-kit-labs-react/text-input';
|
|
3
|
+
import {VStack} from '@workday/canvas-kit-labs-react/layout';
|
|
4
|
+
|
|
5
|
+
export default () => {
|
|
6
|
+
const [value, setValue] = React.useState('');
|
|
7
|
+
|
|
8
|
+
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
9
|
+
setValue(event.target.value);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<VStack spacing="xxxs" alignItems="flex-start">
|
|
14
|
+
<TextInput>
|
|
15
|
+
<TextInput.Label>Email</TextInput.Label>
|
|
16
|
+
<TextInput.Field onChange={handleChange} value={value} placeholder="user@email.com" />
|
|
17
|
+
</TextInput>
|
|
18
|
+
</VStack>
|
|
19
|
+
);
|
|
20
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {TextInput} from '@workday/canvas-kit-labs-react/text-input';
|
|
3
|
+
import {VStack} from '@workday/canvas-kit-labs-react/layout';
|
|
4
|
+
import {PrimaryButton} from '@workday/canvas-kit-react/button';
|
|
5
|
+
|
|
6
|
+
export default () => {
|
|
7
|
+
const [value, setValue] = React.useState('');
|
|
8
|
+
const ref = React.useRef(null);
|
|
9
|
+
|
|
10
|
+
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
11
|
+
setValue(event.target.value);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const handleClick = () => {
|
|
15
|
+
ref.current.focus();
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<VStack spacing="xxxs" alignItems="flex-start">
|
|
20
|
+
<TextInput>
|
|
21
|
+
<TextInput.Label>Email</TextInput.Label>
|
|
22
|
+
<TextInput.Field onChange={handleChange} value={value} ref={ref} />
|
|
23
|
+
</TextInput>
|
|
24
|
+
<PrimaryButton onClick={handleClick}>Focus Text Input</PrimaryButton>
|
|
25
|
+
</VStack>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {TextInput} from '@workday/canvas-kit-labs-react/text-input';
|
|
3
|
+
import {VStack} from '@workday/canvas-kit-labs-react/layout';
|
|
4
|
+
|
|
5
|
+
export default () => {
|
|
6
|
+
const [value, setValue] = React.useState('');
|
|
7
|
+
|
|
8
|
+
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
9
|
+
setValue(event.target.value);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<VStack spacing="xxxs" alignItems="flex-start">
|
|
14
|
+
<TextInput isRequired={true}>
|
|
15
|
+
<TextInput.Label>Email</TextInput.Label>
|
|
16
|
+
<TextInput.Field onChange={handleChange} value={value} />
|
|
17
|
+
</TextInput>
|
|
18
|
+
</VStack>
|
|
19
|
+
);
|
|
20
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {TextInput} from '@workday/canvas-kit-labs-react/text-input';
|
|
3
|
+
import {useThemedRing} from '@workday/canvas-kit-labs-react/common';
|
|
4
|
+
import {VStack} from '@workday/canvas-kit-labs-react/layout';
|
|
5
|
+
import {CanvasProvider, PartialEmotionCanvasTheme, styled} from '@workday/canvas-kit-react/common';
|
|
6
|
+
import {colors, CSSProperties, space} from '@workday/canvas-kit-react/tokens';
|
|
7
|
+
|
|
8
|
+
export default () => {
|
|
9
|
+
const theme: PartialEmotionCanvasTheme = {
|
|
10
|
+
canvas: {
|
|
11
|
+
palette: {
|
|
12
|
+
common: {
|
|
13
|
+
focusOutline: colors.grapeSoda300,
|
|
14
|
+
},
|
|
15
|
+
alert: {
|
|
16
|
+
main: colors.kiwi500,
|
|
17
|
+
darkest: colors.kiwi600,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
return (
|
|
23
|
+
<CanvasProvider theme={theme}>
|
|
24
|
+
<AlertInput />
|
|
25
|
+
</CanvasProvider>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const StyledField = styled(TextInput.Field)<{alertStyles?: CSSProperties}>(
|
|
30
|
+
({alertStyles}) => alertStyles
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const AlertInput = () => {
|
|
34
|
+
const [value, setValue] = React.useState('invalid@email');
|
|
35
|
+
|
|
36
|
+
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
37
|
+
setValue(event.target.value);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const alertStyles = useThemedRing('alert');
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<VStack spacing="xxxs" alignItems="flex-start">
|
|
44
|
+
<TextInput>
|
|
45
|
+
<TextInput.Label>Email</TextInput.Label>
|
|
46
|
+
<StyledField alertStyles={alertStyles} onChange={handleChange} value={value} />
|
|
47
|
+
<TextInput.Hint paddingTop={space.xxs}>Please enter a valid email.</TextInput.Hint>
|
|
48
|
+
</TextInput>
|
|
49
|
+
</VStack>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {TextInput} from '@workday/canvas-kit-labs-react/text-input';
|
|
3
|
+
import {VStack} from '@workday/canvas-kit-labs-react/layout';
|
|
4
|
+
import {CanvasProvider, PartialEmotionCanvasTheme} from '@workday/canvas-kit-react/common';
|
|
5
|
+
import {colors, space} from '@workday/canvas-kit-react/tokens';
|
|
6
|
+
|
|
7
|
+
export default () => {
|
|
8
|
+
const [value, setValue] = React.useState('');
|
|
9
|
+
|
|
10
|
+
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
11
|
+
setValue(event.target.value);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const theme: PartialEmotionCanvasTheme = {
|
|
15
|
+
canvas: {
|
|
16
|
+
palette: {
|
|
17
|
+
common: {
|
|
18
|
+
focusOutline: colors.grapeSoda300,
|
|
19
|
+
},
|
|
20
|
+
error: {
|
|
21
|
+
main: colors.islandPunch400,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<CanvasProvider theme={theme}>
|
|
29
|
+
<VStack spacing="xxxs" alignItems="flex-start">
|
|
30
|
+
<TextInput hasError={!value} isRequired={true}>
|
|
31
|
+
<TextInput.Label>Email</TextInput.Label>
|
|
32
|
+
<TextInput.Field onChange={handleChange} value={value} />
|
|
33
|
+
<TextInput.Hint paddingTop={space.xxs}>
|
|
34
|
+
{!value && 'Please enter an email.'}
|
|
35
|
+
</TextInput.Hint>
|
|
36
|
+
</TextInput>
|
|
37
|
+
</VStack>
|
|
38
|
+
</CanvasProvider>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
@@ -3,7 +3,6 @@ import {Menu, MenuItem} from '@workday/canvas-kit-preview-react/menu';
|
|
|
3
3
|
|
|
4
4
|
import Basic from './examples/Basic';
|
|
5
5
|
import ContextMenu from './examples/ContextMenu';
|
|
6
|
-
import ControlButton from './examples/ControlButton';
|
|
7
6
|
import CustomMenuItem from './examples/CustomMenuItem';
|
|
8
7
|
import Icons from './examples/Icons';
|
|
9
8
|
import ManyItems from './examples/ManyItems';
|
|
@@ -11,7 +10,7 @@ import ManyItems from './examples/ManyItems';
|
|
|
11
10
|
|
|
12
11
|
# Canvas Kit Menu
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
`Menu` displays a list of options when triggered by an action or UI element like an icon or button.
|
|
15
14
|
|
|
16
15
|
[> Workday Design Reference](https://design.workday.com/components/popups/menus)
|
|
17
16
|
|
|
@@ -25,8 +24,15 @@ yarn add @workday/canvas-kit-preview-react
|
|
|
25
24
|
|
|
26
25
|
### Basic Example
|
|
27
26
|
|
|
27
|
+
`Menu` is typically triggered by an action such as pressing a button. Here's an example of how you
|
|
28
|
+
might implement that behavior using a [`Popup`](/components/popups/popup/).
|
|
29
|
+
|
|
28
30
|
<ExampleCodeBlock code={Basic} />
|
|
29
31
|
|
|
32
|
+
`Menu` will automatically assign focus to itself when it appears provided you set the `isOpen` prop
|
|
33
|
+
correctly, so you do **not** need to use the `useInitialFocus` `Popup` hook. You **will**, however,
|
|
34
|
+
need to use `useReturnFocus` to return focus back to the triggering button after closing the `Menu`.
|
|
35
|
+
|
|
30
36
|
`Menu` follows the
|
|
31
37
|
[Actions Menu pattern](https://www.w3.org/TR/wai-aria-practices/examples/menu-button/menu-button-actions-active-descendant.html)
|
|
32
38
|
using `aria-activedescendant`. Below is table of supported keyboard shortcuts and associated
|
|
@@ -42,10 +48,8 @@ actions.
|
|
|
42
48
|
| `End` | Moves focus to the last menu item |
|
|
43
49
|
| `A-Z / a-z` | Moves focus to the next menu item with a label that starts with the typed character if such an menu item exists – otherwise, focus does not move |
|
|
44
50
|
|
|
45
|
-
|
|
46
|
-
and
|
|
47
|
-
|
|
48
|
-
<ExampleCodeBlock code={ControlButton} />
|
|
51
|
+
Note that although `Menu` includes support for keyboard shortcuts for the menu itself, you'll need
|
|
52
|
+
to add your own keyboard handling and aria attributes to the triggering button.
|
|
49
53
|
|
|
50
54
|
### Context Menu
|
|
51
55
|
|
|
@@ -59,7 +63,6 @@ custom menu items, be sure to use semantic `<li>` elements with the following at
|
|
|
59
63
|
|
|
60
64
|
- `role="menuitem"`
|
|
61
65
|
- `tabindex={-1}`
|
|
62
|
-
- `id`s following this pattern: `${MenuId}-${index}`
|
|
63
66
|
|
|
64
67
|
Below is an example:
|
|
65
68
|
|
|
@@ -79,19 +82,22 @@ Below is an example:
|
|
|
79
82
|
|
|
80
83
|
#### Usage
|
|
81
84
|
|
|
82
|
-
`Menu` renders a styled `<ul>` element
|
|
85
|
+
`Menu` renders a styled `<ul role="menu">` element within a [`Card`](/components/containers/card/)
|
|
86
|
+
and follows the
|
|
83
87
|
[Active Menu pattern](https://www.w3.org/TR/wai-aria-practices/examples/menu-button/menu-button-actions-active-descendant.html)
|
|
84
88
|
using `aria-activedescendant`.
|
|
85
89
|
|
|
86
90
|
#### Props
|
|
87
91
|
|
|
92
|
+
Undocumented props are spread to the underlying `<ul>` element.
|
|
93
|
+
|
|
88
94
|
<ArgsTable of={Menu} />
|
|
89
95
|
|
|
90
96
|
### MenuItem
|
|
91
97
|
|
|
92
98
|
#### Usage
|
|
93
99
|
|
|
94
|
-
`MenuItem` renders
|
|
100
|
+
`MenuItem` renders an `<li>` element with the correct attributes to ensure it is accessible. If you
|
|
95
101
|
choose to implement your own custom menu items, be sure to use semantic `<li>` elements with the
|
|
96
102
|
following attributes:
|
|
97
103
|
|
|
@@ -101,6 +107,8 @@ following attributes:
|
|
|
101
107
|
|
|
102
108
|
#### Props
|
|
103
109
|
|
|
110
|
+
Undocumented props are spread to the underlying `<li>` element.
|
|
111
|
+
|
|
104
112
|
<ArgsTable of={MenuItem} />
|
|
105
113
|
|
|
106
114
|
## Specifications
|
|
@@ -1,17 +1,72 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
3
2
|
import {Menu, MenuItem} from '@workday/canvas-kit-preview-react/menu';
|
|
3
|
+
import {SecondaryButton} from '@workday/canvas-kit-react/button';
|
|
4
|
+
import {
|
|
5
|
+
Popup,
|
|
6
|
+
usePopupModel,
|
|
7
|
+
useAlwaysCloseOnOutsideClick,
|
|
8
|
+
useReturnFocus,
|
|
9
|
+
useCloseOnEscape,
|
|
10
|
+
} from '@workday/canvas-kit-react/popup';
|
|
11
|
+
|
|
12
|
+
const menuId = 'basic-menu';
|
|
4
13
|
|
|
5
14
|
export default () => {
|
|
15
|
+
const model = usePopupModel();
|
|
16
|
+
|
|
17
|
+
useAlwaysCloseOnOutsideClick(model);
|
|
18
|
+
useCloseOnEscape(model);
|
|
19
|
+
useReturnFocus(model);
|
|
20
|
+
|
|
21
|
+
const isOpen = model.state.visibility !== 'hidden';
|
|
22
|
+
|
|
23
|
+
const handleButtonKeyDown = (event: React.KeyboardEvent) => {
|
|
24
|
+
let isShortcut = false;
|
|
25
|
+
if (event.key === `Spacebar` || event.key === ` ` || event.key === `Enter`) {
|
|
26
|
+
isShortcut = true;
|
|
27
|
+
if (isOpen) {
|
|
28
|
+
model.events.hide();
|
|
29
|
+
} else {
|
|
30
|
+
model.events.show();
|
|
31
|
+
}
|
|
32
|
+
} else if (event.key === `ArrowDown` || event.key === `ArrowUp`) {
|
|
33
|
+
isShortcut = true;
|
|
34
|
+
model.events.show();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (isShortcut) {
|
|
38
|
+
// Prevent ArrowDown and ArrowUp keys from scrolling the entire page
|
|
39
|
+
event.preventDefault();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
6
43
|
return (
|
|
7
|
-
<
|
|
8
|
-
<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
44
|
+
<Popup model={model}>
|
|
45
|
+
<Popup.Target
|
|
46
|
+
as={SecondaryButton}
|
|
47
|
+
onKeyDown={handleButtonKeyDown}
|
|
48
|
+
aria-expanded={isOpen}
|
|
49
|
+
aria-haspopup={true}
|
|
50
|
+
aria-controls={isOpen ? menuId : undefined}
|
|
51
|
+
>
|
|
52
|
+
Open Menu
|
|
53
|
+
</Popup.Target>
|
|
54
|
+
<Popup.Popper placement="bottom-start">
|
|
55
|
+
{/*
|
|
56
|
+
isOpen must be set for focus to be properly assigned to the Menu;
|
|
57
|
+
onClose must be set in order to the Menu to close properly after
|
|
58
|
+
selecting a MenuItem
|
|
59
|
+
*/}
|
|
60
|
+
<Menu id={menuId} isOpen={isOpen} onClose={model.events.hide}>
|
|
61
|
+
<MenuItem>First Item</MenuItem>
|
|
62
|
+
<MenuItem>Second Item (with a really really really long label)</MenuItem>
|
|
63
|
+
<MenuItem isDisabled>Third Item (disabled)</MenuItem>
|
|
64
|
+
<MenuItem>
|
|
65
|
+
Fourth Item (<b>with markup</b>)
|
|
66
|
+
</MenuItem>
|
|
67
|
+
<MenuItem hasDivider>Fifth Item (with divider)</MenuItem>
|
|
68
|
+
</Menu>
|
|
69
|
+
</Popup.Popper>
|
|
70
|
+
</Popup>
|
|
16
71
|
);
|
|
17
72
|
};
|
|
@@ -1,49 +1,65 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {createComponent, useForkRef} from '@workday/canvas-kit-react/common';
|
|
4
4
|
import {Menu, MenuItem} from '@workday/canvas-kit-preview-react/menu';
|
|
5
5
|
import {
|
|
6
6
|
Popup,
|
|
7
|
+
PopupModelContext,
|
|
7
8
|
usePopupModel,
|
|
8
9
|
useAlwaysCloseOnOutsideClick,
|
|
9
10
|
useCloseOnEscape,
|
|
10
11
|
} from '@workday/canvas-kit-react/popup';
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
const ContextMenuTarget = createComponent('div')({
|
|
14
|
+
displayName: 'Popup.ContextMenuTarget',
|
|
15
|
+
Component: ({children, ...elemProps}, ref, Element) => {
|
|
16
|
+
const model = React.useContext(PopupModelContext);
|
|
17
|
+
const elementRef = useForkRef(ref, model.state.targetRef as any);
|
|
13
18
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
const onContextMenu = (event: React.MouseEvent) => {
|
|
20
|
+
if (model.state.visibility === 'visible') {
|
|
21
|
+
model.events.hide({event});
|
|
22
|
+
} else if (model.state.visibility === 'hidden') {
|
|
23
|
+
model.events.show({event});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Prevent the default context menu from showing to avoid double menus
|
|
27
|
+
event.preventDefault();
|
|
28
|
+
};
|
|
20
29
|
|
|
30
|
+
return (
|
|
31
|
+
<Element ref={elementRef} onContextMenu={onContextMenu} {...elemProps}>
|
|
32
|
+
{children}
|
|
33
|
+
</Element>
|
|
34
|
+
);
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export default () => {
|
|
21
39
|
const model = usePopupModel();
|
|
22
40
|
|
|
23
41
|
useAlwaysCloseOnOutsideClick(model);
|
|
24
42
|
useCloseOnEscape(model);
|
|
25
43
|
|
|
26
44
|
return (
|
|
27
|
-
<
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
<
|
|
33
|
-
<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
</Popup>
|
|
47
|
-
</CanvasProvider>
|
|
45
|
+
<Popup model={model}>
|
|
46
|
+
<ContextMenuTarget style={{display: 'inline'}} tabIndex={0}>
|
|
47
|
+
Right click on this text (Context menu target)
|
|
48
|
+
</ContextMenuTarget>
|
|
49
|
+
<Popup.Popper>
|
|
50
|
+
<Menu onClose={model.events.hide}>
|
|
51
|
+
<MenuItem>Back</MenuItem>
|
|
52
|
+
<MenuItem>Forward</MenuItem>
|
|
53
|
+
<MenuItem>Reload</MenuItem>
|
|
54
|
+
<MenuItem hasDivider>Bookmark Page</MenuItem>
|
|
55
|
+
<MenuItem>Save Page As...</MenuItem>
|
|
56
|
+
<MenuItem>Select All</MenuItem>
|
|
57
|
+
<MenuItem hasDivider>Take Screenshot</MenuItem>
|
|
58
|
+
<MenuItem hasDivider>View Page Source</MenuItem>
|
|
59
|
+
<MenuItem>Inspect Accessibility Properties</MenuItem>
|
|
60
|
+
<MenuItem>Inspect</MenuItem>
|
|
61
|
+
</Menu>
|
|
62
|
+
</Popup.Popper>
|
|
63
|
+
</Popup>
|
|
48
64
|
);
|
|
49
65
|
};
|
|
@@ -4,10 +4,10 @@ import {Menu, MenuItem} from '@workday/canvas-kit-preview-react/menu';
|
|
|
4
4
|
|
|
5
5
|
export default () => {
|
|
6
6
|
return (
|
|
7
|
-
<Menu
|
|
7
|
+
<Menu>
|
|
8
8
|
<MenuItem>First Item</MenuItem>
|
|
9
9
|
<MenuItem>Second Item</MenuItem>
|
|
10
|
-
<li role="
|
|
10
|
+
<li role="menuitem" tabIndex={-1} style={{listStyle: 'none'}}>
|
|
11
11
|
Third Item (custom)
|
|
12
12
|
</li>
|
|
13
13
|
</Menu>
|
|
@@ -8,7 +8,7 @@ export default () => {
|
|
|
8
8
|
{'One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve Thirteen Fourteen Fifteen'
|
|
9
9
|
.split(' ')
|
|
10
10
|
.map(item => {
|
|
11
|
-
return <MenuItem>Item {item}</MenuItem>;
|
|
11
|
+
return <MenuItem key={item}>Item {item}</MenuItem>;
|
|
12
12
|
})}
|
|
13
13
|
</Menu>
|
|
14
14
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workday/canvas-kit-docs",
|
|
3
|
-
"version": "5.3.0-next.
|
|
3
|
+
"version": "5.3.0-next.9+47f4d0a9",
|
|
4
4
|
"description": "Documentation components of Canvas Kit components",
|
|
5
5
|
"author": "Workday, Inc. (https://www.workday.com)",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@storybook/csf": "0.0.1",
|
|
52
|
-
"@workday/canvas-kit-react": "^5.3.0-next.
|
|
52
|
+
"@workday/canvas-kit-react": "^5.3.0-next.9+47f4d0a9"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"fs-extra": "^10.0.0",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"mkdirp": "^1.0.3",
|
|
58
58
|
"typescript": "^3.8.3"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "47f4d0a90fddfb15752be9e6449be2979f934636"
|
|
61
61
|
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import {createComponent, useForkRef} from '@workday/canvas-kit-react/common';
|
|
4
|
-
import {PopupModelContext} from '@workday/canvas-kit-react/popup';
|
|
5
|
-
|
|
6
|
-
interface ContextMenuTargetProps {
|
|
7
|
-
children: React.ReactNode;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export default createComponent('div')({
|
|
11
|
-
displayName: 'Popup.ContextMenuTarget',
|
|
12
|
-
Component: ({children, ...elemProps}: ContextMenuTargetProps, ref, Element) => {
|
|
13
|
-
const model = React.useContext(PopupModelContext);
|
|
14
|
-
const elementRef = useForkRef(ref, model.state.targetRef as any);
|
|
15
|
-
|
|
16
|
-
const onContextMenu = (event: React.MouseEvent) => {
|
|
17
|
-
if (model.state.visibility === 'visible') {
|
|
18
|
-
model.events.hide({event});
|
|
19
|
-
} else if (model.state.visibility === 'hidden') {
|
|
20
|
-
model.events.show({event});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// prevent the default context menu from showing to avoid double menus
|
|
24
|
-
event.preventDefault();
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<Element ref={elementRef} onContextMenu={onContextMenu} {...elemProps}>
|
|
29
|
-
{children}
|
|
30
|
-
</Element>
|
|
31
|
-
);
|
|
32
|
-
},
|
|
33
|
-
});
|