@momentum-ui/react-collaboration
Version:
Cisco Momentum UI Framework for React Collaboration Applications
63 lines • 3.56 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import React, { useImperativeHandle, useRef, forwardRef } from 'react';
import classnames from 'classnames';
import { DEFAULTS, STYLE } from './List.constants';
import './List.style.scss';
import { ListContext } from './List.utils';
import useOrientationBasedKeyboardNavigation from '../../hooks/useOrientationBasedKeyboardNavigation';
import { mergeProps } from '@react-aria/utils';
/**
* @deprecated Use the equivalent from momentum.design (NPM: `@momentum-design/components/dist/react`)
*/
var List = forwardRef(function (props, ref) {
var allItemIndexes = props.allItemIndexes, className = props.className, id = props.id, style = props.style, children = props.children, shouldFocusOnPress = props.shouldFocusOnPress, listSize = props.listSize, role = props.role, shouldItemFocusBeInset = props.shouldItemFocusBeInset, noLoop = props.noLoop, _a = props.orientation, orientation = _a === void 0 ? DEFAULTS.ORIENTATION : _a, _b = props.initialFocus, propInitialFocus = _b === void 0 ? DEFAULTS.INITIAL_FOCUS_NOT_SET : _b, rest = __rest(props, ["allItemIndexes", "className", "id", "style", "children", "shouldFocusOnPress", "listSize", "role", "shouldItemFocusBeInset", "noLoop", "orientation", "initialFocus"]);
var initialFocus = propInitialFocus;
if (initialFocus === DEFAULTS.INITIAL_FOCUS_NOT_SET) {
if (allItemIndexes) {
initialFocus = allItemIndexes[0];
}
else {
initialFocus = 0;
}
}
var _c = useOrientationBasedKeyboardNavigation({
listSize: listSize,
allItemIndexes: allItemIndexes,
orientation: orientation,
noLoop: noLoop,
initialFocus: initialFocus,
contextProps: { shouldFocusOnPress: shouldFocusOnPress, shouldItemFocusBeInset: shouldItemFocusBeInset },
}), keyboardProps = _c.keyboardProps, getContext = _c.getContext, focusWithinProps = _c.focusWithinProps;
var listRef = useRef();
// Expose imperative methods
useImperativeHandle(ref, function () { return ({
listRef: listRef,
focusOnIndex: function (index) { var _a; return (_a = getContext()) === null || _a === void 0 ? void 0 : _a.setCurrentFocus(index); },
getCurrentFocusIndex: function () { var _a; return (_a = getContext()) === null || _a === void 0 ? void 0 : _a.getCurrentFocus(); },
}); });
return (React.createElement(ListContext.Provider, { value: getContext() },
React.createElement("ul", __assign({ className: classnames(className, STYLE.wrapper), ref: listRef, style: style, id: id, role: role }, mergeProps(keyboardProps, focusWithinProps, rest)), children)));
});
export default List;
//# sourceMappingURL=List.js.map