@salesforce/design-system-react
Version:
Salesforce Lightning Design System for React
115 lines (92 loc) • 3.9 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 */
/* eslint-disable jsx-a11y/no-redundant-roles */
// # Global Navigation Bar Region Component
// ## Dependencies
// ### React
import React from 'react';
import createReactClass from 'create-react-class';
import PropTypes from 'prop-types'; // ### classNames
import classNames from 'classnames'; // ## Constants
import { GLOBAL_NAVIGATION_BAR_REGION } from '../../utilities/constants'; // List regions for export
var regions = ['primary', 'secondary', 'tertiary'];
/* eslint-disable react/display-name */
var renderPrimary = function renderPrimary(dividerClass, className, children) {
return React.createElement("div", {
className: classNames('slds-context-bar__primary', dividerClass, className)
}, children);
};
var renderSecondary = function renderSecondary(dividerClass, className, children, navigation) {
var region;
if (navigation) {
region = React.createElement("nav", {
className: classNames('slds-context-bar__secondary', dividerClass, className),
role: "navigation"
}, React.createElement("ul", {
className: "slds-grid"
}, children));
} else {
region = React.createElement("div", {
className: classNames('slds-context-bar__secondary', dividerClass, className)
}, React.createElement("ul", {
className: "slds-grid"
}, children));
}
return region;
};
var renderTertiary = function renderTertiary(dividerClass, className, children) {
return React.createElement("div", {
className: classNames('slds-context-bar__tertiary', 'slds-col--bump-left', dividerClass, className)
}, React.createElement("ul", {
className: "slds-grid"
}, children));
};
/* eslint-enable react/display-name */
/**
* Regions make up a GlobalNavigation Bar and typically contain links and dropdowns. The Primary region contains the AppSwitcher, Application Name, and Object Switcher. The secondary region typically has navigation betweens sections of the application. The tertiary region is aligned to the right side of the screen and contains shortcuts or actions.
*/
var Region = createReactClass({
displayName: GLOBAL_NAVIGATION_BAR_REGION,
propTypes: {
/**
* Contents of region. Expects `GlobalNavigationBarLink`, `GlobalNavigationBarDropdown`, `GlobalNavigationBarApplicationName`, `AppSwitcher`, but could be any component. This is the place to pass in an Object Switcher until that is supported.
*/
children: PropTypes.node,
/**
* Determines position of separating bar.
*/
dividerPosition: PropTypes.oneOf(['left', 'right']),
/**
* CSS classes to be added to the region
*/
className: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string]),
/**
* Wraps the `secondary` region in a `nav` and adds a role attribute
*/
navigation: PropTypes.bool,
/**
* Region wrap children in styling specific to that region.
*/
region: PropTypes.oneOf(['primary', 'secondary', 'tertiary']).isRequired
},
render: function render() {
var region;
var dividerClass = this.props.dividerPosition ? "slds-context-bar__item--divider-".concat(this.props.dividerPosition) : null;
switch (this.props.region) {
case 'primary':
region = renderPrimary(dividerClass, this.props.className, this.props.children);
break;
case 'secondary':
region = renderSecondary(dividerClass, this.props.className, this.props.children, this.props.navigation);
break;
case 'tertiary':
region = renderTertiary(dividerClass, this.props.className, this.props.children);
break;
default: // do nothing
}
return region;
}
});
export default Region;
export { regions };
//# sourceMappingURL=region.js.map