@wordpress/components
Version:
UI components for WordPress.
46 lines (38 loc) • 980 B
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import { createElement } from "@wordpress/element";
/**
* External dependencies
*/
/**
* Internal dependencies
*/
import { useContextSystem, contextConnect } from '../context';
import { View } from '../../view';
function Shortcut(props, forwardedRef) {
const {
as: asProp = 'span',
shortcut,
className,
...otherProps
} = useContextSystem(props, 'Shortcut');
if (!shortcut) {
return null;
}
let displayText;
let ariaLabel;
if (typeof shortcut === 'string') {
displayText = shortcut;
} else {
displayText = shortcut.display;
ariaLabel = shortcut.ariaLabel;
}
return createElement(View, _extends({
as: asProp,
className: className,
"aria-label": ariaLabel,
ref: forwardedRef
}, otherProps), displayText);
}
const ConnectedShortcut = contextConnect(Shortcut, 'Shortcut');
export default ConnectedShortcut;
//# sourceMappingURL=component.js.map