@salesforce/design-system-react
Version:
Salesforce Lightning Design System for React
384 lines (313 loc) • 12.8 kB
JavaScript
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
/* 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 */
// # Page Header Component
// Implements the [Page Header design pattern](https://www.lightningdesignsystem.com/components/page-headers) in React.
// Based on SLDS v2.2.1
// ## Dependencies
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames'; // 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';
import componentDoc from './docs.json';
import Info from './private/info';
import Title from './private/title';
import DetailRow from './private/detail-row';
import DetailBlock from './private/detail-block';
import Base from './private/base';
import RecordHome from './private/record-home';
import ObjectHome from './private/object-home';
import RelatedList from './private/related-list';
import Icon from '../icon';
import Breadcrumb from '../breadcrumb'; // ## Constants
import { PAGE_HEADER } from '../../utilities/constants';
var displayName = PAGE_HEADER;
var propTypes = {
/**
* Optional class name
*/
className: PropTypes.string,
/**
* The type of component
* Note: Extra options are added to make the version backward compatible
*/
variant: PropTypes.oneOf(['base', 'object-home', 'record-home', 'related-list']),
/**
* The info property can be a string or a React element
*/
label: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
/**
* The title property can be a string or a React element
*/
title: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
/**
* The info property can be a string or a React element
*/
info: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
/**
* The page header icon
*/
icon: PropTypes.element,
/**
* Name of the icon. Visit <a href="http://www.lightningdesignsystem.com/resources/icons">Lightning Design System Icons</a> to reference icon names.
*/
iconName: PropTypes.string,
/**
* The icons category
*/
iconCategory: PropTypes.oneOf(['action', 'custom', 'doctype', 'standard', 'utility']),
/**
* If omitted, icon position is centered.
*/
iconPosition: PropTypes.oneOf(['left', 'right']),
/**
* Determines the size of the icon.
*/
iconSize: PropTypes.oneOf(['x-small', 'small', 'medium', 'large']),
/**
* For icon variants, please reference <a href='http://www.lightningdesignsystem.com/components/buttons/#icon'>Lightning Design System Icons</a>.
*/
iconVariant: PropTypes.oneOf(['container', 'border', 'border-filled', 'small', 'more']),
/**
* Content to appear on the right hand side of the page header
* prop 'contentRight' will be deprecated soon, use 'onRenderActions' instead
*/
onRenderActions: PropTypes.func,
/**
* An array of buttons which appear on the component's right hand side.
*/
details: PropTypes.array,
/**
* Nav content which appears in the upper right hand corner.
* prop 'navRight' will be deprecated soon, use 'onRenderControls' instead
*/
onRenderControls: PropTypes.func,
/**
* An array of react elements presumably anchor <a> elements.
*/
trail: PropTypes.array
};
var defaultProps = {
className: '',
variant: 'base',
details: [],
trail: []
};
/**
* The PageHeader component adds PageHeader, PageHeader.Info, PageHeader.Title, PageHeader.DetailRow, and PageHeader.DetailBlock.
*/
var PageHeader =
/*#__PURE__*/
function (_Component) {
_inherits(PageHeader, _Component);
function PageHeader() {
_classCallCheck(this, PageHeader);
return _possibleConstructorReturn(this, _getPrototypeOf(PageHeader).apply(this, arguments));
}
_createClass(PageHeader, [{
key: "componentDidMount",
value: function componentDidMount() {
checkProps(PAGE_HEADER, this.props, componentDoc);
}
}, {
key: "_getClassNames",
value: function _getClassNames(className) {
return classnames('slds-page-header', {
'slds-page-header_object-home': this.props.variant === 'object-home' || this.props.variant === 'objectHome'
}, className);
}
}, {
key: "render",
value: function render() {
/**
* OPTIMIZE ES7 style object destructuring removes the need for _.omit.
* Example: const {foo, ...bar} = this.props;
*/
var _this$props = this.props,
className = _this$props.className,
contentRight = _this$props.contentRight,
details = _this$props.details,
icon = _this$props.icon,
iconCategory = _this$props.iconCategory,
iconName = _this$props.iconName,
iconPosition = _this$props.iconPosition,
iconSize = _this$props.iconSize,
iconVariant = _this$props.iconVariant,
info = _this$props.info,
label = _this$props.label,
navRight = _this$props.navRight,
onRenderActions = _this$props.onRenderActions,
onRenderControls = _this$props.onRenderControls,
title = _this$props.title,
trail = _this$props.trail,
variant = _this$props.variant;
var classes = this._getClassNames(className);
/**
* Render the icon
*/
var renderIcon = function renderIcon() {
if (iconName) {
return React.createElement(Icon, {
name: iconName,
category: iconCategory,
position: iconPosition,
size: iconSize,
variant: iconVariant
});
}
return icon;
};
/**
* Render the label
*/
var renderLabel = function renderLabel() {
var type = _typeof(label);
if (trail.length > 0) {
return React.createElement("nav", {
className: "slds-m-bottom_xx-small",
role: "navigation"
}, React.createElement(Breadcrumb, {
trail: trail
}));
}
if (type === 'string') {
return React.createElement("p", {
className: "slds-line-height_reset"
}, label);
}
return label;
};
/**
* Render the title
*/
var renderTitle = function renderTitle() {
var type = _typeof(title);
if (type === 'string') {
return React.createElement(Title, {
title: title
});
}
return title;
};
/**
* Render info
*/
var renderInfo = function renderInfo() {
var type = _typeof(info);
if (type === 'string') {
return React.createElement(Info, null, info);
}
return info;
};
/**
* Handles onRenderActions
*/
var renderOnRenderActions = function renderOnRenderActions() {
if (onRenderActions) {
var Actions = onRenderActions;
return React.createElement("div", {
className: "slds-col slds-no-flex slds-grid slds-align-top"
}, React.createElement(Actions, null));
}
return null;
};
/**
* Steal contentRight's children
*/
var renderContentRight = function renderContentRight() {
if (onRenderActions) {
return ''; // eslint-disable-next-line no-else-return
} else if (contentRight) {
var type = _typeof(contentRight);
if (type !== 'string') {
return React.createElement("div", _extends({
className: "slds-col slds-no-flex slds-grid slds-align-top"
}, contentRight.props));
}
}
return '';
};
/**
* Handles onRenderControls
*/
var renderOnRenderControls = function renderOnRenderControls() {
if (onRenderControls) {
var Controls = onRenderControls;
return React.createElement("div", {
className: "slds-col slds-no-flex slds-grid slds-align-top"
}, React.createElement(Controls, null));
}
return null;
};
/**
* Steal navRight's children
* For backward compatibility, this function can be deleted once 'navRight' prop is deprecated
*/
var renderNavRight = function renderNavRight() {
if (onRenderControls) {
return ''; // eslint-disable-next-line no-else-return
} else if (navRight) {
var type = _typeof(navRight);
if (type !== 'string') {
return React.createElement("div", _extends({
className: "slds-col slds-no-flex slds-grid slds-align-top"
}, navRight.props));
}
}
return '';
};
var Variant;
switch (variant) {
case 'object-home':
case 'objectHome':
// For backward compatibility
Variant = ObjectHome;
break;
case 'record-home':
case 'recordHome':
// For backward compatibility
Variant = RecordHome;
break;
case 'related-list':
case 'relatedList':
// For backward compatibility
Variant = RelatedList;
break;
default:
Variant = Base;
}
return React.createElement("div", {
className: classes
}, React.createElement(Variant, {
label: renderLabel(),
icon: renderIcon(),
title: renderTitle(),
info: renderInfo(),
contentRight: renderContentRight() // For backward compatibility, 'contentRight' prop will be deprecated sooon
,
navRight: renderNavRight() // For backward compatibility, 'navRight' prop will be deprecate soon
,
onRenderActions: renderOnRenderActions(),
onRenderControls: renderOnRenderControls(),
details: details
}));
}
}]);
return PageHeader;
}(Component);
PageHeader.displayName = displayName;
PageHeader.propTypes = propTypes;
PageHeader.defaultProps = defaultProps;
export default PageHeader;
export { Info, Title, DetailRow, DetailBlock };
//# sourceMappingURL=index.js.map