@salesforce/design-system-react
Version:
Salesforce Lightning Design System for React
89 lines (76 loc) • 2.78 kB
JavaScript
/* Copyright (c) 2015-present, salesforce.com, inc. All rights reserved */
/* Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license */
import React from 'react';
import PropTypes from 'prop-types'; // ### classNames
// [github.com/JedWatson/classnames](https://github.com/JedWatson/classnames)
// This project uses `classnames`, 'a simple javascript utility for conditionally
// joining classNames together.'
import classNames from 'classnames'; // ### isFunction
import isFunction from 'lodash.isfunction';
import { VERTICAL_NAVIGATION_ITEM } from '../../../utilities/constants';
var handleClick = function handleClick(event, _ref) {
var item = _ref.item,
onSelect = _ref.onSelect;
if (!item.url) {
event.preventDefault();
}
if (isFunction(onSelect)) {
onSelect(event, {
item: item
});
}
};
var Item = function Item(_ref2) {
var _ref2$isSelected = _ref2.isSelected,
isSelected = _ref2$isSelected === void 0 ? false : _ref2$isSelected,
item = _ref2.item,
categoryId = _ref2.categoryId,
onSelect = _ref2.onSelect;
return /*#__PURE__*/React.createElement("li", {
className: classNames('slds-nav-vertical__item', {
'slds-is-active': isSelected
})
}, /*#__PURE__*/React.createElement("a", {
"data-id": item.id,
href: item.url || '#',
className: "slds-nav-vertical__action",
"aria-describedby": categoryId,
"aria-current": isSelected ? true : undefined,
onClick: function onClick(event) {
handleClick(event, {
item: item,
onSelect: onSelect
});
}
}, item.icon ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.cloneElement(item.icon, {
className: classNames(item.icon.className, "slds-m-right_".concat(item.icon.props.size || 'medium'))
}), item.label) : item.label, item.notificationBadge ? /*#__PURE__*/React.cloneElement(item.notificationBadge, {
className: classNames(item.notificationBadge.props.className, 'slds-col_bump-left')
}) : /*#__PURE__*/React.createElement(React.Fragment, null)));
}; // ### Display Name
// Always use the canonical component name as the React display name.
Item.displayName = VERTICAL_NAVIGATION_ITEM; // ### Prop Types
Item.propTypes = {
/**
* Item to be rendered.
*/
item: PropTypes.shape({
id: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
url: PropTypes.string
}),
/**
* Whether item is selected or not.
*/
isSelected: PropTypes.bool,
/**
* ID of the category this item belongs to.
*/
categoryId: PropTypes.string.isRequired,
/**
* Function that will run whenever an item is selected.
*/
onSelect: PropTypes.func
};
export default Item;
//# sourceMappingURL=item.js.map