@digital-ai/dot-components 4.10.0 → 4.11.1
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/index.esm.js
CHANGED
|
@@ -4315,24 +4315,36 @@ const DotClickAwayListener = ({
|
|
|
4315
4315
|
};
|
|
4316
4316
|
|
|
4317
4317
|
const TYPEABLE_INPUTS_TYPES = ['date', 'datetime-local', 'email', 'month', 'number', 'password', 'search', 'tel', 'text', 'time', 'url', 'week'];
|
|
4318
|
-
const
|
|
4318
|
+
const checkIfTypableElement = element => {
|
|
4319
4319
|
const type = element.getAttribute('type');
|
|
4320
4320
|
return element.nodeName === 'TEXTAREA' || element.nodeName === 'INPUT' && (!type || TYPEABLE_INPUTS_TYPES.includes(type));
|
|
4321
4321
|
};
|
|
4322
|
-
const
|
|
4322
|
+
const isElementPreventingKeyPress = element => {
|
|
4323
|
+
return checkIfTypableElement(element) || element.isContentEditable;
|
|
4324
|
+
};
|
|
4325
|
+
const isModifierPressed = (event, modifiers) => {
|
|
4326
|
+
return modifiers.includes('shift') === event.shiftKey && modifiers.includes('ctrl') === event.ctrlKey && modifiers.includes('alt') === event.altKey && modifiers.includes('meta') === event.metaKey;
|
|
4327
|
+
};
|
|
4328
|
+
const useKeyPress = (keyOptions, callback, dependencies = []) => {
|
|
4323
4329
|
useEffect(() => {
|
|
4324
|
-
if (!
|
|
4330
|
+
if (!keyOptions) return;
|
|
4331
|
+
const {
|
|
4332
|
+
keys,
|
|
4333
|
+
modifiers
|
|
4334
|
+
} = keyOptions;
|
|
4335
|
+
if (!keys || !keys.length) return;
|
|
4325
4336
|
const handleKeyPress = event => {
|
|
4326
4337
|
const element = event.target;
|
|
4327
|
-
|
|
4328
|
-
|
|
4338
|
+
const isKeyPressed = Array.isArray(keys) ? keys.includes(event.key) : event.key === keys;
|
|
4339
|
+
if (isKeyPressed && !isElementPreventingKeyPress(element) && isModifierPressed(event, modifiers !== null && modifiers !== void 0 ? modifiers : [])) {
|
|
4340
|
+
callback(event);
|
|
4329
4341
|
}
|
|
4330
4342
|
};
|
|
4331
4343
|
window.addEventListener('keydown', handleKeyPress);
|
|
4332
4344
|
return () => {
|
|
4333
4345
|
window.removeEventListener('keydown', handleKeyPress);
|
|
4334
4346
|
};
|
|
4335
|
-
}, [
|
|
4347
|
+
}, [keyOptions, ...dependencies]);
|
|
4336
4348
|
};
|
|
4337
4349
|
|
|
4338
4350
|
const DotList = ({
|
|
@@ -4366,7 +4378,9 @@ const DotList = ({
|
|
|
4366
4378
|
const handleHrefClick = index => () => {
|
|
4367
4379
|
updateSelectedListItem(index);
|
|
4368
4380
|
};
|
|
4369
|
-
useKeyPress(
|
|
4381
|
+
useKeyPress({
|
|
4382
|
+
keys: keyForNestedReset
|
|
4383
|
+
}, handleClickAway);
|
|
4370
4384
|
const list = jsxs(StyledList, {
|
|
4371
4385
|
"aria-label": ariaLabel,
|
|
4372
4386
|
classes: {
|
|
@@ -6017,7 +6031,7 @@ const DotSidebar = ({
|
|
|
6017
6031
|
const hasBackItem = goBack && backItem;
|
|
6018
6032
|
const displayHeader = title || hasAppLogo;
|
|
6019
6033
|
const openClass = isOpen ? 'open' : 'collapsed';
|
|
6020
|
-
const
|
|
6034
|
+
const collapseKeys = ['q', 'Q'];
|
|
6021
6035
|
const checkPrimaryNavMissingIcons = () => navItems.some(item => !item.divider && !item.startIcon);
|
|
6022
6036
|
useEffect(() => {
|
|
6023
6037
|
// Incorrect usage warning
|
|
@@ -6035,7 +6049,9 @@ const DotSidebar = ({
|
|
|
6035
6049
|
onCollapseChange && onCollapseChange(isOpen);
|
|
6036
6050
|
setIsOpen(!isOpen);
|
|
6037
6051
|
};
|
|
6038
|
-
useKeyPress(collapsable &&
|
|
6052
|
+
useKeyPress(collapsable && {
|
|
6053
|
+
keys: collapseKeys
|
|
6054
|
+
}, toggleNavCollapseState, [isOpen, collapsable]);
|
|
6039
6055
|
const sidebarClasses = useStylesWithRootClass('side-nav', openClass);
|
|
6040
6056
|
const rootClasses = useStylesWithRootClass(rootClassName$11, openClass, className);
|
|
6041
6057
|
return jsxs(StyledSidebar, {
|
|
@@ -6079,7 +6095,7 @@ const DotSidebar = ({
|
|
|
6079
6095
|
dense: true,
|
|
6080
6096
|
disablePadding: true,
|
|
6081
6097
|
items: navItems,
|
|
6082
|
-
keyForNestedReset:
|
|
6098
|
+
keyForNestedReset: collapseKeys,
|
|
6083
6099
|
nestedDrawerLeftSpacing: sidebarWidth,
|
|
6084
6100
|
nestedListType: nestedListType,
|
|
6085
6101
|
width: "100%"
|
|
@@ -6089,7 +6105,7 @@ const DotSidebar = ({
|
|
|
6089
6105
|
}), collapsable && jsx("div", {
|
|
6090
6106
|
className: "toggle-nav",
|
|
6091
6107
|
children: jsx(DotTooltip, {
|
|
6092
|
-
title: (isOpen ? 'Collapse' : 'Expand') + ` ${
|
|
6108
|
+
title: (isOpen ? 'Collapse' : 'Expand') + ` ${collapseKeys[0].toUpperCase()}`,
|
|
6093
6109
|
placement: "right",
|
|
6094
6110
|
children: jsx(DotIconButton, {
|
|
6095
6111
|
ariaLabel: "collapse sidebar navigation",
|
|
@@ -6286,7 +6302,7 @@ const StyledAppToolbar = styled.header`
|
|
|
6286
6302
|
align-items: center;
|
|
6287
6303
|
|
|
6288
6304
|
.right-side-pre-nav {
|
|
6289
|
-
margin-right: ${theme.spacing(
|
|
6305
|
+
margin-right: ${theme.spacing(6)};
|
|
6290
6306
|
}
|
|
6291
6307
|
|
|
6292
6308
|
.dot-badge .MuiBadge-anchorOriginTopRightRectangular {
|
|
@@ -6300,6 +6316,7 @@ const StyledAppToolbar = styled.header`
|
|
|
6300
6316
|
align-items: center;
|
|
6301
6317
|
justify-content: center;
|
|
6302
6318
|
width: 40px;
|
|
6319
|
+
height: 40px;
|
|
6303
6320
|
button.dot-avatar:focus-visible {
|
|
6304
6321
|
box-shadow: 0px 0px 0px 3px ${theme.palette.figma.icon.white},
|
|
6305
6322
|
0px 0px 0px 5px ${theme.palette.figma.icon.black};
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@ export interface ListProps extends CommonProps {
|
|
|
18
18
|
/** Array of list items displayed */
|
|
19
19
|
items?: Array<ListItemProps>;
|
|
20
20
|
/** If defined, list selection will reset when key is pressed */
|
|
21
|
-
keyForNestedReset?: string;
|
|
21
|
+
keyForNestedReset?: string | string[];
|
|
22
22
|
/** If nested list type is 'menu', determines the placement of the menu */
|
|
23
23
|
menuPlacement?: PopperPlacement;
|
|
24
24
|
/** If nested type is 'drawer', determines the width of the left spacing */
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
export declare const TYPEABLE_INPUTS_TYPES: string[];
|
|
2
|
-
export
|
|
3
|
+
export type Modifier = 'shift' | 'ctrl' | 'alt' | 'meta';
|
|
4
|
+
interface KeyOptions {
|
|
5
|
+
keys: string | string[];
|
|
6
|
+
modifiers?: Modifier[];
|
|
7
|
+
}
|
|
8
|
+
export declare const useKeyPress: (keyOptions: KeyOptions, callback: (event?: KeyboardEvent | React.KeyboardEvent) => void, dependencies?: unknown[]) => void;
|
|
9
|
+
export {};
|