@carbon-labs/react-ui-shell 0.12.0 → 0.14.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/HeaderPanel.js +6 -6
- package/es/components/Link.d.ts +48 -0
- package/es/components/Link.js +60 -0
- package/es/components/SideNav.d.ts +3 -3
- package/es/components/SideNav.js +16 -16
- package/es/components/SideNavItems.js +1 -1
- package/es/components/SideNavMenu.js +8 -8
- package/es/components/SideNavMenuItem.d.ts +1 -1
- package/es/components/SideNavMenuItem.js +4 -4
- package/es/components/SideNavToggle.js +1 -1
- package/es/internal/environment.d.ts +12 -0
- package/es/internal/environment.js +15 -0
- package/es/internal/keyboard/index.d.ts +3 -0
- package/es/internal/keyboard/keys.d.ts +126 -0
- package/es/internal/keyboard/keys.js +67 -0
- package/es/internal/keyboard/match.d.ts +63 -0
- package/es/internal/keyboard/match.js +88 -0
- package/es/internal/keyboard/navigation.d.ts +19 -0
- package/es/internal/useDelayedState.d.ts +19 -0
- package/es/internal/useDelayedState.js +56 -0
- package/es/internal/useEvent.d.ts +31 -0
- package/es/internal/useEvent.js +55 -0
- package/es/internal/useMatchMedia.d.ts +1 -0
- package/es/internal/useMatchMedia.js +52 -0
- package/es/internal/useMergedRefs.d.ts +13 -0
- package/es/internal/useMergedRefs.js +38 -0
- package/es/internal/usePrefix.d.ts +9 -0
- package/es/internal/usePrefix.js +23 -0
- package/es/internal/warning.d.ts +7 -0
- package/es/internal/warning.js +31 -0
- package/es/prop-types/AriaPropTypes.d.ts +1 -0
- package/es/prop-types/AriaPropTypes.js +16 -0
- package/es/prop-types/deprecate.d.ts +1 -0
- package/es/prop-types/deprecate.js +39 -0
- package/es/prop-types/isRequiredOneOf.d.ts +13 -0
- package/es/prop-types/isRequiredOneOf.js +40 -0
- package/es/types/common.d.ts +29 -0
- package/lib/components/HeaderPanel.js +6 -6
- package/lib/components/Link.d.ts +48 -0
- package/lib/components/Link.js +65 -0
- package/lib/components/SideNav.d.ts +3 -3
- package/lib/components/SideNav.js +16 -35
- package/lib/components/SideNavItems.js +1 -1
- package/lib/components/SideNavMenu.js +10 -29
- package/lib/components/SideNavMenuItem.d.ts +1 -1
- package/lib/components/SideNavMenuItem.js +6 -6
- package/lib/components/SideNavToggle.js +1 -1
- package/lib/internal/environment.d.ts +12 -0
- package/lib/internal/environment.js +17 -0
- package/lib/internal/keyboard/index.d.ts +3 -0
- package/lib/internal/keyboard/keys.d.ts +126 -0
- package/lib/internal/keyboard/keys.js +76 -0
- package/lib/internal/keyboard/match.d.ts +63 -0
- package/lib/internal/keyboard/match.js +91 -0
- package/lib/internal/keyboard/navigation.d.ts +19 -0
- package/lib/internal/useDelayedState.d.ts +19 -0
- package/lib/internal/useDelayedState.js +58 -0
- package/lib/internal/useEvent.d.ts +31 -0
- package/lib/internal/useEvent.js +57 -0
- package/lib/internal/useMatchMedia.d.ts +1 -0
- package/lib/internal/useMatchMedia.js +54 -0
- package/lib/internal/useMergedRefs.d.ts +13 -0
- package/lib/internal/useMergedRefs.js +40 -0
- package/lib/internal/usePrefix.d.ts +9 -0
- package/lib/internal/usePrefix.js +26 -0
- package/lib/internal/warning.d.ts +7 -0
- package/lib/internal/warning.js +33 -0
- package/lib/prop-types/AriaPropTypes.d.ts +1 -0
- package/lib/prop-types/AriaPropTypes.js +18 -0
- package/lib/prop-types/deprecate.d.ts +1 -0
- package/lib/prop-types/deprecate.js +43 -0
- package/lib/prop-types/isRequiredOneOf.d.ts +13 -0
- package/lib/prop-types/isRequiredOneOf.js +44 -0
- package/lib/types/common.d.ts +29 -0
- package/package.json +2 -2
- package/scss/styles/_content.scss +24 -0
- package/scss/styles/_side-nav.scss +8 -1
- package/scss/ui-shell.scss +1 -0
|
@@ -9,11 +9,11 @@ import { extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
|
9
9
|
import cx from '../_virtual/index.js';
|
|
10
10
|
import PropTypes from 'prop-types';
|
|
11
11
|
import React, { useRef, useState } from 'react';
|
|
12
|
-
import { usePrefix } from '
|
|
13
|
-
import {
|
|
14
|
-
import { match } from '
|
|
15
|
-
import { useWindowEvent } from '
|
|
16
|
-
import { useMergedRefs } from '
|
|
12
|
+
import { usePrefix } from '../internal/usePrefix.js';
|
|
13
|
+
import { Escape } from '../internal/keyboard/keys.js';
|
|
14
|
+
import { match } from '../internal/keyboard/match.js';
|
|
15
|
+
import { useWindowEvent } from '../internal/useEvent.js';
|
|
16
|
+
import { useMergedRefs } from '../internal/useMergedRefs.js';
|
|
17
17
|
|
|
18
18
|
const noopFn = () => {};
|
|
19
19
|
const HeaderPanel = /*#__PURE__*/React.forwardRef(function HeaderPanel(_ref, ref) {
|
|
@@ -49,7 +49,7 @@ const HeaderPanel = /*#__PURE__*/React.forwardRef(function HeaderPanel(_ref, ref
|
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
51
|
eventHandlers.onKeyDown = event => {
|
|
52
|
-
if (match(event,
|
|
52
|
+
if (match(event, Escape)) {
|
|
53
53
|
setExpandedState(false);
|
|
54
54
|
onHeaderPanelFocus();
|
|
55
55
|
if (href) {
|
|
@@ -0,0 +1,48 @@
|
|
|
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, { type ElementType, type Ref } from 'react';
|
|
9
|
+
import { type PolymorphicProps } from '../types/common';
|
|
10
|
+
type LinkBaseProps<E extends ElementType> = {
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Use `as` instead
|
|
13
|
+
*/
|
|
14
|
+
element?: E | undefined;
|
|
15
|
+
ref?: Ref<E>;
|
|
16
|
+
};
|
|
17
|
+
export type LinkProps<E extends ElementType> = PolymorphicProps<E, LinkBaseProps<E>>;
|
|
18
|
+
/**
|
|
19
|
+
* Link is a custom component that allows us to supporting rendering elements
|
|
20
|
+
* other than `a` in our markup. The goal is to allow users to support passing
|
|
21
|
+
* in their own components to support use-cases like `react-router` or
|
|
22
|
+
* `@reach/router`
|
|
23
|
+
*/
|
|
24
|
+
declare const Link: (<E extends React.ElementType = "a">(props: LinkProps<E>) => JSX.Element) & {
|
|
25
|
+
displayName?: string | undefined;
|
|
26
|
+
propTypes?: React.WeakValidationMap<LinkProps<any>> | undefined;
|
|
27
|
+
};
|
|
28
|
+
declare const LinkPropTypes: {
|
|
29
|
+
/**
|
|
30
|
+
* Provide a custom element or component to render the top-level node for the
|
|
31
|
+
* component.
|
|
32
|
+
*/
|
|
33
|
+
as: PropTypes.Requireable<PropTypes.ReactComponentLike>;
|
|
34
|
+
/**
|
|
35
|
+
* The base element to use to build the link. Defaults to `a`, can also accept
|
|
36
|
+
* alternative tag names or custom components like `Link` from `react-router`.
|
|
37
|
+
* @deprecated Use `as` instead
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
element: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
|
|
41
|
+
/**
|
|
42
|
+
* Property to indicate if the side nav container is open (or not). Use to
|
|
43
|
+
* keep local state and styling in step with the SideNav expansion state.
|
|
44
|
+
*/
|
|
45
|
+
isSideNavExpanded: PropTypes.Requireable<boolean>;
|
|
46
|
+
};
|
|
47
|
+
export { LinkPropTypes };
|
|
48
|
+
export default Link;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2024
|
|
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
|
+
|
|
8
|
+
import { extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
|
+
import PropTypes from 'prop-types';
|
|
10
|
+
import React, { forwardRef } from 'react';
|
|
11
|
+
import deprecate from '../prop-types/deprecate.js';
|
|
12
|
+
|
|
13
|
+
// Note: Maybe we should use `as` instead of `element`? `as` appears to be
|
|
14
|
+
// standard and is used in other places in this project.
|
|
15
|
+
|
|
16
|
+
function LinkRenderFunction(_ref, ref) {
|
|
17
|
+
let {
|
|
18
|
+
element,
|
|
19
|
+
as: BaseComponent,
|
|
20
|
+
// Captured here to prevent it from being passed into the created element.
|
|
21
|
+
// See https://github.com/carbon-design-system/carbon/issues/3970
|
|
22
|
+
isSideNavExpanded: _isSideNavExpanded,
|
|
23
|
+
...rest
|
|
24
|
+
} = _ref;
|
|
25
|
+
const BaseComponentAsAny = BaseComponent ?? element ?? 'a';
|
|
26
|
+
return /*#__PURE__*/React.createElement(BaseComponentAsAny, _extends({
|
|
27
|
+
ref: ref
|
|
28
|
+
}, rest));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Link is a custom component that allows us to supporting rendering elements
|
|
33
|
+
* other than `a` in our markup. The goal is to allow users to support passing
|
|
34
|
+
* in their own components to support use-cases like `react-router` or
|
|
35
|
+
* `@reach/router`
|
|
36
|
+
*/
|
|
37
|
+
const Link = /*#__PURE__*/forwardRef(LinkRenderFunction);
|
|
38
|
+
const LinkPropTypes = {
|
|
39
|
+
/**
|
|
40
|
+
* Provide a custom element or component to render the top-level node for the
|
|
41
|
+
* component.
|
|
42
|
+
*/
|
|
43
|
+
as: PropTypes.elementType,
|
|
44
|
+
/**
|
|
45
|
+
* The base element to use to build the link. Defaults to `a`, can also accept
|
|
46
|
+
* alternative tag names or custom components like `Link` from `react-router`.
|
|
47
|
+
* @deprecated Use `as` instead
|
|
48
|
+
*
|
|
49
|
+
*/
|
|
50
|
+
element: deprecate(PropTypes.elementType, 'The `element` prop for `Link` has been deprecated. Please use `as` ' + 'instead. This will be removed in the next major release.'),
|
|
51
|
+
/**
|
|
52
|
+
* Property to indicate if the side nav container is open (or not). Use to
|
|
53
|
+
* keep local state and styling in step with the SideNav expansion state.
|
|
54
|
+
*/
|
|
55
|
+
isSideNavExpanded: PropTypes.bool
|
|
56
|
+
};
|
|
57
|
+
Link.displayName = 'Link';
|
|
58
|
+
Link.propTypes = LinkPropTypes;
|
|
59
|
+
|
|
60
|
+
export { LinkPropTypes, Link as default };
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import React, { type ComponentProps, type FocusEvent, type KeyboardEvent, type MouseEventHandler } from 'react';
|
|
8
|
-
import { TranslateWithId } from '
|
|
8
|
+
import { TranslateWithId } from '../types/common';
|
|
9
9
|
export declare enum SIDE_NAV_TYPE {
|
|
10
10
|
DEFAULT = "default",
|
|
11
11
|
RAIL = "rail",
|
|
@@ -31,8 +31,8 @@ export interface SideNavProps extends ComponentProps<'nav'>, TranslateWithId<Tra
|
|
|
31
31
|
onSideNavBlur?: () => void;
|
|
32
32
|
enterDelayMs?: number;
|
|
33
33
|
inert?: boolean;
|
|
34
|
-
isCollapsible
|
|
35
|
-
hideOverlay
|
|
34
|
+
isCollapsible?: boolean;
|
|
35
|
+
hideOverlay?: boolean;
|
|
36
36
|
navType: SIDE_NAV_TYPE;
|
|
37
37
|
}
|
|
38
38
|
interface SideNavContextData {
|
package/es/components/SideNav.js
CHANGED
|
@@ -9,16 +9,16 @@ import { extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
|
9
9
|
import React, { createContext, useRef, isValidElement, useEffect } from 'react';
|
|
10
10
|
import cx from '../_virtual/index.js';
|
|
11
11
|
import PropTypes from 'prop-types';
|
|
12
|
-
import { AriaLabelPropType } from '
|
|
12
|
+
import { AriaLabelPropType } from '../prop-types/AriaPropTypes.js';
|
|
13
13
|
import { CARBON_SIDENAV_ITEMS } from './_utils.js';
|
|
14
|
-
import { usePrefix } from '
|
|
15
|
-
import
|
|
16
|
-
import { match, matches } from '
|
|
17
|
-
import { useMergedRefs } from '
|
|
18
|
-
import { useWindowEvent } from '
|
|
19
|
-
import { useDelayedState } from '
|
|
14
|
+
import { usePrefix } from '../internal/usePrefix.js';
|
|
15
|
+
import { ArrowUp, ArrowDown, Home, End, Escape, Tab } from '../internal/keyboard/keys.js';
|
|
16
|
+
import { match, matches } from '../internal/keyboard/match.js';
|
|
17
|
+
import { useMergedRefs } from '../internal/useMergedRefs.js';
|
|
18
|
+
import { useWindowEvent } from '../internal/useEvent.js';
|
|
19
|
+
import { useDelayedState } from '../internal/useDelayedState.js';
|
|
20
20
|
import { breakpoints } from '../node_modules/@carbon/layout/es/index.js';
|
|
21
|
-
import { useMatchMedia } from '
|
|
21
|
+
import { useMatchMedia } from '../internal/useMatchMedia.js';
|
|
22
22
|
import { SideNavToggle } from './SideNavToggle.js';
|
|
23
23
|
import { SidePanelClose, SidePanelOpen } from '../node_modules/@carbon/icons-react/es/generated/bucket-15.js';
|
|
24
24
|
|
|
@@ -179,7 +179,7 @@ function SideNavRenderFunction(_ref, ref) {
|
|
|
179
179
|
event.stopPropagation();
|
|
180
180
|
|
|
181
181
|
// stops page from scrolling
|
|
182
|
-
if (matches(event, [
|
|
182
|
+
if (matches(event, [ArrowUp, ArrowDown, Home, End,
|
|
183
183
|
// @ts-ignore - `matches` doesn't like the object syntax without missing properties
|
|
184
184
|
{
|
|
185
185
|
code: 'KeyA'
|
|
@@ -188,7 +188,7 @@ function SideNavRenderFunction(_ref, ref) {
|
|
|
188
188
|
}
|
|
189
189
|
treeWalker.currentNode = event.target.closest(`li`) ?? treeWalker?.currentNode;
|
|
190
190
|
let nextFocusNode = null;
|
|
191
|
-
if (match(event,
|
|
191
|
+
if (match(event, ArrowUp)) {
|
|
192
192
|
const parentNode = parentSideNavMenu(treeWalker.currentNode);
|
|
193
193
|
let previousSideNavMenu = parentNode?.previousElementSibling;
|
|
194
194
|
|
|
@@ -209,7 +209,7 @@ function SideNavRenderFunction(_ref, ref) {
|
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
|
-
if (match(event,
|
|
212
|
+
if (match(event, ArrowDown)) {
|
|
213
213
|
if (treeWalker.currentNode.getAttribute('aria-expanded') == 'false') {
|
|
214
214
|
nextFocusNode = treeWalker.nextSibling();
|
|
215
215
|
} else {
|
|
@@ -218,19 +218,19 @@ function SideNavRenderFunction(_ref, ref) {
|
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
// Home/End functionality
|
|
221
|
-
if (matches(event, [
|
|
221
|
+
if (matches(event, [Home, End])) {
|
|
222
222
|
if (!sideNavRef?.current) {
|
|
223
223
|
return;
|
|
224
224
|
}
|
|
225
225
|
const allItems = Array.from(sideNavRef.current.querySelectorAll('a, button'));
|
|
226
|
-
if (match(event,
|
|
226
|
+
if (match(event, Home)) {
|
|
227
227
|
const firstElement = allItems[0];
|
|
228
228
|
if (firstElement) {
|
|
229
229
|
firstElement.tabIndex = 0;
|
|
230
230
|
firstElement?.focus();
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
|
-
if (match(event,
|
|
233
|
+
if (match(event, End)) {
|
|
234
234
|
const allItems = Array.from(sideNavRef.current.querySelectorAll('li'));
|
|
235
235
|
const lastVisibleItem = allItems.reverse().find(item => getComputedStyle(item).visibility !== 'hidden');
|
|
236
236
|
if (lastVisibleItem) {
|
|
@@ -256,7 +256,7 @@ function SideNavRenderFunction(_ref, ref) {
|
|
|
256
256
|
}
|
|
257
257
|
|
|
258
258
|
// close menu
|
|
259
|
-
if (match(event,
|
|
259
|
+
if (match(event, Escape)) {
|
|
260
260
|
if (expanded && !isFixedNav) {
|
|
261
261
|
if (onSideNavBlur) {
|
|
262
262
|
onSideNavBlur();
|
|
@@ -289,7 +289,7 @@ function SideNavRenderFunction(_ref, ref) {
|
|
|
289
289
|
const focusedElement = document.activeElement;
|
|
290
290
|
|
|
291
291
|
// going from header menu to sideNav
|
|
292
|
-
if (match(event,
|
|
292
|
+
if (match(event, Tab) && expanded && !isFixedNav && sideNavRef?.current && focusedElement?.classList.contains(`${prefix}--header__menu-toggle`) && !focusedElement.closest('nav')) {
|
|
293
293
|
sideNavRef.current.focus();
|
|
294
294
|
}
|
|
295
295
|
});
|
|
@@ -9,7 +9,7 @@ import cx from '../_virtual/index.js';
|
|
|
9
9
|
import PropTypes from 'prop-types';
|
|
10
10
|
import React from 'react';
|
|
11
11
|
import { CARBON_SIDENAV_ITEMS } from './_utils.js';
|
|
12
|
-
import { usePrefix } from '
|
|
12
|
+
import { usePrefix } from '../internal/usePrefix.js';
|
|
13
13
|
|
|
14
14
|
const SideNavItems = _ref => {
|
|
15
15
|
let {
|
|
@@ -9,12 +9,12 @@ import cx from '../_virtual/index.js';
|
|
|
9
9
|
import PropTypes from 'prop-types';
|
|
10
10
|
import React, { useContext, useState, useRef, useEffect } from 'react';
|
|
11
11
|
import { CARBON_SIDENAV_ITEMS } from './_utils.js';
|
|
12
|
-
import SideNavIcon from '@carbon/react
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
12
|
+
import { SideNavIcon } from '@carbon/react';
|
|
13
|
+
import { Escape, ArrowLeft, ArrowRight } from '../internal/keyboard/keys.js';
|
|
14
|
+
import { match } from '../internal/keyboard/match.js';
|
|
15
|
+
import { usePrefix } from '../internal/usePrefix.js';
|
|
15
16
|
import { SideNavContext } from './SideNav.js';
|
|
16
|
-
import { useMergedRefs } from '
|
|
17
|
-
import * as keys from '@carbon/react/lib/internal/keyboard/keys';
|
|
17
|
+
import { useMergedRefs } from '../internal/useMergedRefs.js';
|
|
18
18
|
import { ChevronDown } from '../node_modules/@carbon/icons-react/es/generated/bucket-3.js';
|
|
19
19
|
|
|
20
20
|
var _ChevronDown;
|
|
@@ -109,14 +109,14 @@ const SideNavMenu = /*#__PURE__*/React.forwardRef(function SideNavMenu(_ref, ref
|
|
|
109
109
|
return node;
|
|
110
110
|
}
|
|
111
111
|
function handleKeyDown(event) {
|
|
112
|
-
if (match(event,
|
|
112
|
+
if (match(event, Escape)) {
|
|
113
113
|
setIsExpanded(false);
|
|
114
114
|
}
|
|
115
115
|
const node = event.target;
|
|
116
116
|
const isMenu = node.hasAttribute('aria-expanded');
|
|
117
117
|
const isExpanded = node.getAttribute('aria-expanded');
|
|
118
118
|
const parent = parentSideNavMenu(node);
|
|
119
|
-
if (match(event,
|
|
119
|
+
if (match(event, ArrowLeft)) {
|
|
120
120
|
event.stopPropagation();
|
|
121
121
|
if (isMenu) {
|
|
122
122
|
// collapse menu
|
|
@@ -139,7 +139,7 @@ const SideNavMenu = /*#__PURE__*/React.forwardRef(function SideNavMenu(_ref, ref
|
|
|
139
139
|
button?.focus();
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
if (match(event,
|
|
142
|
+
if (match(event, ArrowRight)) {
|
|
143
143
|
event.stopPropagation();
|
|
144
144
|
|
|
145
145
|
// expand menu
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import React, { ElementType, ComponentProps } from 'react';
|
|
8
|
-
import Link from '
|
|
8
|
+
import Link from './Link';
|
|
9
9
|
export interface SideNavMenuItemProps extends ComponentProps<typeof Link> {
|
|
10
10
|
/**
|
|
11
11
|
* Specify the children to be rendered inside of the `SideNavMenuItem`
|
|
@@ -9,10 +9,10 @@ import { extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
|
9
9
|
import cx from '../_virtual/index.js';
|
|
10
10
|
import PropTypes from 'prop-types';
|
|
11
11
|
import React, { useRef, useEffect } from 'react';
|
|
12
|
-
import SideNavLinkText from '@carbon/react
|
|
13
|
-
import Link from '
|
|
14
|
-
import { usePrefix } from '
|
|
15
|
-
import { useMergedRefs } from '
|
|
12
|
+
import { SideNavLinkText } from '@carbon/react';
|
|
13
|
+
import Link from './Link.js';
|
|
14
|
+
import { usePrefix } from '../internal/usePrefix.js';
|
|
15
|
+
import { useMergedRefs } from '../internal/useMergedRefs.js';
|
|
16
16
|
|
|
17
17
|
const SideNavMenuItem = /*#__PURE__*/React.forwardRef(function SideNavMenuItem(props, ref) {
|
|
18
18
|
const prefix = usePrefix();
|
|
@@ -9,7 +9,7 @@ import { extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
|
9
9
|
import PropTypes from 'prop-types';
|
|
10
10
|
import React from 'react';
|
|
11
11
|
import { SideNavIcon } from '@carbon/react';
|
|
12
|
-
import { usePrefix } from '
|
|
12
|
+
import { usePrefix } from '../internal/usePrefix.js';
|
|
13
13
|
|
|
14
14
|
const SideNavToggle = /*#__PURE__*/React.forwardRef(function SideNavToggle(_ref, ref) {
|
|
15
15
|
let {
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
/**
|
|
8
|
+
* Indicate whether current execution environment can access the DOM.
|
|
9
|
+
*
|
|
10
|
+
* @see https://github.com/facebook/fbjs/blob/4d1751311d3f67af2dcce2e40df8512a23c7b9c6/packages/fbjs/src/core/ExecutionEnvironment.js#L12
|
|
11
|
+
*/
|
|
12
|
+
export const canUseDOM: boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2024
|
|
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
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Indicate whether current execution environment can access the DOM.
|
|
10
|
+
*
|
|
11
|
+
* @see https://github.com/facebook/fbjs/blob/4d1751311d3f67af2dcce2e40df8512a23c7b9c6/packages/fbjs/src/core/ExecutionEnvironment.js#L12
|
|
12
|
+
*/
|
|
13
|
+
const canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
|
|
14
|
+
|
|
15
|
+
export { canUseDOM };
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
export namespace Tab {
|
|
2
|
+
let key: string;
|
|
3
|
+
let which: number;
|
|
4
|
+
let keyCode: number;
|
|
5
|
+
let code: string;
|
|
6
|
+
}
|
|
7
|
+
export namespace Enter {
|
|
8
|
+
let key_1: string;
|
|
9
|
+
export { key_1 as key };
|
|
10
|
+
let which_1: number;
|
|
11
|
+
export { which_1 as which };
|
|
12
|
+
let keyCode_1: number;
|
|
13
|
+
export { keyCode_1 as keyCode };
|
|
14
|
+
let code_1: string;
|
|
15
|
+
export { code_1 as code };
|
|
16
|
+
}
|
|
17
|
+
export namespace Escape {
|
|
18
|
+
let key_2: string[];
|
|
19
|
+
export { key_2 as key };
|
|
20
|
+
let which_2: number;
|
|
21
|
+
export { which_2 as which };
|
|
22
|
+
let keyCode_2: number;
|
|
23
|
+
export { keyCode_2 as keyCode };
|
|
24
|
+
let code_2: string;
|
|
25
|
+
export { code_2 as code };
|
|
26
|
+
}
|
|
27
|
+
export namespace Space {
|
|
28
|
+
let key_3: string;
|
|
29
|
+
export { key_3 as key };
|
|
30
|
+
let which_3: number;
|
|
31
|
+
export { which_3 as which };
|
|
32
|
+
let keyCode_3: number;
|
|
33
|
+
export { keyCode_3 as keyCode };
|
|
34
|
+
let code_3: string;
|
|
35
|
+
export { code_3 as code };
|
|
36
|
+
}
|
|
37
|
+
export namespace PageUp {
|
|
38
|
+
let key_4: string;
|
|
39
|
+
export { key_4 as key };
|
|
40
|
+
let which_4: number;
|
|
41
|
+
export { which_4 as which };
|
|
42
|
+
let keyCode_4: number;
|
|
43
|
+
export { keyCode_4 as keyCode };
|
|
44
|
+
let code_4: string;
|
|
45
|
+
export { code_4 as code };
|
|
46
|
+
}
|
|
47
|
+
export namespace PageDown {
|
|
48
|
+
let key_5: string;
|
|
49
|
+
export { key_5 as key };
|
|
50
|
+
let which_5: number;
|
|
51
|
+
export { which_5 as which };
|
|
52
|
+
let keyCode_5: number;
|
|
53
|
+
export { keyCode_5 as keyCode };
|
|
54
|
+
let code_5: string;
|
|
55
|
+
export { code_5 as code };
|
|
56
|
+
}
|
|
57
|
+
export namespace End {
|
|
58
|
+
let key_6: string;
|
|
59
|
+
export { key_6 as key };
|
|
60
|
+
let which_6: number;
|
|
61
|
+
export { which_6 as which };
|
|
62
|
+
let keyCode_6: number;
|
|
63
|
+
export { keyCode_6 as keyCode };
|
|
64
|
+
let code_6: string;
|
|
65
|
+
export { code_6 as code };
|
|
66
|
+
}
|
|
67
|
+
export namespace Home {
|
|
68
|
+
let key_7: string;
|
|
69
|
+
export { key_7 as key };
|
|
70
|
+
let which_7: number;
|
|
71
|
+
export { which_7 as which };
|
|
72
|
+
let keyCode_7: number;
|
|
73
|
+
export { keyCode_7 as keyCode };
|
|
74
|
+
let code_7: string;
|
|
75
|
+
export { code_7 as code };
|
|
76
|
+
}
|
|
77
|
+
export namespace ArrowLeft {
|
|
78
|
+
let key_8: string;
|
|
79
|
+
export { key_8 as key };
|
|
80
|
+
let which_8: number;
|
|
81
|
+
export { which_8 as which };
|
|
82
|
+
let keyCode_8: number;
|
|
83
|
+
export { keyCode_8 as keyCode };
|
|
84
|
+
let code_8: string;
|
|
85
|
+
export { code_8 as code };
|
|
86
|
+
}
|
|
87
|
+
export namespace ArrowUp {
|
|
88
|
+
let key_9: string;
|
|
89
|
+
export { key_9 as key };
|
|
90
|
+
let which_9: number;
|
|
91
|
+
export { which_9 as which };
|
|
92
|
+
let keyCode_9: number;
|
|
93
|
+
export { keyCode_9 as keyCode };
|
|
94
|
+
let code_9: string;
|
|
95
|
+
export { code_9 as code };
|
|
96
|
+
}
|
|
97
|
+
export namespace ArrowRight {
|
|
98
|
+
let key_10: string;
|
|
99
|
+
export { key_10 as key };
|
|
100
|
+
let which_10: number;
|
|
101
|
+
export { which_10 as which };
|
|
102
|
+
let keyCode_10: number;
|
|
103
|
+
export { keyCode_10 as keyCode };
|
|
104
|
+
let code_10: string;
|
|
105
|
+
export { code_10 as code };
|
|
106
|
+
}
|
|
107
|
+
export namespace ArrowDown {
|
|
108
|
+
let key_11: string;
|
|
109
|
+
export { key_11 as key };
|
|
110
|
+
let which_11: number;
|
|
111
|
+
export { which_11 as which };
|
|
112
|
+
let keyCode_11: number;
|
|
113
|
+
export { keyCode_11 as keyCode };
|
|
114
|
+
let code_11: string;
|
|
115
|
+
export { code_11 as code };
|
|
116
|
+
}
|
|
117
|
+
export namespace Delete {
|
|
118
|
+
let key_12: string;
|
|
119
|
+
export { key_12 as key };
|
|
120
|
+
let which_12: number;
|
|
121
|
+
export { which_12 as which };
|
|
122
|
+
let keyCode_12: number;
|
|
123
|
+
export { keyCode_12 as keyCode };
|
|
124
|
+
let code_12: string;
|
|
125
|
+
export { code_12 as code };
|
|
126
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2024
|
|
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
|
+
|
|
8
|
+
/* eslint-disable jsdoc/require-jsdoc */
|
|
9
|
+
/**
|
|
10
|
+
* Copyright IBM Corp. 2016, 2023
|
|
11
|
+
*
|
|
12
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
13
|
+
* LICENSE file in the root directory of this source tree.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const Tab = {
|
|
17
|
+
key: 'Tab',
|
|
18
|
+
which: 9,
|
|
19
|
+
keyCode: 9,
|
|
20
|
+
code: 'Tab'
|
|
21
|
+
};
|
|
22
|
+
const Escape = {
|
|
23
|
+
key: ['Escape',
|
|
24
|
+
// IE11 Escape
|
|
25
|
+
'Esc'],
|
|
26
|
+
which: 27,
|
|
27
|
+
keyCode: 27,
|
|
28
|
+
code: 'Esc'
|
|
29
|
+
};
|
|
30
|
+
const End = {
|
|
31
|
+
key: 'End',
|
|
32
|
+
which: 35,
|
|
33
|
+
keyCode: 35,
|
|
34
|
+
code: 'Numpad1'
|
|
35
|
+
};
|
|
36
|
+
const Home = {
|
|
37
|
+
key: 'Home',
|
|
38
|
+
which: 36,
|
|
39
|
+
keyCode: 36,
|
|
40
|
+
code: 'Numpad7'
|
|
41
|
+
};
|
|
42
|
+
const ArrowLeft = {
|
|
43
|
+
key: 'ArrowLeft',
|
|
44
|
+
which: 37,
|
|
45
|
+
keyCode: 37,
|
|
46
|
+
code: 'ArrowLeft'
|
|
47
|
+
};
|
|
48
|
+
const ArrowUp = {
|
|
49
|
+
key: 'ArrowUp',
|
|
50
|
+
which: 38,
|
|
51
|
+
keyCode: 38,
|
|
52
|
+
code: 'ArrowUp'
|
|
53
|
+
};
|
|
54
|
+
const ArrowRight = {
|
|
55
|
+
key: 'ArrowRight',
|
|
56
|
+
which: 39,
|
|
57
|
+
keyCode: 39,
|
|
58
|
+
code: 'ArrowRight'
|
|
59
|
+
};
|
|
60
|
+
const ArrowDown = {
|
|
61
|
+
key: 'ArrowDown',
|
|
62
|
+
which: 40,
|
|
63
|
+
keyCode: 40,
|
|
64
|
+
code: 'ArrowDown'
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export { ArrowDown, ArrowLeft, ArrowRight, ArrowUp, End, Escape, Home, Tab };
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
/**
|
|
8
|
+
* @typedef Key
|
|
9
|
+
* @property key {Array<string>|string}
|
|
10
|
+
* @property which {number}
|
|
11
|
+
* @property keyCode {number}
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Check to see if at least one key code matches the key code of the
|
|
15
|
+
* given event.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* import * as keys from '../keys';
|
|
19
|
+
* import { matches } from '../match';
|
|
20
|
+
*
|
|
21
|
+
* function handleOnKeyDown(event) {
|
|
22
|
+
* if (matches(event, [keys.Enter, keys.Space]) {
|
|
23
|
+
* // ...
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* @param {Event|React.SyntheticEvent} event
|
|
28
|
+
* @param {Array<Key>} keysToMatch
|
|
29
|
+
* @returns {boolean}
|
|
30
|
+
*/
|
|
31
|
+
export function matches(event: Event | React.SyntheticEvent, keysToMatch: Array<Key>): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Check to see if the given key matches the corresponding keyboard event. Also
|
|
34
|
+
* supports passing in the value directly if you can't used the given event.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* import * as keys from '../keys';
|
|
38
|
+
* import { matches } from '../match';
|
|
39
|
+
*
|
|
40
|
+
* function handleOnKeyDown(event) {
|
|
41
|
+
* if (match(event, keys.Enter) {
|
|
42
|
+
* // ...
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
* @param {React.SyntheticEvent|Event|number|string} eventOrCode
|
|
47
|
+
* @param {Key} key
|
|
48
|
+
* @returns {boolean}
|
|
49
|
+
*/
|
|
50
|
+
export function match(eventOrCode: React.SyntheticEvent | Event | number | string, { key, which, keyCode, code }?: Key): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Get a string character for a given event or event code (useful for synthetic
|
|
53
|
+
* events)
|
|
54
|
+
*
|
|
55
|
+
* @param {Event|number} eventOrCode
|
|
56
|
+
* @returns {string}
|
|
57
|
+
*/
|
|
58
|
+
export function getCharacterFor(eventOrCode: Event | number): string;
|
|
59
|
+
export type Key = {
|
|
60
|
+
key: Array<string> | string;
|
|
61
|
+
which: number;
|
|
62
|
+
keyCode: number;
|
|
63
|
+
};
|