UNPKG

@salesforce/design-system-react

Version:

Salesforce Lightning Design System for React

180 lines (153 loc) 5.51 kB
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } /* Copyright (c) 2015-present, salesforce.com, inc. All rights reserved */ /* Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license */ // # GlobalNavigationBar Link Component // ## Dependencies // ### React import React from 'react'; import PropTypes from 'prop-types'; // ### classNames import classNames from 'classnames'; // ### isFunction import isFunction from 'lodash.isfunction'; // ## Constants import { GLOBAL_NAVIGATION_BAR_LINK } from '../../utilities/constants'; /** * Wraps a link in the proper markup to support use in the GlobalNavigationBar. */ var GlobalNavigationBarLink = function GlobalNavigationBarLink(props) { // Separate props we care about in order to pass others along passively to the `a` tag var active = props.active, activeBackgroundColor = props.activeBackgroundColor, _props$assistiveText = props.assistiveText, assistiveText = _props$assistiveText === void 0 ? { activeDescriptor: 'Current page:' } : _props$assistiveText, className = props.className, dividerPosition = props.dividerPosition, _props$href = props.href, href = _props$href === void 0 ? '#' : _props$href, id = props.id, label = props.label, onBlur = props.onBlur, onClick = props.onClick, onFocus = props.onFocus, onKeyDown = props.onKeyDown, onKeyPress = props.onKeyPress, onKeyUp = props.onKeyUp, onMouseEnter = props.onMouseEnter, onMouseLeave = props.onMouseLeave, tabIndex = props.tabIndex; var listItemstyle = active ? { backgroundColor: activeBackgroundColor, borderBottomColor: activeBackgroundColor } : null; function handleOnClick(event) { if (isFunction(onClick) || href === '#') { event.preventDefault(); } if (isFunction(onClick)) { onClick(event, { href: href }); } } return /*#__PURE__*/React.createElement("li", { className: classNames('slds-context-bar__item', _defineProperty({ 'slds-is-active': active }, "slds-context-bar__item_divider-".concat(dividerPosition), dividerPosition)), id: id, style: listItemstyle }, /*#__PURE__*/React.createElement("a", { href: href, className: classNames('slds-context-bar__label-action', className), onBlur: onBlur, onClick: handleOnClick, onFocus: onFocus, onKeyDown: onKeyDown, onKeyPress: onKeyPress, onKeyUp: onKeyUp, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, tabIndex: tabIndex, title: label }, active ? /*#__PURE__*/React.createElement("span", { className: "slds-assistive-text" }, assistiveText.activeDescriptor) : null, /*#__PURE__*/React.createElement("span", { className: "slds-truncate", title: label }, label))); }; GlobalNavigationBarLink.displayName = GLOBAL_NAVIGATION_BAR_LINK; // ### Prop Types GlobalNavigationBarLink.propTypes = { /** * Whether the item is active or not. */ active: PropTypes.bool, /** * Allows alignment of active item with active application background color. If application background is dark, text color may need to be `#fff`. This can be done with the style prop. */ activeBackgroundColor: PropTypes.string, /** * **Assistive text for accessibility.** * * `activeDescriptor`: The text that appears alongside a link that is currently active. */ assistiveText: PropTypes.shape({ activeDescriptor: PropTypes.string }), /** * Class names to be added to the anchor element */ className: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string]), /** * Determines position of separating bar. */ dividerPosition: PropTypes.oneOf(['left', 'right']), /** * The `href` attribute of the link. Please pass in bookmarkable URLs from your routing library. Use `GlobalNavigationBarButton` if a "real URL" is not desired. If the `onClick` callback is specified this URL will still be prevented from changing the browser's location. */ href: PropTypes.string, /** * The `id` attribute is applied to the `li` tag. _This was recently changed from being on the anchor tag._ */ id: PropTypes.string, /** * Text to show for link item. */ label: PropTypes.string, /** * Triggered when focus is removed. */ onBlur: PropTypes.func, /** * `function (event, href)` - fires when the link is clicked. If set, the browser location change to the `href` specified will be ignored, but the `href` will be included in an additional parameter passed to the callback. */ onClick: PropTypes.func, /** * Triggered when component is focused. */ onFocus: PropTypes.func, /** * Triggered when a key is pressed down */ onKeyDown: PropTypes.func, /** * Triggered when a key is pressed and released */ onKeyPress: PropTypes.func, /** * Triggered when a key is released */ onKeyUp: PropTypes.func, /** * Triggered when a mouse arrow hovers */ onMouseEnter: PropTypes.func, /** * Triggered when a mouse arrow no longer hovers */ onMouseLeave: PropTypes.func, /** * Write "-1" if you don't want the user to tab to the button. */ tabIndex: PropTypes.string }; export default GlobalNavigationBarLink; //# sourceMappingURL=link.js.map