react-spatial
Version:
Components to build React map apps.
89 lines (74 loc) • 1.93 kB
JavaScript
import React from 'react';
import PropTypes from 'prop-types';
import Button from '../Button';
var propTypes = {
/**
* Add an active class to the item.
*/
active: PropTypes.bool,
/**
* Function triggered on click event.
*/
onClick: PropTypes.func.isRequired,
/**
* Icon of the sidebar item.
*/
icon: PropTypes.node.isRequired,
/**
* Show only the icon of the sidebar item.
*/
showIconOnly: PropTypes.bool,
/**
* CSS class of the sidebar item.
*/
className: PropTypes.string,
/**
* HTML tabIndex attribute
*/
tabIndex: PropTypes.number,
/**
* Keyboard accesskey shortcut.
*/
accessKey: PropTypes.string,
/**
* Content of the sidebar item.
*/
children: PropTypes.node,
/**
* Title of the sidebar item, used in content if no children are provided.
*/
title: PropTypes.string.isRequired,
};
var defaultProps = {
active: false,
showIconOnly: false,
className: 'tm-sidebar-item',
tabIndex: 0,
accessKey: undefined,
children: undefined,
};
/**
* This component displays an Item in the Sidebar.
*/
function SidebarMenuItem(ref) {
var active = ref.active;
var onClick = ref.onClick;
var icon = ref.icon;
var showIconOnly = ref.showIconOnly;
var className = ref.className;
var title = ref.title;
var tabIndex = ref.tabIndex;
var accessKey = ref.accessKey;
var children = ref.children;
return (
React.createElement( Button, {
tabIndex: tabIndex, className: ("" + className + (active ? ' tm-active' : '')), title: title, onClick: function (e) { return onClick(e); }, accessKey: accessKey },
React.createElement( 'div', null, icon ),
showIconOnly ? null : React.createElement( 'span', null, children || title )
)
);
}
SidebarMenuItem.propTypes = propTypes;
SidebarMenuItem.defaultProps = defaultProps;
export default SidebarMenuItem;
//# sourceMappingURL=SidebarMenuItem.js.map