@patternfly/react-core 4.229.0 → 4.231.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.
- package/CHANGELOG.md +30 -0
- package/dist/esm/components/ContextSelector/ContextSelector.d.ts +4 -2
- package/dist/esm/components/ContextSelector/ContextSelector.d.ts.map +1 -1
- package/dist/esm/components/ContextSelector/ContextSelector.js.map +1 -1
- package/dist/esm/components/ContextSelector/ContextSelectorToggle.d.ts +4 -2
- package/dist/esm/components/ContextSelector/ContextSelectorToggle.d.ts.map +1 -1
- package/dist/esm/components/ContextSelector/ContextSelectorToggle.js.map +1 -1
- package/dist/esm/components/MenuToggle/MenuToggle.d.ts +8 -0
- package/dist/esm/components/MenuToggle/MenuToggle.d.ts.map +1 -1
- package/dist/esm/components/MenuToggle/MenuToggle.js +12 -7
- package/dist/esm/components/MenuToggle/MenuToggle.js.map +1 -1
- package/dist/esm/components/MenuToggle/MenuToggleAction.d.ts +19 -0
- package/dist/esm/components/MenuToggle/MenuToggleAction.d.ts.map +1 -0
- package/dist/esm/components/MenuToggle/MenuToggleAction.js +17 -0
- package/dist/esm/components/MenuToggle/MenuToggleAction.js.map +1 -0
- package/dist/esm/components/MenuToggle/MenuToggleCheckbox.d.ts +36 -0
- package/dist/esm/components/MenuToggle/MenuToggleCheckbox.d.ts.map +1 -0
- package/dist/esm/components/MenuToggle/MenuToggleCheckbox.js +43 -0
- package/dist/esm/components/MenuToggle/MenuToggleCheckbox.js.map +1 -0
- package/dist/esm/components/MenuToggle/index.d.ts +2 -0
- package/dist/esm/components/MenuToggle/index.d.ts.map +1 -1
- package/dist/esm/components/MenuToggle/index.js +2 -0
- package/dist/esm/components/MenuToggle/index.js.map +1 -1
- package/dist/esm/components/Page/Page.d.ts +13 -0
- package/dist/esm/components/Page/Page.d.ts.map +1 -1
- package/dist/esm/components/Page/Page.js +18 -19
- package/dist/esm/components/Page/Page.js.map +1 -1
- package/dist/esm/components/Page/PageBreadcrumb.d.ts +11 -2
- package/dist/esm/components/Page/PageBreadcrumb.d.ts.map +1 -1
- package/dist/esm/components/Page/PageBreadcrumb.js +5 -2
- package/dist/esm/components/Page/PageBreadcrumb.js.map +1 -1
- package/dist/esm/components/Page/PageGroup.d.ts +11 -2
- package/dist/esm/components/Page/PageGroup.d.ts.map +1 -1
- package/dist/esm/components/Page/PageGroup.js +5 -2
- package/dist/esm/components/Page/PageGroup.js.map +1 -1
- package/dist/esm/components/Page/PageNavigation.d.ts +11 -2
- package/dist/esm/components/Page/PageNavigation.d.ts.map +1 -1
- package/dist/esm/components/Page/PageNavigation.js +5 -2
- package/dist/esm/components/Page/PageNavigation.js.map +1 -1
- package/dist/esm/components/Page/PageSection.d.ts +10 -1
- package/dist/esm/components/Page/PageSection.d.ts.map +1 -1
- package/dist/esm/components/Page/PageSection.js +4 -2
- package/dist/esm/components/Page/PageSection.js.map +1 -1
- package/dist/esm/helpers/constants.d.ts +14 -0
- package/dist/esm/helpers/constants.d.ts.map +1 -1
- package/dist/esm/helpers/constants.js +24 -0
- package/dist/esm/helpers/constants.js.map +1 -1
- package/dist/esm/helpers/util.d.ts +8 -1
- package/dist/esm/helpers/util.d.ts.map +1 -1
- package/dist/esm/helpers/util.js +36 -9
- package/dist/esm/helpers/util.js.map +1 -1
- package/dist/js/components/ContextSelector/ContextSelector.d.ts +4 -2
- package/dist/js/components/ContextSelector/ContextSelector.d.ts.map +1 -1
- package/dist/js/components/ContextSelector/ContextSelector.js.map +1 -1
- package/dist/js/components/ContextSelector/ContextSelectorToggle.d.ts +4 -2
- package/dist/js/components/ContextSelector/ContextSelectorToggle.d.ts.map +1 -1
- package/dist/js/components/ContextSelector/ContextSelectorToggle.js.map +1 -1
- package/dist/js/components/MenuToggle/MenuToggle.d.ts +8 -0
- package/dist/js/components/MenuToggle/MenuToggle.d.ts.map +1 -1
- package/dist/js/components/MenuToggle/MenuToggle.js +12 -7
- package/dist/js/components/MenuToggle/MenuToggle.js.map +1 -1
- package/dist/js/components/MenuToggle/MenuToggleAction.d.ts +19 -0
- package/dist/js/components/MenuToggle/MenuToggleAction.d.ts.map +1 -0
- package/dist/js/components/MenuToggle/MenuToggleAction.js +21 -0
- package/dist/js/components/MenuToggle/MenuToggleAction.js.map +1 -0
- package/dist/js/components/MenuToggle/MenuToggleCheckbox.d.ts +36 -0
- package/dist/js/components/MenuToggle/MenuToggleCheckbox.d.ts.map +1 -0
- package/dist/js/components/MenuToggle/MenuToggleCheckbox.js +47 -0
- package/dist/js/components/MenuToggle/MenuToggleCheckbox.js.map +1 -0
- package/dist/js/components/MenuToggle/index.d.ts +2 -0
- package/dist/js/components/MenuToggle/index.d.ts.map +1 -1
- package/dist/js/components/MenuToggle/index.js +2 -0
- package/dist/js/components/MenuToggle/index.js.map +1 -1
- package/dist/js/components/Page/Page.d.ts +13 -0
- package/dist/js/components/Page/Page.d.ts.map +1 -1
- package/dist/js/components/Page/Page.js +17 -18
- package/dist/js/components/Page/Page.js.map +1 -1
- package/dist/js/components/Page/PageBreadcrumb.d.ts +11 -2
- package/dist/js/components/Page/PageBreadcrumb.d.ts.map +1 -1
- package/dist/js/components/Page/PageBreadcrumb.js +5 -2
- package/dist/js/components/Page/PageBreadcrumb.js.map +1 -1
- package/dist/js/components/Page/PageGroup.d.ts +11 -2
- package/dist/js/components/Page/PageGroup.d.ts.map +1 -1
- package/dist/js/components/Page/PageGroup.js +5 -2
- package/dist/js/components/Page/PageGroup.js.map +1 -1
- package/dist/js/components/Page/PageNavigation.d.ts +11 -2
- package/dist/js/components/Page/PageNavigation.d.ts.map +1 -1
- package/dist/js/components/Page/PageNavigation.js +5 -2
- package/dist/js/components/Page/PageNavigation.js.map +1 -1
- package/dist/js/components/Page/PageSection.d.ts +10 -1
- package/dist/js/components/Page/PageSection.d.ts.map +1 -1
- package/dist/js/components/Page/PageSection.js +4 -2
- package/dist/js/components/Page/PageSection.js.map +1 -1
- package/dist/js/helpers/constants.d.ts +14 -0
- package/dist/js/helpers/constants.d.ts.map +1 -1
- package/dist/js/helpers/constants.js +26 -1
- package/dist/js/helpers/constants.js.map +1 -1
- package/dist/js/helpers/util.d.ts +8 -1
- package/dist/js/helpers/util.d.ts.map +1 -1
- package/dist/js/helpers/util.js +37 -9
- package/dist/js/helpers/util.js.map +1 -1
- package/dist/umd/react-core.css +60 -10
- package/dist/umd/react-core.js +220 -72
- package/dist/umd/react-core.min.css +124 -74
- package/dist/umd/react-core.min.js +6 -5
- package/package.json +6 -6
- package/src/components/ContextSelector/ContextSelector.tsx +4 -2
- package/src/components/ContextSelector/ContextSelectorToggle.tsx +4 -2
- package/src/components/MenuToggle/MenuToggle.tsx +53 -27
- package/src/components/MenuToggle/MenuToggleAction.tsx +42 -0
- package/src/components/MenuToggle/MenuToggleCheckbox.tsx +104 -0
- package/src/components/MenuToggle/__tests__/__snapshots__/MenuToggle.test.tsx.snap +1 -1
- package/src/components/MenuToggle/examples/MenuToggle.md +35 -2
- package/src/components/MenuToggle/examples/MenuToggleSplitButtonAction.tsx +51 -0
- package/src/components/MenuToggle/examples/MenuToggleSplitButtonActionPrimary.tsx +58 -0
- package/src/components/MenuToggle/examples/MenuToggleSplitButtonActionSecondary.tsx +58 -0
- package/src/components/MenuToggle/examples/MenuToggleSplitButtonCheckbox.tsx +40 -0
- package/src/components/MenuToggle/examples/MenuToggleSplitButtonCheckboxPrimary.tsx +55 -0
- package/src/components/MenuToggle/examples/MenuToggleSplitButtonCheckboxSecondary.tsx +55 -0
- package/src/components/MenuToggle/examples/MenuToggleSplitButtonCheckboxWithText.tsx +52 -0
- package/src/components/MenuToggle/index.ts +2 -0
- package/src/components/Page/Page.tsx +58 -21
- package/src/components/Page/PageBreadcrumb.tsx +37 -20
- package/src/components/Page/PageGroup.tsx +35 -19
- package/src/components/Page/PageNavigation.tsx +37 -20
- package/src/components/Page/PageSection.tsx +41 -25
- package/src/components/Page/__tests__/Page.test.tsx +126 -2
- package/src/components/Page/__tests__/__snapshots__/Page.test.tsx.snap +683 -14
- package/src/demos/Page/Page.md +356 -3
- package/src/helpers/constants.ts +28 -0
- package/src/helpers/util.ts +44 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.231.0",
|
|
4
4
|
"description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
|
|
5
5
|
"main": "dist/js/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -34,16 +34,16 @@
|
|
|
34
34
|
"generate": "node scripts/copyStyles.js"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@patternfly/react-icons": "^4.
|
|
38
|
-
"@patternfly/react-styles": "^4.
|
|
39
|
-
"@patternfly/react-tokens": "^4.
|
|
37
|
+
"@patternfly/react-icons": "^4.82.0",
|
|
38
|
+
"@patternfly/react-styles": "^4.81.0",
|
|
39
|
+
"@patternfly/react-tokens": "^4.83.0",
|
|
40
40
|
"focus-trap": "6.9.2",
|
|
41
41
|
"react-dropzone": "9.0.0",
|
|
42
42
|
"tippy.js": "5.1.2",
|
|
43
43
|
"tslib": "^2.0.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@patternfly/patternfly": "4.206.
|
|
46
|
+
"@patternfly/patternfly": "4.206.2",
|
|
47
47
|
"@rollup/plugin-commonjs": "^21.0.0",
|
|
48
48
|
"@rollup/plugin-node-resolve": "^13.0.0",
|
|
49
49
|
"@rollup/plugin-replace": "^3.0.0",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"react": "^16.8.0 || ^17.0.0",
|
|
61
61
|
"react-dom": "^16.8.0 || ^17.0.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "6e1df86d6c02166eb1b8ea4a5afeb252da326d22"
|
|
64
64
|
}
|
|
@@ -37,8 +37,10 @@ export interface ContextSelectorProps extends Omit<ToggleMenuBaseProps, 'menuApp
|
|
|
37
37
|
isFullHeight?: boolean;
|
|
38
38
|
/** Labels the Context Selector for Screen Readers */
|
|
39
39
|
screenReaderLabel?: string;
|
|
40
|
-
/**
|
|
41
|
-
|
|
40
|
+
/** Component or string that will be used in the context selector.
|
|
41
|
+
* This prop is placed in a button, and cannot contain any interactive elements
|
|
42
|
+
*/
|
|
43
|
+
toggleText?: React.ReactNode;
|
|
42
44
|
/** Aria-label for the Context Selector Search Button */
|
|
43
45
|
searchButtonAriaLabel?: string;
|
|
44
46
|
/** Value in the Search field */
|
|
@@ -10,8 +10,10 @@ export interface ContextSelectorToggleProps {
|
|
|
10
10
|
id: string;
|
|
11
11
|
/** Classes applied to root element of toggle */
|
|
12
12
|
className?: string;
|
|
13
|
-
/**
|
|
14
|
-
|
|
13
|
+
/** Component or string that will be used in the context selector.
|
|
14
|
+
* This prop is placed in a button, and cannot contain any interactive elements
|
|
15
|
+
*/
|
|
16
|
+
toggleText?: React.ReactNode;
|
|
15
17
|
/** Flag to indicate if menu is opened */
|
|
16
18
|
isOpen?: boolean;
|
|
17
19
|
/** Callback called when toggle is clicked */
|
|
@@ -6,6 +6,13 @@ import { BadgeProps } from '../Badge';
|
|
|
6
6
|
|
|
7
7
|
export type MenuToggleElement = HTMLDivElement | HTMLButtonElement;
|
|
8
8
|
|
|
9
|
+
export interface SplitButtonOptions {
|
|
10
|
+
/** Elements to display before the toggle button. When included, renders the menu toggle as a split button. */
|
|
11
|
+
items: React.ReactNode[];
|
|
12
|
+
/** Variant of split button toggle */
|
|
13
|
+
variant?: 'action' | 'checkbox';
|
|
14
|
+
}
|
|
15
|
+
|
|
9
16
|
export interface MenuToggleProps
|
|
10
17
|
extends Omit<React.DetailedHTMLProps<React.HTMLAttributes<MenuToggleElement>, MenuToggleElement>, 'ref'> {
|
|
11
18
|
/** Content rendered inside the toggle */
|
|
@@ -20,6 +27,8 @@ export interface MenuToggleProps
|
|
|
20
27
|
isFullHeight?: boolean;
|
|
21
28
|
/** Flag indicating the toggle takes up the full width of its parent */
|
|
22
29
|
isFullWidth?: boolean;
|
|
30
|
+
/** Object used to configure a split button menu toggle */
|
|
31
|
+
splitButtonOptions?: SplitButtonOptions;
|
|
23
32
|
/** Variant styles of the menu toggle */
|
|
24
33
|
variant?: 'default' | 'plain' | 'primary' | 'plainText' | 'secondary' | 'typeahead';
|
|
25
34
|
/** Optional icon rendered inside the toggle, before the children content */
|
|
@@ -37,8 +46,7 @@ export class MenuToggleBase extends React.Component<MenuToggleProps> {
|
|
|
37
46
|
isExpanded: false,
|
|
38
47
|
isDisabled: false,
|
|
39
48
|
isFullWidth: false,
|
|
40
|
-
isFullHeight: false
|
|
41
|
-
variant: 'default'
|
|
49
|
+
isFullHeight: false
|
|
42
50
|
};
|
|
43
51
|
|
|
44
52
|
render() {
|
|
@@ -51,6 +59,7 @@ export class MenuToggleBase extends React.Component<MenuToggleProps> {
|
|
|
51
59
|
isDisabled,
|
|
52
60
|
isFullHeight,
|
|
53
61
|
isFullWidth,
|
|
62
|
+
splitButtonOptions,
|
|
54
63
|
variant,
|
|
55
64
|
innerRef,
|
|
56
65
|
onClick,
|
|
@@ -71,7 +80,7 @@ export class MenuToggleBase extends React.Component<MenuToggleProps> {
|
|
|
71
80
|
const content = (
|
|
72
81
|
<>
|
|
73
82
|
{icon && <span className={css(styles.menuToggleIcon)}>{icon}</span>}
|
|
74
|
-
{isTypeahead ? children : <span className=
|
|
83
|
+
{isTypeahead ? children : <span className={css(styles.menuToggleText)}>{children}</span>}
|
|
75
84
|
{badge && <span className={css(styles.menuToggleCount)}>{badge}</span>}
|
|
76
85
|
{isTypeahead ? (
|
|
77
86
|
<button
|
|
@@ -89,44 +98,61 @@ export class MenuToggleBase extends React.Component<MenuToggleProps> {
|
|
|
89
98
|
</>
|
|
90
99
|
);
|
|
91
100
|
|
|
101
|
+
const commonStyles = css(
|
|
102
|
+
styles.menuToggle,
|
|
103
|
+
isExpanded && styles.modifiers.expanded,
|
|
104
|
+
variant === 'primary' && styles.modifiers.primary,
|
|
105
|
+
variant === 'secondary' && styles.modifiers.secondary,
|
|
106
|
+
(isPlain || isPlainText) && styles.modifiers.plain,
|
|
107
|
+
isPlainText && styles.modifiers.text,
|
|
108
|
+
isFullHeight && styles.modifiers.fullHeight,
|
|
109
|
+
isFullWidth && styles.modifiers.fullWidth,
|
|
110
|
+
isDisabled && styles.modifiers.disabled,
|
|
111
|
+
className
|
|
112
|
+
);
|
|
113
|
+
|
|
92
114
|
const componentProps = {
|
|
93
|
-
className: css(
|
|
94
|
-
styles.menuToggle,
|
|
95
|
-
isExpanded && styles.modifiers.expanded,
|
|
96
|
-
variant === 'primary' && styles.modifiers.primary,
|
|
97
|
-
(isPlain || isPlainText) && styles.modifiers.plain,
|
|
98
|
-
isPlainText && styles.modifiers.text,
|
|
99
|
-
isFullHeight && styles.modifiers.fullHeight,
|
|
100
|
-
isTypeahead && styles.modifiers.typeahead,
|
|
101
|
-
isFullWidth && styles.modifiers.fullWidth,
|
|
102
|
-
className
|
|
103
|
-
),
|
|
104
115
|
children: isPlain ? children : content,
|
|
105
116
|
...(isDisabled && { disabled: true }),
|
|
106
117
|
...otherProps
|
|
107
118
|
};
|
|
108
119
|
|
|
109
120
|
if (isTypeahead) {
|
|
110
|
-
return <div ref={innerRef as React.Ref<HTMLDivElement>} {...componentProps} />;
|
|
121
|
+
return <div ref={innerRef as React.Ref<HTMLDivElement>} className={css(commonStyles)} {...componentProps} />;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (splitButtonOptions) {
|
|
125
|
+
return (
|
|
126
|
+
<div
|
|
127
|
+
className={css(
|
|
128
|
+
commonStyles,
|
|
129
|
+
styles.modifiers.splitButton,
|
|
130
|
+
splitButtonOptions?.variant === 'action' && styles.modifiers.action
|
|
131
|
+
)}
|
|
132
|
+
>
|
|
133
|
+
{splitButtonOptions?.items}
|
|
134
|
+
<button
|
|
135
|
+
className={css(styles.menuToggleButton)}
|
|
136
|
+
type="button"
|
|
137
|
+
aria-expanded={isExpanded}
|
|
138
|
+
aria-label={ariaLabel}
|
|
139
|
+
disabled={isDisabled}
|
|
140
|
+
{...otherProps}
|
|
141
|
+
>
|
|
142
|
+
{toggleControls}
|
|
143
|
+
</button>
|
|
144
|
+
</div>
|
|
145
|
+
);
|
|
111
146
|
}
|
|
112
147
|
|
|
113
148
|
return (
|
|
114
149
|
<button
|
|
115
|
-
className={css(
|
|
116
|
-
styles.menuToggle,
|
|
117
|
-
isExpanded && styles.modifiers.expanded,
|
|
118
|
-
variant === 'primary' && styles.modifiers.primary,
|
|
119
|
-
variant === 'secondary' && styles.modifiers.secondary,
|
|
120
|
-
(isPlain || isPlainText) && styles.modifiers.plain,
|
|
121
|
-
isPlainText && styles.modifiers.text,
|
|
122
|
-
isFullHeight && styles.modifiers.fullHeight,
|
|
123
|
-
isFullWidth && styles.modifiers.fullWidth,
|
|
124
|
-
className
|
|
125
|
-
)}
|
|
126
|
-
ref={innerRef as React.Ref<HTMLButtonElement>}
|
|
150
|
+
className={css(commonStyles)}
|
|
127
151
|
type="button"
|
|
128
152
|
aria-label={ariaLabel}
|
|
129
153
|
aria-expanded={isExpanded}
|
|
154
|
+
ref={innerRef as React.Ref<HTMLButtonElement>}
|
|
155
|
+
disabled={isDisabled}
|
|
130
156
|
onClick={onClick}
|
|
131
157
|
{...componentProps}
|
|
132
158
|
/>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import styles from '@patternfly/react-styles/css/components/MenuToggle/menu-toggle';
|
|
3
|
+
import { css } from '@patternfly/react-styles';
|
|
4
|
+
|
|
5
|
+
export interface MenuToggleActionProps {
|
|
6
|
+
/** Additional classes added to the MenuToggleAction */
|
|
7
|
+
className?: string;
|
|
8
|
+
/** Flag to show if the action button is disabled */
|
|
9
|
+
isDisabled?: boolean;
|
|
10
|
+
/** A callback for when the action button is clicked */
|
|
11
|
+
onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void;
|
|
12
|
+
/** Element to be rendered inside the <button> */
|
|
13
|
+
children?: React.ReactNode;
|
|
14
|
+
/** Id of the action button */
|
|
15
|
+
id?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class MenuToggleAction extends React.Component<MenuToggleActionProps> {
|
|
19
|
+
static displayName = 'MenuToggleAction';
|
|
20
|
+
static defaultProps: MenuToggleActionProps = {
|
|
21
|
+
className: '',
|
|
22
|
+
isDisabled: false,
|
|
23
|
+
onClick: () => {}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
render() {
|
|
27
|
+
const { id, className, onClick, isDisabled, children, ...props } = this.props;
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<button
|
|
31
|
+
id={id}
|
|
32
|
+
className={css(styles.menuToggleButton, className)}
|
|
33
|
+
onClick={onClick}
|
|
34
|
+
type="button"
|
|
35
|
+
disabled={isDisabled}
|
|
36
|
+
{...props}
|
|
37
|
+
>
|
|
38
|
+
{children}
|
|
39
|
+
</button>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import styles from '@patternfly/react-styles/css/components/Check/check';
|
|
3
|
+
import { css } from '@patternfly/react-styles';
|
|
4
|
+
import { PickOptional } from '../../helpers/typeUtils';
|
|
5
|
+
import { getOUIAProps, OUIAProps, getDefaultOUIAId } from '../../helpers';
|
|
6
|
+
|
|
7
|
+
export interface MenuToggleCheckboxProps
|
|
8
|
+
extends Omit<React.HTMLProps<HTMLInputElement>, 'type' | 'onChange' | 'disabled' | 'checked'>,
|
|
9
|
+
OUIAProps {
|
|
10
|
+
/** Additional classes added to the MenuToggleCheckbox */
|
|
11
|
+
className?: string;
|
|
12
|
+
/** Flag to show if the checkbox selection is valid or invalid */
|
|
13
|
+
isValid?: boolean;
|
|
14
|
+
/** Flag to show if the checkbox is disabled */
|
|
15
|
+
isDisabled?: boolean;
|
|
16
|
+
/** Flag to show if the checkbox is checked when it is controlled by React state.
|
|
17
|
+
* To make the checkbox uncontrolled instead use the defaultChecked prop, but do not use both.
|
|
18
|
+
*/
|
|
19
|
+
isChecked?: boolean | null;
|
|
20
|
+
/** Flag to set the default checked value of the checkbox when it is uncontrolled by React state.
|
|
21
|
+
* To make the checkbox controlled instead use the isChecked prop, but do not use both.
|
|
22
|
+
*/
|
|
23
|
+
defaultChecked?: boolean | null;
|
|
24
|
+
/** A callback for when the checkbox selection changes */
|
|
25
|
+
onChange?: (checked: boolean, event: React.FormEvent<HTMLInputElement>) => void;
|
|
26
|
+
/** Element to be rendered inside the <span> */
|
|
27
|
+
children?: React.ReactNode;
|
|
28
|
+
/** Id of the checkbox */
|
|
29
|
+
id: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class MenuToggleCheckbox extends React.Component<MenuToggleCheckboxProps, { ouiaStateId: string }> {
|
|
33
|
+
static displayName = 'MenuToggleCheckbox';
|
|
34
|
+
static defaultProps: PickOptional<MenuToggleCheckboxProps> = {
|
|
35
|
+
isValid: true,
|
|
36
|
+
isDisabled: false,
|
|
37
|
+
onChange: () => undefined as any
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
constructor(props: MenuToggleCheckboxProps) {
|
|
41
|
+
super(props);
|
|
42
|
+
this.state = {
|
|
43
|
+
ouiaStateId: getDefaultOUIAId(MenuToggleCheckbox.displayName)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
handleChange = (event: React.FormEvent<HTMLInputElement>) => {
|
|
48
|
+
this.props.onChange((event.target as HTMLInputElement).checked, event);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
calculateChecked = () => {
|
|
52
|
+
const { isChecked, defaultChecked } = this.props;
|
|
53
|
+
if (isChecked === null) {
|
|
54
|
+
// return false here and the indeterminate state will be set to true through the ref
|
|
55
|
+
return false;
|
|
56
|
+
} else if (isChecked !== undefined) {
|
|
57
|
+
return isChecked;
|
|
58
|
+
}
|
|
59
|
+
return defaultChecked;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
render() {
|
|
63
|
+
const {
|
|
64
|
+
className,
|
|
65
|
+
isValid,
|
|
66
|
+
isDisabled,
|
|
67
|
+
isChecked,
|
|
68
|
+
children,
|
|
69
|
+
ouiaId,
|
|
70
|
+
ouiaSafe,
|
|
71
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
72
|
+
onChange,
|
|
73
|
+
defaultChecked,
|
|
74
|
+
id,
|
|
75
|
+
...props
|
|
76
|
+
} = this.props;
|
|
77
|
+
const text = children && (
|
|
78
|
+
<span className={css(styles.checkLabel, className)} aria-hidden="true" id={id}>
|
|
79
|
+
{children}
|
|
80
|
+
</span>
|
|
81
|
+
);
|
|
82
|
+
return (
|
|
83
|
+
<label className={css(styles.check, !children && styles.modifiers.standalone, className)} htmlFor={id}>
|
|
84
|
+
<input
|
|
85
|
+
className={css(styles.checkInput)}
|
|
86
|
+
{...(this.calculateChecked() !== undefined && { onChange: this.handleChange })}
|
|
87
|
+
name={id}
|
|
88
|
+
type="checkbox"
|
|
89
|
+
ref={elem => elem && (elem.indeterminate = isChecked === null)}
|
|
90
|
+
aria-invalid={!isValid}
|
|
91
|
+
disabled={isDisabled}
|
|
92
|
+
{...(defaultChecked !== undefined ? { defaultChecked } : { checked: isChecked })}
|
|
93
|
+
{...getOUIAProps(
|
|
94
|
+
MenuToggleCheckbox.displayName,
|
|
95
|
+
ouiaId !== undefined ? ouiaId : this.state.ouiaStateId,
|
|
96
|
+
ouiaSafe
|
|
97
|
+
)}
|
|
98
|
+
{...props}
|
|
99
|
+
/>
|
|
100
|
+
{text}
|
|
101
|
+
</label>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
id: Menu toggle
|
|
3
3
|
section: components
|
|
4
4
|
cssPrefix: pf-c-menu-toggle
|
|
5
|
-
propComponents: ['MenuToggle']
|
|
5
|
+
propComponents: ['MenuToggle', 'MenuToggleAction', 'MenuToggleCheckbox', 'SplitButtonOptions']
|
|
6
6
|
beta: true
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -137,6 +137,40 @@ import { MenuToggle } from '@patternfly/react-core';
|
|
|
137
137
|
</React.Fragment>
|
|
138
138
|
```
|
|
139
139
|
|
|
140
|
+
### Split button (checkbox)
|
|
141
|
+
|
|
142
|
+
```ts file='MenuToggleSplitButtonCheckbox.tsx'
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Split button (checkbox with toggle text)
|
|
146
|
+
|
|
147
|
+
```ts file='MenuToggleSplitButtonCheckboxWithText.tsx'
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Split button (checkbox, primary)
|
|
151
|
+
|
|
152
|
+
```ts file='MenuToggleSplitButtonCheckboxPrimary.tsx'
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Split button (checkbox, secondary)
|
|
156
|
+
|
|
157
|
+
```ts file='MenuToggleSplitButtonCheckboxSecondary.tsx'
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Split button (action)
|
|
161
|
+
|
|
162
|
+
```ts file='MenuToggleSplitButtonAction.tsx'
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Split button (action, primary)
|
|
166
|
+
|
|
167
|
+
```ts file='MenuToggleSplitButtonActionPrimary.tsx'
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Split button (action, secondary)
|
|
171
|
+
|
|
172
|
+
```ts file='MenuToggleSplitButtonActionSecondary.tsx'
|
|
173
|
+
```
|
|
140
174
|
|
|
141
175
|
### With icon/image and text
|
|
142
176
|
|
|
@@ -191,5 +225,4 @@ const fullWidth: React.FunctionComponent = () => {
|
|
|
191
225
|
</MenuToggle>
|
|
192
226
|
);
|
|
193
227
|
}
|
|
194
|
-
|
|
195
228
|
```
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MenuToggleAction, MenuToggle } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const MenuToggleSplitButtonAction: React.FunctionComponent = () => (
|
|
5
|
+
<React.Fragment>
|
|
6
|
+
<MenuToggle
|
|
7
|
+
isDisabled
|
|
8
|
+
splitButtonOptions={{
|
|
9
|
+
variant: 'action',
|
|
10
|
+
items: [
|
|
11
|
+
<MenuToggleAction
|
|
12
|
+
id="split-button-action-disabled-example-with-toggle-button"
|
|
13
|
+
key="split-action-disabled"
|
|
14
|
+
aria-label="Action"
|
|
15
|
+
isDisabled
|
|
16
|
+
>
|
|
17
|
+
Action
|
|
18
|
+
</MenuToggleAction>
|
|
19
|
+
]
|
|
20
|
+
}}
|
|
21
|
+
aria-label="Menu toggle with action split button"
|
|
22
|
+
/>{' '}
|
|
23
|
+
<MenuToggle
|
|
24
|
+
splitButtonOptions={{
|
|
25
|
+
variant: 'action',
|
|
26
|
+
items: [
|
|
27
|
+
<MenuToggleAction id="split-button-action-example-with-toggle-button" key="split-action" aria-label="Action">
|
|
28
|
+
Action
|
|
29
|
+
</MenuToggleAction>
|
|
30
|
+
]
|
|
31
|
+
}}
|
|
32
|
+
aria-label="Menu toggle with action split button"
|
|
33
|
+
/>{' '}
|
|
34
|
+
<MenuToggle
|
|
35
|
+
isExpanded
|
|
36
|
+
splitButtonOptions={{
|
|
37
|
+
variant: 'action',
|
|
38
|
+
items: [
|
|
39
|
+
<MenuToggleAction
|
|
40
|
+
id="split-button-action-expanded-example-with-toggle-button"
|
|
41
|
+
key="split-action-expanded"
|
|
42
|
+
aria-label="Action"
|
|
43
|
+
>
|
|
44
|
+
Action
|
|
45
|
+
</MenuToggleAction>
|
|
46
|
+
]
|
|
47
|
+
}}
|
|
48
|
+
aria-label="Menu toggle with action split button"
|
|
49
|
+
/>
|
|
50
|
+
</React.Fragment>
|
|
51
|
+
);
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MenuToggleAction, MenuToggle } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const MenuToggleSplitButtonActionPrimary: React.FunctionComponent = () => (
|
|
5
|
+
<React.Fragment>
|
|
6
|
+
<MenuToggle
|
|
7
|
+
isDisabled
|
|
8
|
+
variant="primary"
|
|
9
|
+
splitButtonOptions={{
|
|
10
|
+
variant: 'action',
|
|
11
|
+
items: [
|
|
12
|
+
<MenuToggleAction
|
|
13
|
+
id="split-button-action-primary-disabled-example-with-toggle-button"
|
|
14
|
+
key="split-action-primary-disabled"
|
|
15
|
+
aria-label="Action"
|
|
16
|
+
isDisabled
|
|
17
|
+
>
|
|
18
|
+
Action
|
|
19
|
+
</MenuToggleAction>
|
|
20
|
+
]
|
|
21
|
+
}}
|
|
22
|
+
aria-label="Menu toggle with action split button"
|
|
23
|
+
/>{' '}
|
|
24
|
+
<MenuToggle
|
|
25
|
+
variant="primary"
|
|
26
|
+
splitButtonOptions={{
|
|
27
|
+
variant: 'action',
|
|
28
|
+
items: [
|
|
29
|
+
<MenuToggleAction
|
|
30
|
+
id="split-button-action-primary-example-with-toggle-button"
|
|
31
|
+
key="split-action-primary"
|
|
32
|
+
aria-label="Action"
|
|
33
|
+
>
|
|
34
|
+
Action
|
|
35
|
+
</MenuToggleAction>
|
|
36
|
+
]
|
|
37
|
+
}}
|
|
38
|
+
aria-label="Menu toggle with action split button"
|
|
39
|
+
/>{' '}
|
|
40
|
+
<MenuToggle
|
|
41
|
+
isExpanded
|
|
42
|
+
variant="primary"
|
|
43
|
+
splitButtonOptions={{
|
|
44
|
+
variant: 'action',
|
|
45
|
+
items: [
|
|
46
|
+
<MenuToggleAction
|
|
47
|
+
id="split-button-action-primary-expanded-example-with-toggle-button"
|
|
48
|
+
key="split-action-primary-expanded"
|
|
49
|
+
aria-label="Action"
|
|
50
|
+
>
|
|
51
|
+
Action
|
|
52
|
+
</MenuToggleAction>
|
|
53
|
+
]
|
|
54
|
+
}}
|
|
55
|
+
aria-label="Menu toggle with action split button"
|
|
56
|
+
/>
|
|
57
|
+
</React.Fragment>
|
|
58
|
+
);
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MenuToggleAction, MenuToggle } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const MenuToggleSplitButtonActionSecondary: React.FunctionComponent = () => (
|
|
5
|
+
<React.Fragment>
|
|
6
|
+
<MenuToggle
|
|
7
|
+
isDisabled
|
|
8
|
+
variant="secondary"
|
|
9
|
+
splitButtonOptions={{
|
|
10
|
+
variant: 'action',
|
|
11
|
+
items: [
|
|
12
|
+
<MenuToggleAction
|
|
13
|
+
id="split-button-action-secondary-disabled-example-with-toggle-button"
|
|
14
|
+
key="split-action-secondary-disabled"
|
|
15
|
+
aria-label="Action"
|
|
16
|
+
isDisabled
|
|
17
|
+
>
|
|
18
|
+
Action
|
|
19
|
+
</MenuToggleAction>
|
|
20
|
+
]
|
|
21
|
+
}}
|
|
22
|
+
aria-label="Menu toggle with action split button"
|
|
23
|
+
/>{' '}
|
|
24
|
+
<MenuToggle
|
|
25
|
+
variant="secondary"
|
|
26
|
+
splitButtonOptions={{
|
|
27
|
+
variant: 'action',
|
|
28
|
+
items: [
|
|
29
|
+
<MenuToggleAction
|
|
30
|
+
id="split-button-action-secondary-example-with-toggle-button"
|
|
31
|
+
key="split-action-secondary"
|
|
32
|
+
aria-label="Action"
|
|
33
|
+
>
|
|
34
|
+
Action
|
|
35
|
+
</MenuToggleAction>
|
|
36
|
+
]
|
|
37
|
+
}}
|
|
38
|
+
aria-label="Menu toggle with action split button"
|
|
39
|
+
/>{' '}
|
|
40
|
+
<MenuToggle
|
|
41
|
+
isExpanded
|
|
42
|
+
variant="secondary"
|
|
43
|
+
splitButtonOptions={{
|
|
44
|
+
variant: 'action',
|
|
45
|
+
items: [
|
|
46
|
+
<MenuToggleAction
|
|
47
|
+
id="split-button-action-secondary-expanded-example-with-toggle-button"
|
|
48
|
+
key="split-action-secondary-expanded"
|
|
49
|
+
aria-label="Action"
|
|
50
|
+
>
|
|
51
|
+
Action
|
|
52
|
+
</MenuToggleAction>
|
|
53
|
+
]
|
|
54
|
+
}}
|
|
55
|
+
aria-label="Menu toggle with action split button"
|
|
56
|
+
/>
|
|
57
|
+
</React.Fragment>
|
|
58
|
+
);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MenuToggleCheckbox, MenuToggle } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const MenuToggleSplitButtonCheckbox: React.FunctionComponent = () => (
|
|
5
|
+
<React.Fragment>
|
|
6
|
+
<MenuToggle
|
|
7
|
+
isDisabled
|
|
8
|
+
splitButtonOptions={{
|
|
9
|
+
items: [
|
|
10
|
+
<MenuToggleCheckbox
|
|
11
|
+
id="split-button-checkbox-disabled-example"
|
|
12
|
+
key="split-checkbox-disabled"
|
|
13
|
+
aria-label="Select all"
|
|
14
|
+
isDisabled
|
|
15
|
+
/>
|
|
16
|
+
]
|
|
17
|
+
}}
|
|
18
|
+
aria-label="Menu toggle with checkbox split button"
|
|
19
|
+
/>{' '}
|
|
20
|
+
<MenuToggle
|
|
21
|
+
splitButtonOptions={{
|
|
22
|
+
items: [<MenuToggleCheckbox id="split-button-checkbox-example" key="split-checkbox" aria-label="Select all" />]
|
|
23
|
+
}}
|
|
24
|
+
aria-label="Menu toggle with checkbox split button"
|
|
25
|
+
/>{' '}
|
|
26
|
+
<MenuToggle
|
|
27
|
+
isExpanded
|
|
28
|
+
splitButtonOptions={{
|
|
29
|
+
items: [
|
|
30
|
+
<MenuToggleCheckbox
|
|
31
|
+
id="split-button-checkbox-expanded-example"
|
|
32
|
+
key="split-checkbox-expanded"
|
|
33
|
+
aria-label="Select all"
|
|
34
|
+
/>
|
|
35
|
+
]
|
|
36
|
+
}}
|
|
37
|
+
aria-label="Menu toggle with checkbox split button"
|
|
38
|
+
/>
|
|
39
|
+
</React.Fragment>
|
|
40
|
+
);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MenuToggleCheckbox, MenuToggle } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const MenuToggleSplitButtonCheckboxPrimary: React.FunctionComponent = () => (
|
|
5
|
+
<React.Fragment>
|
|
6
|
+
<MenuToggle
|
|
7
|
+
isDisabled
|
|
8
|
+
variant="primary"
|
|
9
|
+
splitButtonOptions={{
|
|
10
|
+
items: [
|
|
11
|
+
<MenuToggleCheckbox
|
|
12
|
+
id="split-button-checkbox-primary-disabled-example"
|
|
13
|
+
key="split-checkbox-primary-disabled"
|
|
14
|
+
aria-label="Select all"
|
|
15
|
+
isDisabled
|
|
16
|
+
>
|
|
17
|
+
10 selected
|
|
18
|
+
</MenuToggleCheckbox>
|
|
19
|
+
]
|
|
20
|
+
}}
|
|
21
|
+
aria-label="Primary menu toggle with checkbox split button"
|
|
22
|
+
/>{' '}
|
|
23
|
+
<MenuToggle
|
|
24
|
+
variant="primary"
|
|
25
|
+
splitButtonOptions={{
|
|
26
|
+
items: [
|
|
27
|
+
<MenuToggleCheckbox
|
|
28
|
+
id="split-button-checkbox-primary-example"
|
|
29
|
+
key="split-checkbox-primary"
|
|
30
|
+
aria-label="Select all"
|
|
31
|
+
>
|
|
32
|
+
10 selected
|
|
33
|
+
</MenuToggleCheckbox>
|
|
34
|
+
]
|
|
35
|
+
}}
|
|
36
|
+
aria-label="Primary menu toggle with checkbox split button"
|
|
37
|
+
/>{' '}
|
|
38
|
+
<MenuToggle
|
|
39
|
+
isExpanded
|
|
40
|
+
variant="primary"
|
|
41
|
+
splitButtonOptions={{
|
|
42
|
+
items: [
|
|
43
|
+
<MenuToggleCheckbox
|
|
44
|
+
id="split-button-checkbox-primary-expanded-example"
|
|
45
|
+
key="split-checkbox-expanded"
|
|
46
|
+
aria-label="Select all"
|
|
47
|
+
>
|
|
48
|
+
10 selected
|
|
49
|
+
</MenuToggleCheckbox>
|
|
50
|
+
]
|
|
51
|
+
}}
|
|
52
|
+
aria-label="Primary menu toggle with checkbox split button"
|
|
53
|
+
/>
|
|
54
|
+
</React.Fragment>
|
|
55
|
+
);
|