@rmwc/menu
Advanced tools
@@ -21,8 +21,8 @@ "use strict"; | ||
var useMenuSurfaceFoundation = function (props, menuSurfaceWrapperRef) { | ||
var _a = tslib_1.__read(react_1.useState(props.open), 2), open = _a[0], setOpen = _a[1]; | ||
var firstFocusableElementRef = react_1.useRef(null); | ||
var previousFocusRef = react_1.useRef(null); | ||
var anchorElementRef = react_1.useRef(null); | ||
var timerIdRef = react_1.useRef(null); | ||
var _b = base_1.useFoundation({ | ||
var _a = tslib_1.__read((0, react_1.useState)(props.open), 2), open = _a[0], setOpen = _a[1]; | ||
var firstFocusableElementRef = (0, react_1.useRef)(null); | ||
var previousFocusRef = (0, react_1.useRef)(null); | ||
var anchorElementRef = (0, react_1.useRef)(null); | ||
var timerIdRef = (0, react_1.useRef)(null); | ||
var _b = (0, base_1.useFoundation)({ | ||
props: props, | ||
@@ -136,3 +136,3 @@ elements: { rootEl: true }, | ||
}, setTransformOrigin: function (origin) { | ||
var propertyName = animation_1.getCorrectPropertyName(window, 'transform') + "-origin"; | ||
var propertyName = "".concat((0, animation_1.getCorrectPropertyName)(window, 'transform'), "-origin"); | ||
rootEl.setStyle(propertyName, origin); | ||
@@ -164,3 +164,3 @@ } }, getFocusAdapterMethods()), getDimensionAdapterMethods())); | ||
var onKeyDown = props.onKeyDown; | ||
var handleKeydown = react_1.useCallback(function (evt) { | ||
var handleKeydown = (0, react_1.useCallback)(function (evt) { | ||
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(evt); | ||
@@ -171,10 +171,10 @@ foundation.handleKeydown(evt); | ||
// fixed | ||
react_1.useEffect(function () { | ||
(0, react_1.useEffect)(function () { | ||
foundation.setFixedPosition(!!props.fixed); | ||
}, [props.fixed, foundation]); | ||
// on mount | ||
react_1.useEffect(function () { | ||
(0, react_1.useEffect)(function () { | ||
var el = (menuSurfaceWrapperRef === null || menuSurfaceWrapperRef === void 0 ? void 0 : menuSurfaceWrapperRef.current) || rootEl.ref; | ||
if (el) { | ||
var anchor = base_1.closest(el, "." + menu_surface_1.MDCMenuSurfaceFoundation.cssClasses.ANCHOR); | ||
var anchor = (0, base_1.closest)(el, ".".concat(menu_surface_1.MDCMenuSurfaceFoundation.cssClasses.ANCHOR)); | ||
anchor && (anchorElementRef.current = anchor); | ||
@@ -184,3 +184,3 @@ } | ||
// renderToPortal | ||
react_1.useEffect(function () { | ||
(0, react_1.useEffect)(function () { | ||
props.renderToPortal | ||
@@ -200,3 +200,3 @@ ? foundation.setIsHoisted(true) | ||
var handler = props.renderToPortal ? autoPosition : function () { }; | ||
base_1.raf(function () { | ||
(0, base_1.raf)(function () { | ||
foundation.isOpen(); | ||
@@ -211,3 +211,3 @@ }); | ||
// anchorCorner | ||
react_1.useEffect(function () { | ||
(0, react_1.useEffect)(function () { | ||
var anchorCorner = props.anchorCorner && getAnchorCornerFromProp(props.anchorCorner); | ||
@@ -227,3 +227,3 @@ if (anchorCorner !== undefined) { | ||
// open | ||
react_1.useEffect(function () { | ||
(0, react_1.useEffect)(function () { | ||
if (open) { | ||
@@ -241,7 +241,7 @@ var focusableElements = rootEl.ref | ||
}, [open, foundation, rootEl.ref]); | ||
react_1.useEffect(function () { | ||
(0, react_1.useEffect)(function () { | ||
setOpen(!!props.open); | ||
}, [props.open]); | ||
// cleanup | ||
react_1.useEffect(function () { | ||
(0, react_1.useEffect)(function () { | ||
return function () { | ||
@@ -248,0 +248,0 @@ timerIdRef.current && window.clearTimeout(timerIdRef.current); |
@@ -13,3 +13,3 @@ "use strict"; | ||
/** A generic menu component for displaying any type of content. */ | ||
exports.MenuSurface = base_1.createComponent(function MenuSurface(props, ref) { | ||
exports.MenuSurface = (0, base_1.createComponent)(function MenuSurface(props, ref) { | ||
var children = props.children, open = props.open, anchorCorner = props.anchorCorner, onOpen = props.onOpen, onClose = props.onClose, renderToPortal = props.renderToPortal, fixed = props.fixed, apiRef = props.apiRef, foundationRef = props.foundationRef, rest = tslib_1.__rest(props, ["children", "open", "anchorCorner", "onOpen", "onClose", "renderToPortal", "fixed", "apiRef", "foundationRef"]); | ||
@@ -21,4 +21,4 @@ // menuSurfaceDomPositionRef is used to position the menu when it's rendered | ||
var menuSurfaceDomPositionRef = react_1.default.useRef(null); | ||
var rootEl = foundation_1.useMenuSurfaceFoundation(props, menuSurfaceDomPositionRef).rootEl; | ||
var className = base_1.useClassNames(props, [ | ||
var rootEl = (0, foundation_1.useMenuSurfaceFoundation)(props, menuSurfaceDomPositionRef).rootEl; | ||
var className = (0, base_1.useClassNames)(props, [ | ||
'mdc-menu-surface', | ||
@@ -34,5 +34,5 @@ { | ||
/** A Menu Anchor. When using the anchorCorner prop of Menu, you must set MenuSurfaceAnchors css style position to absolute. */ | ||
exports.MenuSurfaceAnchor = base_1.createComponent(function MenuSurfaceAnchor(props, ref) { | ||
var className = base_1.useClassNames(props, ['mdc-menu-surface--anchor']); | ||
exports.MenuSurfaceAnchor = (0, base_1.createComponent)(function MenuSurfaceAnchor(props, ref) { | ||
var className = (0, base_1.useClassNames)(props, ['mdc-menu-surface--anchor']); | ||
return react_1.default.createElement(base_1.Tag, tslib_1.__assign({}, props, { className: className, ref: ref })); | ||
}); |
@@ -9,4 +9,4 @@ "use strict"; | ||
var useMenuFoundation = function (props) { | ||
var menuSurfaceApi = react_1.useRef(); | ||
var listApi = react_1.useRef(); | ||
var menuSurfaceApi = (0, react_1.useRef)(); | ||
var listApi = (0, react_1.useRef)(); | ||
var setListApi = function (api) { | ||
@@ -18,7 +18,7 @@ listApi.current = api; | ||
}; | ||
var items = react_1.useCallback(function () { | ||
var items = (0, react_1.useCallback)(function () { | ||
var _a; | ||
return ((_a = listApi.current) === null || _a === void 0 ? void 0 : _a.listElements()) || []; | ||
}, []); | ||
var _a = base_1.useFoundation({ | ||
var _a = (0, base_1.useFoundation)({ | ||
props: tslib_1.__assign(tslib_1.__assign({}, props), { | ||
@@ -39,3 +39,3 @@ // we don't want to pass the apiRef all the way through | ||
} | ||
return (_a = listApi.current) === null || _a === void 0 ? void 0 : _a.addClassToElementIndex.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args))); | ||
return (_a = listApi.current) === null || _a === void 0 ? void 0 : _a.addClassToElementIndex.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)); | ||
}, | ||
@@ -48,3 +48,3 @@ removeClassFromElementAtIndex: function () { | ||
} | ||
return (_a = listApi.current) === null || _a === void 0 ? void 0 : _a.removeClassFromElementAtIndex.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args))); | ||
return (_a = listApi.current) === null || _a === void 0 ? void 0 : _a.removeClassFromElementAtIndex.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)); | ||
}, | ||
@@ -57,3 +57,3 @@ addAttributeToElementAtIndex: function () { | ||
} | ||
return (_a = listApi.current) === null || _a === void 0 ? void 0 : _a.setAttributeForElementIndex.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args))); | ||
return (_a = listApi.current) === null || _a === void 0 ? void 0 : _a.setAttributeForElementIndex.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)); | ||
}, | ||
@@ -87,3 +87,3 @@ removeAttributeFromElementAtIndex: function (index, attr) { | ||
} | ||
return (_a = listApi.current) === null || _a === void 0 ? void 0 : _a.focusItemAtIndex.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args))); | ||
return (_a = listApi.current) === null || _a === void 0 ? void 0 : _a.focusItemAtIndex.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)); | ||
}, | ||
@@ -96,10 +96,10 @@ focusListRoot: function () { var _a; return (_a = listApi.current) === null || _a === void 0 ? void 0 : _a.focusRoot(); } | ||
var onClick = props.onClick; | ||
var handleClick = react_1.useCallback(function (evt) { | ||
var handleClick = (0, react_1.useCallback)(function (evt) { | ||
onClick === null || onClick === void 0 ? void 0 : onClick(evt); | ||
// fixes an issue with nested span element on list items | ||
var el = base_1.closest(evt.target, '.mdc-deprecated-list-item'); | ||
var el = (0, base_1.closest)(evt.target, '.mdc-deprecated-list-item'); | ||
el && foundation.handleItemAction(el); | ||
}, [foundation, onClick]); | ||
var onKeyDown = props.onKeyDown; | ||
var handleKeydown = react_1.useCallback(function (evt) { | ||
var handleKeydown = (0, react_1.useCallback)(function (evt) { | ||
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(evt); | ||
@@ -119,3 +119,3 @@ foundation.handleKeydown(evt); | ||
var onOpen = props.onOpen, focusOnOpen = props.focusOnOpen; | ||
var handleOpen = react_1.useCallback(function (evt) { | ||
var handleOpen = (0, react_1.useCallback)(function (evt) { | ||
var list = items(); | ||
@@ -133,3 +133,3 @@ if ((focusOnOpen || focusOnOpen === undefined) && | ||
var canSetApi = listApi.current && menuSurfaceApi.current && props.apiRef; | ||
react_1.useEffect(function () { | ||
(0, react_1.useEffect)(function () { | ||
if (listApi.current && menuSurfaceApi.current && props.apiRef) { | ||
@@ -136,0 +136,0 @@ props.apiRef(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, listApi.current), menuSurfaceApi.current), { items: items })); |
@@ -11,4 +11,4 @@ "use strict"; | ||
/** A wrapper for menu items */ | ||
exports.MenuItems = base_1.createComponent(function MenuItems(props, ref) { | ||
var className = base_1.useClassNames(props, ['mdc-list mdc-menu__items']); | ||
exports.MenuItems = (0, base_1.createComponent)(function MenuItems(props, ref) { | ||
var className = (0, base_1.useClassNames)(props, ['mdc-list mdc-menu__items']); | ||
return react_1.default.createElement(list_1.List, tslib_1.__assign({ role: "menu" }, props, { className: className, ref: ref })); | ||
@@ -18,12 +18,12 @@ }); | ||
/** This is just the ListItem component exported from the Menu module for convenience. You can use `ListItem` or `SimpleListItem` components from the List section as long as you add `role="menuitem"` and `tabIndex="0"` to the components for accessibility. */ | ||
exports.MenuItem = base_1.createComponent(function MenuItem(props, ref) { | ||
exports.MenuItem = (0, base_1.createComponent)(function MenuItem(props, ref) { | ||
return react_1.default.createElement(list_1.ListItem, tslib_1.__assign({ role: "menuitem", tabIndex: 0 }, props, { ref: ref })); | ||
}); | ||
var isMenuItems = function (child) { | ||
return base_1.getDisplayName(child) === 'MenuItems'; | ||
return (0, base_1.getDisplayName)(child) === 'MenuItems'; | ||
}; | ||
/** A menu component for displaying lists items. */ | ||
exports.Menu = base_1.createComponent(function Menu(props, ref) { | ||
exports.Menu = (0, base_1.createComponent)(function Menu(props, ref) { | ||
var children = props.children, focusOnOpen = props.focusOnOpen, onSelect = props.onSelect, foundationRef = props.foundationRef, rest = tslib_1.__rest(props, ["children", "focusOnOpen", "onSelect", "foundationRef"]); | ||
var _a = foundation_1.useMenuFoundation(props), rootEl = _a.rootEl, setListApi = _a.setListApi, setMenuSurfaceApi = _a.setMenuSurfaceApi; | ||
var _a = (0, foundation_1.useMenuFoundation)(props), rootEl = _a.rootEl, setListApi = _a.setListApi, setMenuSurfaceApi = _a.setMenuSurfaceApi; | ||
var needsMenuItemsWrapper = (react_1.default.Children.map(children, isMenuItems) || []).every(function (val) { return val === false; }); | ||
@@ -33,3 +33,3 @@ var menuItemsProps = { | ||
}; | ||
return (react_1.default.createElement(menu_surface_1.MenuSurface, tslib_1.__assign({}, rootEl.props(rest), { "aria-hidden": !rest.open, className: base_1.classNames('mdc-menu', rest.className), apiRef: setMenuSurfaceApi, ref: ref }), needsMenuItemsWrapper ? (react_1.default.createElement(exports.MenuItems, tslib_1.__assign({}, menuItemsProps), children)) : (react_1.default.Children.map(children, function (child) { | ||
return (react_1.default.createElement(menu_surface_1.MenuSurface, tslib_1.__assign({}, rootEl.props(rest), { "aria-hidden": !rest.open, className: (0, base_1.classNames)('mdc-menu', rest.className), apiRef: setMenuSurfaceApi, ref: ref }), needsMenuItemsWrapper ? (react_1.default.createElement(exports.MenuItems, tslib_1.__assign({}, menuItemsProps), children)) : (react_1.default.Children.map(children, function (child) { | ||
if (isMenuItems(child)) { | ||
@@ -43,4 +43,4 @@ return react_1.default.cloneElement(child, tslib_1.__assign(tslib_1.__assign({}, (react_1.default.isValidElement(child) ? child.props : {})), menuItemsProps)); | ||
return function (props) { | ||
var _a = tslib_1.__read(react_1.useState(!!props.open), 2), stateOpen = _a[0], setStateOpen = _a[1]; | ||
react_1.useEffect(function () { | ||
var _a = tslib_1.__read((0, react_1.useState)(!!props.open), 2), stateOpen = _a[0], setStateOpen = _a[1]; | ||
(0, react_1.useEffect)(function () { | ||
if (props.open !== undefined && props.open !== stateOpen) { | ||
@@ -47,0 +47,0 @@ setStateOpen(!!props.open); |
@@ -28,3 +28,3 @@ "use strict"; | ||
return (react_1.default.createElement(_1.MenuSurfaceAnchor, null, | ||
react_1.default.createElement(_1.Menu, { open: open, onSelect: function (evt) { return console.log(evt.detail.index); }, onClose: function (evt) { return setOpen(false); } }, | ||
react_1.default.createElement(_1.Menu, { open: open, onSelect: function (evt) { return console.log(evt.detail.index); }, onClose: function () { return setOpen(false); } }, | ||
react_1.default.createElement(_1.MenuItem, null, "Cookies"), | ||
@@ -34,3 +34,3 @@ react_1.default.createElement(_1.MenuItem, null, "Pizza"), | ||
react_1.default.createElement(_1.MenuItem, null, "Icecream")), | ||
react_1.default.createElement(button_1.Button, { raised: true, onClick: function (evt) { return setOpen(!open); } }, "Menu"))); | ||
react_1.default.createElement(button_1.Button, { raised: true, onClick: function () { return setOpen(!open); } }, "Menu"))); | ||
}), | ||
@@ -47,5 +47,5 @@ react_1.default.createElement(_doc_utils_1.DocsExample, null, function Example() { | ||
return (react_1.default.createElement(_1.MenuSurfaceAnchor, null, | ||
react_1.default.createElement(_1.MenuSurface, { open: open, onClose: function (evt) { return setOpen(false); } }, | ||
react_1.default.createElement(_1.MenuSurface, { open: open, onClose: function () { return setOpen(false); } }, | ||
react_1.default.createElement("div", { style: { padding: '1rem', width: '8rem' } }, "Menu")), | ||
react_1.default.createElement(icon_button_1.IconButton, { icon: "menu", onClick: function (evt) { return setOpen(!open); } }))); | ||
react_1.default.createElement(icon_button_1.IconButton, { icon: "menu", onClick: function () { return setOpen(!open); } }))); | ||
}), | ||
@@ -55,3 +55,3 @@ react_1.default.createElement(_doc_utils_1.DocsExample, null, function Example() { | ||
return (react_1.default.createElement(_1.MenuSurfaceAnchor, null, | ||
react_1.default.createElement(_1.Menu, { open: open, onSelect: function (evt) { return console.log(evt.detail.index); }, onClose: function (evt) { return setOpen(false); } }, | ||
react_1.default.createElement(_1.Menu, { open: open, onSelect: function (evt) { return console.log(evt.detail.index); }, onClose: function () { return setOpen(false); } }, | ||
react_1.default.createElement(_1.MenuItem, null, "Item One"), | ||
@@ -58,0 +58,0 @@ react_1.default.createElement(_1.MenuItem, { disabled: true }, "Item Two (disabled)"), |
@@ -132,3 +132,3 @@ import { __assign, __read, __rest } from "tslib"; | ||
}, setTransformOrigin: function (origin) { | ||
var propertyName = getCorrectPropertyName(window, 'transform') + "-origin"; | ||
var propertyName = "".concat(getCorrectPropertyName(window, 'transform'), "-origin"); | ||
rootEl.setStyle(propertyName, origin); | ||
@@ -173,3 +173,3 @@ } }, getFocusAdapterMethods()), getDimensionAdapterMethods())); | ||
if (el) { | ||
var anchor = closest(el, "." + MDCMenuSurfaceFoundation.cssClasses.ANCHOR); | ||
var anchor = closest(el, ".".concat(MDCMenuSurfaceFoundation.cssClasses.ANCHOR)); | ||
anchor && (anchorElementRef.current = anchor); | ||
@@ -176,0 +176,0 @@ } |
@@ -34,3 +34,3 @@ import { __assign, __read, __rest, __spreadArray } from "tslib"; | ||
} | ||
return (_a = listApi.current) === null || _a === void 0 ? void 0 : _a.addClassToElementIndex.apply(_a, __spreadArray([], __read(args))); | ||
return (_a = listApi.current) === null || _a === void 0 ? void 0 : _a.addClassToElementIndex.apply(_a, __spreadArray([], __read(args), false)); | ||
}, | ||
@@ -43,3 +43,3 @@ removeClassFromElementAtIndex: function () { | ||
} | ||
return (_a = listApi.current) === null || _a === void 0 ? void 0 : _a.removeClassFromElementAtIndex.apply(_a, __spreadArray([], __read(args))); | ||
return (_a = listApi.current) === null || _a === void 0 ? void 0 : _a.removeClassFromElementAtIndex.apply(_a, __spreadArray([], __read(args), false)); | ||
}, | ||
@@ -52,3 +52,3 @@ addAttributeToElementAtIndex: function () { | ||
} | ||
return (_a = listApi.current) === null || _a === void 0 ? void 0 : _a.setAttributeForElementIndex.apply(_a, __spreadArray([], __read(args))); | ||
return (_a = listApi.current) === null || _a === void 0 ? void 0 : _a.setAttributeForElementIndex.apply(_a, __spreadArray([], __read(args), false)); | ||
}, | ||
@@ -82,3 +82,3 @@ removeAttributeFromElementAtIndex: function (index, attr) { | ||
} | ||
return (_a = listApi.current) === null || _a === void 0 ? void 0 : _a.focusItemAtIndex.apply(_a, __spreadArray([], __read(args))); | ||
return (_a = listApi.current) === null || _a === void 0 ? void 0 : _a.focusItemAtIndex.apply(_a, __spreadArray([], __read(args), false)); | ||
}, | ||
@@ -85,0 +85,0 @@ focusListRoot: function () { var _a; return (_a = listApi.current) === null || _a === void 0 ? void 0 : _a.focusRoot(); } |
@@ -25,3 +25,3 @@ import { __read } from "tslib"; | ||
return (React.createElement(MenuSurfaceAnchor, null, | ||
React.createElement(Menu, { open: open, onSelect: function (evt) { return console.log(evt.detail.index); }, onClose: function (evt) { return setOpen(false); } }, | ||
React.createElement(Menu, { open: open, onSelect: function (evt) { return console.log(evt.detail.index); }, onClose: function () { return setOpen(false); } }, | ||
React.createElement(MenuItem, null, "Cookies"), | ||
@@ -31,3 +31,3 @@ React.createElement(MenuItem, null, "Pizza"), | ||
React.createElement(MenuItem, null, "Icecream")), | ||
React.createElement(Button, { raised: true, onClick: function (evt) { return setOpen(!open); } }, "Menu"))); | ||
React.createElement(Button, { raised: true, onClick: function () { return setOpen(!open); } }, "Menu"))); | ||
}), | ||
@@ -44,5 +44,5 @@ React.createElement(DocsExample, null, function Example() { | ||
return (React.createElement(MenuSurfaceAnchor, null, | ||
React.createElement(MenuSurface, { open: open, onClose: function (evt) { return setOpen(false); } }, | ||
React.createElement(MenuSurface, { open: open, onClose: function () { return setOpen(false); } }, | ||
React.createElement("div", { style: { padding: '1rem', width: '8rem' } }, "Menu")), | ||
React.createElement(IconButton, { icon: "menu", onClick: function (evt) { return setOpen(!open); } }))); | ||
React.createElement(IconButton, { icon: "menu", onClick: function () { return setOpen(!open); } }))); | ||
}), | ||
@@ -52,3 +52,3 @@ React.createElement(DocsExample, null, function Example() { | ||
return (React.createElement(MenuSurfaceAnchor, null, | ||
React.createElement(Menu, { open: open, onSelect: function (evt) { return console.log(evt.detail.index); }, onClose: function (evt) { return setOpen(false); } }, | ||
React.createElement(Menu, { open: open, onSelect: function (evt) { return console.log(evt.detail.index); }, onClose: function () { return setOpen(false); } }, | ||
React.createElement(MenuItem, null, "Item One"), | ||
@@ -55,0 +55,0 @@ React.createElement(MenuItem, { disabled: true }, "Item Two (disabled)"), |
{ | ||
"name": "@rmwc/menu", | ||
"version": "14.0.0-alpha.0", | ||
"version": "14.0.1-alpha.0", | ||
"description": "RMWC Menu component", | ||
@@ -42,7 +42,7 @@ "main": "dist/index.js", | ||
"@material/menu-surface": "^14.0.0", | ||
"@rmwc/base": "^14.0.0-alpha.0", | ||
"@rmwc/list": "^14.0.0-alpha.0", | ||
"@rmwc/types": "^14.0.0-alpha.0" | ||
"@rmwc/base": "^14.0.1-alpha.0", | ||
"@rmwc/list": "^14.0.1-alpha.0", | ||
"@rmwc/types": "^14.0.1-alpha.0" | ||
}, | ||
"gitHead": "d9befec0e3b258864b71686eecd16c16feb43cf1" | ||
} |
Sorry, the diff of this file is not supported yet
108903
0.22%