@carbon/react 1.28.0 → 1.29.0-rc.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/es/components/Checkbox/Checkbox.d.ts +2 -2
- package/es/components/Heading/index.d.ts +51 -0
- package/es/components/Heading/index.js +5 -9
- package/es/components/StructuredList/StructuredList.Skeleton.js +2 -10
- package/es/components/StructuredList/StructuredList.js +2 -2
- package/es/components/Theme/index.d.ts +62 -0
- package/es/components/Theme/index.js +4 -4
- package/es/components/UIShell/HeaderContainer.js +8 -0
- package/es/components/UIShell/HeaderMenuButton.d.ts +38 -0
- package/es/components/UIShell/HeaderMenuButton.js +7 -12
- package/es/components/UIShell/HeaderNavigation.d.ts +24 -0
- package/es/components/UIShell/HeaderNavigation.js +8 -13
- package/es/components/UIShell/HeaderSideNavItems.d.ts +33 -0
- package/es/components/UIShell/HeaderSideNavItems.js +4 -9
- package/es/components/UIShell/SideNav.d.ts +21 -0
- package/es/components/UIShell/SideNav.js +37 -38
- package/es/index.js +1 -1
- package/es/internal/useEvent.js +20 -1
- package/es/types/common.d.ts +11 -0
- package/lib/components/Checkbox/Checkbox.d.ts +2 -2
- package/lib/components/Heading/index.d.ts +51 -0
- package/lib/components/Heading/index.js +5 -9
- package/lib/components/StructuredList/StructuredList.Skeleton.js +2 -10
- package/lib/components/StructuredList/StructuredList.js +2 -2
- package/lib/components/Theme/index.d.ts +62 -0
- package/lib/components/Theme/index.js +4 -4
- package/lib/components/UIShell/HeaderContainer.js +8 -0
- package/lib/components/UIShell/HeaderMenuButton.d.ts +38 -0
- package/lib/components/UIShell/HeaderMenuButton.js +7 -12
- package/lib/components/UIShell/HeaderNavigation.d.ts +24 -0
- package/lib/components/UIShell/HeaderNavigation.js +7 -13
- package/lib/components/UIShell/HeaderSideNavItems.d.ts +33 -0
- package/lib/components/UIShell/HeaderSideNavItems.js +4 -9
- package/lib/components/UIShell/SideNav.d.ts +21 -0
- package/lib/components/UIShell/SideNav.js +36 -37
- package/lib/index.js +2 -2
- package/lib/internal/useEvent.js +20 -0
- package/lib/types/common.d.ts +11 -0
- package/package.json +4 -4
|
@@ -6,35 +6,37 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
|
-
import React__default, { useRef, useState } from 'react';
|
|
9
|
+
import React__default, { useRef, useState, isValidElement } from 'react';
|
|
10
10
|
import cx from 'classnames';
|
|
11
11
|
import PropTypes from 'prop-types';
|
|
12
12
|
import { AriaLabelPropType } from '../../prop-types/AriaPropTypes.js';
|
|
13
13
|
import { CARBON_SIDENAV_ITEMS } from './_utils.js';
|
|
14
14
|
import { usePrefix } from '../../internal/usePrefix.js';
|
|
15
|
+
import { match } from '../../internal/keyboard/match.js';
|
|
16
|
+
import { Escape } from '../../internal/keyboard/keys.js';
|
|
15
17
|
|
|
16
18
|
// import SideNavFooter from './SideNavFooter';
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
function SideNavRenderFunction(_ref, ref) {
|
|
21
|
+
let {
|
|
20
22
|
expanded: expandedProp,
|
|
21
|
-
defaultExpanded,
|
|
22
|
-
isChildOfHeader,
|
|
23
|
+
defaultExpanded = false,
|
|
24
|
+
isChildOfHeader = true,
|
|
23
25
|
'aria-label': ariaLabel,
|
|
24
26
|
'aria-labelledby': ariaLabelledBy,
|
|
25
27
|
children,
|
|
26
28
|
onToggle,
|
|
27
29
|
className: customClassName,
|
|
28
30
|
// TO-DO: comment back in when footer is added for rails
|
|
29
|
-
// translateById: t,
|
|
30
|
-
isFixedNav,
|
|
31
|
+
// translateById: t = (id) => translations[id],
|
|
32
|
+
isFixedNav = false,
|
|
31
33
|
isRail,
|
|
32
|
-
isPersistent,
|
|
33
|
-
addFocusListeners,
|
|
34
|
-
addMouseListeners,
|
|
34
|
+
isPersistent = true,
|
|
35
|
+
addFocusListeners = true,
|
|
36
|
+
addMouseListeners = true,
|
|
35
37
|
onOverlayClick,
|
|
36
38
|
...other
|
|
37
|
-
} =
|
|
39
|
+
} = _ref;
|
|
38
40
|
const prefix = usePrefix();
|
|
39
41
|
const {
|
|
40
42
|
current: controlled
|
|
@@ -67,12 +69,11 @@ const SideNav = /*#__PURE__*/React__default.forwardRef(function SideNav(props, r
|
|
|
67
69
|
// ? t('carbon.sidenav.state.open')
|
|
68
70
|
// : t('carbon.sidenav.state.closed');
|
|
69
71
|
|
|
70
|
-
const className = cx({
|
|
72
|
+
const className = cx(customClassName, {
|
|
71
73
|
[`${prefix}--side-nav`]: true,
|
|
72
74
|
[`${prefix}--side-nav--expanded`]: expanded || expandedViaHoverState,
|
|
73
75
|
[`${prefix}--side-nav--collapsed`]: !expanded && isFixedNav,
|
|
74
76
|
[`${prefix}--side-nav--rail`]: isRail,
|
|
75
|
-
[customClassName]: !!customClassName,
|
|
76
77
|
[`${prefix}--side-nav--ux`]: isChildOfHeader,
|
|
77
78
|
[`${prefix}--side-nav--hidden`]: !isPersistent
|
|
78
79
|
});
|
|
@@ -84,19 +85,25 @@ const SideNav = /*#__PURE__*/React__default.forwardRef(function SideNav(props, r
|
|
|
84
85
|
|
|
85
86
|
if (isRail) {
|
|
86
87
|
childrenToRender = React__default.Children.map(children, child => {
|
|
87
|
-
var _child$type, _child$type2;
|
|
88
|
-
|
|
89
88
|
// if we are controlled, check for if we have hovered over or the expanded state, else just use the expanded state (uncontrolled)
|
|
90
|
-
|
|
89
|
+
const currentExpansionState = controlled ? expandedViaHoverState || expanded : expanded;
|
|
90
|
+
|
|
91
|
+
if ( /*#__PURE__*/isValidElement(child)) {
|
|
92
|
+
var _childJsxElement$type, _childJsxElement$type2;
|
|
93
|
+
|
|
94
|
+
const childJsxElement = child; // avoid spreading `isSideNavExpanded` to non-Carbon UI Shell children
|
|
95
|
+
|
|
96
|
+
return /*#__PURE__*/React__default.cloneElement(childJsxElement, { ...(CARBON_SIDENAV_ITEMS.includes(((_childJsxElement$type = childJsxElement.type) === null || _childJsxElement$type === void 0 ? void 0 : _childJsxElement$type.displayName) ?? ((_childJsxElement$type2 = childJsxElement.type) === null || _childJsxElement$type2 === void 0 ? void 0 : _childJsxElement$type2.name)) ? {
|
|
97
|
+
isSideNavExpanded: currentExpansionState
|
|
98
|
+
} : {})
|
|
99
|
+
});
|
|
100
|
+
}
|
|
91
101
|
|
|
92
|
-
return
|
|
93
|
-
isSideNavExpanded: currentExpansionState
|
|
94
|
-
} : {})
|
|
95
|
-
});
|
|
102
|
+
return child;
|
|
96
103
|
});
|
|
97
104
|
}
|
|
98
105
|
|
|
99
|
-
|
|
106
|
+
const eventHandlers = {};
|
|
100
107
|
|
|
101
108
|
if (addFocusListeners) {
|
|
102
109
|
eventHandlers.onFocus = event => {
|
|
@@ -110,6 +117,12 @@ const SideNav = /*#__PURE__*/React__default.forwardRef(function SideNav(props, r
|
|
|
110
117
|
handleToggle(event, false);
|
|
111
118
|
}
|
|
112
119
|
};
|
|
120
|
+
|
|
121
|
+
eventHandlers.onKeyDown = event => {
|
|
122
|
+
if (match(event, Escape)) {
|
|
123
|
+
handleToggle(event, false);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
113
126
|
}
|
|
114
127
|
|
|
115
128
|
if (addMouseListeners && isRail) {
|
|
@@ -128,24 +141,10 @@ const SideNav = /*#__PURE__*/React__default.forwardRef(function SideNav(props, r
|
|
|
128
141
|
ref: ref,
|
|
129
142
|
className: `${prefix}--side-nav__navigation ${className}`
|
|
130
143
|
}, accessibilityLabel, eventHandlers, other), childrenToRender));
|
|
131
|
-
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const SideNav = /*#__PURE__*/React__default.forwardRef(SideNavRenderFunction);
|
|
132
147
|
SideNav.displayName = 'SideNav';
|
|
133
|
-
SideNav.defaultProps = {
|
|
134
|
-
// TO-DO: comment back in when footer is added for rails
|
|
135
|
-
// translateById: (id) => {
|
|
136
|
-
// const translations = {
|
|
137
|
-
// 'carbon.sidenav.state.open': 'Close',
|
|
138
|
-
// 'carbon.sidenav.state.closed': 'Open',
|
|
139
|
-
// };
|
|
140
|
-
// return translations[id];
|
|
141
|
-
// },
|
|
142
|
-
defaultExpanded: false,
|
|
143
|
-
isChildOfHeader: true,
|
|
144
|
-
isFixedNav: false,
|
|
145
|
-
isPersistent: true,
|
|
146
|
-
addFocusListeners: true,
|
|
147
|
-
addMouseListeners: true
|
|
148
|
-
};
|
|
149
148
|
SideNav.propTypes = {
|
|
150
149
|
/**
|
|
151
150
|
* Required props for accessibility label on the underlying menu
|
package/es/index.js
CHANGED
|
@@ -94,6 +94,7 @@ export { default as TreeView } from './components/TreeView/TreeView.js';
|
|
|
94
94
|
export { default as HeaderMenuButton } from './components/UIShell/HeaderMenuButton.js';
|
|
95
95
|
export { default as HeaderName } from './components/UIShell/HeaderName.js';
|
|
96
96
|
export { default as HeaderNavigation } from './components/UIShell/HeaderNavigation.js';
|
|
97
|
+
export { default as HeaderSideNavItems } from './components/UIShell/HeaderSideNavItems.js';
|
|
97
98
|
export { default as SkipToContent } from './components/UIShell/SkipToContent.js';
|
|
98
99
|
export { default as SideNavDivider } from './components/UIShell/SideNavDivider.js';
|
|
99
100
|
export { default as SideNavFooter } from './components/UIShell/SideNavFooter.js';
|
|
@@ -205,7 +206,6 @@ export { default as HeaderGlobalBar } from './components/UIShell/HeaderGlobalBar
|
|
|
205
206
|
export { default as HeaderMenu } from './components/UIShell/HeaderMenu.js';
|
|
206
207
|
export { default as HeaderMenuItem } from './components/UIShell/HeaderMenuItem.js';
|
|
207
208
|
export { default as HeaderPanel } from './components/UIShell/HeaderPanel.js';
|
|
208
|
-
export { default as HeaderSideNavItems } from './components/UIShell/HeaderSideNavItems.js';
|
|
209
209
|
export { default as Switcher } from './components/UIShell/Switcher.js';
|
|
210
210
|
export { default as SwitcherItem } from './components/UIShell/SwitcherItem.js';
|
|
211
211
|
export { default as SwitcherDivider } from './components/UIShell/SwitcherDivider.js';
|
package/es/internal/useEvent.js
CHANGED
|
@@ -7,6 +7,25 @@
|
|
|
7
7
|
|
|
8
8
|
import { useRef, useEffect } from 'react';
|
|
9
9
|
|
|
10
|
+
function useEvent(elementOrRef, eventName, callback) {
|
|
11
|
+
const savedCallback = useRef(null);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
savedCallback.current = callback;
|
|
14
|
+
});
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
function handler(event) {
|
|
17
|
+
if (savedCallback.current) {
|
|
18
|
+
savedCallback.current(event);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const element = elementOrRef.current ?? elementOrRef;
|
|
23
|
+
element.addEventListener(eventName, handler);
|
|
24
|
+
return () => {
|
|
25
|
+
element.removeEventListener(eventName, handler);
|
|
26
|
+
};
|
|
27
|
+
}, [elementOrRef, eventName]);
|
|
28
|
+
}
|
|
10
29
|
function useWindowEvent(eventName, callback) {
|
|
11
30
|
const savedCallback = useRef(null);
|
|
12
31
|
useEffect(() => {
|
|
@@ -26,4 +45,4 @@ function useWindowEvent(eventName, callback) {
|
|
|
26
45
|
}, [eventName]);
|
|
27
46
|
}
|
|
28
47
|
|
|
29
|
-
export { useWindowEvent };
|
|
48
|
+
export { useEvent, useWindowEvent };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export type ReactAttr<T = HTMLElement> = React.HTMLAttributes<T>;
|
|
3
|
+
export type ForwardRefProps<T, P = unknown> = React.PropsWithoutRef<React.PropsWithChildren<P>> & React.RefAttributes<T>;
|
|
4
|
+
export type ForwardRefReturn<T, P = unknown> = React.ForwardRefExoticComponent<ForwardRefProps<T, P>>;
|
|
5
|
+
/**
|
|
6
|
+
* For "as" props. Creates an "as" property that supports native html tags such as 'span', 'a', 'button' as well as custom functional components
|
|
7
|
+
* All native props for the supplied html tag/component are inferred as part of the base component props, allowing us to use props like `href` on an 'a' element ect
|
|
8
|
+
*/
|
|
9
|
+
export type PolymorphicProps<Element extends React.ElementType, Props> = Props & Omit<React.ComponentProps<Element>, 'as'> & {
|
|
10
|
+
as?: Element;
|
|
11
|
+
};
|
|
@@ -44,7 +44,7 @@ export interface CheckboxProps extends Omit<React.InputHTMLAttributes<HTMLInputE
|
|
|
44
44
|
/**
|
|
45
45
|
* Provide the text that is displayed when the Checkbox is in an invalid state
|
|
46
46
|
*/
|
|
47
|
-
invalidText
|
|
47
|
+
invalidText?: React.ReactNode;
|
|
48
48
|
/**
|
|
49
49
|
* Specify whether the Checkbox is currently invalid
|
|
50
50
|
*/
|
|
@@ -52,7 +52,7 @@ export interface CheckboxProps extends Omit<React.InputHTMLAttributes<HTMLInputE
|
|
|
52
52
|
/**
|
|
53
53
|
* Provide the text that is displayed when the Checkbox is in an invalid state
|
|
54
54
|
*/
|
|
55
|
-
warnText
|
|
55
|
+
warnText?: React.ReactNode;
|
|
56
56
|
/**
|
|
57
57
|
* Provide an optional handler that is called when the internal state of
|
|
58
58
|
* Checkbox changes. This handler is called with event and state info.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import PropTypes from 'prop-types';
|
|
8
|
+
import { type ElementType } from 'react';
|
|
9
|
+
import type { PolymorphicProps } from '../../types/common';
|
|
10
|
+
type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
11
|
+
type SectionBaseProps = {
|
|
12
|
+
level?: HeadingLevel;
|
|
13
|
+
};
|
|
14
|
+
type SectionProps<E extends ElementType> = PolymorphicProps<E, SectionBaseProps>;
|
|
15
|
+
export declare function Section<E extends ElementType = 'section'>({ as: BaseComponent, level: levelOverride, ...rest }: SectionProps<E>): JSX.Element;
|
|
16
|
+
export declare namespace Section {
|
|
17
|
+
var propTypes: {
|
|
18
|
+
/**
|
|
19
|
+
* Provide an alternative tag or component to use instead of the default
|
|
20
|
+
* <section> element
|
|
21
|
+
*/
|
|
22
|
+
as: PropTypes.Requireable<PropTypes.ReactComponentLike>;
|
|
23
|
+
/**
|
|
24
|
+
* Specify the content that will be placed in the component
|
|
25
|
+
*/
|
|
26
|
+
children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
27
|
+
/**
|
|
28
|
+
* Specify a class name for the outermost node of the component
|
|
29
|
+
*/
|
|
30
|
+
className: PropTypes.Requireable<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Overrides the level of the section
|
|
33
|
+
*/
|
|
34
|
+
level: PropTypes.Requireable<number>;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
type HeadingProps = JSX.IntrinsicElements[`h${HeadingLevel}`];
|
|
38
|
+
export declare function Heading(props: HeadingProps): JSX.Element;
|
|
39
|
+
export declare namespace Heading {
|
|
40
|
+
var propTypes: {
|
|
41
|
+
/**
|
|
42
|
+
* Specify the content that will be placed in the component
|
|
43
|
+
*/
|
|
44
|
+
children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
45
|
+
/**
|
|
46
|
+
* Specify a class name for the outermost node of the component
|
|
47
|
+
*/
|
|
48
|
+
className: PropTypes.Requireable<string>;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export {};
|
|
@@ -18,21 +18,19 @@ var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
|
18
18
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
19
19
|
|
|
20
20
|
const HeadingContext = /*#__PURE__*/React__default["default"].createContext(1);
|
|
21
|
-
|
|
22
21
|
function Section(_ref) {
|
|
23
22
|
let {
|
|
24
23
|
as: BaseComponent = 'section',
|
|
25
24
|
level: levelOverride,
|
|
26
|
-
children,
|
|
27
25
|
...rest
|
|
28
26
|
} = _ref;
|
|
29
27
|
const parentLevel = React__default["default"].useContext(HeadingContext);
|
|
30
|
-
const level =
|
|
28
|
+
const level = levelOverride ?? parentLevel + 1;
|
|
29
|
+
const BaseComponentAsAny = BaseComponent;
|
|
31
30
|
return /*#__PURE__*/React__default["default"].createElement(HeadingContext.Provider, {
|
|
32
31
|
value: Math.min(level, 6)
|
|
33
|
-
}, /*#__PURE__*/React__default["default"].createElement(
|
|
32
|
+
}, /*#__PURE__*/React__default["default"].createElement(BaseComponentAsAny, rest));
|
|
34
33
|
}
|
|
35
|
-
|
|
36
34
|
Section.propTypes = {
|
|
37
35
|
/**
|
|
38
36
|
* Provide an alternative tag or component to use instead of the default
|
|
@@ -55,12 +53,10 @@ Section.propTypes = {
|
|
|
55
53
|
*/
|
|
56
54
|
level: PropTypes__default["default"].number
|
|
57
55
|
};
|
|
58
|
-
|
|
59
56
|
function Heading(props) {
|
|
60
|
-
const
|
|
61
|
-
return /*#__PURE__*/React__default["default"].createElement(
|
|
57
|
+
const HeadingIntrinsic = `h${React__default["default"].useContext(HeadingContext)}`;
|
|
58
|
+
return /*#__PURE__*/React__default["default"].createElement(HeadingIntrinsic, props);
|
|
62
59
|
}
|
|
63
|
-
|
|
64
60
|
Heading.propTypes = {
|
|
65
61
|
/**
|
|
66
62
|
* Specify the content that will be placed in the component
|
|
@@ -26,15 +26,13 @@ var _span, _span2, _span3;
|
|
|
26
26
|
const StructuredListSkeleton = _ref => {
|
|
27
27
|
let {
|
|
28
28
|
rowCount,
|
|
29
|
-
border,
|
|
30
29
|
className,
|
|
31
30
|
...rest
|
|
32
31
|
} = _ref;
|
|
33
32
|
const prefix = usePrefix.usePrefix();
|
|
34
33
|
const StructuredListSkeletonClasses = cx__default["default"](className, {
|
|
35
34
|
[`${prefix}--skeleton`]: true,
|
|
36
|
-
[`${prefix}--structured-list`]: true
|
|
37
|
-
[`${prefix}--structured-list--border`]: border
|
|
35
|
+
[`${prefix}--structured-list`]: true
|
|
38
36
|
});
|
|
39
37
|
const rows = [];
|
|
40
38
|
|
|
@@ -69,11 +67,6 @@ const StructuredListSkeleton = _ref => {
|
|
|
69
67
|
};
|
|
70
68
|
|
|
71
69
|
StructuredListSkeleton.propTypes = {
|
|
72
|
-
/**
|
|
73
|
-
* Specify whether a border should be added to your StructuredListSkeleton
|
|
74
|
-
*/
|
|
75
|
-
border: PropTypes__default["default"].bool,
|
|
76
|
-
|
|
77
70
|
/**
|
|
78
71
|
* Specify an optional className to add.
|
|
79
72
|
*/
|
|
@@ -85,8 +78,7 @@ StructuredListSkeleton.propTypes = {
|
|
|
85
78
|
rowCount: PropTypes__default["default"].number
|
|
86
79
|
};
|
|
87
80
|
StructuredListSkeleton.defaultProps = {
|
|
88
|
-
rowCount: 5
|
|
89
|
-
border: false
|
|
81
|
+
rowCount: 5
|
|
90
82
|
};
|
|
91
83
|
var StructuredListSkeleton$1 = StructuredListSkeleton;
|
|
92
84
|
|
|
@@ -40,7 +40,7 @@ function StructuredListWrapper(props) {
|
|
|
40
40
|
const classes = cx__default["default"](`${prefix}--structured-list`, className, {
|
|
41
41
|
[`${prefix}--structured-list--selection`]: selection,
|
|
42
42
|
[`${prefix}--structured-list--condensed`]: isCondensed,
|
|
43
|
-
[`${prefix}--structured-list--flush`]: isFlush
|
|
43
|
+
[`${prefix}--structured-list--flush`]: isFlush && !selection
|
|
44
44
|
});
|
|
45
45
|
const [selectedRow, setSelectedRow] = React__default["default"].useState(null);
|
|
46
46
|
return /*#__PURE__*/React__default["default"].createElement(GridSelectedRowStateContext.Provider, {
|
|
@@ -82,7 +82,7 @@ StructuredListWrapper.propTypes = {
|
|
|
82
82
|
isCondensed: PropTypes__default["default"].bool,
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
|
-
* Specify if structured list is flush, default is false
|
|
85
|
+
* Specify if structured list is flush, not valid for selection variant, default is false
|
|
86
86
|
*/
|
|
87
87
|
isFlush: PropTypes__default["default"].bool,
|
|
88
88
|
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import PropTypes from 'prop-types';
|
|
8
|
+
import React, { ElementType, type PropsWithChildren } from 'react';
|
|
9
|
+
import { PolymorphicProps } from '../../types/common';
|
|
10
|
+
interface GlobalThemeProps {
|
|
11
|
+
theme?: 'white' | 'g10' | 'g90' | 'g100';
|
|
12
|
+
}
|
|
13
|
+
export declare const ThemeContext: React.Context<GlobalThemeProps>;
|
|
14
|
+
export declare function GlobalTheme({ children, theme, }: PropsWithChildren<GlobalThemeProps>): JSX.Element;
|
|
15
|
+
export declare namespace GlobalTheme {
|
|
16
|
+
var propTypes: {
|
|
17
|
+
/**
|
|
18
|
+
* Provide child elements to be rendered inside of `GlobalTheme`, this is
|
|
19
|
+
* typically the root of your app
|
|
20
|
+
*/
|
|
21
|
+
children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
22
|
+
/**
|
|
23
|
+
* Specify the global theme for your app
|
|
24
|
+
*/
|
|
25
|
+
theme: PropTypes.Requireable<string>;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
type ThemeBaseProps = GlobalThemeProps & {
|
|
29
|
+
className?: string;
|
|
30
|
+
};
|
|
31
|
+
type ThemeProps<E extends ElementType> = PolymorphicProps<E, ThemeBaseProps>;
|
|
32
|
+
/**
|
|
33
|
+
* Specify the theme to be applied to a page, or a region in a page
|
|
34
|
+
*/
|
|
35
|
+
export declare function Theme<E extends ElementType = 'div'>({ as: BaseComponent, className: customClassName, theme, ...rest }: ThemeProps<E>): JSX.Element;
|
|
36
|
+
export declare namespace Theme {
|
|
37
|
+
var propTypes: {
|
|
38
|
+
/**
|
|
39
|
+
* Specify a custom component or element to be rendered as the top-level
|
|
40
|
+
* element in the component
|
|
41
|
+
*/
|
|
42
|
+
as: PropTypes.Requireable<NonNullable<((...args: any[]) => any) | PropTypes.ReactComponentLike | null | undefined>>;
|
|
43
|
+
/**
|
|
44
|
+
* Provide child elements to be rendered inside of `Theme`
|
|
45
|
+
*/
|
|
46
|
+
children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
47
|
+
/**
|
|
48
|
+
* Provide a custom class name to be used on the outermost element rendered by
|
|
49
|
+
* the component
|
|
50
|
+
*/
|
|
51
|
+
className: PropTypes.Requireable<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Specify the theme
|
|
54
|
+
*/
|
|
55
|
+
theme: PropTypes.Requireable<string>;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get access to the current theme
|
|
60
|
+
*/
|
|
61
|
+
export declare function useTheme(): GlobalThemeProps;
|
|
62
|
+
export {};
|
|
@@ -51,14 +51,13 @@ GlobalTheme.propTypes = {
|
|
|
51
51
|
*/
|
|
52
52
|
theme: PropTypes__default["default"].oneOf(['white', 'g10', 'g90', 'g100'])
|
|
53
53
|
};
|
|
54
|
+
|
|
54
55
|
/**
|
|
55
56
|
* Specify the theme to be applied to a page, or a region in a page
|
|
56
57
|
*/
|
|
57
|
-
|
|
58
58
|
function Theme(_ref2) {
|
|
59
59
|
let {
|
|
60
60
|
as: BaseComponent = 'div',
|
|
61
|
-
children,
|
|
62
61
|
className: customClassName,
|
|
63
62
|
theme,
|
|
64
63
|
...rest
|
|
@@ -76,13 +75,14 @@ function Theme(_ref2) {
|
|
|
76
75
|
theme
|
|
77
76
|
};
|
|
78
77
|
}, [theme]);
|
|
78
|
+
const BaseComponentAsAny = BaseComponent;
|
|
79
79
|
return /*#__PURE__*/React__default["default"].createElement(ThemeContext.Provider, {
|
|
80
80
|
value: value
|
|
81
81
|
}, /*#__PURE__*/React__default["default"].createElement(LayerContext.LayerContext.Provider, {
|
|
82
82
|
value: 1
|
|
83
|
-
}, /*#__PURE__*/React__default["default"].createElement(
|
|
83
|
+
}, /*#__PURE__*/React__default["default"].createElement(BaseComponentAsAny, _rollupPluginBabelHelpers["extends"]({}, rest, {
|
|
84
84
|
className: className
|
|
85
|
-
})
|
|
85
|
+
}))));
|
|
86
86
|
}
|
|
87
87
|
Theme.propTypes = {
|
|
88
88
|
/**
|
|
@@ -11,6 +11,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
11
11
|
|
|
12
12
|
var PropTypes = require('prop-types');
|
|
13
13
|
var React = require('react');
|
|
14
|
+
var useEvent = require('../../internal/useEvent.js');
|
|
15
|
+
var match = require('../../internal/keyboard/match.js');
|
|
16
|
+
var keys = require('../../internal/keyboard/keys.js');
|
|
14
17
|
|
|
15
18
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
19
|
|
|
@@ -24,6 +27,11 @@ const HeaderContainer = _ref => {
|
|
|
24
27
|
} = _ref;
|
|
25
28
|
//state for expandable sidenav
|
|
26
29
|
const [isSideNavExpandedState, setIsSideNavExpandedState] = React.useState(isSideNavExpanded);
|
|
30
|
+
useEvent.useEvent(window, 'keydown', event => {
|
|
31
|
+
if (match.match(event, keys.Escape)) {
|
|
32
|
+
setIsSideNavExpandedState(false);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
27
35
|
const handleHeaderMenuButtonClick = React.useCallback(() => {
|
|
28
36
|
setIsSideNavExpandedState(prevIsSideNavExpanded => !prevIsSideNavExpanded);
|
|
29
37
|
}, [setIsSideNavExpandedState]);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { type ComponentProps } from 'react';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
type HeaderMenuButtonBaseProps = Omit<ComponentProps<'button'>, 'title' | 'type'>;
|
|
10
|
+
interface HeaderMenuButtonProps extends HeaderMenuButtonBaseProps {
|
|
11
|
+
'aria-label'?: string;
|
|
12
|
+
'aria-labelledby'?: string;
|
|
13
|
+
className?: string;
|
|
14
|
+
renderMenuIcon?: JSX.Element;
|
|
15
|
+
renderCloseIcon?: JSX.Element;
|
|
16
|
+
isActive?: boolean;
|
|
17
|
+
isCollapsible?: boolean;
|
|
18
|
+
}
|
|
19
|
+
declare function HeaderMenuButton({ 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, className: customClassName, renderMenuIcon, renderCloseIcon, isActive, isCollapsible, ...rest }: HeaderMenuButtonProps): JSX.Element;
|
|
20
|
+
declare namespace HeaderMenuButton {
|
|
21
|
+
var propTypes: {
|
|
22
|
+
/**
|
|
23
|
+
* Optionally provide a custom class name that is applied to the underlying
|
|
24
|
+
* button
|
|
25
|
+
*/
|
|
26
|
+
className: PropTypes.Requireable<string>;
|
|
27
|
+
/**
|
|
28
|
+
* Specify whether the menu button is "active".
|
|
29
|
+
*/
|
|
30
|
+
isActive: PropTypes.Requireable<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Optionally provide an onClick handler that is called when the underlying
|
|
33
|
+
* button fires it's onclick event
|
|
34
|
+
*/
|
|
35
|
+
onClick: PropTypes.Requireable<(...args: any[]) => any>;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export default HeaderMenuButton;
|
|
@@ -24,7 +24,6 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
|
24
24
|
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
25
25
|
|
|
26
26
|
var _Menu, _Close;
|
|
27
|
-
|
|
28
27
|
function HeaderMenuButton(_ref) {
|
|
29
28
|
let {
|
|
30
29
|
'aria-label': ariaLabel,
|
|
@@ -32,38 +31,34 @@ function HeaderMenuButton(_ref) {
|
|
|
32
31
|
className: customClassName,
|
|
33
32
|
renderMenuIcon,
|
|
34
33
|
renderCloseIcon,
|
|
35
|
-
onClick,
|
|
36
34
|
isActive,
|
|
37
35
|
isCollapsible,
|
|
38
36
|
...rest
|
|
39
37
|
} = _ref;
|
|
40
38
|
const prefix = usePrefix.usePrefix();
|
|
41
|
-
const className = cx__default["default"]({
|
|
42
|
-
|
|
39
|
+
const className = cx__default["default"]({ ...(typeof customClassName === 'string' && {
|
|
40
|
+
[customClassName]: !!customClassName
|
|
41
|
+
}),
|
|
43
42
|
[`${prefix}--header__action`]: true,
|
|
44
43
|
[`${prefix}--header__menu-trigger`]: true,
|
|
45
44
|
[`${prefix}--header__action--active`]: isActive,
|
|
46
45
|
[`${prefix}--header__menu-toggle`]: true,
|
|
47
46
|
[`${prefix}--header__menu-toggle__hidden`]: !isCollapsible
|
|
48
47
|
});
|
|
49
|
-
const accessibilityLabel = {
|
|
50
|
-
'aria-label': ariaLabel,
|
|
51
|
-
'aria-labelledby': ariaLabelledBy
|
|
52
|
-
};
|
|
53
48
|
const menuIcon = renderMenuIcon ? renderMenuIcon : _Menu || (_Menu = /*#__PURE__*/React__default["default"].createElement(iconsReact.Menu, {
|
|
54
49
|
size: 20
|
|
55
50
|
}));
|
|
56
51
|
const closeIcon = renderCloseIcon ? renderCloseIcon : _Close || (_Close = /*#__PURE__*/React__default["default"].createElement(iconsReact.Close, {
|
|
57
52
|
size: 20
|
|
58
53
|
}));
|
|
59
|
-
return /*#__PURE__*/React__default["default"].createElement("button", _rollupPluginBabelHelpers["extends"]({}, rest,
|
|
54
|
+
return /*#__PURE__*/React__default["default"].createElement("button", _rollupPluginBabelHelpers["extends"]({}, rest, {
|
|
55
|
+
"aria-label": ariaLabel,
|
|
56
|
+
"aria-labelledby": ariaLabelledBy,
|
|
60
57
|
className: className,
|
|
61
58
|
title: ariaLabel,
|
|
62
|
-
type: "button"
|
|
63
|
-
onClick: onClick
|
|
59
|
+
type: "button"
|
|
64
60
|
}), isActive ? closeIcon : menuIcon);
|
|
65
61
|
}
|
|
66
|
-
|
|
67
62
|
HeaderMenuButton.propTypes = {
|
|
68
63
|
/**
|
|
69
64
|
* Required props for accessibility label on the underlying menu button
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { type ComponentProps } from 'react';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
type HeaderNavigationProps = ComponentProps<'nav'>;
|
|
10
|
+
declare function HeaderNavigation({ 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, children, className: customClassName, ...rest }: HeaderNavigationProps): JSX.Element;
|
|
11
|
+
declare namespace HeaderNavigation {
|
|
12
|
+
var propTypes: {
|
|
13
|
+
/**
|
|
14
|
+
* Provide valid children of HeaderNavigation, for example `HeaderMenuItem`
|
|
15
|
+
* or `HeaderMenu`
|
|
16
|
+
*/
|
|
17
|
+
children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
18
|
+
/**
|
|
19
|
+
* Optionally provide a custom class to apply to the underlying <nav> node
|
|
20
|
+
*/
|
|
21
|
+
className: PropTypes.Requireable<string>;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export default HeaderNavigation;
|
|
@@ -22,29 +22,24 @@ var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
|
|
|
22
22
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
23
23
|
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
24
24
|
|
|
25
|
-
function HeaderNavigation(
|
|
26
|
-
|
|
25
|
+
function HeaderNavigation(_ref) {
|
|
26
|
+
let {
|
|
27
27
|
'aria-label': ariaLabel,
|
|
28
28
|
'aria-labelledby': ariaLabelledBy,
|
|
29
29
|
children,
|
|
30
30
|
className: customClassName,
|
|
31
31
|
...rest
|
|
32
|
-
} =
|
|
32
|
+
} = _ref;
|
|
33
33
|
const prefix = usePrefix.usePrefix();
|
|
34
|
-
const className = cx__default["default"](`${prefix}--header__nav`, customClassName);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
'aria-label': ariaLabel,
|
|
39
|
-
'aria-labelledby': ariaLabelledBy
|
|
40
|
-
};
|
|
41
|
-
return /*#__PURE__*/React__default["default"].createElement("nav", _rollupPluginBabelHelpers["extends"]({}, rest, accessibilityLabel, {
|
|
34
|
+
const className = cx__default["default"](`${prefix}--header__nav`, customClassName);
|
|
35
|
+
return /*#__PURE__*/React__default["default"].createElement("nav", _rollupPluginBabelHelpers["extends"]({}, rest, {
|
|
36
|
+
"aria-label": ariaLabel,
|
|
37
|
+
"aria-labelledby": ariaLabelledBy,
|
|
42
38
|
className: className
|
|
43
39
|
}), /*#__PURE__*/React__default["default"].createElement("ul", {
|
|
44
40
|
className: `${prefix}--header__menu-bar`
|
|
45
41
|
}, children));
|
|
46
42
|
}
|
|
47
|
-
|
|
48
43
|
HeaderNavigation.propTypes = {
|
|
49
44
|
/**
|
|
50
45
|
* Required props for accessibility label on the underlying menu
|
|
@@ -63,5 +58,4 @@ HeaderNavigation.propTypes = {
|
|
|
63
58
|
className: PropTypes__default["default"].string
|
|
64
59
|
};
|
|
65
60
|
|
|
66
|
-
exports.HeaderNavigation = HeaderNavigation;
|
|
67
61
|
exports["default"] = HeaderNavigation;
|