@salesforce/design-system-react
Version:
Salesforce Lightning Design System for React
142 lines (127 loc) • 5.79 kB
JavaScript
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
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 */
// # Global Header Component
// Implements the [Global Header design pattern](https://www.lightningdesignsystem.com/components/global-header) in React.
// Based on SLDS v2.1.0-rc.2
// ## Dependencies
// ### React
import React from 'react';
import createReactClass from 'create-react-class';
import PropTypes from 'prop-types'; // This component's `checkProps` which issues warnings to developers about properties when in development mode (similar to React's built in development tools)
import checkProps from './check-props'; // ### Event Helpers
import EventUtil from '../../utilities/event'; // ## Constants
import { GLOBAL_HEADER, GLOBAL_HEADER_PROFILE, GLOBAL_HEADER_SEARCH, GLOBAL_HEADER_TOOL } from '../../utilities/constants';
var defaultProps = {
assistiveText: {
skipToNav: 'Skip to Navigation',
skipToContent: 'Skip to Main Content'
},
logoSrc: '/assets/images/logo-noname.svg'
};
/**
* The global header is the anchor for the Salesforce platform and spans all other parts of the UI. It accepts children to define the items displayed within.
*
* Example:
* ```
* <SLDSGlobalHeader>
* <SLDSGlobalHeaderSearch />
* <SLDSGlobalHeaderButton />
* <SLDSGlobalHeaderDropdown />
* <SLDSGlobalHeaderDropdown />
* <SLDSGlobalHeaderProfile />
* </SLDSGlobalHeader>
* ```
*/
var GlobalHeader = createReactClass({
displayName: GLOBAL_HEADER,
propTypes: {
/**
* **Assistive text for accessibility.**
* This object is merged with the default props object on every render.
* * `skipToNav`: The localized text that will be read back for the "Skip to Navigation" accessibility link.
* * `skipToContent`: The localized text that will be read back for the "Skip to Main Content" accessibility link.
*/
assistiveText: PropTypes.shape({
skipToNav: PropTypes.string,
skipToContent: PropTypes.string
}),
/**
* See the component description, this accepts some combination of `SLDSGlobalHeaderSearch`, `SLDSGlobalHeaderButton`, `SLDSGlobalHeaderDropdown`, and `SLDSGlobalHeaderProfile` components.
*/
children: PropTypes.node,
/**
* The Salesforce logo to display in the header.
*/
logoSrc: PropTypes.string,
/**
* Pass in the Global Navigation Bar component
*/
navigation: PropTypes.node,
/**
* Required for accessibility. Should jump the user to the primary content area.
*/
onSkipToContent: PropTypes.func,
/**
* Required for accessibility. Should jump the user to the primary navigation.
*/
onSkipToNav: PropTypes.func
},
getDefaultProps: function getDefaultProps() {
return defaultProps;
},
componentWillMount: function componentWillMount() {
checkProps(GLOBAL_HEADER, this.props);
},
handleSkipToContent: function handleSkipToContent(e) {
EventUtil.trap(e);
this.props.onSkipToContent(e);
},
handleSkipToNav: function handleSkipToNav(e) {
EventUtil.trap(e);
this.props.onSkipToNav(e);
},
render: function render() {
var tools;
var search;
var profile;
React.Children.forEach(this.props.children, function (child) {
if (child && child.type.displayName === GLOBAL_HEADER_TOOL) {
if (!tools) tools = [];
tools.push(child);
} else if (child && child.type.displayName === GLOBAL_HEADER_SEARCH) {
search = child;
} else if (child && child.type.displayName === GLOBAL_HEADER_PROFILE) {
profile = child;
}
});
var assistiveText = _objectSpread({}, defaultProps.assistiveText, this.props.assistiveText);
/* eslint-disable max-len, no-script-url */
return React.createElement("header", {
className: "slds-global-header_container"
}, this.props.onSkipToNav ? React.createElement("a", {
href: "javascript:void(0);",
className: "slds-assistive-text slds-assistive-text--focus",
onClick: this.handleSkipToNav
}, this.props.skipToNavAssistiveText || assistiveText.skipToNav) : null, this.props.onSkipToContent ? React.createElement("a", {
href: "javascript:void(0);",
className: "slds-assistive-text slds-assistive-text--focus",
onClick: this.handleSkipToContent
}, this.props.skipToContentAssistiveText || assistiveText.skipToContent) : null, React.createElement("div", {
className: "slds-global-header slds-grid slds-grid--align-spread"
}, React.createElement("div", {
className: "slds-global-header__item"
}, React.createElement("div", {
className: "slds-global-header__logo",
style: {
backgroundImage: "url(".concat(this.props.logoSrc, ")")
}
})), search, React.createElement("ul", {
className: "slds-global-header__item slds-grid slds-grid--vertical-align-center"
}, tools, profile)), this.props.navigation);
/* eslint-enable max-len, no-script-url */
}
});
export default GlobalHeader;
//# sourceMappingURL=index.js.map