@redsift/design-system 11.6.0-muiv5-alpha.5 → 11.6.0-muiv5-alpha.7
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/_internal/Alert2.js +182 -39
- package/_internal/AppBar.js +240 -29
- package/_internal/AppContainer.js +132 -86
- package/_internal/AppContent.js +84 -17
- package/_internal/Badge2.js +137 -4
- package/_internal/BreadcrumbItem.js +85 -3
- package/_internal/Breadcrumbs2.js +86 -21
- package/_internal/Button2.js +81 -20
- package/_internal/ButtonGroup.js +165 -25
- package/_internal/ButtonLink.js +74 -18
- package/_internal/Card2.js +151 -29
- package/_internal/CardActions.js +38 -3
- package/_internal/CardBody.js +36 -3
- package/_internal/CardHeader.js +77 -3
- package/_internal/Checkbox2.js +234 -58
- package/_internal/CheckboxGroup.js +182 -4
- package/_internal/ConditionalWrapper.js +11 -12
- package/_internal/DetailedCard.js +6912 -48
- package/_internal/DetailedCardCollapsibleSectionItems.js +58 -3
- package/_internal/DetailedCardHeader.js +61 -3
- package/_internal/DetailedCardSection.js +166 -3
- package/_internal/DetailedCardSectionItem.js +88 -3
- package/_internal/Flexbox2.js +85 -22
- package/_internal/Grid2.js +87 -24
- package/_internal/GridItem.js +34 -3
- package/_internal/Heading2.js +107 -3
- package/_internal/Icon2.js +206 -5
- package/_internal/IconButton.js +71 -3
- package/_internal/IconButtonLink.js +65 -18
- package/_internal/Item2.js +390 -73
- package/_internal/Link2.js +56 -15
- package/_internal/LinkButton.js +56 -13
- package/_internal/Number2.js +103 -61
- package/_internal/NumberField.js +3959 -65
- package/_internal/Pill2.js +400 -4
- package/_internal/ProgressBar.js +61 -18
- package/_internal/Radio2.js +227 -56
- package/_internal/RadioGroup.js +170 -4
- package/_internal/Shield2.js +220 -4
- package/_internal/SideNavigationMenu.js +586 -4
- package/_internal/SideNavigationMenuItem.js +299 -4
- package/_internal/Skeleton2.js +36 -9
- package/_internal/SkeletonCircle.js +52 -3
- package/_internal/SkeletonText.js +71 -3
- package/_internal/Spinner2.js +319 -29
- package/_internal/Switch2.js +310 -56
- package/_internal/SwitchGroup.js +182 -4
- package/_internal/Text2.js +45 -3
- package/_internal/TextArea.js +430 -20
- package/_internal/TextField.js +463 -19
- package/_internal/alert.js +2 -5
- package/_internal/app-bar.js +2 -8
- package/_internal/app-container.js +3 -9
- package/_internal/app-content.js +2 -5
- package/_internal/app-side-panel.js +3 -11
- package/_internal/badge.js +2 -6
- package/_internal/breadcrumb-item.js +1 -4
- package/_internal/breadcrumbs.js +2 -6
- package/_internal/button-group.js +2 -5
- package/_internal/button-link.js +2 -8
- package/_internal/button.js +3 -8
- package/_internal/card-actions.js +1 -4
- package/_internal/card-body.js +1 -4
- package/_internal/card-header.js +1 -8
- package/_internal/card.js +2 -11
- package/_internal/checkbox-group.js +2 -6
- package/_internal/checkbox.js +2 -6
- package/_internal/colors.js +87 -91
- package/_internal/conditional-wrapper.js +2 -2
- package/_internal/detailed-card-collapsible-section-items.js +1 -3
- package/_internal/detailed-card-header.js +1 -7
- package/_internal/detailed-card-section-item.js +1 -10
- package/_internal/detailed-card-section.js +1 -6
- package/_internal/detailed-card.js +2 -16
- package/_internal/flexbox.js +2 -5
- package/_internal/focus-within-group.js +3 -3
- package/_internal/fonts.js +4 -6
- package/_internal/gradient-border.js +35 -16
- package/_internal/grid-item.js +1 -4
- package/_internal/grid.js +2 -6
- package/_internal/heading.js +2 -6
- package/_internal/icon-button-link.js +2 -8
- package/_internal/icon-button.js +2 -6
- package/_internal/icon.js +2 -6
- package/_internal/item.js +2 -8
- package/_internal/link-button.js +2 -8
- package/_internal/link.js +3 -8
- package/_internal/listbox.js +3 -6
- package/_internal/number-field.js +2 -9
- package/_internal/number.js +2 -7
- package/_internal/pill.js +2 -6
- package/_internal/progress-bar.js +2 -5
- package/_internal/radio-group.js +2 -6
- package/_internal/radio.js +2 -6
- package/_internal/shared.js +2 -5
- package/_internal/shield.js +2 -6
- package/_internal/side-navigation-menu-bar.js +3 -9
- package/_internal/side-navigation-menu-item.js +2 -8
- package/_internal/side-navigation-menu.js +2 -8
- package/_internal/skeleton-circle.js +1 -6
- package/_internal/skeleton-text.js +2 -6
- package/_internal/skeleton.js +1 -7
- package/_internal/spinner.js +2 -5
- package/_internal/styles.js +235 -17
- package/_internal/styles2.js +44 -280
- package/_internal/switch-group.js +2 -6
- package/_internal/switch.js +2 -6
- package/_internal/text-area.js +2 -9
- package/_internal/text-field.js +2 -10
- package/_internal/text.js +2 -6
- package/_internal/theme.js +1 -3
- package/_internal/types.js +7 -31
- package/_internal/types2.js +18 -29
- package/_internal/types3.js +15 -18
- package/_internal/useAppSidePanel.js +331 -6
- package/_internal/useFocusOnList.js +502 -44
- package/_internal/useListboxItem.js +120 -23
- package/_internal/useSideNavigationMenuBar.js +371 -7
- package/_internal/useTheme.js +10 -8
- package/index.d.ts +4667 -0
- package/index.js +523 -1674
- package/package.json +2 -2
- package/_internal/SideNavigationMenuBar.js +0 -9
- package/_internal/helpers.js +0 -23
- package/_internal/types10.js +0 -20
- package/_internal/types11.js +0 -27
- package/_internal/types12.js +0 -35
- package/_internal/types13.js +0 -143
- package/_internal/types14.js +0 -11
- package/_internal/types15.js +0 -62
- package/_internal/types16.js +0 -56
- package/_internal/types17.js +0 -57
- package/_internal/types18.js +0 -40
- package/_internal/types19.js +0 -101
- package/_internal/types20.js +0 -47
- package/_internal/types21.js +0 -68
- package/_internal/types22.js +0 -52
- package/_internal/types23.js +0 -174
- package/_internal/types24.js +0 -18
- package/_internal/types25.js +0 -12
- package/_internal/types26.js +0 -36
- package/_internal/types27.js +0 -72
- package/_internal/types28.js +0 -73
- package/_internal/types29.js +0 -99
- package/_internal/types4.js +0 -67
- package/_internal/types5.js +0 -11
- package/_internal/types6.js +0 -11
- package/_internal/types7.js +0 -28
- package/_internal/types8.js +0 -72
- package/_internal/types9.js +0 -16
|
@@ -1,32 +1,129 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { C as Comp } from './helpers.js';
|
|
1
|
+
import React__default, { useContext, useCallback, useEffect } from 'react';
|
|
2
|
+
import { c as useFocusOnListItem } from './useFocusOnListItem.js';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const LISTBOX_INITIAL_STATE = {
|
|
5
|
+
isDisabled: false,
|
|
6
|
+
isReadOnly: false,
|
|
7
|
+
selectedValues: [],
|
|
8
|
+
selectionMode: 'single'
|
|
9
|
+
};
|
|
10
|
+
const ListboxContext = /*#__PURE__*/React__default.createContext({
|
|
11
|
+
state: LISTBOX_INITIAL_STATE,
|
|
12
|
+
dispatch: () => {}
|
|
13
|
+
});
|
|
8
14
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Component variant.
|
|
17
|
+
*/
|
|
18
|
+
const ListboxSelectionMode = {
|
|
19
|
+
single: 'single',
|
|
20
|
+
multiple: 'multiple'
|
|
21
|
+
};
|
|
12
22
|
|
|
13
23
|
/**
|
|
14
|
-
*
|
|
15
|
-
* Can be used as controlled or uncontrolled.
|
|
24
|
+
* Context props.
|
|
16
25
|
*/
|
|
17
|
-
declare const Listbox: Comp<ListboxProps, HTMLDivElement>;
|
|
18
26
|
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
let ListboxActionType = /*#__PURE__*/function (ListboxActionType) {
|
|
28
|
+
ListboxActionType["TOGGLE"] = "TOGGLE";
|
|
29
|
+
ListboxActionType["SET"] = "SET";
|
|
30
|
+
ListboxActionType["UPDATE_OPTIONS"] = "UPDATE_OPTIONS";
|
|
31
|
+
return ListboxActionType;
|
|
32
|
+
}({});
|
|
33
|
+
/**
|
|
34
|
+
* Component variant.
|
|
35
|
+
*/
|
|
36
|
+
const ListboxVariant = {
|
|
37
|
+
standalone: 'standalone',
|
|
38
|
+
unstyled: 'unstyled'
|
|
39
|
+
};
|
|
21
40
|
|
|
22
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Component props.
|
|
43
|
+
*/
|
|
23
44
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
45
|
+
function useListboxItem(props) {
|
|
46
|
+
var _context$state, _context$state$select;
|
|
47
|
+
const {
|
|
48
|
+
domElementRef,
|
|
49
|
+
value,
|
|
50
|
+
id,
|
|
51
|
+
isDisabled,
|
|
52
|
+
propsIsSelected
|
|
53
|
+
} = props;
|
|
54
|
+
const {
|
|
55
|
+
tabIndex,
|
|
56
|
+
isFocused,
|
|
57
|
+
handleKeyDown: handleFocusKeyDown,
|
|
58
|
+
handleClick: handleFocusClick
|
|
59
|
+
} = useFocusOnListItem({
|
|
60
|
+
domElementRef,
|
|
61
|
+
isDisabled: isDisabled,
|
|
62
|
+
id,
|
|
63
|
+
value
|
|
64
|
+
});
|
|
65
|
+
const context = useContext(ListboxContext);
|
|
66
|
+
const handleKeyDown = useCallback(event => {
|
|
67
|
+
handleFocusKeyDown(event);
|
|
68
|
+
const code = event.code;
|
|
69
|
+
if (code === 'Enter' || code === 'Space') {
|
|
70
|
+
if (context.state.selectionMode === 'multiple') {
|
|
71
|
+
context.dispatch({
|
|
72
|
+
type: ListboxActionType.TOGGLE,
|
|
73
|
+
payload: {
|
|
74
|
+
value,
|
|
75
|
+
activedescendant: [id, value]
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
context.dispatch({
|
|
80
|
+
type: ListboxActionType.SET,
|
|
81
|
+
payload: {
|
|
82
|
+
values: [value],
|
|
83
|
+
activedescendant: [id, value]
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}, []);
|
|
89
|
+
const handleClick = useCallback(() => {
|
|
90
|
+
handleFocusClick();
|
|
91
|
+
if (context.state.selectionMode === 'multiple') {
|
|
92
|
+
if (value) {
|
|
93
|
+
context.dispatch({
|
|
94
|
+
type: ListboxActionType.TOGGLE,
|
|
95
|
+
payload: {
|
|
96
|
+
value,
|
|
97
|
+
activedescendant: [id, value]
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
context.dispatch({
|
|
103
|
+
type: ListboxActionType.SET,
|
|
104
|
+
payload: {
|
|
105
|
+
values: [value],
|
|
106
|
+
activedescendant: [id, value]
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}, [value]);
|
|
111
|
+
const isSelected = propsIsSelected !== null && propsIsSelected !== void 0 ? propsIsSelected : (context === null || context === void 0 ? void 0 : (_context$state = context.state) === null || _context$state === void 0 ? void 0 : (_context$state$select = _context$state.selectedValues) === null || _context$state$select === void 0 ? void 0 : _context$state$select.find(selectedValue => selectedValue === value)) !== undefined;
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
if (isFocused && domElementRef.current) {
|
|
114
|
+
var _current;
|
|
115
|
+
(_current = domElementRef.current) === null || _current === void 0 ? void 0 : _current.focus();
|
|
116
|
+
}
|
|
117
|
+
}, [isFocused]);
|
|
118
|
+
return {
|
|
119
|
+
tabIndex,
|
|
120
|
+
isFocused,
|
|
121
|
+
isSelected,
|
|
122
|
+
isDisabled,
|
|
123
|
+
handleKeyDown,
|
|
124
|
+
handleClick
|
|
125
|
+
};
|
|
126
|
+
}
|
|
31
127
|
|
|
32
|
-
export {
|
|
128
|
+
export { ListboxSelectionMode as L, ListboxActionType as a, ListboxVariant as b, LISTBOX_INITIAL_STATE as c, ListboxContext as d, useListboxItem as u };
|
|
129
|
+
//# sourceMappingURL=useListboxItem.js.map
|
|
@@ -1,9 +1,373 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b as _objectWithoutProperties, c as _extends } from './_rollupPluginBabelHelpers.js';
|
|
2
|
+
import React__default, { useState, useEffect, forwardRef, useRef, useContext, useMemo } from 'react';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { w as warnIfNoAccessibleLabelFound } from './warnIfNoAccessibleLabelFound.js';
|
|
5
|
+
import styled, { css } from 'styled-components';
|
|
6
|
+
import { S as SideNavigationMenuBarVariant, b as SideNavigationMenuBarContext, a as SideNavigationMenuItem } from './SideNavigationMenuItem.js';
|
|
7
|
+
import { f as filterComponents } from './filterComponents.js';
|
|
8
|
+
import { a as SideNavigationMenu } from './SideNavigationMenu.js';
|
|
9
|
+
import { A as AppContainerContext } from './context.js';
|
|
10
|
+
import { u as useTheme, a as ThemeProvider } from './useTheme.js';
|
|
11
|
+
import { A as AppSidePanelVariant } from './types.js';
|
|
2
12
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Get the bounding rect of a component.
|
|
15
|
+
*/
|
|
16
|
+
const useBoundingClientRect = (ref, deps) => {
|
|
17
|
+
const [boundingRect, setBoundingRect] = useState({});
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (ref.current) {
|
|
20
|
+
setBoundingRect(ref.current.getBoundingClientRect());
|
|
21
|
+
}
|
|
22
|
+
}, deps);
|
|
23
|
+
return boundingRect;
|
|
24
|
+
};
|
|
8
25
|
|
|
9
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Component style.
|
|
28
|
+
*/
|
|
29
|
+
const StyledSideNavigationMenuBar = styled.nav`
|
|
30
|
+
background-color: ${_ref => {
|
|
31
|
+
let {
|
|
32
|
+
$theme
|
|
33
|
+
} = _ref;
|
|
34
|
+
return `var(--redsift-color-${$theme}-components-side-navigation-background)`;
|
|
35
|
+
}};
|
|
36
|
+
box-sizing: content-box;
|
|
37
|
+
overflow-x: hidden;
|
|
38
|
+
overflow-y: auto;
|
|
39
|
+
scrollbar-gutter: stable;
|
|
40
|
+
transition: width 300ms ease-out;
|
|
41
|
+
width: ${_ref2 => {
|
|
42
|
+
let {
|
|
43
|
+
$variant
|
|
44
|
+
} = _ref2;
|
|
45
|
+
return $variant === SideNavigationMenuBarVariant.shrinked ? '64px' : '250px';
|
|
46
|
+
}};
|
|
47
|
+
|
|
48
|
+
${_ref3 => {
|
|
49
|
+
let {
|
|
50
|
+
$marginTop = 0
|
|
51
|
+
} = _ref3;
|
|
52
|
+
return $marginTop ? css`
|
|
53
|
+
height: calc(100% - ${$marginTop}px);
|
|
54
|
+
` : '';
|
|
55
|
+
}}
|
|
56
|
+
|
|
57
|
+
ul {
|
|
58
|
+
list-style: none;
|
|
59
|
+
margin: unset;
|
|
60
|
+
padding: unset;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
scrollbar-color: ${_ref4 => {
|
|
64
|
+
let {
|
|
65
|
+
$theme
|
|
66
|
+
} = _ref4;
|
|
67
|
+
return `var(--redsift-color-${$theme}-components-side-navigation-scrollbar-resting) transparent`;
|
|
68
|
+
}};
|
|
69
|
+
scrollbar-width: thin;
|
|
70
|
+
|
|
71
|
+
&::-webkit-scrollbar {
|
|
72
|
+
block-size: 9px;
|
|
73
|
+
inline-size: 9px;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
&::-webkit-scrollbar-thumb {
|
|
77
|
+
background-clip: padding-box;
|
|
78
|
+
background-color: ${_ref5 => {
|
|
79
|
+
let {
|
|
80
|
+
$theme
|
|
81
|
+
} = _ref5;
|
|
82
|
+
return `var(--redsift-color-${$theme}-components-side-navigation-scrollbar-resting)`;
|
|
83
|
+
}};
|
|
84
|
+
border-radius: 0px;
|
|
85
|
+
border-left: 2px solid transparent;
|
|
86
|
+
border-right: 2px solid transparent;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
&::-webkit-scrollbar-track {
|
|
90
|
+
background-color: transparent;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
&::-webkit-scrollbar-thumb:horizontal,
|
|
94
|
+
&::-webkit-scrollbar-thumb:vertical {
|
|
95
|
+
&:hover {
|
|
96
|
+
background-color: ${_ref6 => {
|
|
97
|
+
let {
|
|
98
|
+
$theme
|
|
99
|
+
} = _ref6;
|
|
100
|
+
return `var(--redsift-color-${$theme}-components-side-navigation-scrollbar-hover)`;
|
|
101
|
+
}};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
&::-webkit-scrollbar-corner {
|
|
106
|
+
visibility: hidden;
|
|
107
|
+
}
|
|
108
|
+
`;
|
|
109
|
+
|
|
110
|
+
const _excluded$1 = ["aria-label", "aria-labelledby", "canHaveMultipleMenuOpenAtOnce", "children", "className", "isDisabled", "menubarProps", "menubarRef", "theme", "variant"];
|
|
111
|
+
const COMPONENT_NAME = 'SideNavigationMenuBar';
|
|
112
|
+
const CLASSNAME = 'redsift-side-navigation-menu-bar';
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Hook to store the previous index for further use
|
|
116
|
+
*/
|
|
117
|
+
const usePrevious = value => {
|
|
118
|
+
const ref = useRef(0);
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
ref.current = value;
|
|
121
|
+
}, [value]);
|
|
122
|
+
return ref.current;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The SideNavigationMenuBar component.
|
|
127
|
+
*/
|
|
128
|
+
const SideNavigationMenuBar = /*#__PURE__*/forwardRef((props, ref) => {
|
|
129
|
+
const navRef = ref || useRef();
|
|
130
|
+
const {
|
|
131
|
+
'aria-label': ariaLabel,
|
|
132
|
+
'aria-labelledby': ariaLabelledby,
|
|
133
|
+
canHaveMultipleMenuOpenAtOnce,
|
|
134
|
+
children,
|
|
135
|
+
className,
|
|
136
|
+
isDisabled,
|
|
137
|
+
menubarProps = {},
|
|
138
|
+
menubarRef = useRef(),
|
|
139
|
+
theme: propsTheme,
|
|
140
|
+
variant: propsVariant = SideNavigationMenuBarVariant.standard
|
|
141
|
+
} = props,
|
|
142
|
+
forwardedProps = _objectWithoutProperties(props, _excluded$1);
|
|
143
|
+
warnIfNoAccessibleLabelFound(props, undefined, 'SideNavigationMenuBar');
|
|
144
|
+
const appContainerState = useContext(AppContainerContext);
|
|
145
|
+
const theme = useTheme(propsTheme);
|
|
146
|
+
const {
|
|
147
|
+
top
|
|
148
|
+
} = useBoundingClientRect(navRef, [children]);
|
|
149
|
+
const [variant, setVariant] = useState(appContainerState ? appContainerState.sidePanelVariant === AppSidePanelVariant.hidden ? SideNavigationMenuBarVariant.shrinked : appContainerState.sidePanelVariant : propsVariant);
|
|
150
|
+
const [currentOpenMenuId, setCurrentOpenMenuId] = useState();
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
setVariant(propsVariant);
|
|
153
|
+
}, [propsVariant]);
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
if (appContainerState && appContainerState.sidePanelVariant && appContainerState.sidePanelVariant !== variant) {
|
|
156
|
+
setVariant(appContainerState.sidePanelVariant === AppSidePanelVariant.hidden ? SideNavigationMenuBarVariant.shrinked : appContainerState.sidePanelVariant);
|
|
157
|
+
}
|
|
158
|
+
}, [appContainerState === null || appContainerState === void 0 ? void 0 : appContainerState.sidePanelVariant]);
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Create an array containing only valid children being either SideNavigationMenu or SideNavigationMenuItem.
|
|
162
|
+
*/
|
|
163
|
+
const childArray = filterComponents([SideNavigationMenu, SideNavigationMenuItem])(children);
|
|
164
|
+
const navItems = childArray.map((child, index) => {
|
|
165
|
+
var _child$key, _child$key2;
|
|
166
|
+
return /*#__PURE__*/React__default.createElement("li", {
|
|
167
|
+
key: (_child$key = child.key) !== null && _child$key !== void 0 ? _child$key : index,
|
|
168
|
+
role: "none"
|
|
169
|
+
}, /*#__PURE__*/React__default.cloneElement(child, {
|
|
170
|
+
isDisabled: child.props.isDisabled || isDisabled || undefined,
|
|
171
|
+
key: (_child$key2 = child.key) !== null && _child$key2 !== void 0 ? _child$key2 : index,
|
|
172
|
+
tabIndex: index === 0 ? 0 : -1
|
|
173
|
+
}));
|
|
174
|
+
});
|
|
175
|
+
const menuItems = useRef(new Set()).current;
|
|
176
|
+
const [currentIndex, setCurrentIndex] = useState(0);
|
|
177
|
+
const previousIndex = usePrevious(currentIndex);
|
|
178
|
+
const first = () => setCurrentIndex(0);
|
|
179
|
+
const last = () => setCurrentIndex(menuItems.size - 1);
|
|
180
|
+
const next = () => {
|
|
181
|
+
const index = currentIndex === menuItems.size - 1 ? 0 : currentIndex + 1;
|
|
182
|
+
setCurrentIndex(index);
|
|
183
|
+
};
|
|
184
|
+
const previous = () => {
|
|
185
|
+
const index = currentIndex === 0 ? menuItems.size - 1 : currentIndex - 1;
|
|
186
|
+
setCurrentIndex(index);
|
|
187
|
+
};
|
|
188
|
+
const match = event => {
|
|
189
|
+
const items = Array.from(menuItems);
|
|
190
|
+
|
|
191
|
+
// Reorder the array, starting with the currentNode
|
|
192
|
+
const reorderedItems = [...items.slice(currentIndex), ...items.slice(0, currentIndex)];
|
|
193
|
+
|
|
194
|
+
// Find all nodes that begin with the pressed letter
|
|
195
|
+
const matches = reorderedItems.filter(menuItem => {
|
|
196
|
+
const {
|
|
197
|
+
textContent
|
|
198
|
+
} = menuItem;
|
|
199
|
+
// istanbul ignore next
|
|
200
|
+
const firstLetter = textContent === null || textContent === void 0 ? void 0 : textContent.toLowerCase().charAt(0);
|
|
201
|
+
return event.key === firstLetter;
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// Exit early if there are no matches
|
|
205
|
+
if (!matches.length) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// If the focused item is a match, focus the next match.
|
|
210
|
+
// Otherwise, focus the first match
|
|
211
|
+
const currentNode = items[currentIndex];
|
|
212
|
+
const nextMatch = matches.includes(currentNode) ? matches[1] : matches[0];
|
|
213
|
+
const index = items.findIndex(item => {
|
|
214
|
+
return item === nextMatch;
|
|
215
|
+
});
|
|
216
|
+
setCurrentIndex(index);
|
|
217
|
+
};
|
|
218
|
+
const keyDown = e => {
|
|
219
|
+
var _menubarProps$onKeyDo, _currentNode$parentNo;
|
|
220
|
+
(_menubarProps$onKeyDo = menubarProps.onKeyDown) === null || _menubarProps$onKeyDo === void 0 ? void 0 : _menubarProps$onKeyDo.call(menubarProps, e);
|
|
221
|
+
e.stopPropagation();
|
|
222
|
+
const currentNode = e.target;
|
|
223
|
+
// istanbul ignore next
|
|
224
|
+
const parentMenu = currentNode === null || currentNode === void 0 ? void 0 : (_currentNode$parentNo = currentNode.parentNode) === null || _currentNode$parentNo === void 0 ? void 0 : _currentNode$parentNo.parentNode;
|
|
225
|
+
const isFromSubmenu = parentMenu.getAttribute('role') === 'menu';
|
|
226
|
+
switch (e.code) {
|
|
227
|
+
case 'ArrowUp':
|
|
228
|
+
e.preventDefault();
|
|
229
|
+
previous();
|
|
230
|
+
break;
|
|
231
|
+
case 'ArrowDown':
|
|
232
|
+
e.preventDefault();
|
|
233
|
+
next();
|
|
234
|
+
break;
|
|
235
|
+
case 'ArrowRight':
|
|
236
|
+
e.preventDefault();
|
|
237
|
+
if (isFromSubmenu) {
|
|
238
|
+
next();
|
|
239
|
+
}
|
|
240
|
+
break;
|
|
241
|
+
case 'End':
|
|
242
|
+
e.preventDefault();
|
|
243
|
+
last();
|
|
244
|
+
break;
|
|
245
|
+
case 'Home':
|
|
246
|
+
e.preventDefault();
|
|
247
|
+
first();
|
|
248
|
+
break;
|
|
249
|
+
case 'Enter':
|
|
250
|
+
case 'Space':
|
|
251
|
+
e.preventDefault();
|
|
252
|
+
currentNode.click();
|
|
253
|
+
break;
|
|
254
|
+
default:
|
|
255
|
+
match(e);
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
const value = useMemo(() => ({
|
|
260
|
+
menuItems,
|
|
261
|
+
sideNavigationMenuBarVariant: variant,
|
|
262
|
+
setSideNavigationMenuBarVariant: setVariant,
|
|
263
|
+
currentOpenMenuId,
|
|
264
|
+
setCurrentOpenMenuId: value => {
|
|
265
|
+
if (!canHaveMultipleMenuOpenAtOnce) {
|
|
266
|
+
setCurrentOpenMenuId(value);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}), [menuItems, variant, setVariant, currentOpenMenuId, setCurrentOpenMenuId]);
|
|
270
|
+
useEffect(() => {
|
|
271
|
+
if (currentIndex !== previousIndex) {
|
|
272
|
+
const items = Array.from(menuItems);
|
|
273
|
+
const currentNode = items[currentIndex];
|
|
274
|
+
const previousNode = items[previousIndex];
|
|
275
|
+
|
|
276
|
+
// istanbul ignore next
|
|
277
|
+
previousNode === null || previousNode === void 0 ? void 0 : previousNode.setAttribute('tabindex', '-1');
|
|
278
|
+
currentNode === null || currentNode === void 0 ? void 0 : currentNode.setAttribute('tabindex', '0');
|
|
279
|
+
currentNode === null || currentNode === void 0 ? void 0 : currentNode.focus();
|
|
280
|
+
}
|
|
281
|
+
}, [currentIndex, previousIndex, menuItems]);
|
|
282
|
+
return /*#__PURE__*/React__default.createElement(ThemeProvider, {
|
|
283
|
+
value: {
|
|
284
|
+
theme
|
|
285
|
+
}
|
|
286
|
+
}, /*#__PURE__*/React__default.createElement(StyledSideNavigationMenuBar, _extends({}, forwardedProps, {
|
|
287
|
+
$isDisabled: isDisabled,
|
|
288
|
+
$marginTop: top,
|
|
289
|
+
$theme: theme,
|
|
290
|
+
$variant: variant,
|
|
291
|
+
"aria-label": ariaLabel,
|
|
292
|
+
"aria-labelledby": ariaLabelledby,
|
|
293
|
+
className: classNames(SideNavigationMenuBar.className, className),
|
|
294
|
+
ref: navRef
|
|
295
|
+
}), /*#__PURE__*/React__default.createElement(SideNavigationMenuBarContext.Provider, {
|
|
296
|
+
value: value
|
|
297
|
+
}, /*#__PURE__*/React__default.createElement("ul", _extends({}, menubarProps, {
|
|
298
|
+
"aria-label": ariaLabel,
|
|
299
|
+
"aria-labelledby": ariaLabelledby,
|
|
300
|
+
"aria-orientation": "vertical",
|
|
301
|
+
onKeyDown: keyDown,
|
|
302
|
+
ref: menubarRef,
|
|
303
|
+
role: "menubar"
|
|
304
|
+
}), navItems))));
|
|
305
|
+
});
|
|
306
|
+
SideNavigationMenuBar.className = CLASSNAME;
|
|
307
|
+
SideNavigationMenuBar.displayName = COMPONENT_NAME;
|
|
308
|
+
|
|
309
|
+
const _excluded = ["title", "href", "ref"],
|
|
310
|
+
_excluded2 = ["title", "children", "ref"],
|
|
311
|
+
_excluded3 = ["title", "href", "ref"];
|
|
312
|
+
const isMenu = item => {
|
|
313
|
+
return item.children !== undefined;
|
|
314
|
+
};
|
|
315
|
+
const useSideNavigationMenuBar = _ref => {
|
|
316
|
+
let {
|
|
317
|
+
items,
|
|
318
|
+
isActive
|
|
319
|
+
} = _ref;
|
|
320
|
+
const menuBarChildren = [];
|
|
321
|
+
items.map(item => {
|
|
322
|
+
if (!isMenu(item)) {
|
|
323
|
+
const {
|
|
324
|
+
title,
|
|
325
|
+
href,
|
|
326
|
+
ref
|
|
327
|
+
} = item,
|
|
328
|
+
rest = _objectWithoutProperties(item, _excluded);
|
|
329
|
+
menuBarChildren.push( /*#__PURE__*/React__default.createElement(SideNavigationMenuItem, _extends({
|
|
330
|
+
key: title,
|
|
331
|
+
isCurrent: isActive ? isActive(href) : undefined
|
|
332
|
+
}, rest, {
|
|
333
|
+
href: href,
|
|
334
|
+
ref: ref
|
|
335
|
+
}), title));
|
|
336
|
+
} else {
|
|
337
|
+
const {
|
|
338
|
+
title,
|
|
339
|
+
children,
|
|
340
|
+
ref
|
|
341
|
+
} = item,
|
|
342
|
+
rest = _objectWithoutProperties(item, _excluded2);
|
|
343
|
+
menuBarChildren.push( /*#__PURE__*/React__default.createElement(SideNavigationMenu, _extends({
|
|
344
|
+
key: title,
|
|
345
|
+
"aria-label": title,
|
|
346
|
+
isExpanded: isActive ? children.filter(child => isActive(child.href)).length > 0 : undefined,
|
|
347
|
+
hasBadge: children.filter(child => child.badge).length > 0
|
|
348
|
+
}, rest, {
|
|
349
|
+
ref: ref
|
|
350
|
+
}), children.map(child => {
|
|
351
|
+
const {
|
|
352
|
+
title,
|
|
353
|
+
href,
|
|
354
|
+
ref
|
|
355
|
+
} = child,
|
|
356
|
+
rest = _objectWithoutProperties(child, _excluded3);
|
|
357
|
+
return /*#__PURE__*/React__default.createElement(SideNavigationMenuItem, _extends({
|
|
358
|
+
key: title,
|
|
359
|
+
href: href,
|
|
360
|
+
isCurrent: isActive ? isActive(href) : undefined
|
|
361
|
+
}, rest, {
|
|
362
|
+
ref: ref
|
|
363
|
+
}), title);
|
|
364
|
+
})));
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
return {
|
|
368
|
+
children: menuBarChildren
|
|
369
|
+
};
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
export { SideNavigationMenuBar as S, useSideNavigationMenuBar as a, useBoundingClientRect as u };
|
|
373
|
+
//# sourceMappingURL=useSideNavigationMenuBar.js.map
|
package/_internal/useTheme.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React__default, { useContext } from 'react';
|
|
2
2
|
import { T as Theme } from './colors.js';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} | null>;
|
|
7
|
-
declare const ThemeProvider: React.Provider<{
|
|
8
|
-
theme?: Theme | undefined;
|
|
9
|
-
} | null>;
|
|
4
|
+
const ThemeContext = /*#__PURE__*/React__default.createContext(null);
|
|
5
|
+
const ThemeProvider = ThemeContext.Provider;
|
|
10
6
|
|
|
11
|
-
|
|
7
|
+
function useTheme(theme) {
|
|
8
|
+
var _ref;
|
|
9
|
+
const themeState = useContext(ThemeContext);
|
|
10
|
+
const contextTheme = (_ref = theme !== null && theme !== void 0 ? theme : themeState === null || themeState === void 0 ? void 0 : themeState.theme) !== null && _ref !== void 0 ? _ref : Theme.light;
|
|
11
|
+
return contextTheme;
|
|
12
|
+
}
|
|
12
13
|
|
|
13
14
|
export { ThemeContext as T, ThemeProvider as a, useTheme as u };
|
|
15
|
+
//# sourceMappingURL=useTheme.js.map
|