@workday/canvas-kit-preview-react 9.0.0-alpha.364-next.3 → 9.0.0-alpha.382-next.2
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/color-picker/lib/ColorPicker.js +24 -47
- package/dist/commonjs/color-picker/lib/parts/ColorReset.js +32 -23
- package/dist/commonjs/color-picker/lib/parts/SwatchBook.js +26 -39
- package/dist/commonjs/form-field/lib/FormField.js +10 -33
- package/dist/commonjs/form-field/lib/FormFieldHint.js +8 -31
- package/dist/commonjs/form-field/lib/FormFieldInput.js +6 -17
- package/dist/commonjs/form-field/lib/FormFieldLabel.js +8 -31
- package/dist/commonjs/form-field/lib/hooks/useFormFieldHint.js +4 -5
- package/dist/commonjs/form-field/lib/hooks/useFormFieldInput.js +5 -6
- package/dist/commonjs/form-field/lib/hooks/useFormFieldLabel.js +4 -5
- package/dist/commonjs/form-field/lib/hooks/useFormFieldModel.js +8 -16
- package/dist/commonjs/form-field/lib/hooks/useFormFieldOrientation.js +3 -3
- package/dist/commonjs/menu/lib/Menu.js +96 -129
- package/dist/commonjs/menu/lib/MenuItem.js +94 -109
- package/dist/commonjs/pill/lib/Pill.js +55 -60
- package/dist/commonjs/pill/lib/PillAvatar.js +6 -17
- package/dist/commonjs/pill/lib/PillCount.js +7 -30
- package/dist/commonjs/pill/lib/PillIcon.js +8 -31
- package/dist/commonjs/pill/lib/PillIconButton.js +13 -36
- package/dist/commonjs/pill/lib/PillLabel.js +10 -33
- package/dist/commonjs/pill/lib/usePillModel.js +8 -16
- package/dist/commonjs/segmented-control/lib/SegmentedControl.js +6 -7
- package/dist/commonjs/segmented-control/lib/SegmentedControlItem.js +24 -49
- package/dist/commonjs/segmented-control/lib/SegmentedControlList.js +13 -38
- package/dist/commonjs/segmented-control/lib/hooks/useSegmentedControlItem.js +8 -10
- package/dist/commonjs/segmented-control/lib/hooks/useSegmentedControlModel.js +31 -31
- package/dist/commonjs/select/lib/Select.js +147 -189
- package/dist/commonjs/select/lib/SelectBase.js +106 -101
- package/dist/commonjs/select/lib/SelectMenu.js +53 -84
- package/dist/commonjs/select/lib/SelectOption.js +33 -47
- package/dist/commonjs/select/lib/scrolling.js +6 -7
- package/dist/commonjs/select/lib/utils.js +4 -4
- package/dist/commonjs/side-panel/lib/SidePanel.js +36 -51
- package/dist/commonjs/side-panel/lib/SidePanelToggleButton.js +17 -40
- package/dist/commonjs/side-panel/lib/hooks.js +20 -20
- package/dist/commonjs/status-indicator/lib/StatusIndicator.js +10 -34
- package/dist/commonjs/status-indicator/lib/StatusIndicatorIcon.js +9 -21
- package/dist/commonjs/status-indicator/lib/StatusIndicatorLabel.js +5 -28
- package/dist/commonjs/status-indicator/lib/hooks/useStatusIndicatorModel.js +6 -15
- package/dist/commonjs/text-area/lib/TextArea.js +8 -31
- package/dist/commonjs/text-area/lib/TextAreaField.d.ts.map +1 -1
- package/dist/commonjs/text-area/lib/TextAreaField.js +12 -36
- package/dist/commonjs/text-input/lib/TextInput.js +8 -31
- package/dist/commonjs/text-input/lib/TextInputField.d.ts.map +1 -1
- package/dist/commonjs/text-input/lib/TextInputField.js +12 -24
- package/dist/commonjs/text-input/lib/hooks/useTextInputField.js +3 -3
- package/dist/commonjs/text-input/lib/hooks/useTextInputModel.js +1 -1
- package/dist/es6/color-picker/lib/ColorPicker.js +15 -38
- package/dist/es6/color-picker/lib/parts/ColorReset.js +27 -18
- package/dist/es6/color-picker/lib/parts/SwatchBook.js +21 -34
- package/dist/es6/form-field/lib/FormField.js +4 -27
- package/dist/es6/form-field/lib/FormFieldHint.js +4 -27
- package/dist/es6/form-field/lib/FormFieldInput.js +3 -14
- package/dist/es6/form-field/lib/FormFieldLabel.js +4 -27
- package/dist/es6/form-field/lib/hooks/useFormFieldHint.js +2 -3
- package/dist/es6/form-field/lib/hooks/useFormFieldInput.js +3 -4
- package/dist/es6/form-field/lib/hooks/useFormFieldLabel.js +2 -3
- package/dist/es6/form-field/lib/hooks/useFormFieldModel.js +8 -16
- package/dist/es6/form-field/lib/hooks/useFormFieldOrientation.js +2 -2
- package/dist/es6/menu/lib/Menu.js +91 -125
- package/dist/es6/menu/lib/MenuItem.js +90 -106
- package/dist/es6/pill/lib/Pill.js +45 -50
- package/dist/es6/pill/lib/PillAvatar.js +3 -14
- package/dist/es6/pill/lib/PillCount.js +4 -27
- package/dist/es6/pill/lib/PillIcon.js +3 -26
- package/dist/es6/pill/lib/PillIconButton.js +7 -30
- package/dist/es6/pill/lib/PillLabel.js +5 -28
- package/dist/es6/pill/lib/usePillModel.js +8 -16
- package/dist/es6/segmented-control/lib/SegmentedControl.js +2 -3
- package/dist/es6/segmented-control/lib/SegmentedControlItem.js +17 -42
- package/dist/es6/segmented-control/lib/SegmentedControlList.js +9 -34
- package/dist/es6/segmented-control/lib/hooks/useSegmentedControlItem.js +5 -7
- package/dist/es6/segmented-control/lib/hooks/useSegmentedControlModel.js +29 -29
- package/dist/es6/select/lib/Select.js +144 -186
- package/dist/es6/select/lib/SelectBase.js +99 -94
- package/dist/es6/select/lib/SelectMenu.js +49 -80
- package/dist/es6/select/lib/SelectOption.js +30 -44
- package/dist/es6/select/lib/scrolling.js +6 -7
- package/dist/es6/select/lib/utils.js +4 -4
- package/dist/es6/side-panel/lib/SidePanel.js +31 -46
- package/dist/es6/side-panel/lib/SidePanelToggleButton.js +10 -33
- package/dist/es6/side-panel/lib/hooks.js +19 -19
- package/dist/es6/status-indicator/lib/StatusIndicator.js +5 -29
- package/dist/es6/status-indicator/lib/StatusIndicatorIcon.js +6 -18
- package/dist/es6/status-indicator/lib/StatusIndicatorLabel.js +3 -26
- package/dist/es6/status-indicator/lib/hooks/useStatusIndicatorModel.js +6 -15
- package/dist/es6/text-area/lib/TextArea.js +4 -27
- package/dist/es6/text-area/lib/TextAreaField.d.ts.map +1 -1
- package/dist/es6/text-area/lib/TextAreaField.js +9 -33
- package/dist/es6/text-input/lib/TextInput.js +4 -27
- package/dist/es6/text-input/lib/TextInputField.d.ts.map +1 -1
- package/dist/es6/text-input/lib/TextInputField.js +9 -21
- package/dist/es6/text-input/lib/hooks/useTextInputField.js +1 -1
- package/dist/es6/text-input/lib/hooks/useTextInputModel.js +1 -1
- package/package.json +3 -4
- package/text-area/lib/TextAreaField.tsx +6 -2
- package/text-input/lib/TextInputField.tsx +6 -2
|
@@ -1,40 +1,17 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
-
var t = {};
|
|
14
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
-
t[p] = s[p];
|
|
16
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
-
t[p[i]] = s[p[i]];
|
|
20
|
-
}
|
|
21
|
-
return t;
|
|
22
|
-
};
|
|
23
1
|
import React from 'react';
|
|
24
2
|
import { createSubcomponent, useTheme } from '@workday/canvas-kit-react/common';
|
|
25
3
|
import { space } from '@workday/canvas-kit-react/tokens';
|
|
26
4
|
import { useFormFieldHint, useFormFieldModel } from './hooks';
|
|
27
5
|
import { Subtext } from '@workday/canvas-kit-react/text';
|
|
28
|
-
export
|
|
6
|
+
export const FormFieldHint = createSubcomponent('p')({
|
|
29
7
|
displayName: 'FormField.Hint',
|
|
30
8
|
modelHook: useFormFieldModel,
|
|
31
9
|
elemPropsHook: useFormFieldHint,
|
|
32
|
-
})(
|
|
33
|
-
|
|
34
|
-
var theme = useTheme();
|
|
10
|
+
})(({ children, ...elemProps }, Element, model) => {
|
|
11
|
+
const theme = useTheme();
|
|
35
12
|
if (!children) {
|
|
36
13
|
// If there is no hint text just skip rendering
|
|
37
14
|
return null;
|
|
38
15
|
}
|
|
39
|
-
return (React.createElement(Subtext,
|
|
16
|
+
return (React.createElement(Subtext, Object.assign({ as: Element, size: "medium", color: model.state.hasError ? theme.canvas.palette.error.main : undefined, marginY: space.xxs }, elemProps), children));
|
|
40
17
|
});
|
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
1
|
import React from 'react';
|
|
13
2
|
import { createSubcomponent } from '@workday/canvas-kit-react/common';
|
|
14
3
|
import { Box } from '@workday/canvas-kit-react/layout';
|
|
15
4
|
import { useFormFieldInput, useFormFieldModel } from './hooks';
|
|
16
|
-
export
|
|
5
|
+
export const FormFieldInput = createSubcomponent('input')({
|
|
17
6
|
displayName: 'FormField.Input',
|
|
18
7
|
modelHook: useFormFieldModel,
|
|
19
8
|
elemPropsHook: useFormFieldInput,
|
|
20
|
-
})(
|
|
21
|
-
return React.createElement(Box,
|
|
9
|
+
})((elemProps, Element) => {
|
|
10
|
+
return React.createElement(Box, Object.assign({ as: Element }, elemProps));
|
|
22
11
|
});
|
|
@@ -1,38 +1,15 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
-
var t = {};
|
|
14
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
-
t[p] = s[p];
|
|
16
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
-
t[p[i]] = s[p[i]];
|
|
20
|
-
}
|
|
21
|
-
return t;
|
|
22
|
-
};
|
|
23
1
|
import React from 'react';
|
|
24
2
|
import { createSubcomponent, useTheme } from '@workday/canvas-kit-react/common';
|
|
25
3
|
import { Flex } from '@workday/canvas-kit-react/layout';
|
|
26
4
|
import { LabelText, Text } from '@workday/canvas-kit-react/text';
|
|
27
5
|
import { useFormFieldLabel, useFormFieldModel } from './hooks';
|
|
28
|
-
export
|
|
6
|
+
export const FormFieldLabel = createSubcomponent('label')({
|
|
29
7
|
displayName: 'FormField.Label',
|
|
30
8
|
modelHook: useFormFieldModel,
|
|
31
9
|
elemPropsHook: useFormFieldLabel,
|
|
32
|
-
})(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return (React.createElement(Flex, __assign({ as: Element, gap: gap, minWidth: "180px" }, elemProps),
|
|
10
|
+
})(({ gap = 'xxxs', children, ...elemProps }, Element, model) => {
|
|
11
|
+
const theme = useTheme();
|
|
12
|
+
return (React.createElement(Flex, Object.assign({ as: Element, gap: gap, minWidth: "180px" }, elemProps),
|
|
36
13
|
React.createElement(LabelText, { as: "span", fontWeight: "medium" }, children),
|
|
37
14
|
model.state.isRequired && (React.createElement(Text, { fontSize: 20, fontWeight: "regular", textDecoration: "unset", color: theme.canvas.palette.error.main, "aria-hidden": "true" }, "*"))));
|
|
38
15
|
});
|
|
@@ -4,9 +4,8 @@ import { useFormFieldModel } from './useFormFieldModel';
|
|
|
4
4
|
* Adds the necessary props to a `Hint` component.
|
|
5
5
|
* Used by the FormField.Hint subcomponent and other input type components
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
var state = _a.state;
|
|
7
|
+
export const useFormFieldHint = createElemPropsHook(useFormFieldModel)(({ state }) => {
|
|
9
8
|
return {
|
|
10
|
-
id:
|
|
9
|
+
id: `hint-${state.id}`,
|
|
11
10
|
};
|
|
12
11
|
});
|
|
@@ -4,12 +4,11 @@ import { useFormFieldModel } from './useFormFieldModel';
|
|
|
4
4
|
* Adds the necessary props to an `Input` component.
|
|
5
5
|
* Used by the FormField.Input subcomponent and other input type components
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
var state = _a.state;
|
|
7
|
+
export const useFormFieldInput = createElemPropsHook(useFormFieldModel)(({ state }) => {
|
|
9
8
|
return {
|
|
10
9
|
required: state.isRequired ? true : undefined,
|
|
11
10
|
'aria-invalid': state.hasError ? true : undefined,
|
|
12
|
-
'aria-describedby':
|
|
13
|
-
id:
|
|
11
|
+
'aria-describedby': `hint-${state.id}`,
|
|
12
|
+
id: `input-${state.id}`,
|
|
14
13
|
};
|
|
15
14
|
});
|
|
@@ -4,9 +4,8 @@ import { useFormFieldModel } from './useFormFieldModel';
|
|
|
4
4
|
* Adds the necessary props to a `Label` component.
|
|
5
5
|
* Used by the FormField.Label subcomponent and other input type components
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
var state = _a.state;
|
|
7
|
+
export const useFormFieldLabel = createElemPropsHook(useFormFieldModel)(({ state }) => {
|
|
9
8
|
return {
|
|
10
|
-
htmlFor:
|
|
9
|
+
htmlFor: `input-${state.id}`,
|
|
11
10
|
};
|
|
12
11
|
});
|
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
1
|
import { createModelHook, useUniqueId } from '@workday/canvas-kit-react/common';
|
|
13
|
-
export
|
|
2
|
+
export const useFormFieldModel = createModelHook({
|
|
14
3
|
defaultConfig: {
|
|
15
4
|
/**
|
|
16
5
|
* Optional flag to denote if this field has an error to display. When true the `FormField.Input` will have
|
|
@@ -34,11 +23,14 @@ export var useFormFieldModel = createModelHook({
|
|
|
34
23
|
*/
|
|
35
24
|
isRequired: false,
|
|
36
25
|
},
|
|
37
|
-
})(
|
|
38
|
-
|
|
39
|
-
|
|
26
|
+
})(config => {
|
|
27
|
+
const id = useUniqueId(config.id);
|
|
28
|
+
const state = {
|
|
29
|
+
...config,
|
|
30
|
+
id,
|
|
31
|
+
};
|
|
40
32
|
return {
|
|
41
|
-
state
|
|
33
|
+
state,
|
|
42
34
|
events: {},
|
|
43
35
|
};
|
|
44
36
|
});
|
|
@@ -2,8 +2,8 @@ import { space } from '@workday/canvas-kit-react/tokens';
|
|
|
2
2
|
/**
|
|
3
3
|
* Adds the necessary layout props to a `FormField` component.
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
6
|
-
|
|
5
|
+
export const useFormFieldOrientation = (orientation) => {
|
|
6
|
+
let layoutProps;
|
|
7
7
|
if (orientation === 'horizontal') {
|
|
8
8
|
layoutProps = {
|
|
9
9
|
flexDirection: 'row',
|
|
@@ -1,48 +1,18 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
|
-
var __assign = (this && this.__assign) || function () {
|
|
17
|
-
__assign = Object.assign || function(t) {
|
|
18
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
-
s = arguments[i];
|
|
20
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
-
t[p] = s[p];
|
|
22
|
-
}
|
|
23
|
-
return t;
|
|
24
|
-
};
|
|
25
|
-
return __assign.apply(this, arguments);
|
|
26
|
-
};
|
|
27
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
28
|
-
var t = {};
|
|
29
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
30
|
-
t[p] = s[p];
|
|
31
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
32
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
33
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
34
|
-
t[p[i]] = s[p[i]];
|
|
35
|
-
}
|
|
36
|
-
return t;
|
|
37
|
-
};
|
|
38
1
|
import * as React from 'react';
|
|
39
2
|
import styled from '@emotion/styled';
|
|
40
3
|
import { Card } from '@workday/canvas-kit-react/card';
|
|
41
4
|
import { commonColors, space, borderRadius } from '@workday/canvas-kit-react/tokens';
|
|
42
5
|
import { hideMouseFocus, generateUniqueId } from '@workday/canvas-kit-react/common';
|
|
43
|
-
|
|
6
|
+
const List = styled('ul')({
|
|
7
|
+
background: commonColors.background,
|
|
8
|
+
borderRadius: borderRadius.m,
|
|
9
|
+
padding: 0,
|
|
10
|
+
margin: `${space.xxs} 0`,
|
|
11
|
+
'&:focus': {
|
|
44
12
|
outline: 'none',
|
|
45
|
-
}
|
|
13
|
+
},
|
|
14
|
+
...hideMouseFocus,
|
|
15
|
+
});
|
|
46
16
|
/**
|
|
47
17
|
* As of Canvas Kit v8, this component is being soft-deprecated. It will be hard-deprecated
|
|
48
18
|
* (completely removed) in v9. Please see the [upgrade
|
|
@@ -58,46 +28,45 @@ var List = styled('ul')(__assign({ background: commonColors.background, borderRa
|
|
|
58
28
|
*
|
|
59
29
|
* @deprecated
|
|
60
30
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
var lastItem = itemCount - 1;
|
|
31
|
+
export class DeprecatedMenu extends React.Component {
|
|
32
|
+
constructor(props) {
|
|
33
|
+
super(props);
|
|
34
|
+
this.id = generateUniqueId();
|
|
35
|
+
this.getNormalizedItemIndex = (index) => {
|
|
36
|
+
const itemCount = React.Children.count(this.props.children);
|
|
37
|
+
const firstItem = 0;
|
|
38
|
+
const lastItem = itemCount - 1;
|
|
70
39
|
if (!index) {
|
|
71
40
|
return firstItem;
|
|
72
41
|
}
|
|
73
42
|
return index < 0 ? firstItem : index >= itemCount ? lastItem : index;
|
|
74
43
|
};
|
|
75
|
-
|
|
76
|
-
|
|
44
|
+
this.setNormalizedItemIndex = (index) => {
|
|
45
|
+
this.setState({ selectedItemIndex: this.getNormalizedItemIndex(index) });
|
|
77
46
|
};
|
|
78
|
-
|
|
47
|
+
this.handleKeyboardShortcuts = (event) => {
|
|
79
48
|
if (event.ctrlKey || event.altKey || event.metaKey) {
|
|
80
49
|
return;
|
|
81
50
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
51
|
+
const children = React.Children.toArray(this.props.children);
|
|
52
|
+
let nextSelectedIndex = 0;
|
|
53
|
+
let isShortcut = false;
|
|
54
|
+
const interactiveItems = children.filter(child => {
|
|
86
55
|
var _a, _b;
|
|
87
56
|
return !((_b = (_a = child) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.isHeader);
|
|
88
57
|
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
58
|
+
const interactiveItemCount = interactiveItems.length;
|
|
59
|
+
const firstIndex = 0;
|
|
60
|
+
const lastIndex = interactiveItemCount - 1;
|
|
92
61
|
if (event.key.length === 1 && event.key.match(/\S/)) {
|
|
93
|
-
|
|
94
|
-
|
|
62
|
+
let start = this.state.selectedItemIndex + 1;
|
|
63
|
+
let searchIndex;
|
|
95
64
|
if (start === children.length) {
|
|
96
65
|
start = 0;
|
|
97
66
|
}
|
|
98
|
-
searchIndex =
|
|
67
|
+
searchIndex = this.getIndexFirstChars(start, event.key.toLowerCase());
|
|
99
68
|
if (searchIndex === -1) {
|
|
100
|
-
searchIndex =
|
|
69
|
+
searchIndex = this.getIndexFirstChars(0, event.key.toLowerCase(), start);
|
|
101
70
|
}
|
|
102
71
|
if (searchIndex > -1) {
|
|
103
72
|
isShortcut = true;
|
|
@@ -108,48 +77,48 @@ var DeprecatedMenu = /** @class */ (function (_super) {
|
|
|
108
77
|
switch (event.key) {
|
|
109
78
|
case 'ArrowUp':
|
|
110
79
|
case 'ArrowDown':
|
|
111
|
-
|
|
80
|
+
const direction = event.key === 'ArrowUp' ? -1 : 1;
|
|
112
81
|
isShortcut = true;
|
|
113
|
-
|
|
82
|
+
const nextIndex = this.state.selectedItemIndex + direction;
|
|
114
83
|
nextSelectedIndex =
|
|
115
84
|
nextIndex < 0 ? lastIndex : nextIndex >= interactiveItemCount ? firstIndex : nextIndex;
|
|
116
85
|
break;
|
|
117
86
|
case 'Home':
|
|
118
87
|
case 'End':
|
|
119
|
-
|
|
88
|
+
const skipTo = event.key === 'Home' ? firstIndex : lastIndex;
|
|
120
89
|
isShortcut = true;
|
|
121
90
|
nextSelectedIndex = skipTo;
|
|
122
91
|
break;
|
|
123
92
|
case 'Tab':
|
|
124
|
-
if (
|
|
125
|
-
|
|
93
|
+
if (this.props.onClose) {
|
|
94
|
+
this.props.onClose();
|
|
126
95
|
}
|
|
127
96
|
break;
|
|
128
97
|
case 'Escape':
|
|
129
98
|
case 'Esc': // IE/Edge specific value
|
|
130
99
|
isShortcut = true;
|
|
131
|
-
if (
|
|
132
|
-
|
|
100
|
+
if (this.props.onClose) {
|
|
101
|
+
this.props.onClose();
|
|
133
102
|
}
|
|
134
103
|
break;
|
|
135
104
|
case 'Spacebar':
|
|
136
105
|
case ' ':
|
|
137
106
|
case 'Enter':
|
|
138
|
-
nextSelectedIndex =
|
|
139
|
-
|
|
140
|
-
|
|
107
|
+
nextSelectedIndex = this.state.selectedItemIndex;
|
|
108
|
+
const child = interactiveItems[this.state.selectedItemIndex];
|
|
109
|
+
this.handleClick(event, child.props);
|
|
141
110
|
isShortcut = true;
|
|
142
111
|
break;
|
|
143
112
|
default:
|
|
144
113
|
}
|
|
145
114
|
}
|
|
146
115
|
if (isShortcut) {
|
|
147
|
-
|
|
116
|
+
this.setNormalizedItemIndex(nextSelectedIndex);
|
|
148
117
|
event.stopPropagation();
|
|
149
118
|
event.preventDefault();
|
|
150
119
|
}
|
|
151
120
|
};
|
|
152
|
-
|
|
121
|
+
this.handleClick = (event, menuItemProps) => {
|
|
153
122
|
/* istanbul ignore next line for coverage */
|
|
154
123
|
if (menuItemProps.isDisabled) {
|
|
155
124
|
// You should only hit this point if you are using a custom DeprecatedMenuItem implementation.
|
|
@@ -158,27 +127,26 @@ var DeprecatedMenu = /** @class */ (function (_super) {
|
|
|
158
127
|
if (menuItemProps.onClick) {
|
|
159
128
|
menuItemProps.onClick(event);
|
|
160
129
|
}
|
|
161
|
-
if (
|
|
162
|
-
|
|
130
|
+
if (this.props.onSelect) {
|
|
131
|
+
this.props.onSelect();
|
|
163
132
|
}
|
|
164
|
-
if (
|
|
133
|
+
if (this.props.onClose) {
|
|
165
134
|
if (menuItemProps.shouldClose) {
|
|
166
|
-
|
|
135
|
+
this.props.onClose();
|
|
167
136
|
}
|
|
168
137
|
}
|
|
169
138
|
};
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if (character === _this.firstCharacters[i]) {
|
|
139
|
+
this.getIndexFirstChars = (startIndex, character, lastIndex = this.firstCharacters.length) => {
|
|
140
|
+
for (let i = startIndex; i < lastIndex; i++) {
|
|
141
|
+
if (character === this.firstCharacters[i]) {
|
|
174
142
|
return i;
|
|
175
143
|
}
|
|
176
144
|
}
|
|
177
145
|
return -1;
|
|
178
146
|
};
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
147
|
+
this.setFirstCharacters = () => {
|
|
148
|
+
const getFirstCharacter = (child) => {
|
|
149
|
+
let character = '';
|
|
182
150
|
if (!child || typeof child === 'boolean') {
|
|
183
151
|
character = '';
|
|
184
152
|
}
|
|
@@ -194,7 +162,7 @@ var DeprecatedMenu = /** @class */ (function (_super) {
|
|
|
194
162
|
character = getFirstCharacter(child[0]);
|
|
195
163
|
}
|
|
196
164
|
else if ('props' in child) {
|
|
197
|
-
|
|
165
|
+
const { children } = child.props;
|
|
198
166
|
if (Array.isArray(children)) {
|
|
199
167
|
character = getFirstCharacter(children[0]);
|
|
200
168
|
}
|
|
@@ -204,43 +172,41 @@ var DeprecatedMenu = /** @class */ (function (_super) {
|
|
|
204
172
|
}
|
|
205
173
|
return character;
|
|
206
174
|
};
|
|
207
|
-
|
|
175
|
+
const firstCharacters = React.Children.map(this.props.children, child => {
|
|
208
176
|
var _a, _b;
|
|
209
177
|
if ((_b = (_a = child) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.isHeader) {
|
|
210
178
|
return;
|
|
211
179
|
}
|
|
212
180
|
return getFirstCharacter(child);
|
|
213
181
|
});
|
|
214
|
-
|
|
182
|
+
this.firstCharacters = firstCharacters;
|
|
215
183
|
};
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
selected = selected < 0 ? React.Children.count(
|
|
184
|
+
this.getInitialSelectedItem = () => {
|
|
185
|
+
let selected = this.props.initialSelectedItem || 0;
|
|
186
|
+
selected = selected < 0 ? React.Children.count(this.props.children) + selected : selected;
|
|
219
187
|
if (selected < 0) {
|
|
220
188
|
selected = 0;
|
|
221
189
|
}
|
|
222
|
-
else if (selected > React.Children.count(
|
|
223
|
-
selected = React.Children.count(
|
|
190
|
+
else if (selected > React.Children.count(this.props.children) - 1) {
|
|
191
|
+
selected = React.Children.count(this.props.children) - 1;
|
|
224
192
|
}
|
|
225
193
|
return selected;
|
|
226
194
|
};
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
195
|
+
this.setInitialSelectedItem = () => {
|
|
196
|
+
const selected = this.getInitialSelectedItem();
|
|
197
|
+
this.setState({ selectedItemIndex: selected });
|
|
230
198
|
};
|
|
231
|
-
|
|
232
|
-
|
|
199
|
+
this.menuRef = React.createRef();
|
|
200
|
+
const selected = this.getInitialSelectedItem();
|
|
233
201
|
// We track the active menu item by index so we can avoid setting a bunch of refs
|
|
234
202
|
// for doing things like selecting an item by first character (or really calling .focus() at all)
|
|
235
203
|
// It allows us to use the activedescendant design pattern
|
|
236
204
|
// https://www.w3.org/TR/wai-aria-practices/examples/menu-button/menu-button-actions-active-descendant.html
|
|
237
|
-
|
|
205
|
+
this.state = {
|
|
238
206
|
selectedItemIndex: selected,
|
|
239
207
|
};
|
|
240
|
-
return _this;
|
|
241
208
|
}
|
|
242
|
-
|
|
243
|
-
var _this = this;
|
|
209
|
+
componentDidUpdate(prevProps) {
|
|
244
210
|
if (this.props.children !== prevProps.children) {
|
|
245
211
|
this.setFirstCharacters();
|
|
246
212
|
this.setInitialSelectedItem();
|
|
@@ -248,45 +214,45 @@ var DeprecatedMenu = /** @class */ (function (_super) {
|
|
|
248
214
|
if (this.props.isOpen && !prevProps.isOpen) {
|
|
249
215
|
this.setInitialSelectedItem();
|
|
250
216
|
}
|
|
251
|
-
this.animateId = requestAnimationFrame(
|
|
252
|
-
if (
|
|
253
|
-
|
|
217
|
+
this.animateId = requestAnimationFrame(() => {
|
|
218
|
+
if (this.props.isOpen && this.menuRef.current) {
|
|
219
|
+
this.menuRef.current.focus();
|
|
254
220
|
}
|
|
255
221
|
});
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
console.warn(
|
|
222
|
+
}
|
|
223
|
+
componentDidMount() {
|
|
224
|
+
console.warn(`This component is being deprecated and will be removed in Canvas Kit V9.\n
|
|
225
|
+
For more information, please see the V8 upgrade guide:\n
|
|
226
|
+
https://workday.github.io/canvas-kit/?path=/story/welcome-upgrade-guides-v8-0--page
|
|
227
|
+
`);
|
|
259
228
|
this.setFirstCharacters();
|
|
260
229
|
this.setInitialSelectedItem();
|
|
261
|
-
}
|
|
262
|
-
|
|
230
|
+
}
|
|
231
|
+
componentWillUnmount() {
|
|
263
232
|
cancelAnimationFrame(this.animateId);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
var _this = this;
|
|
233
|
+
}
|
|
234
|
+
render() {
|
|
267
235
|
// TODO: Standardize on prop spread location (see #150)
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
236
|
+
const { id = this.id, isOpen = true, children, 'aria-labelledby': ariaLabelledby, grow, width, onSelect, onClose, initialSelectedItem, ...elemProps } = this.props;
|
|
237
|
+
const { selectedItemIndex } = this.state;
|
|
238
|
+
const cardWidth = grow ? '100%' : width;
|
|
239
|
+
let interactiveItemIndex = null;
|
|
272
240
|
return (React.createElement(Card, { display: "inline-block", padding: space.zero, width: cardWidth, depth: 3 },
|
|
273
241
|
React.createElement(Card.Body, null,
|
|
274
|
-
React.createElement(List,
|
|
242
|
+
React.createElement(List, Object.assign({ role: "menu", tabIndex: 0, id: id, "aria-labelledby": ariaLabelledby, "aria-activedescendant": `${id}-${selectedItemIndex}`, onKeyDown: this.handleKeyboardShortcuts, ref: this.menuRef }, elemProps), React.Children.map(children, menuItem => {
|
|
275
243
|
if (!React.isValidElement(menuItem)) {
|
|
276
244
|
return;
|
|
277
245
|
}
|
|
278
|
-
|
|
246
|
+
let itemId;
|
|
279
247
|
if (!menuItem.props.isHeader) {
|
|
280
248
|
interactiveItemIndex = (interactiveItemIndex !== null && interactiveItemIndex !== void 0 ? interactiveItemIndex : -1) + 1;
|
|
281
|
-
itemId = id
|
|
249
|
+
itemId = `${id}-${interactiveItemIndex}`;
|
|
282
250
|
}
|
|
283
251
|
return (React.createElement(React.Fragment, { key: itemId }, React.cloneElement(menuItem, {
|
|
284
|
-
onClick:
|
|
252
|
+
onClick: (event) => this.handleClick(event, menuItem.props),
|
|
285
253
|
id: itemId,
|
|
286
254
|
isFocused: selectedItemIndex === interactiveItemIndex && !menuItem.props.isHeader,
|
|
287
255
|
})));
|
|
288
256
|
})))));
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
}(React.Component));
|
|
292
|
-
export { DeprecatedMenu };
|
|
257
|
+
}
|
|
258
|
+
}
|